2022-10-03 23:28:15 +02:00
|
|
|
{
|
|
|
|
lzma
|
|
|
|
, stdenv
|
|
|
|
, ubootTools
|
2022-10-05 22:52:30 +02:00
|
|
|
, dtc
|
2023-09-20 18:57:17 +02:00
|
|
|
, lib
|
2022-10-03 23:28:15 +02:00
|
|
|
} :
|
|
|
|
let
|
|
|
|
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
|
|
|
in {
|
2022-10-19 18:34:22 +02:00
|
|
|
kernel
|
2022-10-05 22:52:30 +02:00
|
|
|
, commandLine
|
2022-10-03 23:28:15 +02:00
|
|
|
, entryPoint
|
2022-10-05 22:52:30 +02:00
|
|
|
, extraName ? "" # e.g. socFamily
|
2022-10-03 23:28:15 +02:00
|
|
|
, loadAddress
|
2022-10-05 22:52:30 +02:00
|
|
|
, dtb ? null
|
2022-10-03 23:28:15 +02:00
|
|
|
} :
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "kernel.image";
|
2022-10-05 22:52:30 +02:00
|
|
|
phases = [
|
|
|
|
"preparePhase"
|
|
|
|
(if dtb != null then "dtbPhase" else ":")
|
|
|
|
"buildPhase"
|
|
|
|
"installPhase" ];
|
2022-10-03 23:28:15 +02:00
|
|
|
nativeBuildInputs = [
|
|
|
|
lzma
|
2022-10-05 22:52:30 +02:00
|
|
|
dtc
|
2022-10-03 23:28:15 +02:00
|
|
|
stdenv.cc
|
|
|
|
ubootTools
|
|
|
|
];
|
2022-10-05 22:52:30 +02:00
|
|
|
preparePhase = ''
|
2022-10-19 18:34:22 +02:00
|
|
|
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
|
2022-10-05 22:52:30 +02:00
|
|
|
'';
|
|
|
|
dtbPhase = ''
|
|
|
|
dtc -I dtb -O dts -o tmp.dts ${dtb}
|
|
|
|
echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
|
|
|
|
dtc -I dts -O dtb -o tmp.dtb tmp.dts
|
|
|
|
'';
|
|
|
|
|
2023-09-20 18:57:17 +02:00
|
|
|
buildPhase =
|
|
|
|
let arch =
|
|
|
|
# per output of "mkimage -A list". I *think* these
|
|
|
|
# are the same as the kernel arch convention, but
|
|
|
|
# maybe that's coincidence
|
|
|
|
if stdenv.isMips
|
|
|
|
then "mips"
|
|
|
|
else if stdenv.isAarch64
|
|
|
|
then "arm64"
|
|
|
|
else throw "unknown arch";
|
|
|
|
in ''
|
|
|
|
${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
|
2023-10-01 23:13:51 +02:00
|
|
|
cat ${./kernel_fdt.its} > mkimage.its
|
|
|
|
echo '/ { images { kernel { data = /incbin/("./vmlinux.bin.lzma"); }; }; };' >> mkimage.its
|
|
|
|
echo '/ { images { kernel { load = <${loadAddress}>; }; }; };' >> mkimage.its
|
|
|
|
echo '/ { images { kernel { entry = <${entryPoint}>; }; }; };' >> mkimage.its
|
|
|
|
echo '/ { images { kernel { compression = "lzma"; }; }; };' >> mkimage.its
|
|
|
|
echo '/ { images { fdt-1 { data = /incbin/("./tmp.dtb"); }; }; }; ' >> mkimage.its
|
|
|
|
mkimage -f mkimage.its mkimage.itb
|
|
|
|
mkimage -l mkimage.itb
|
2023-09-20 18:57:17 +02:00
|
|
|
'';
|
2022-10-03 23:28:15 +02:00
|
|
|
installPhase = ''
|
2023-10-01 23:13:51 +02:00
|
|
|
cp mkimage.itb $out
|
2022-10-03 23:28:15 +02:00
|
|
|
'';
|
|
|
|
}
|