mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: uol@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master v2 4/7] firmware: optionally turn missing firmware errors into warnings
Date: Tue, 27 Jun 2023 07:52:36 +0200	[thread overview]
Message-ID: <20230627055239.3908872-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230627055239.3908872-1-a.fatoum@pengutronix.de>

Previous commit turned compile-time errors into link-time errors.
This commit goes a step further and allows the link to succeed
unconditionally for build coverage and then dependent on the newly
introduced CONFIG_MISSING_FIRMWARE_ERROR option abort the build with an
error code and a listing of missing firmware printed to stderr.

In any case, barebox images which contain firmware in their PBL
that's not available will be marked specially to reduce the risk
of accidentally putting them to use:

  * They're truncated to zero size

  * The final "images built:" section marks them as having firmware
    missing

  * They are omitted from the listing in the barebox-flash-images file

  * Each barebox-broken.img is accompanied with a
    barebox-broken.img.missing-firmware containing a newline delimited
    list of missing firmware images

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 firmware/Kconfig     | 14 ++++++++++++++
 firmware/Makefile    |  5 +++++
 images/Makefile      | 21 ++++++++++++++++-----
 scripts/Makefile.lib |  3 +++
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/firmware/Kconfig b/firmware/Kconfig
index 56ced00bc430..56d6d0d6c030 100644
--- a/firmware/Kconfig
+++ b/firmware/Kconfig
@@ -6,6 +6,20 @@ config EXTRA_FIRMWARE_DIR
 	string "Firmware blobs root directory"
 	default "firmware"
 
+config MISSING_FIRMWARE_ERROR
+	bool "Fail the build when required firmware is missing"
+	default y
+	help
+	  In-tree Defconfigs that enable multiple boards with different firmware
+	  binary requirements would say y here, so you don't need unrelated firmware
+	  for the build to succeed.
+
+	  Defconfigs custom-tailored to products would say n here as all boards
+	  being built should be functional and have their firmware available.
+
+	  If in doubt, say Y and refer to the documentation on where to acquire the
+	  needed firmware.
+
 config HAVE_FIRMWARE_IMX_LPDDR4_PMU_TRAIN
 	bool
 	default y
