2023-03-19 10:49:32 +01:00
|
|
|
{
|
|
|
|
config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) mkOption mkForce types concatStringsSep;
|
|
|
|
in {
|
|
|
|
imports = [ ./ramdisk.nix ];
|
|
|
|
config = {
|
|
|
|
boot.ramdisk.enable = true;
|
|
|
|
|
|
|
|
outputs.kexecboot =
|
|
|
|
let o = config.outputs; in
|
|
|
|
pkgs.runCommand "kexecboot" {} ''
|
|
|
|
mkdir $out
|
|
|
|
cd $out
|
2023-04-10 19:09:37 +02:00
|
|
|
ln -s ${o.rootfs} rootfs
|
2023-03-19 10:49:32 +01:00
|
|
|
ln -s ${o.kernel} kernel
|
|
|
|
ln -s ${o.manifest} manifest
|
|
|
|
ln -s ${o.boot-sh} boot.sh
|
2023-03-24 21:51:46 +01:00
|
|
|
ln -s ${pkgs.kexec-tools-static}/bin/kexec ./kexec
|
2023-03-19 10:49:32 +01:00
|
|
|
ln -s ${o.dtb} dtb
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputs.boot-sh =
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib.trivial) toHexString;
|
2023-04-10 19:09:37 +02:00
|
|
|
inherit (config.outputs) rootfs kernel;
|
2023-03-19 10:49:32 +01:00
|
|
|
cmdline = concatStringsSep " " config.boot.commandLine;
|
|
|
|
in
|
|
|
|
pkgs.buildPackages.runCommand "boot.sh.sh" {
|
|
|
|
} ''
|
2023-04-10 19:09:37 +02:00
|
|
|
rootfsStart=${toString (100 * 1024 * 1024)}
|
|
|
|
rootfsBytes=$(stat -L -c %s ${rootfs})
|
|
|
|
append_cmd="mtdparts=phram0:''${rootfsBytes}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes} memmap=''${rootfsBytes}\$''${rootfsStart}";
|
2023-03-19 10:49:32 +01:00
|
|
|
cat > $out <<EOF
|
|
|
|
#!/bin/sh
|
|
|
|
test -d \$1
|
|
|
|
cd \$1
|
2023-04-10 19:09:37 +02:00
|
|
|
./kexec -f -d --map-file rootfs@$rootfsStart --dtb dtb --command-line '${cmdline} $append_cmd' kernel
|
2023-03-19 10:49:32 +01:00
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|