forked from DGNum/liminix
0a8343be66
Certain devices like the Zyxel NWA50AX will pass information on the command-line to explain what is the current image (`bootImage=1` vs. `bootImage=0`). Unfortunately, if we set the `chosen/bootargs` node, this will be overridden forcibly by U-Boot. To avoid this problem, it's easier to simply just use another DTB node like `bootargs-override` which is what OpenWRT does [1]. [1]: https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/ramips/patches-5.15/314-MIPS-add-bootargs-override-property.patch;h=e7dca7af886e8c0b69ba2b23f5855ddfeeb0d4a1;hb=refs/heads/main Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
80 lines
2.2 KiB
Nix
80 lines
2.2 KiB
Nix
{
|
|
lzma
|
|
, stdenv
|
|
, ubootTools
|
|
, dtc
|
|
, lib
|
|
} :
|
|
let
|
|
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
|
arch = stdenv.hostPlatform.linuxArch;
|
|
stripAndZip = ''
|
|
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
|
|
rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
|
|
'';
|
|
in {
|
|
kernel
|
|
, commandLine
|
|
, commandLineDtbNode ? "bootargs"
|
|
, entryPoint
|
|
, extraName ? "" # e.g. socFamily
|
|
, loadAddress
|
|
, imageFormat
|
|
, dtb ? null
|
|
} : stdenv.mkDerivation {
|
|
name = "kernel.image";
|
|
phases = [
|
|
"preparePhase"
|
|
(if commandLine != null then assert dtb != null; "mungeDtbPhase" else ":")
|
|
(if imageFormat == "fit" then "buildPhaseFIT" else "buildPhaseUImage")
|
|
"installPhase"
|
|
];
|
|
nativeBuildInputs = [
|
|
lzma
|
|
dtc
|
|
stdenv.cc
|
|
ubootTools
|
|
];
|
|
preparePhase = ''
|
|
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
|
|
'';
|
|
mungeDtbPhase = ''
|
|
dtc -I dtb -O dts -o tmp.dts ${dtb}
|
|
echo '/{ chosen { ${commandLineDtbNode} = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
|
|
dtc -I dts -O dtb -o tmp.dtb tmp.dts
|
|
'';
|
|
|
|
buildPhaseUImage = ''
|
|
test -f tmp.dtb && ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=tmp.dtb vmlinux.elf
|
|
${stripAndZip}
|
|
mkimage -A ${arch} -O linux -T kernel -C lzma -a 0x${lib.toHexString loadAddress} -e 0x${lib.toHexString entryPoint} -n '${lib.toUpper arch} Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
|
|
'';
|
|
|
|
buildPhaseFIT = ''
|
|
${stripAndZip}
|
|
cat ${./kernel_fdt.its} > mkimage.its
|
|
cat << _VARS >> mkimage.its
|
|
/ {
|
|
images {
|
|
kernel {
|
|
data = /incbin/("./vmlinux.bin.lzma");
|
|
load = <0x${lib.toHexString loadAddress}>;
|
|
entry = <0x${lib.toHexString entryPoint}>;
|
|
arch = "${arch}";
|
|
compression = "lzma";
|
|
};
|
|
fdt-1 {
|
|
data = /incbin/("./tmp.dtb");
|
|
arch = "${arch}";
|
|
};
|
|
};
|
|
};
|
|
_VARS
|
|
mkimage -f mkimage.its kernel.uimage
|
|
mkimage -l kernel.uimage
|
|
'';
|
|
|
|
installPhase = ''
|
|
cp kernel.uimage $out
|
|
'';
|
|
}
|