diff --git a/firmware/Makefile b/firmware/Makefile
index 1888154ce86c..27cd17b2d5b6 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -58,6 +58,11 @@ filechk_fwbin = { \
 	echo "\#endif"						;\
 	echo ".global _fw_$(FWSTR)_end"				;\
 	echo "_fw_$(FWSTR)_end:"				;\
+	echo "\#ifdef __PBL__"					;\
+	echo "    .section .missing_fw,\"a\""			;\
+	echo "_fwname_$(FWSTR):"				;\
+	echo ".ascii \"firmware/$(FWNAME)\\\\n\""		;\
+	echo "\#endif" 						;\
 }
 
 __fwbin_sha = { \
diff --git a/images/Makefile b/images/Makefile
index c93f9e268978..9f8a9e910174 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -72,6 +72,8 @@ $(obj)/%.pbl: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(obj)/piggy.o $(obj)/sha_sum.o FOR
 
 $(obj)/%.pblb: $(obj)/%.pbl FORCE
 	$(call if_changed,objcopy_bin,$(*F))
+	$(Q)$(OBJCOPY) -O binary --only-section=.missing_fw $< $@.missing-firmware
+	$(Q)[ -s $@.missing-firmware ] || rm -f $@.missing-firmware
 	$(call cmd,check_file_size,$@,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
 
 #
@@ -127,10 +129,14 @@ $(obj)/barebox.z: $(obj)/../barebox.bin FORCE
 
 # %.img - create a copy from another file
 # ----------------------------------------------------------------
+
+missing_fw = $(strip $(wildcard $(obj)/$(FILE_$(@F)).missing-firmware $(basename $(obj)/$(FILE_$(@F))).missing-firmware))
+
 .SECONDEXPANSION:
 $(obj)/%.img: $(obj)/$$(FILE_$$(@F))
 	$(Q)if [ -z $(FILE_$(@F)) ]; then echo "FILE_$(@F) empty!"; false; fi
-	$(call if_changed,shipped)
+	$(Q)$(if $(missing_fw),cat $(missing_fw) >$@.missing-firmware,rm -f $@.missing-firmware)
+	$(call if_changed,$(if $(missing_fw),0size,shipped))
 
 board = $(srctree)/arch/$(SRCARCH)/boards
 objboard = $(objtree)/arch/$(SRCARCH)/boards
@@ -194,10 +200,15 @@ multi-image-build:
 
 images: $(image-y-path) $(flash-link) $(flash-list) FORCE
 	@echo "images built:"
-	@for i in $(image-y); do echo $$i; done
+	@for i in $(image-y); do \
+	  if [ -s $(obj)/$$i ]; then echo $$i; \
+	  else >&2 echo "** firmware missing for $$i **"; \
+	  $(if $(CONFIG_MISSING_FIRMWARE_ERROR), >&2 sed 's/^/\t/' <$(obj)/$${i}.missing-firmware; missing=1;) \
+	  fi; done; if [ -n "$$missing" ]; then \
+	    echo >&2 "Firmware missing in CONFIG_MISSING_FIRMWARE_ERROR=y build"; exit 1; fi
 
 __images_install: images
-	@for i in $(image-y-path); do install -t "$(INSTALL_PATH)" $$i; done
+	@for i in $(image-y-path); do if [ -s $$i ]; then install -t "$(INSTALL_PATH)" $$i; fi; done
 
 PHONY += __images_install
 
@@ -205,10 +216,10 @@ $(flash-link): $(link-dest) FORCE
 	$(call if_changed,ln)
 
 $(flash-list): $(image-y-path)
-	@for i in $^; do echo $$i; done > $@
+	@for i in $^; do if [ -s $$i ]; then echo $$i; fi; done > $@
 
 clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
 	start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
 	*.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
-	start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped
+	start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped *.missing-firmware
 clean-files += pbl.lds
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 90cfa579e5d5..e25e0d6eb25e 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -235,6 +235,9 @@ endef
 # Shipped files
 # ===========================================================================
 
+quiet_cmd_0size = 0SIZE $@
+cmd_0size = : > $@
+
 quiet_cmd_shipped = SHIPPED $@
 cmd_shipped = cat $< > $@
 
-- 
2.39.2




  parent reply	other threads:[~2023-06-27  5:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27  5:52 [PATCH master v2 0/7] " Ahmad Fatoum
2023-06-27  5:52 ` [PATCH master v2 1/7] firmware: reference pointer alignment defined in <asm-generic/pointer.h> Ahmad Fatoum
2023-06-28  7:14   ` Sascha Hauer
2023-06-27  5:52 ` [PATCH master v2 2/7] firmware: mark firmware used in PBL as pbl-only Ahmad Fatoum
2023-06-27  5:52 ` [PATCH master v2 3/7] firmware: turn missing firmware into linker error Ahmad Fatoum
2023-06-27  5:52 ` Ahmad Fatoum [this message]
2023-06-27  5:52 ` [PATCH master v2 5/7] ARM64: Rockchip: gracefully handle missing firmware Ahmad Fatoum
2023-06-27  5:52 ` [PATCH master v2 6/7] ARM64: unset CONFIG_MISSING_FIRMWARE_ERROR for Rockchip/i.MX Ahmad Fatoum
2023-06-27  5:52 ` [PATCH master v2 7/7] firmware: don't hardcode firmware paths in srctree for existence check Ahmad Fatoum
2023-06-28  8:45 ` [PATCH master v2 0/7] firmware: optionally turn missing firmware errors into warnings Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230627055239.3908872-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=uol@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox