From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] firmware: handle firmware files being links correctly
Date: Wed, 17 Sep 2025 11:58:34 +0200 [thread overview]
Message-ID: <20250917095834.2727068-1-s.hauer@pengutronix.de> (raw)
Sometimes firmware files can be links. When rebuilding barebox correctly
rebuilds the firmware when file the link points to is updated, but the
firmware is not rebuilt when the link itself is changed to link to
another file.
Fix this by including the sha256sum directly in the generated assembly
file by using .byte rather than generating a file containing the
binary sha256sum and include that using .incbin. This way the generated
assembly file for sure changes when the firmware file changes and it's
rebuilt when necessary (and not when it's not).
Reproducer:
export ARCH=arm
make imx_v8_defconfig
echo foo > firmware/foo
echo bar > firmware/bar
ln -sf foo firmware/imx8mm-bl31.bin
make
The following should rebuild the barebox image including the updated
firmware, but doesn't:
ln -sf bar firmware/imx8mm-bl31.bin
make
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
firmware/Makefile | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/firmware/Makefile b/firmware/Makefile
index 0c9da2996f..df9f277475 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -57,6 +57,8 @@ FWSTR = $(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))
FWNAME_EXISTS = $(if $(wildcard $(FIRMWARE_DIR)/$(FWNAME)),1,0)
filechk_fwbin = { \
+ SHA=$$(sha256sum $(FIRMWARE_DIR)/$(FWNAME) | sed 's/ .*$$//;s/../0x&, /g;s/, $$//') ;\
+ \
echo "/* Generated by $(src)/Makefile */" ;\
echo "\#include <asm-generic/pointer.h>" ;\
echo ".section .note.GNU-stack,\"\",%progbits" ;\
@@ -80,7 +82,7 @@ filechk_fwbin = { \
echo " .p2align ASM_LGPTR" ;\
echo ".global _fw_$(FWSTR)_sha_start" ;\
echo "_fw_$(FWSTR)_sha_start:" ;\
- echo " .incbin \"$(fwobjdir)/$(FWNAME).sha.bin\"" ;\
+ echo " .byte $${SHA}" ;\
echo ".global _fw_$(FWSTR)_sha_end" ;\
echo "_fw_$(FWSTR)_sha_end:" ;\
}
@@ -89,20 +91,12 @@ filechk_fwbin_ext = { \
$(filechk_fwbin) ;\
}
-$(obj)/%.gen.S: $(obj)/%.sha.bin FORCE
+$(obj)/%.gen.S: FORCE
$(call filechk,fwbin,.rodata.$(FWSTR),)
-$(obj)/%.extgen.S: $(obj)/%.sha.bin FORCE
+$(obj)/%.extgen.S: FORCE
$(call filechk,fwbin_ext,.pblext.$(FWSTR),a)
-$(obj)/%.sha.bin: $(obj)/%.sum FORCE
- $(call if_changed,sha256bin)
-
-$(obj)/%.sum: FORCE
- $(if $(wildcard $(FIRMWARE_DIR)/$*), $(call if_changed,sha256sum,$(FIRMWARE_DIR)/$*), @touch $@)
-
-clean-files += *.sha.bin *.sum
-
# This dependency is used if missing firmware should fail the build immediately
fwdep-required-y = $(FIRMWARE_DIR)/%
# This dependency expands to nothing if the file doesn't exist. This allows
--
2.47.3
next reply other threads:[~2025-09-17 9:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 9:58 Sascha Hauer [this message]
2025-09-17 10:06 ` Sascha Hauer
2025-09-17 10:21 ` Ahmad Fatoum
2025-09-17 13:04 ` Sascha Hauer
2025-09-18 14:24 ` 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=20250917095834.2727068-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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