forked from DGNum/liminix
WIP generate bootable disk image with partition table
This commit is contained in:
parent
b519bd15df
commit
5adfb0230f
5 changed files with 73 additions and 12 deletions
|
@ -30,7 +30,7 @@ in
|
|||
} ''
|
||||
cp -a ${o.rootfsFiles} tmp
|
||||
${if config.boot.loader.extlinux.enable
|
||||
then "(cd tmp && ln -s ${o.extlinux} boot)"
|
||||
then "(cd tmp && chmod -R +w . && rmdir boot && cp -a ${o.extlinux} boot)"
|
||||
else ""
|
||||
}
|
||||
size=$(du -s --apparent-size --block-size 1024 tmp |cut -f1)
|
||||
|
|
52
modules/outputs/diskimage.nix
Normal file
52
modules/outputs/diskimage.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
config
|
||||
, pkgs
|
||||
, lib
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkOption types concatStringsSep;
|
||||
o = config.system.outputs;
|
||||
phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024);
|
||||
in {
|
||||
# imports = [ ./flashimage.nix ];
|
||||
options.system.outputs = {
|
||||
diskimage = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
diskimage
|
||||
*********
|
||||
|
||||
This creates a disk image file with a partition table containing
|
||||
the contents of ``outputs.rootfs`` as its only partition.
|
||||
'';
|
||||
};
|
||||
vmdisk = mkOption { type = types.package; };
|
||||
};
|
||||
|
||||
config = {
|
||||
system.outputs = {
|
||||
diskimage =
|
||||
let
|
||||
o = config.system.outputs;
|
||||
in pkgs.runCommand "diskimage" {
|
||||
depsBuildBuild = [ pkgs.pkgsBuildBuild.util-linux ];
|
||||
} ''
|
||||
# leave 4 sectors at start for partition table
|
||||
# and alignment to 2048 bytes (does that help?)
|
||||
dd if=${o.rootfs} of=$out bs=512 seek=4 conv=sync
|
||||
echo '4,-,L,*' | sfdisk $out
|
||||
'';
|
||||
vmdisk = pkgs.runCommand "vmdisk" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.diskimage} ./diskimage
|
||||
cat > run.sh <<EOF
|
||||
#!${pkgs.runtimeShell}
|
||||
${pkgs.pkgsBuildBuild.run-liminix-vm}/bin/run-liminix-vm --arch ${pkgs.stdenv.hostPlatform.qemuArch} --u-boot ${pkgs.ubootQemuArm}/u-boot.bin --phram-address 0x${phram_address} --disk-image ${o.diskimage} /dev/null /dev/null
|
||||
EOF
|
||||
chmod +x run.sh
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
|
@ -20,17 +20,18 @@ in {
|
|||
system.outputs.extlinux = pkgs.runCommand "extlinux" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.dtb} dtb
|
||||
ln -s ${o.initramfs} initramfs
|
||||
# cp {o.dtb} dtb
|
||||
cp ${o.initramfs} initramfs
|
||||
gzip -9f < ${o.kernel} > kernel.gz
|
||||
cat > extlinux.conf << _EOF
|
||||
mkdir extlinux
|
||||
cat > extlinux/extlinux.conf << _EOF
|
||||
menu title Liminix
|
||||
timeout 100
|
||||
label Liminix
|
||||
kernel kernel.gz
|
||||
initrd initramfs
|
||||
fdt dtb
|
||||
kernel /boot/kernel.gz
|
||||
initrd /boot/initramfs
|
||||
append ${cmdline}
|
||||
# fdt /boot/dtb
|
||||
_EOF
|
||||
'';
|
||||
};
|
||||
|
|
|
@ -210,6 +210,8 @@ extraPkgs // {
|
|||
extraConfig = ''
|
||||
CONFIG_CMD_UBI=y
|
||||
CONFIG_CMD_UBIFS=y
|
||||
CONFIG_BOOTSTD=y
|
||||
CONFIG_BOOTMETH_DISTRO=y
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
(match args
|
||||
["--background" dir & rest] (assoc (parse-args rest) :background dir)
|
||||
["--u-boot" bin & rest]
|
||||
(assoc (parse-args rest) :u-boot (pad-file bin (* 4 1024) "\xff"))
|
||||
(assoc (parse-args rest) :u-boot (pad-file bin (* 64 1024) "\xff"))
|
||||
["--disk-image" image & rest ] (assoc (parse-args rest)
|
||||
:disk-image (pad-file image 1024))
|
||||
["--arch" arch & rest] (assoc (parse-args rest) :arch arch)
|
||||
["--phram-address" addr & rest] (assoc (parse-args rest) :phram-address addr)
|
||||
["--lan" spec & rest] (assoc (parse-args rest) :lan spec)
|
||||
|
@ -73,9 +75,12 @@
|
|||
])
|
||||
|
||||
|
||||
(fn bootable [cmdline uboot]
|
||||
(fn bootable [cmdline uboot disk]
|
||||
(if uboot
|
||||
["-drive" (.. "if=pflash,format=raw,file=" uboot )]
|
||||
["-drive" (.. "if=pflash,format=raw,file=" uboot )
|
||||
"-drive" (.. "if=none,format=raw,id=hd0,file=" disk)
|
||||
"-device" "virtio-blk-device,drive=hd0"
|
||||
]
|
||||
(let [cmdline (.. cmdline " mem=256M liminix mtdparts=phram0:16M(rootfs) phram.phram=phram0," options.phram-address ",16Mi,65536 root=/dev/mtdblock0")]
|
||||
["-kernel" options.kernel "-append" cmdline])))
|
||||
|
||||
|
@ -94,13 +99,13 @@
|
|||
"-echr" "16"
|
||||
"-device"
|
||||
(.. "loader,file=" options.rootfs ",addr=" options.phram-address)
|
||||
|
||||
])
|
||||
(appendm
|
||||
(if options.background
|
||||
(background options.background)
|
||||
["-serial" "mon:stdio"]))
|
||||
(appendm (bootable (or options.command-line "") options.u-boot))
|
||||
(appendm (bootable (or options.command-line "")
|
||||
options.u-boot options.disk-image))
|
||||
(appendm (access-net))
|
||||
(appendm (local-net options.lan))
|
||||
(appendm ["-display" "none"])))
|
||||
|
@ -113,3 +118,4 @@
|
|||
|
||||
(if options.rootfs (unlink options.rootfs))
|
||||
(if options.u-boot (unlink options.u-boot))
|
||||
(if options.disk-image (unlink options.disk-image))
|
||||
|
|
Loading…
Reference in a new issue