2022-10-07 01:24:35 +02:00
|
|
|
{
|
|
|
|
config
|
2023-02-11 14:10:38 +01:00
|
|
|
, pkgs
|
|
|
|
, lib
|
2022-10-07 01:24:35 +02:00
|
|
|
, ...
|
|
|
|
}:
|
2023-02-11 14:10:38 +01:00
|
|
|
let
|
|
|
|
inherit (lib) mkOption types concatStringsSep;
|
|
|
|
cfg = config.boot.tftp;
|
|
|
|
in {
|
2023-03-17 13:22:20 +01:00
|
|
|
imports = [ ./ramdisk.nix ];
|
2023-04-24 00:29:53 +02:00
|
|
|
options.boot.tftp.freeSpaceBytes = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
};
|
2022-10-07 01:24:35 +02:00
|
|
|
config = {
|
2023-03-17 13:22:20 +01:00
|
|
|
boot.ramdisk.enable = true;
|
2022-10-07 01:24:35 +02:00
|
|
|
|
2023-03-17 13:22:20 +01:00
|
|
|
outputs.tftpboot =
|
2023-02-11 14:10:38 +01:00
|
|
|
let o = config.outputs; in
|
2023-03-17 13:22:20 +01:00
|
|
|
pkgs.runCommand "tftpboot" {} ''
|
2023-02-11 14:10:38 +01:00
|
|
|
mkdir $out
|
|
|
|
cd $out
|
2023-04-10 19:09:37 +02:00
|
|
|
ln -s ${o.rootfs} rootfs
|
2023-02-11 14:10:38 +01:00
|
|
|
ln -s ${o.kernel} vmlinux
|
|
|
|
ln -s ${o.manifest} manifest
|
|
|
|
ln -s ${o.kernel.headers} build
|
|
|
|
ln -s ${o.uimage} uimage
|
2023-03-02 16:11:12 +01:00
|
|
|
ln -s ${o.boot-scr} boot.scr
|
2023-02-11 14:10:38 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputs.boot-scr =
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib.trivial) toHexString;
|
|
|
|
in
|
2023-03-17 13:22:20 +01:00
|
|
|
pkgs.buildPackages.runCommand "boot-scr" {} ''
|
2023-02-11 14:10:38 +01:00
|
|
|
uimageSize=$(($(stat -L -c %s ${config.outputs.uimage}) + 0x1000 &(~0xfff)))
|
2023-04-10 19:09:37 +02:00
|
|
|
rootfsStart=0x$(printf %x $((${cfg.loadAddress} + 0x100000 + $uimageSize)))
|
|
|
|
rootfsBytes=$(($(stat -L -c %s ${config.outputs.rootfs}) + 0x100000 &(~0xfffff)))
|
2023-04-24 00:29:53 +02:00
|
|
|
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";
|
2023-03-17 13:22:20 +01:00
|
|
|
|
2023-02-11 14:10:38 +01:00
|
|
|
cat > $out << EOF
|
|
|
|
setenv serverip ${cfg.serverip}
|
|
|
|
setenv ipaddr ${cfg.ipaddr}
|
2023-03-23 22:50:44 +01:00
|
|
|
setenv bootargs 'liminix $cmd'
|
2023-04-10 19:09:37 +02:00
|
|
|
tftp 0x$(printf %x ${cfg.loadAddress}) result/uimage ; tftp 0x$(printf %x $rootfsStart) result/rootfs
|
2023-02-11 14:10:38 +01:00
|
|
|
bootm 0x$(printf %x ${cfg.loadAddress})
|
|
|
|
EOF
|
|
|
|
'';
|
2022-10-07 01:24:35 +02:00
|
|
|
};
|
|
|
|
}
|