Adds option for uncompressed image and vm script.
This commit is contained in:
parent
4a1993e75b
commit
bb3c82e2a5
3 changed files with 36 additions and 18 deletions
33
flake.nix
33
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
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
}
|
||||
|
|
19
sd-card.nix
19
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
|
||||
''}
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue