raspberry-pi/firmware: stage vendor overlays independent of dtbSrc

install-rpi-firmware picks a single $dtbSrc for both the base .dtb
files and the overlays/ directory staged onto the firmware partition.
When useGenerationDeviceTree = true, $dtbSrc becomes
/run/current-system/dtbs, the NixOS generation's device-tree output.
That directory never has an overlays/ subdirectory unless the
generation was itself built with hardware.deviceTree.overlays, so the
"stage overlays from $dtbSrc/overlays" step silently does nothing, and
the stale-file prune then deletes any vendor .dtbo already sitting in
the firmware partition's overlays/ from a previous run.

In practice this makes
hardware.raspberry-pi.configtxt.deviceTreeOverlays
non-functional whenever useGenerationDeviceTree = true is also set - a
combination that legitimately occurs, e.g. a Pi 4 profile needing
apply-overlays-dtmerge/tc358743 (which requires the generation's
dtmerge-produced dtb as the base, since
boot.loader.generic-extlinux-compatible.useGenerationDeviceTree is
usually false with U-Boot enabled) together with a stock overlay like
dwc2 applied by the firmware from config.txt.

Stage vendor overlays from $firmwareBoot/overlays unconditionally,
since hardware.raspberry-pi.configtxt.deviceTreeOverlays entries are
matched against that vendor filename set regardless of where the base
dtb comes from. Additionally stage $dtbSrc/overlays when it differs
from $firmwareBoot and exists, so overlays produced by
hardware.deviceTree.overlays on the generation side still take
precedence over same-named vendor ones.

Related: #1946

Assisted-by: Claude sonnet 5 high
This commit is contained in:
eymeric committed 2026-09-27 11:00:58 +02:00
1 parent 30d48a0ec6
commit 34fef44f65
1 file changed
+20 -2
+20 -2
View File
@@ -70,14 +70,32 @@ let
kept[$dst]=1
done
if [ -d "$dtbSrc/overlays" ]; then
for ovr in "$dtbSrc"/overlays/*; do
# hardware.raspberry-pi.configtxt.deviceTreeOverlays entries are
# matched by filename against the vendor .dtbo set the Raspberry Pi
# firmware ships, regardless of whether the *base* dtb above came
# from the generation or from firmwareBoot. Stage those
# unconditionally so config.txt's "dtoverlay=" lines have a target
# to apply, even when useGenerationDeviceTree = true.
if [ -d "$firmwareBoot/overlays" ]; then
for ovr in "$firmwareBoot"/overlays/*; do
dst="$target/overlays/$(basename "$ovr")"
copyForced "$ovr" "$dst"
kept[$dst]=1
done
fi
# When useGenerationDeviceTree also produced its own overlays
# (built via hardware.deviceTree.overlays), stage those too,
# letting them take precedence over same-named vendor overlays.
if [ "$dtbSrc" != "$firmwareBoot" ] && [ -d "$dtbSrc/overlays" ]; then
for ovr in "$dtbSrc"/overlays/*; do
dst="$target/overlays/$(basename "$ovr")"
copyForced "$ovr" "$dst"
kept[$dst]=1
done
fi
# Prune stale device trees / overlays.
for fn in "$target"/*.dtb "$target"/overlays/*; do
if [ "''${kept[$fn]:-}" != 1 ]; then