NixOS on ARM/Raspberry Pi 5: Difference between revisions
Malteneuss (talk | contribs) Summarize the current state of NixOS on Pi 5 |
Malteneuss (talk | contribs) m Highlight important sentences |
||
| Line 32: | Line 32: | ||
Support for the Raspberry Pi 5 is currently downstream and experimental. | |||
'''Support for the Raspberry Pi 5 is currently downstream and experimental'''. | |||
It will not be fully supported until mature support exists in the upstream Linux kernel and | It will not be fully supported until mature support exists in the upstream Linux kernel and | ||
the [https://github.com/u-boot/u-boot U-Boot] boot loader, but using an UEFI bootloader already provides a workable solution. | the [https://github.com/u-boot/u-boot U-Boot] boot loader, but using an '''UEFI bootloader already provides a workable solution'''. | ||
The Raspberry Pi 5's boot process follows the [https://youtu.be/UvFG76qM6co?si=e9O1s9mS3wpIpEl9&t=308 typical boot stages on embedded devices], | The Raspberry Pi 5's boot process follows the [https://youtu.be/UvFG76qM6co?si=e9O1s9mS3wpIpEl9&t=308 typical boot stages on embedded devices], some of which have to be adapted to work with NixOS. For that it's helpful to understand more about the stages: | ||
some of which have to be adapted to work with NixOS: | |||
1. ROM boot loader: The first-stage boot loader comes "burned in" on the Pi in a tiny | 1. '''ROM boot loader''': The first-stage boot loader comes "burned in" on the Pi in a tiny | ||
[https://de.wikipedia.org/wiki/One_Time_Programmable One-Time-Programmable memory (OTP)] | [https://de.wikipedia.org/wiki/One_Time_Programmable One-Time-Programmable memory (OTP)] | ||
so it cannot be changed anymore. It's only able to load the next second-stage boot loader below, and reset it in case you have messed up. | so it cannot be changed anymore. It's '''only able to load the next second-stage boot loader below''', and reset it in case you have messed up. | ||
See the [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#first-stage-bootloader official documentation]. | See the [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#first-stage-bootloader official documentation]. | ||
Nothing to adapt here. | Nothing to adapt here. | ||
2. EEPROM boot loader: The second-stage boot loader comes built-in on the Pi in a bit larger, rewriteable | 2. '''EEPROM boot loader''': The second-stage boot loader comes built-in on the Pi in a bit larger, rewriteable | ||
[https://en.wikipedia.org/wiki/EEPROM EEPROM] memory | [https://en.wikipedia.org/wiki/EEPROM EEPROM] memory | ||
This loader is also very limited is only able to search for and start yet another, third-stage boot loader from other | '''This loader is also very limited is only able to search for and start yet another, third-stage boot loader from other | ||
storage hardware like an SD card, an NVME SSD, an USB disk, or from the network. | storage hardware like an SD card, an NVME SSD''', an USB disk, or from the network. | ||
This loader (as many other second-stage boot loaders of other devices) is so size-constraint that it only contains | This loader (as many other second-stage boot loaders of other devices) is so size-constraint that it only contains | ||
the bare mimum code to be able to read from an FAT formatted partition. That's why you see and want a separate small | the bare mimum code to be able to read from an FAT formatted partition. That's why you see and want a separate small | ||
| Line 67: | Line 67: | ||
3. Firmware boot loader: The third-stage boot loader is loaded from the first partition (usually called <code>/boot</code>) | |||
3. '''Firmware boot loader''': The third-stage boot loader is loaded from the first partition (usually called <code>/boot</code>) | |||
of an SD card, NVME SSD or other storage hardware described above. | of an SD card, NVME SSD or other storage hardware described above. | ||
Because size is usually not an issue here anymore you can have large, fully-fledged boot loaders like | Because '''size is usually not an issue here anymore you can have large, fully-fledged boot loaders''' like | ||
[https://www.freedesktop.org/software/systemd/man/latest/systemd-boot.html systemd-boot] (default with NixOS; requires UEFI), or full | [https://www.freedesktop.org/software/systemd/man/latest/systemd-boot.html systemd-boot] (default with NixOS; requires UEFI), or full | ||
[https://github.com/u-boot/u-boot U-Boot] (popular with embedded devices like the Pi) or | [https://github.com/u-boot/u-boot U-Boot] (popular with embedded devices like the Pi) or | ||
[https://www.gnu.org/software/grub/ GRUB] (generally popular with Linux Distros). | [https://www.gnu.org/software/grub/ GRUB] (generally popular with Linux Distros). | ||
However, the standard Pi 5 setup has no third-stage boot loader. | However, '''the standard Pi 5 setup has no third-stage boot loader'''. | ||
The second stage EEPROM boot loader loads the firmware (code to control other hardware on the Pi 5; [https://en.wikipedia.org/wiki/Devicetree device tree | The second stage EEPROM boot loader loads the firmware (code to control other hardware on the Pi 5; [https://en.wikipedia.org/wiki/Devicetree device tree | ||
files] in compact binary format <code>*.dtb</code>), some settings (<code>cmdline.txt</code> on which partition to find the rest of the system; | files] in compact binary format <code>*.dtb</code>), some settings (<code>cmdline.txt</code> on which partition to find the rest of the system; | ||
| Line 85: | Line 86: | ||
See the [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#differences-on-raspberry-pi-5 official documentation]. | See the [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#differences-on-raspberry-pi-5 official documentation]. | ||
Adaptions for NixOS: | '''Adaptions for booting NixOS''': | ||
In order to boot NixOS with it's default boot loader systemd-boot we need UEFI support so replace the | |||
In order to boot NixOS with it's default boot loader systemd-boot we need UEFI support, so replace the | |||
1. ROM -> 2. EEPROM -> Kernel -> NixOS | 1. ROM -> 2. EEPROM -> Kernel -> NixOS | ||
workflow with third-stage and fourth-stage boot loaders (both as firmware on an SD card or NVME SSD etc.) | workflow with third-stage and fourth-stage boot loaders (both as firmware on an SD card or NVME SSD etc.) | ||
1. ROM -> 2. EEPROM -> 3. EDK2 (UEFI boot loader) -> 4. systemd-boot -> Kernel -> NixOS | 1. ROM -> 2. EEPROM -> 3. EDK2 (UEFI boot loader) -> 4. systemd-boot -> Kernel -> NixOS | ||
as follows: | as follows: | ||
1. Install EDK2: | 1. '''Install EDK2''': | ||
We need the first partition of the SD card (or NVME SSD, etc.) again to be formatted as FAT | We need the first partition of the SD card (or NVME SSD, etc.) again to be formatted as FAT | ||
but labelled <code>ESP</code> (EFI System Partition) to conform to (U)EFI standards. | but labelled <code>ESP</code> (EFI System Partition) to conform to (U)EFI standards. | ||
| Line 106: | Line 105: | ||
See a [https://github.com/NixOS/nixpkgs/issues/260754#issuecomment-1908664693 guide on how to setup partitions and these files]. | See a [https://github.com/NixOS/nixpkgs/issues/260754#issuecomment-1908664693 guide on how to setup partitions and these files]. | ||
2. Install systemd-boot, kernel and NixOS: | 2. '''Install systemd-boot, kernel and NixOS''': | ||
The rest is usual NixOS installation on a second partition with the caveat to select a Linux kernel that supports the Pi 5; | The rest is usual NixOS installation on a second partition with the caveat to select a Linux kernel that supports the Pi 5; | ||
a suitable kernel can be created using [https://gitlab.com/vriska/nix-rpi5/-/blob/main/linux-rpi.nix leo60228's flake] until | a suitable kernel can be created using [https://gitlab.com/vriska/nix-rpi5/-/blob/main/linux-rpi.nix leo60228's flake] until | ||
| Line 122: | Line 121: | ||
Missing: | Missing: | ||
# How to do faster cross-compilation without binfmt. | |||
# How to create a convenient SD card image to not install anything manually. | |||
# How to install U-Boot instead of EDK2 and systemd-boot. | |||
=== GPU === | === GPU === | ||