2 # nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-aarch64.nix -A config.system.build.sdImage
3 { config, lib, pkgs, ... }:
7 ../../profiles/base.nix
11 boot.loader.grub.enable = false;
12 boot.loader.generic-extlinux-compatible.enable = true;
14 boot.consoleLogLevel = lib.mkDefault 7;
16 # The serial ports listed here are:
17 # - ttyS0: for Tegra (Jetson TX1)
18 # - ttyAMA0: for QEMU's -machine virt
19 boot.kernelParams = ["console=ttyS0,115200n8" "console=ttyAMA0,115200n8" "console=tty0"];
22 populateFirmwareCommands = let
23 configTxt = pkgs.writeText "config.txt" ''
25 kernel=u-boot-rpi3.bin
28 kernel=u-boot-rpi3.bin
31 kernel=u-boot-rpi4.bin
33 armstub=armstub8-gic.bin
35 # Otherwise the resolution will be weird in most cases, compared to
36 # what the pi3 firmware does by default.
39 # Supported in newer board revisions
43 # Enable host mode on the 2711 built-in XHCI USB controller.
44 # This line should be removed if the legacy DWC2 controller is required
45 # (e.g. for USB device mode) or if USB support is not required.
49 # Boot in 64-bit mode.
52 # U-Boot needs this to work, regardless of whether UART is actually used or not.
53 # Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still
54 # a requirement in the future.
57 # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
58 # when attempting to show low-voltage or overtemperature warnings.
62 (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/)
65 cp ${configTxt} firmware/config.txt
67 # Add pi3 specific files
68 cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin
69 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-2-b.dtb firmware/
70 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-3-b.dtb firmware/
71 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-3-b-plus.dtb firmware/
72 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-cm3.dtb firmware/
73 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-zero-2.dtb firmware/
74 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-zero-2-w.dtb firmware/
76 # Add pi4 specific files
77 cp ${pkgs.ubootRaspberryPi4_64bit}/u-boot.bin firmware/u-boot-rpi4.bin
78 cp ${pkgs.raspberrypi-armstubs}/armstub8-gic.bin firmware/armstub8-gic.bin
79 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb firmware/
80 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-400.dtb firmware/
81 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4.dtb firmware/
82 cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4s.dtb firmware/
84 populateRootCommands = ''
86 ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot