[PATCH 1/3] firmware: support optional firmware in barebox proper

Ahmad Fatoum a.fatoum at pengutronix.de
Fri May 3 03:32:28 PDT 2024


For firmware used in the prebootloader, missing firmware is handled
according to the CONFIG_MISSING_FIRMWARE_ERROR symbol:

  - If set, barebox will throw an error when assmebling the final image
    with a list of missing firmware

  - If unset, a warning will be printed for each barebox image that
    can't be built due to missing firmware and all

This replaced the previous behavior of make throwing an error due to a
missing dependency, which broke the ability to use a single config for
multiple platforms, where only some have missing firmware.

Nothing of the sort was done for firmware in barebox proper. We only
have that on Layerscape for PPA (EL3 Secure Monitor) and FMan (NIC).

With the addition of Layerscape to multi_v8_defconfig, building that
config now also throws aforementioned make errors.

This is now also resolved depending on CONFIG_MISSING_FIRMWARE_ERROR:

  - If set, an immediate make error occurs as before as we can't
    pinpoint which of the enabled barebox images will at runtime
    instantiate the driver that requires the firmware.

  - If unset, we continue build as normal and the size of the firmware
    as determined at runtime will be zero bytes. Code in barebox
    proper is expected to check for that and report an error.

Fixes: 9922f78ec58c3a7b8d28427f470edc469627c9cd.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 firmware/Makefile | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index 83ce77f510ba..d5e4cee8594b 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -61,7 +61,7 @@ filechk_fwbin = { \
 	echo "_fw_$(FWSTR)_start:"				;\
 	echo "\#if $(FWNAME_EXISTS)"				;\
 	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
-	echo "\#else"						;\
+	echo "\#elif defined(__PBL__)"				;\
 	echo "ASM_PTR _fwname_$(FWSTR)"				;\
 	echo "\#endif"						;\
 	echo ".global _fw_$(FWSTR)_end"				;\
@@ -102,13 +102,25 @@ $(obj)/%.sum: FORCE
 
 clean-files += *.sha.bin *.sum
 
-# The .o files depend on the binaries directly; the .S files don't.
-$(patsubst %.gen.o,$(obj)/%.gen.o, $(obj-pbl-y)): $(obj)/%.gen.o: $(fwdir)/%
+# This dependency is used if missing firmware should fail the build immediately
+fwdep-required-y = $(fwdir)/%
+# This dependency expands to nothing if the file doesn't exist. This allows
+# delaying the firmware check:
+#
+#   - to final assembly of the PBL image for pbl-firmware
+#   - to runtime for firmware in barebox proper
+#
+# This way, we allow users to build defconfigs with multiple images without requiring
+# them to install all firmware for all platforms if only few are of interest.
+fwdep-required-n = $$(wildcard $(fwdir)/%)
 
-# The same for pbl:
 .SECONDEXPANSION:
-$(patsubst %.gen.o,$(obj)/%.gen.pbl.o, $(obj-pbl-y) $(pbl-y)): $(obj)/%.gen.pbl.o: $$(wildcard $(fwdir)/%)
-$(patsubst %.extgen.o,$(obj)/%.extgen.pbl.o, $(pbl-fwext-y)): $(obj)/%.extgen.pbl.o: $$(wildcard $(fwdir)/%)
+# The .o files depend on the binaries directly if available; the .S files don't.
+$(patsubst %.gen.o,$(obj)/%.gen.pbl.o, $(obj-pbl-y) $(pbl-y)): $(obj)/%.gen.pbl.o: $(fwdep-required-n)
+$(patsubst %.extgen.o,$(obj)/%.extgen.pbl.o, $(pbl-fwext-y)): $(obj)/%.extgen.pbl.o: $(fwdep-required-n)
+# For barebox proper, firmware existance is either checked here
+# or in driver code by checking whether size != 0
+$(patsubst %.gen.o,$(obj)/%.gen.o, $(obj-pbl-y)): $(obj)/%.gen.o: $(fwdep-required-$(CONFIG_MISSING_FIRMWARE_ERROR))
 
 pbl-y += $(pbl-fwext-y)
 
-- 
2.39.2




More information about the barebox mailing list