commit ad25a74ac0ea39855dfe36f0bab8014477401779 Author: Bailey Stevens Date: Tue Apr 4 13:51:16 2023 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/config.txt b/config.txt new file mode 100644 index 0000000..36b0e3a --- /dev/null +++ b/config.txt @@ -0,0 +1,15 @@ +[pi02] +kernel=u-boot-rpi3.bin + +[all] +# Boot in 64-bit mode. +arm_64bit=1 + +# U-Boot needs this to work, regardless of whether UART is actually used or not. +# Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still +# a requirement in the future. +enable_uart=1 + +# Prevent the firmware from smashing the framebuffer setup done by the mainline kernel +# when attempting to show low-voltage or overtemperature warnings. +avoid_warnings=1 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e43b1b8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1680398059, + "narHash": "sha256-qtbKRe+pWuf5nNINdiCgn6EwOIQZxj0Ig/wybBpFNkQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7c656856e9eb863c4d21c83e2601dd77f95f6941", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ea10b1c --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "my project description"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = inputs@{self, nixpkgs, flake-utils, ...}: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + crossSystem = nixpkgs.lib.systems.examples.aarch64-multiplatform; + }; + in + { + packages = { + default = import ./orange.nix { inherit pkgs; }; + }; + } + ); +} diff --git a/orange.nix b/orange.nix new file mode 100644 index 0000000..7a904b1 --- /dev/null +++ b/orange.nix @@ -0,0 +1,90 @@ +{ pkgs }: + +let + imageName = "orange"; + firmwarePartition = { + offset = 8; + id = "0xfeed3425"; + name = "FIRMWARE"; + size = 512; + }; + + rootfsImage = import ./rootfs.nix { inherit pkgs; }; + + configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt); + populateFirmwareCommands = '' + # Add config.txt + 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/ + + # Add pi3 specific files + cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin + ''; +in + pkgs.stdenv.mkDerivation { + name = imageName; + + nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ]; + + buildCommand = '' + mkdir -p $out/nix-support $out/sd-image + export img=$out/sd-image/${imageName} + echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system + echo "file sd-image $img.zst" >> $out/nix-support/hydra-build-products + root_fs=${rootfsImage} + + # Gap in front of the first partition, in MiB + gap=${toString firmwarePartition.offset} + + # Create the image file sized to fit /boot/firmware and /, plus slack for the gap. + rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }') + firmwareSizeBlocks=$((${toString firmwarePartition.size} * 1024 * 1024 / 512)) + imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024)) + truncate -s $imageSize $img + + # type=b is 'W95 FAT32', type=83 is 'Linux'. + # The "bootable" partition is where u-boot will look file for the bootloader + # information (dtbs, extlinux.conf file). + sfdisk $img <