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

nixos rpi bootloader: install files for raspberry pi 4 (rpi4) #112677

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ let
'' else ''
kernel=kernel.img
initramfs initrd followkernel
'') + (optional (cfg.version == 4) ''
enable_gic=1
armstub=armstub8-gic.bin
'') + optional (cfg.firmwareConfig != null) cfg.firmwareConfig);

in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ let
pkgs.ubootRaspberryPi3_64bit
else
pkgs.ubootRaspberryPi3_32bit
else if version == 4 then
if isAarch64 then
pkgs.ubootRaspberryPi4_64bit
else
pkgs.ubootRaspberryPi4_32bit
else
throw "U-Boot is not yet supported on the raspberry pi 4.";
throw "U-Boot is not yet supported on the raspberry pi ${toString version}.";

extlinuxConfBuilder =
import ../generic-extlinux-compatible/extlinux-conf-builder.nix {
Expand All @@ -29,6 +34,7 @@ pkgs.substituteAll {
inherit (pkgs) bash;
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
firmware = pkgs.raspberrypifw;
armstubs = pkgs.raspberrypi-armstubs;
inherit uboot;
inherit configTxt;
inherit extlinuxConfBuilder;
Expand Down
26 changes: 23 additions & 3 deletions nixos/modules/system/boot/loader/raspberrypi/uboot-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ done
copyForced() {
local src="$1"
local dst="$2"
cp $src $dst.tmp
cp -r $src $dst.tmp
rm -rf $dst
lheckemann marked this conversation as resolved.
Show resolved Hide resolved
mv $dst.tmp $dst
}

Expand All @@ -21,6 +22,7 @@ copyForced() {

# Add the firmware files
fwdir=@firmware@/share/raspberrypi/boot/
copyForced $fwdir/overlays $target/overlays
copyForced $fwdir/bootcode.bin $target/bootcode.bin
copyForced $fwdir/fixup.dat $target/fixup.dat
copyForced $fwdir/fixup_cd.dat $target/fixup_cd.dat
Expand All @@ -31,8 +33,26 @@ copyForced $fwdir/start_cd.elf $target/start_cd.elf
copyForced $fwdir/start_db.elf $target/start_db.elf
copyForced $fwdir/start_x.elf $target/start_x.elf

# Add the config.txt
copyForced @configTxt@ $target/config.txt

# Add the uboot file
copyForced @uboot@/u-boot.bin $target/u-boot-rpi.bin

# Add the config.txt
copyForced @configTxt@ $target/config.txt
# Add the raspberry pi 4 specific files
if [[ "@version@" == "4" ]]; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was previously wrong. I noticed since I wiped my rpi4 /boot and these files were missing afterward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't rather support all aarch64 Raspberry Pi at once.

Right now configuring for the Raspberry Pi 4 means you also get the files for the Raspberry Pi 3 family, but not the inverse. Unless I'm mistaken?

Doing so would require config.txt to be aware of the [pi_] sections I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your analysis is right, and the improvement you suggest would be the next/last big thing on the road to re-using this exact logic/builder for the sd-card image...

... but I can't sign-up for that right now.

copyForced @armstubs@/armstub8-gic.bin $target/armstub8-gic.bin

copyForced $fwdir/fixup4.dat $target/fixup4.dat
copyForced $fwdir/fixup4cd.dat $target/fixup4cd.dat
copyForced $fwdir/fixup4db.dat $target/fixup4db.dat
copyForced $fwdir/fixup4x.dat $target/fixup4x.dat
copyForced $fwdir/start4.elf $target/start4.elf
copyForced $fwdir/start4cd.elf $target/start4cd.elf
copyForced $fwdir/start4db.elf $target/start4db.elf
copyForced $fwdir/start4x.elf $target/start4x.elf

copyForced @firmware@/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb $target/bcm2711-rpi-4-b.dtb
copyForced @firmware@/share/raspberrypi/boot/bcm2711-rpi-400.dtb $target/bcm2711-rpi-400.dtb
copyForced @firmware@/share/raspberrypi/boot/bcm2711-rpi-cm4.dtb $target/bcm2711-rpi-cm4.dtb
fi