Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WAIT] - eeprom: flashing and bootconfig #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ arm64 machine for every package/derivation that needs to be compiled. Binfmt is
a kernel feature that will allows programs like QEMU to be span up whenever any
program tries to spawn a process for a foreign architecture.

## Update Raspberry pi

Build and copy the following drv results to the first partion on rpi formatted sdcard

```
nix build .#build-eeprom -L
```

The next boot it will update the firmware

### Ref

1. https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#eeprom-update-files

###
75 changes: 63 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,70 @@
pi-kiosk-sdImage = (self.nixosConfigurations.pi-kiosk.extendModules {
modules = [ "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel-no-zfs-installer.nix" ];
}).config.system.build.sdImage;
pi-eeprom-sdImage = (self.nixosConfigurations.pi-eeprom.extendModules {
modules = [ "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel-no-zfs-installer.nix" ];
}).config.system.build.sdImage;
build-eeprom = lib.mkOverridable
{ flash ? true }:
let
bootconf = pkgs.writeText "bootconf" ''
[all]
BOOT_UART=1
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
ENABLE_SELF_UPDATE=1
BOOT_ORDER=0xf2 # 2=Network boot 1=sdcard, order matters
NET_BOOT_MAX_RETRIES=5
USE_IPV6=1 # Enable IPv6, netboot is on by default

[none]
FREEZE_VERSION=0
'';
pkgs = nixpkgs.legacyPackages.aarch64-linux;
pieeprom = if flash then "pieeprom.bin" else "pieeprom.upd";
in
pkgs.runCommand "eeprom.img"
{
buildInputs = [ pkgs.raspberrypi-eeprom ];
} ''
mkdir $out
# Apply config
echo ${bootconf}
rpi-eeprom-config --config ${bootconf} --out $out/${pieeprom} ${pkgs.raspberrypi-eeprom}/share/rpi-eeprom/latest/pieeprom-2023-01-11.bin
sha256sum $out/${pieeprom} | cut -d' ' -f1 > $out/pieeprom.sig
cp ${pkgs.raspberrypi-eeprom}/share/rpi-eeprom/latest/recovery.bin $out/recovery.bin
# This needs to increase after every update to the eeprom
echo 'ts: 102' >> $out/pieeprom.sig
'';
);
};
};
};
nixosConfigurations = {
pi-kiosk = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
nixos-hardware.nixosModules.raspberry-pi-4
./configuration.nix
./base.nix
];
nixosConfigurations = {
pi-kiosk = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
nixos-hardware.nixosModules.raspberry-pi-4
./configuration.nix
./base.nix
];
};
pi-eeprom = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
nixos-hardware.nixosModules.raspberry-pi-4
./base.nix
({ pkgs, ... }: {
environment.systemPackages = with pkgs; [ raspberrypi-eeprom ];
# without this we dont actually get a shell
boot.kernelParams = [
"console=ttyS0,115200"
"console=tty1"
];
})
];
};

};
};
};
};
}

}