Raspberry pi boot.loader.raspberrypi.firmwareConfig not taking effect

I have this config for boot

  boot = { 
    extraModulePackages = [ ];
    initrd = { 
      availableKernelModules = [ "xhci_pci" "usbhid" ];
      kernelModules = [ ];
    };  
    kernelPackages = pkgs.linuxPackages_rpi4;
    loader = { 
      raspberryPi = { 
        enable = true;
        uboot.enable = false;
        version = 4;
        firmwareConfig = ''
          arm_freq=1200
        '';
      };  
      grub.enable = false;
    };  
    tmpOnTmpfs = false;
  };  

This does modify /boot/config.txt to include arm_freq=1200, but I installed raspberry pi using generic aarch64 sd image available here as specified on nix.dev and this installation method seems to use config.txt inside FIRMWARE partition, which isn’t mounted by default.
The blog says that to make any changes to config.txt, you need to mount FIRMWARE partition and manually edit config.txt there. That method works.
But, I wish to control it from configuration.nix. How to do that?

I’d guess you’re booting from FIRMWARE, which probably doesn’t get mounted (unless you do in fact have an entry for it in fileSystems). So there would be a separate /boot in the other partition to which nixos writes config.txt changes. I guess you could either make a fileSystems entry for the FIRMWARE partition or turn off boot flag for FIRMWARE, turn it on for the main partition.

Thanks for the response. It’s been 23 days and I tried many things. I’ll summarize my findings and give an update.

I guess you could either make a fileSystems entry for the FIRMWARE partition

Yes, this works, but the thing is my NIXOS_SD’s /boot is 352 MB and the default nixos aarch64 sd card image has FIRMWARE partition of 18 MB. I need to resize FIRMWARE fat16 partition to hold all the new files.
I tried resizing using gparted, but that isn’t implemented yet. The bugzilla link has a workaround.
I tried moving my NIXOS_SD ext4 partition ahead and creating a new fat32 partition moving existing files, but I couldn’t get it to boot. I did mark it bootable. Maybe I missed something.

I could check-out nix/nixpkgs repo and build a custom aarch64 image with 2GB firmware partition size. I’ll try that next time I install everything from scratch.

or turn off boot flag for FIRMWARE, turn it on for the main partition.

Raspberry Pi needs fat16 / fat32 to marked as boot partition on sd card. My main partition is ext4.

Update on the situation:

I found there’s another big problem in my config. Earlier while I was on nixos 21.11, I had boot.loader.generic-extlinux-compatible.enable = true;. and boot.loader.raspberryPi.enable = true;
The former one was getting used. 22.05 added an assertion that only 1 bootloader can be enabled. I disabled generic-extlinux bootloader, and could no longer boot into latest generations of my system :expressionless:. I was stuck on the last system I built on 21.11. Some programs like nextcloud don’t like if you downgrade them on the next boot. I’ve worked around by disabling raspberry pi bootloader and keeping generic-extlinux-compatible bootloader.

I was running into similar issues, I also had both extlinux and raspberryPi bootloader enabled. Thanks for the summary.

I did a quick test. I built a custom image with just:

{ config, pkgs, lib, ... }:
{

  imports = [
    <nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix>
  ];

  sdImage.compressImage = false;

  sdImage.firmwareSize = 512; # size of vfat partition, could increase to 1024 or 2048

  system.stateVersion = "22.05";

}

nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage -I nixos-config=my-sd-image.nix --argstr system aarch64-linux --option sandbox false

Flash and boot.

nixos-install --root /
reboot

And then (maybe skipping some steps):

  • Copy your configuration.nix (something with fileSystems."/boot" = { ... };)
  • nixos-rebuild switch
  • Reboot
  • Only now is the real vfat /boot mounted
  • Make changes to boot.loader.raspberryPi.firmwareConfig which get inserted into config.txt
  • nixos-rebuild switch and reboot

Did a modest overclock with this method.

Too bad the resizing / moving didn’t work, seems like it should have. Maybe you could also make the new image and just copy contents from your previous card / image.

1 Like

Why does your boot partition have to be so big? My x86 boot partition contains 210M of files. This includes 8 nixOS initrd/efi file pairs to boot those 8 OS generations.

A typical linux config will have /boot (or /boot/EFI) as a vfat partition mounted with the running OS. EFI requires that it be FAT formatted and specifies some directory name requirements. RPi uses the same layout, if I recall correctly.

If your configuration.nix mounts your boot vfat partition at /boot, then nixos-rebuild should make the expected modifications. Files in /boot on an ext4 partition will not be seen by the RPi during boot. (The RPi boot loader can read only FAT partitions, and probably ignores all but one of those.)

I have 194M currently in my fresh setup, with three old Images in /boot/old. I was sure I had seen ~300M in /boot previously, though some backup images are not agreeing with me. Maybe 512M is overkill. It’s the least power of 2 greater what I thought was the biggest value I had seen, albeit probably with stale generations. I think >1G is definitely overkill. I was also unsure of how to do housekeeping in /boot/old at the time, or how big things would be growing.

Hosted by Flying Circus.