WIP generate bootable disk image with partition table

This commit is contained in:
Daniel Barlow 2023-12-05 23:16:53 +00:00
parent b519bd15df
commit 5adfb0230f
5 changed files with 73 additions and 12 deletions

View file

@ -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)

View 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
'';
};
};
}

View file

@ -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
'';
};