Initial commit
This commit is contained in:
commit
ad25a74ac0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
result
|
15
config.txt
Normal file
15
config.txt
Normal file
|
@ -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
|
43
flake.lock
Normal file
43
flake.lock
Normal file
|
@ -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
|
||||||
|
}
|
23
flake.nix
Normal file
23
flake.nix
Normal file
|
@ -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; };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
90
orange.nix
Normal file
90
orange.nix
Normal file
|
@ -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 <<EOF
|
||||||
|
label: dos
|
||||||
|
label-id: ${firmwarePartition.id}
|
||||||
|
start=''${gap}M, size=$firmwareSizeBlocks, type=b
|
||||||
|
start=$((gap + ${toString firmwarePartition.size}))M, type=83, bootable
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Copy the rootfs into the SD image
|
||||||
|
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
||||||
|
dd conv=notrunc if=$root_fs of=$img seek=$START count=$SECTORS
|
||||||
|
|
||||||
|
# Create a FAT32 /boot/firmware partition of suitable size into firmware_part.img
|
||||||
|
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
||||||
|
truncate -s $((SECTORS * 512)) firmware_part.img
|
||||||
|
mkfs.vfat --invariant -i ${toString firmwarePartition.size} -n ${firmwarePartition.name} firmware_part.img
|
||||||
|
|
||||||
|
# Populate the files intended for /boot/firmware
|
||||||
|
mkdir firmware
|
||||||
|
${populateFirmwareCommands}
|
||||||
|
find firmware -exec touch --date=2000-01-01 {} +
|
||||||
|
|
||||||
|
# Copy the populated /boot/firmware into the SD image
|
||||||
|
cd firmware
|
||||||
|
# Force a fixed order in mcopy for better determinism, and avoid file globbing
|
||||||
|
for d in $(find . -type d -mindepth 1 | sort); do
|
||||||
|
faketime "2000-01-01 00:00:00" mmd -i ../firmware_part.img "::/$d"
|
||||||
|
done
|
||||||
|
for f in $(find . -type f | sort); do
|
||||||
|
mcopy -pvm -i ../firmware_part.img "$f" "::/$f"
|
||||||
|
done
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Verify the FAT partition before copying it.
|
||||||
|
fsck.vfat -vn firmware_part.img
|
||||||
|
|
||||||
|
dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS
|
||||||
|
zstd -T$NIX_BUILD_CORES --rm $img
|
||||||
|
'';
|
||||||
|
}
|
3
rootfs.nix
Normal file
3
rootfs.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
pkgs.runCommand "rootfs" {} "truncate -s 1M $out"
|
Loading…
Reference in a new issue