commit 64a3f5024865bca61ed099d408e290821b70426c
parent c5e9fcecc7424fdbfef07552b2738cf9d5a8de34
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 22 Dec 2023 23:20:35 +0000
tftpboot: support compressed root
Diffstat:
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix
@@ -18,6 +18,10 @@ in {
type = types.enum [ "zimage" "uimage" ];
default = "uimage";
};
+ compressRoot = mkOption {
+ type = types.bool;
+ default = false;
+ };
};
options.system.outputs = {
tftpboot = mkOption {
@@ -74,9 +78,16 @@ in {
dtbSize=$(binsize ${o.dtb} )
ln -s ${o.manifest} manifest
- ln -s ${o.rootfs} rootfs
ln -s ${image} image
+ ${if cfg.compressRoot
+ then ''
+ lzma -z9cv ${o.rootfs} > rootfs.lz
+ rootfsLzStart=$(($dtbStart + $dtbSize))
+ rootfsLzSize=$(binsize rootfs.lz)
+ ''
+ else "ln -s ${o.rootfs} rootfs"
+ }
cat ${o.dtb} > dtb
address_cells=$(fdtget dtb / '#address-cells')
size_cells=$(fdtget dtb / '#size-cells')
@@ -98,7 +109,15 @@ in {
setenv serverip ${cfg.serverip}
setenv ipaddr ${cfg.ipaddr}
setenv bootargs 'liminix ${cmdline} $cmd'
- tftpboot $(hex $imageStart) result/image ; tftpboot $(hex $rootfsStart) result/rootfs ; tftpboot $(hex $dtbStart) result/dtb
+ tftpboot $(hex $imageStart) result/image ; ${
+ if cfg.compressRoot
+ then "tftpboot $(hex $rootfsLzStart) result/rootfs.lz"
+ else "tftpboot $(hex $rootfsStart) result/rootfs"
+ }; tftpboot $(hex $dtbStart) result/dtb
+ ${if cfg.compressRoot
+ then "lzmadec $(hex $rootfsLzStart) $(hex $rootfsStart)"
+ else ""
+ }
${bootCommand} $(hex $imageStart) - $(hex $dtbStart)
EOF
'';
diff --git a/tests/tftpboot/test.nix b/tests/tftpboot/test.nix
@@ -22,13 +22,15 @@ in pkgsBuild.runCommand "check" {
mkdir vm
ln -s ${img} result
+touch empty empty2
+
run-liminix-vm \
--background ./vm \
--u-boot ${uboot}/u-boot.bin \
--arch ${derivation.pkgs.stdenv.hostPlatform.qemuArch} \
--wan "user,tftp=`pwd`" \
- --disk-image result/rootfs \
- result/uimage result/rootfs
+ --disk-image empty2 \
+ empty empty2
expect ${./script.expect} 2>&1 |tee $out
'';
@@ -39,4 +41,7 @@ in {
boot.tftp.kernelFormat = "zimage";
};
mips = check "qemu" "ubootQemuMips" {};
+ mipsLz = check "qemu" "ubootQemuMips" {
+ boot.tftp.compressRoot = true;
+ };
}