From a3f6234ef0674cd9327914aab16de400cad6fcdc Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Thu, 2 Jan 2025 09:46:34 +0100 Subject: [PATCH] WIP: create a FIT image for TFTP booting TODO: make 'traditional' and FIT methods work side-by-side --- modules/outputs/tftpboot.nix | 45 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix index 9c6d038..33dcb5e 100644 --- a/modules/outputs/tftpboot.nix +++ b/modules/outputs/tftpboot.nix @@ -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 ''; };