2022-10-03 21:28:15 +00:00
|
|
|
{
|
2025-02-10 21:55:08 +00:00
|
|
|
lzma,
|
|
|
|
stdenv,
|
|
|
|
ubootTools,
|
|
|
|
dtc,
|
|
|
|
lib,
|
|
|
|
}:
|
2022-10-03 21:28:15 +00:00
|
|
|
let
|
|
|
|
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
2023-10-08 21:35:30 +00:00
|
|
|
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
|
|
|
|
'';
|
2025-02-10 21:55:08 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
kernel,
|
|
|
|
commandLine,
|
|
|
|
commandLineDtbNode ? "bootargs",
|
|
|
|
entryPoint,
|
|
|
|
extraName ? "", # e.g. socFamily
|
|
|
|
loadAddress,
|
|
|
|
imageFormat,
|
|
|
|
alignment ? null,
|
|
|
|
dtb ? null,
|
|
|
|
}:
|
|
|
|
stdenv.mkDerivation {
|
2022-10-03 21:28:15 +00:00
|
|
|
name = "kernel.image";
|
2022-10-05 20:52:30 +00:00
|
|
|
phases = [
|
|
|
|
"preparePhase"
|
2025-02-10 21:55:08 +00:00
|
|
|
(
|
|
|
|
if commandLine != null then
|
|
|
|
assert dtb != null;
|
|
|
|
"mungeDtbPhase"
|
|
|
|
else
|
|
|
|
":"
|
|
|
|
)
|
2023-10-08 21:35:30 +00:00
|
|
|
(if imageFormat == "fit" then "buildPhaseFIT" else "buildPhaseUImage")
|
|
|
|
"installPhase"
|
|
|
|
];
|
2022-10-03 21:28:15 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
lzma
|
2022-10-05 20:52:30 +00:00
|
|
|
dtc
|
2022-10-03 21:28:15 +00:00
|
|
|
stdenv.cc
|
|
|
|
ubootTools
|
|
|
|
];
|
2022-10-05 20:52:30 +00:00
|
|
|
preparePhase = ''
|
2022-10-19 16:34:22 +00:00
|
|
|
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
|
2022-10-05 20:52:30 +00:00
|
|
|
'';
|
2023-10-08 21:35:30 +00:00
|
|
|
mungeDtbPhase = ''
|
2022-10-05 20:52:30 +00:00
|
|
|
dtc -I dtb -O dts -o tmp.dts ${dtb}
|
2024-02-17 01:16:20 +00:00
|
|
|
echo '/{ chosen { ${commandLineDtbNode} = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
|
2022-10-05 20:52:30 +00:00
|
|
|
dtc -I dts -O dtb -o tmp.dtb tmp.dts
|
|
|
|
'';
|
|
|
|
|
2023-10-08 21:35:30 +00:00
|
|
|
buildPhaseUImage = ''
|
|
|
|
test -f tmp.dtb && ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=tmp.dtb vmlinux.elf
|
|
|
|
${stripAndZip}
|
2023-11-12 20:39:06 +00:00
|
|
|
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
|
2023-10-08 21:35:30 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhaseFIT = ''
|
|
|
|
${stripAndZip}
|
|
|
|
cat ${./kernel_fdt.its} > mkimage.its
|
|
|
|
cat << _VARS >> mkimage.its
|
|
|
|
/ {
|
|
|
|
images {
|
|
|
|
kernel {
|
|
|
|
data = /incbin/("./vmlinux.bin.lzma");
|
2023-11-12 18:47:31 +00:00
|
|
|
load = <0x${lib.toHexString loadAddress}>;
|
2023-11-12 18:50:47 +00:00
|
|
|
entry = <0x${lib.toHexString entryPoint}>;
|
2023-10-29 11:50:23 +00:00
|
|
|
arch = "${arch}";
|
2023-10-08 21:35:30 +00:00
|
|
|
compression = "lzma";
|
|
|
|
};
|
2023-10-29 11:50:23 +00:00
|
|
|
fdt-1 {
|
|
|
|
data = /incbin/("./tmp.dtb");
|
|
|
|
arch = "${arch}";
|
|
|
|
};
|
2023-10-08 21:35:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
_VARS
|
2025-02-10 21:55:08 +00:00
|
|
|
mkimage -f mkimage.its -E ${
|
|
|
|
lib.optionalString (alignment != null) "-B 0x${lib.toHexString alignment}"
|
|
|
|
} kernel.uimage
|
2023-10-08 21:35:30 +00:00
|
|
|
mkimage -l kernel.uimage
|
|
|
|
'';
|
|
|
|
|
2022-10-03 21:28:15 +00:00
|
|
|
installPhase = ''
|
2023-10-08 21:35:30 +00:00
|
|
|
cp kernel.uimage $out
|
2022-10-03 21:28:15 +00:00
|
|
|
'';
|
|
|
|
}
|