From 2b35a491b5bee1dda14f2c15c0bddc27ae137f43 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 30 Jan 2024 11:25:08 +0100 Subject: [PATCH] WIP: support for TFTP on 'old' uboot versions Older uboot versions don't have an option to override the DTB from the `mboot` command, so the updated DTB needs to be replaced in the image itself. --- modules/outputs/tftpboot.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix index 36d96ff..20eb4e7 100644 --- a/modules/outputs/tftpboot.nix +++ b/modules/outputs/tftpboot.nix @@ -63,8 +63,13 @@ in { zimage = "bootz"; }; in choices.${cfg.kernelFormat}; cmdline = concatStringsSep " " config.boot.commandLine; + objcopy = "${pkgs.stdenv.cc.bintools.targetPrefix}objcopy"; + 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 - pkgs.runCommand "tftpboot" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ lzma dtc ]; } '' + pkgs.runCommand "tftpboot" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ lzma dtc pkgs.stdenv.cc ubootTools ]; } '' mkdir $out cd $out binsize() { local s=$(stat -L -c %s $1); echo $(($s + 0x1000 &(~0xfff))); } @@ -77,12 +82,12 @@ in { imageSize=$(binsize ${image}) ln -s ${o.manifest} manifest - ln -s ${image} image ln -s ${o.kernel} vmlinux # handy for gdb ${if cfg.compressRoot then '' lzma -z9cv ${o.rootfs} > rootfs.lz + # TODO this is no longer correct rootfsLzStart=$(($imageStart + $imageSize)) rootfsLzSize=$(binsize rootfs.lz) '' @@ -107,6 +112,13 @@ in { cmd="liminix ${cmdline} mtdparts=phram0:''${rootfsSize}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsSize},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; fdtput -t s dtb /chosen bootargs "$cmd" + # re-package image with updated dtb + cp ${o.kernel} vmlinux.elf; chmod +w vmlinux.elf + ${objcopy} --update-section .appended_dtb=dtb vmlinux.elf + ${stripAndZip} + # TODO don't hardcode mips, entryPoint, loadAddress, name + mkimage -A mips -O linux -T kernel -C lzma -a 0x80001000 -e 0x80001000 -n 'MIPS Liminix Linux' -d vmlinux.bin.lzma image + # dtc -I dtb -O dts -o /dev/stdout dtb | grep -A10 chosen ; exit 1 cat > boot.scr << EOF