Adds option for uncompressed image and vm script.

This commit is contained in:
Bailey Stevens 2023-04-04 13:51:16 -04:00
parent 4a1993e75b
commit bb3c82e2a5
3 changed files with 36 additions and 18 deletions

View file

@ -11,16 +11,33 @@
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
crossSystem = nixpkgs.lib.systems.examples.aarch64-multiplatform;
}; };
crossPkgs = pkgs.pkgsCross.aarch64-multiplatform;
in in
{ {
packages = let apps.default = {
orange = import ./sd-card.nix { inherit pkgs; }; type = "app";
in program = "${self.outputs.packages.${system}.vmscript}/bin/vmscript";
{
default = orange;
}; };
} packages = {
); default = import ./sd-card.nix { inherit pkgs crossPkgs; };
uncompressed = import ./sd-card.nix { inherit pkgs crossPkgs; compress = false; };
vmscript = pkgs.writeScriptBin "vmscript" ''
#!${pkgs.runtimeShell}
img=${self.outputs.packages.${system}.uncompressed}/sd-card.img
${pkgs.qemu}/bin/qemu-system-aarch64 \
-machine raspi3b \
-kernel "${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin" \
-cpu max \
-m 1G \
-smp 4 \
-drive file="$img",format=raw \
-serial null \
-serial mon:stdio
'';
};
});
} }

View file

@ -6,7 +6,7 @@ pkgs.stdenv.mkDerivation {
nativeBuildInputs = with pkgs; [ zstd ]; nativeBuildInputs = with pkgs; [ zstd ];
buildCommand = '' buildCommand = ''
truncate -s 1M ./rootfs.img truncate -s 512M ./rootfs.img
zstd -T$NIX_BUILD_CORES ./rootfs.img -o $out zstd -T$NIX_BUILD_CORES ./rootfs.img -o $out
''; '';
} }

View file

@ -1,4 +1,4 @@
{ pkgs }: { pkgs, crossPkgs, compress ? true}:
let let
firmwarePartition = { firmwarePartition = {
@ -7,7 +7,6 @@ let
name = "FIRMWARE"; name = "FIRMWARE";
size = 512; size = 512;
}; };
rootfsImage = import ./rootfs.nix { inherit pkgs; }; rootfsImage = import ./rootfs.nix { inherit pkgs; };
configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt); configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt);
@ -16,12 +15,12 @@ let
cp ${configTxt} firmware/config.txt cp ${configTxt} firmware/config.txt
# Copy the firmware files # Copy the firmware files
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/ cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/ cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/ cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/
# Add pi3 specific files # Add pi3 specific files
cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin cp ${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin
''; '';
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
@ -30,7 +29,8 @@ in
nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ]; nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ];
buildCommand = '' buildCommand = ''
img=./sd-card.img mkdir $out
img=$out/sd-card.img
root_fs=./rootfs.img root_fs=./rootfs.img
zstd -d --no-progress "${rootfsImage}" -o $root_fs zstd -d --no-progress "${rootfsImage}" -o $root_fs
@ -83,7 +83,8 @@ in
dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS
mkdir $out ${pkgs.lib.optionalString compress ''
zstd -T$NIX_BUILD_CORES $img -o $out/orange.img.zstd zstd -T$NIX_BUILD_CORES --rm $img
''}
''; '';
} }