From 8c5214f6d424c46e6e25d24cbc0c86034cfcdbed Mon Sep 17 00:00:00 2001 From: Olivier Benjamin Date: Wed, 7 May 2025 18:08:32 +0200 Subject: [PATCH] rpi-firmware: support installing extra files There are several use cases for installing additional files in the boot partition that is read by the RPi firmware. - autoboot.txt is an optional configuration file for the RPi firmware [1]. Supporting several autoboot files will enable A/B setups, as using the renameat2() system call with the RENAME_EXCHANGE flag will let users atomically replace one autoboot configuration file with the other. This improves reliability in the case of an update which could potentially be interrupted. - Multiple cmdline.txt files are useful in the context of a new [boot_partition] conditional filter introduced in config.txt in commit [2]. This is useful for A/B systems to have identical BootFS partitions on both slots, and not have to edit the kernel command line to ensure the kernel will load the right rootFS after update of the BootFS. - rpi-firmware contains DTB overlays for many "standard" hats, but a custom hat may require a custom overlay. Although it is possible to install additional files in the boot partition in the post-image script, it is very convenient to be able to use the standard RPi post-image script in board/raspberrypi/post-image.sh. That script looks in $BINARIES_DIR/rpi-firmware, so it is convenient to be able to place additional files there. Add the option BR2_PACKAGE_RPI_FIRMWARE_EXTRA_FILES which is simply a list of files to be copied to $BINARIES_DIR/rpi-firmware, which will eventually end up as the boot partition. Make sure that this is done as the last step of RPI_FIRMWARE_INSTALL_IMAGES_CMDS, so the files can override files installed by earlier steps. [1] https://www.raspberrypi.com/documentation/computers/config_txt.html#autoboot-txt [2] https://github.com/raspberrypi/rpi-eeprom/commit/d50b2b32f162292ab6e235932075ce00bddda4ae Signed-off-by: Olivier Benjamin Signed-off-by: Arnout Vandecappelle --- package/rpi-firmware/Config.in | 9 +++++++++ package/rpi-firmware/rpi-firmware.mk | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/package/rpi-firmware/Config.in b/package/rpi-firmware/Config.in index 4dda33a713..625f0ccf67 100644 --- a/package/rpi-firmware/Config.in +++ b/package/rpi-firmware/Config.in @@ -100,4 +100,13 @@ config BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS overlays, to support HATs (Hardware Attached on Top, add-on modules). +config BR2_PACKAGE_RPI_FIRMWARE_EXTRA_FILES + string "List of path(s) to additional file(s) in boot partition" + help + Space-separated path(s) to file(s) that should be stored + in the boot partition. They will be stored under their own + name in rpi-firmware. They can override any of the other + files. Use cases include autoboot configuration, + alternative cmdline.txt files, additional DTB overlays. + endif # BR2_PACKAGE_RPI_FIRMWARE diff --git a/package/rpi-firmware/rpi-firmware.mk b/package/rpi-firmware/rpi-firmware.mk index 83d0808990..f1b1b110ce 100644 --- a/package/rpi-firmware/rpi-firmware.mk +++ b/package/rpi-firmware/rpi-firmware.mk @@ -62,12 +62,20 @@ define RPI_FIRMWARE_INSTALL_DTB_OVERLAYS endef endif +RPI_FIRMWARE_EXTRA_FILES = $(call qstrip,$(BR2_PACKAGE_RPI_FIRMWARE_EXTRA_FILES)) +define RPI_FIRMWARE_INSTALL_EXTRA_FILES + $(foreach f,$(RPI_FIRMWARE_EXTRA_FILES), \ + $(INSTALL) -D -m 0644 $(f) $(BINARIES_DIR)/rpi-firmware/$(notdir $(f)) + ) +endef + define RPI_FIRMWARE_INSTALL_IMAGES_CMDS $(RPI_FIRMWARE_INSTALL_BIN) $(RPI_FIRMWARE_INSTALL_CONFIG) $(RPI_FIRMWARE_INSTALL_CMDLINE) $(RPI_FIRMWARE_INSTALL_DTB) $(RPI_FIRMWARE_INSTALL_DTB_OVERLAYS) + $(RPI_FIRMWARE_INSTALL_EXTRA_FILES) endef $(eval $(generic-package))