From 6d6dbe1cbbf1c339035fa57e56a5374a58dfb0c9 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 23 Apr 2023 23:29:53 +0100 Subject: [PATCH] tftpboot: allow padding image with freeSpaceBytes this is useful for writable filesystems so that there's more than an erase block of space to write into --- examples/rotuer.nix | 2 +- modules/tftpboot.nix | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 749232c..42140f5 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -25,7 +25,7 @@ let in rec { boot = { tftp = { - enable = true; + freeSpaceBytes = 3 * 1024 * 1024; serverip = "10.0.0.1"; ipaddr = "10.0.0.8"; }; diff --git a/modules/tftpboot.nix b/modules/tftpboot.nix index 6eb2e79..6be5fdd 100644 --- a/modules/tftpboot.nix +++ b/modules/tftpboot.nix @@ -9,6 +9,10 @@ let cfg = config.boot.tftp; in { imports = [ ./ramdisk.nix ]; + options.boot.tftp.freeSpaceBytes = mkOption { + type = types.int; + default = 0; + }; config = { boot.ramdisk.enable = true; @@ -33,8 +37,8 @@ in { uimageSize=$(($(stat -L -c %s ${config.outputs.uimage}) + 0x1000 &(~0xfff))) rootfsStart=0x$(printf %x $((${cfg.loadAddress} + 0x100000 + $uimageSize))) rootfsBytes=$(($(stat -L -c %s ${config.outputs.rootfs}) + 0x100000 &(~0xfffff))) - rootfsMb=$(($rootfsBytes >> 20)) - cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsMb}Mi,${config.hardware.flash.eraseBlockSize} memmap=''${rootfsMb}M\$''${rootfsStart} root=/dev/mtdblock0"; + rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} )) + cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${config.hardware.flash.eraseBlockSize} memmap=''${rootfsBytes}\$''${rootfsStart} root=/dev/mtdblock0"; cat > $out << EOF setenv serverip ${cfg.serverip}