From bb3c82e2a50525eb69fb65c18e87ecd5760908ba Mon Sep 17 00:00:00 2001 From: Bailey Stevens Date: Tue, 4 Apr 2023 13:51:16 -0400 Subject: [PATCH] Adds option for uncompressed image and vm script. --- flake.nix | 33 +++++++++++++++++++++++++-------- rootfs.nix | 2 +- sd-card.nix | 19 ++++++++++--------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 71726a5..fa75d49 100644 --- a/flake.nix +++ b/flake.nix @@ -11,16 +11,33 @@ let pkgs = import nixpkgs { inherit system; - crossSystem = nixpkgs.lib.systems.examples.aarch64-multiplatform; }; + crossPkgs = pkgs.pkgsCross.aarch64-multiplatform; in { - packages = let - orange = import ./sd-card.nix { inherit pkgs; }; - in - { - default = orange; + apps.default = { + type = "app"; + program = "${self.outputs.packages.${system}.vmscript}/bin/vmscript"; }; - } - ); + 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 + ''; + + }; + + }); } diff --git a/rootfs.nix b/rootfs.nix index 9ee1adb..7f51672 100644 --- a/rootfs.nix +++ b/rootfs.nix @@ -6,7 +6,7 @@ pkgs.stdenv.mkDerivation { nativeBuildInputs = with pkgs; [ zstd ]; buildCommand = '' - truncate -s 1M ./rootfs.img + truncate -s 512M ./rootfs.img zstd -T$NIX_BUILD_CORES ./rootfs.img -o $out ''; } diff --git a/sd-card.nix b/sd-card.nix index 0a57566..c861f0b 100644 --- a/sd-card.nix +++ b/sd-card.nix @@ -1,4 +1,4 @@ -{ pkgs }: +{ pkgs, crossPkgs, compress ? true}: let firmwarePartition = { @@ -7,7 +7,6 @@ let name = "FIRMWARE"; size = 512; }; - rootfsImage = import ./rootfs.nix { inherit pkgs; }; configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt); @@ -16,12 +15,12 @@ let cp ${configTxt} firmware/config.txt # Copy the firmware files - cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/ - cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/ - cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/ + cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/ + cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/ + cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/ # 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 pkgs.stdenv.mkDerivation { @@ -30,7 +29,8 @@ in nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ]; buildCommand = '' - img=./sd-card.img + mkdir $out + img=$out/sd-card.img root_fs=./rootfs.img 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 - mkdir $out - zstd -T$NIX_BUILD_CORES $img -o $out/orange.img.zstd + ${pkgs.lib.optionalString compress '' + zstd -T$NIX_BUILD_CORES --rm $img + ''} ''; }