forked from DGNum/liminix
tftpboot: add option for kernel image format
This commit is contained in:
parent
44a0cf364b
commit
ff0ef825a6
2 changed files with 32 additions and 12 deletions
|
@ -9,10 +9,16 @@ let
|
||||||
cfg = config.boot.tftp;
|
cfg = config.boot.tftp;
|
||||||
in {
|
in {
|
||||||
imports = [ ../ramdisk.nix ];
|
imports = [ ../ramdisk.nix ];
|
||||||
options.boot.tftp.freeSpaceBytes = mkOption {
|
options.boot.tftp = {
|
||||||
|
freeSpaceBytes = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
default = 0;
|
default = 0;
|
||||||
};
|
};
|
||||||
|
kernelFormat = mkOption {
|
||||||
|
type = types.enum [ "zimage" "uimage" ];
|
||||||
|
default = "uimage";
|
||||||
|
};
|
||||||
|
};
|
||||||
options.system.outputs = {
|
options.system.outputs = {
|
||||||
tftpboot = mkOption {
|
tftpboot = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
|
@ -44,6 +50,14 @@ in {
|
||||||
let
|
let
|
||||||
inherit (pkgs.lib.trivial) toHexString;
|
inherit (pkgs.lib.trivial) toHexString;
|
||||||
o = config.system.outputs;
|
o = config.system.outputs;
|
||||||
|
image = let choices = {
|
||||||
|
uimage = o.uimage;
|
||||||
|
zimage = o.zimage;
|
||||||
|
}; in choices.${cfg.kernelFormat};
|
||||||
|
bootCommand = let choices = {
|
||||||
|
uimage = "bootm";
|
||||||
|
zimage = "bootz";
|
||||||
|
}; in choices.${cfg.kernelFormat};
|
||||||
cmdline = concatStringsSep " " config.boot.commandLine;
|
cmdline = concatStringsSep " " config.boot.commandLine;
|
||||||
in
|
in
|
||||||
pkgs.runCommand "tftpboot" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } ''
|
pkgs.runCommand "tftpboot" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } ''
|
||||||
|
@ -53,8 +67,8 @@ in {
|
||||||
ln -s ${o.kernel} vmlinux
|
ln -s ${o.kernel} vmlinux
|
||||||
ln -s ${o.manifest} manifest
|
ln -s ${o.manifest} manifest
|
||||||
ln -s ${o.kernel.headers} build
|
ln -s ${o.kernel.headers} build
|
||||||
ln -s ${o.uimage} uimage
|
ln -s ${image} image
|
||||||
uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff)))
|
uimageSize=$(($(stat -L -c %s ${image}) + 0x1000 &(~0xfff)))
|
||||||
rootfsStart=$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) )))
|
rootfsStart=$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) )))
|
||||||
rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff)))
|
rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff)))
|
||||||
rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} ))
|
rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} ))
|
||||||
|
@ -82,8 +96,8 @@ in {
|
||||||
setenv serverip ${cfg.serverip}
|
setenv serverip ${cfg.serverip}
|
||||||
setenv ipaddr ${cfg.ipaddr}
|
setenv ipaddr ${cfg.ipaddr}
|
||||||
setenv bootargs 'liminix ${cmdline} $cmd'
|
setenv bootargs 'liminix ${cmdline} $cmd'
|
||||||
tftpboot 0x${lib.toHexString cfg.loadAddress} result/uimage ; tftpboot 0x$rootfsStart result/rootfs ; tftpboot 0x$dtbStart result/dtb
|
tftpboot 0x${lib.toHexString cfg.loadAddress} result/image ; tftpboot 0x$rootfsStart result/rootfs ; tftpboot 0x$dtbStart result/dtb
|
||||||
bootm 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart
|
${bootCommand} 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart
|
||||||
EOF
|
EOF
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
{
|
{
|
||||||
liminix
|
liminix
|
||||||
}:
|
}:
|
||||||
let check = deviceName : ubootName :
|
let check = deviceName : ubootName : config :
|
||||||
let derivation = (import liminix {
|
let derivation = (import liminix {
|
||||||
device = import "${liminix}/devices/${deviceName}/";
|
device = import "${liminix}/devices/${deviceName}/";
|
||||||
liminix-config = ./configuration.nix;
|
liminix-config = { pkgs, ... } : {
|
||||||
|
imports = [./configuration.nix];
|
||||||
|
inherit config;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
img = derivation.outputs.tftpboot;
|
img = derivation.outputs.tftpboot;
|
||||||
uboot = derivation.pkgs.${ubootName};
|
uboot = derivation.pkgs.${ubootName};
|
||||||
|
@ -30,7 +33,10 @@ run-liminix-vm \
|
||||||
expect ${./script.expect} 2>&1 |tee $out
|
expect ${./script.expect} 2>&1 |tee $out
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
aarch64 = check "qemu-aarch64" "ubootQemuAarch64";
|
aarch64 = check "qemu-aarch64" "ubootQemuAarch64" {};
|
||||||
arm = check "qemu-armv7l" "ubootQemuArm";
|
arm = check "qemu-armv7l" "ubootQemuArm" {};
|
||||||
mips = check "qemu" "ubootQemuMips";
|
armZimage = check "qemu-armv7l" "ubootQemuArm" {
|
||||||
|
boot.tftp.kernelFormat = "zimage";
|
||||||
|
};
|
||||||
|
mips = check "qemu" "ubootQemuMips" {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue