1
0
forked from dan/liminix

WIP: create a FIT image for TFTP booting

TODO: make 'traditional' and FIT methods work side-by-side
This commit is contained in:
Arnout Engelen 2025-01-02 09:46:34 +01:00
parent 2e513eb4a7
commit a3f6234ef0
No known key found for this signature in database
GPG Key ID: 061107B0F74A6DAA

View File

@ -73,6 +73,7 @@ in {
cmdline = concatStringsSep " " config.boot.commandLine;
objcopy = "${pkgs.stdenv.cc.bintools.targetPrefix}objcopy";
stripAndZip = ''
cp vmlinux vmlinux.elf; chmod +w vmlinux.elf
${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
'';
@ -96,7 +97,7 @@ in {
# decompression code will assume that any memory after the
# end of the kernel is free
dtbStart=$(($rootfsStart + $rootfsSize))
imageStart=$(($rootfsStart + $rootfsSize))
${if cfg.compressRoot
then ''
lzma -z9cv ${o.rootfs} > rootfs.lz
@ -127,22 +128,30 @@ in {
dtbSize=$(binsize ./dtb )
${if cfg.appendDTB then ''
imageStart=$dtbStart
# re-package image with updated dtb
cat ${o.kernel} > vmlinux.elf
${objcopy} --update-section .appended_dtb=dtb vmlinux.elf
${stripAndZip}
mkimage -A ${arch} -O linux -T kernel -C lzma -a $(hex ${toString hw.loadAddress}) -e $(hex ${toString hw.entryPoint}) -n '${lib.toUpper arch} Liminix Linux tftpboot' -d vmlinux.bin.lzma image
# dtc -I dtb -O dts -o /dev/stdout dtb | grep -A10 chosen ; exit 1
tftpcmd="tftpboot $(hex $imageStart) result/image "
bootcmd="bootm $(hex $imageStart)"
'' else ''
imageStart=$(($dtbStart + $dtbSize))
tftpcmd="tftpboot $(hex $imageStart) result/image; tftpboot $(hex $dtbStart) result/dtb "
ln -s ${image} image
bootcmd="${bootCommand} $(hex $imageStart) - $(hex $dtbStart)"
''}
${stripAndZip}
cat ${../../pkgs/kernel/kernel_fdt.its} > mkimage.its
cat << _VARS >> mkimage.its
/ {
images {
kernel {
description = "${arch} Liminix kernel";
data = /incbin/("./vmlinux.bin.lzma");
load = <0x${lib.toHexString hw.loadAddress}>;
entry = <0x${lib.toHexString hw.entryPoint}>;
arch = "${arch}";
compression = "lzma";
};
fdt-1 {
description = "${arch} Liminix DTB";
data = /incbin/("./dtb");
arch = "${arch}";
};
};
};
_VARS
mkimage -f mkimage.its image
tftpcmd="tftpboot $(hex $imageStart) result/image "
bootcmd="bootm $(hex $imageStart)"
cat > boot.scr << EOF
setenv serverip ${cfg.serverip}
@ -156,7 +165,7 @@ in {
then "lzmadec $(hex $rootfsLzStart) $(hex $rootfsStart); "
else ""
} $bootcmd
EOF
EOF
'';
};