commit 5adfb0230f7a3b42b29c53af52b54080d8514ddf
parent b519bd15df814cf076d7b3288c7a9f5620daa837
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 5 Dec 2023 23:16:53 +0000
WIP generate bootable disk image with partition table
Diffstat:
5 files changed, 73 insertions(+), 12 deletions(-)
diff --git a/modules/ext4fs.nix b/modules/ext4fs.nix
@@ -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)
diff --git a/modules/outputs/diskimage.nix b/modules/outputs/diskimage.nix
@@ -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
+ '';
+ };
+ };
+}
diff --git a/modules/outputs/extlinux.nix b/modules/outputs/extlinux.nix
@@ -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
'';
};
diff --git a/overlay.nix b/overlay.nix
@@ -210,6 +210,8 @@ extraPkgs // {
extraConfig = ''
CONFIG_CMD_UBI=y
CONFIG_CMD_UBIFS=y
+ CONFIG_BOOTSTD=y
+ CONFIG_BOOTMETH_DISTRO=y
'';
};
}
diff --git a/pkgs/run-liminix-vm/run-liminix-vm.fnl b/pkgs/run-liminix-vm/run-liminix-vm.fnl
@@ -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))