2023-03-03 00:01:26 +01:00
|
|
|
{
|
|
|
|
config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) mkOption types concatStringsSep;
|
|
|
|
inherit (config.boot) tftp;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
};
|
|
|
|
config = {
|
|
|
|
kernel = {
|
|
|
|
config = {
|
|
|
|
MTD_SPLIT_UIMAGE_FW = "y";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-24 18:32:46 +01:00
|
|
|
programs.busybox.applets = [
|
|
|
|
"flashcp"
|
|
|
|
];
|
|
|
|
|
2023-03-03 00:01:26 +01:00
|
|
|
outputs.firmware =
|
|
|
|
let o = config.outputs; in
|
|
|
|
pkgs.runCommand "firmware" {} ''
|
|
|
|
dd if=${o.uimage} of=$out bs=128k conv=sync
|
2023-04-10 19:09:37 +02:00
|
|
|
dd if=${o.rootfs} of=$out bs=128k conv=sync,nocreat,notrunc oflag=append
|
2023-03-03 00:01:26 +01:00
|
|
|
'';
|
2023-04-10 19:09:37 +02:00
|
|
|
outputs.flashimage =
|
2023-03-03 00:01:26 +01:00
|
|
|
let o = config.outputs; in
|
2023-04-10 19:09:37 +02:00
|
|
|
pkgs.runCommand "flashimage" {} ''
|
2023-03-03 00:01:26 +01:00
|
|
|
mkdir $out
|
|
|
|
cd $out
|
|
|
|
ln -s ${o.firmware} firmware.bin
|
2023-04-10 19:09:37 +02:00
|
|
|
ln -s ${o.rootfs} rootfs
|
2023-03-03 00:01:26 +01:00
|
|
|
ln -s ${o.kernel} vmlinux
|
|
|
|
ln -s ${o.manifest} manifest
|
|
|
|
ln -s ${o.kernel.headers} build
|
|
|
|
ln -s ${o.uimage} uimage
|
|
|
|
ln -s ${o.dtb} dtb
|
|
|
|
ln -s ${o.flash-scr} flash.scr
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputs.flash-scr =
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib.trivial) toHexString;
|
2023-03-03 23:52:33 +01:00
|
|
|
inherit (config.hardware) flash;
|
2023-03-03 00:01:26 +01:00
|
|
|
in
|
|
|
|
pkgs.buildPackages.runCommand "" {} ''
|
|
|
|
imageSize=$(stat -L -c %s ${config.outputs.firmware})
|
|
|
|
cat > $out << EOF
|
|
|
|
setenv serverip ${tftp.serverip}
|
|
|
|
setenv ipaddr ${tftp.ipaddr}
|
|
|
|
tftp 0x$(printf %x ${tftp.loadAddress}) result/firmware.bin
|
2023-03-18 15:50:09 +01:00
|
|
|
erase 0x$(printf %x ${flash.address}) +\''${filesize})
|
2023-03-03 00:01:26 +01:00
|
|
|
cp.b 0x$(printf %x ${tftp.loadAddress}) 0x$(printf %x ${flash.address}) \''${filesize}
|
|
|
|
echo command line was ${builtins.toJSON (concatStringsSep " " config.boot.commandLine)}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|