mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH master 1/2] kbuild: images/Makefile: fix broken if_changed usage
Date: Thu, 14 Aug 2025 22:22:53 +0200	[thread overview]
Message-ID: <20250814202254.344010-1-a.fatoum@barebox.org> (raw)

if_changed also triggers when the command line changes by comparing the
command executed against what was written last time.

This necessarily means that there may only be a single if_changed called
per target, a rule which we violated.

This led to breakage on RISC-V, because every build triggered a relink
of the PBLs, but only every second build executed cmd_prelink__.

Switch over to if_changed_rule to fix this. This also means we need to
move the comments out of the define, so they aren't printed.

Fixes: 912696b571bb ("images: don't compute size if input file didn't change")
Fixes: 4c31478919f5 ("images: don't prelink if input file didn't change")
Fixes: c2e320f6b243 ("images: don't check for missing FW if file didn't change")
Fixes: 8ddc2d799b4a ("images: don't compare filesizes if file didn't change")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 images/Makefile | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/images/Makefile b/images/Makefile
index e20d11e1501a..03c7fdc0240b 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -69,19 +69,20 @@ quiet_cmd_elf__ ?= LD      $@
 
 PBL_CPPFLAGS	+= -fdata-sections -ffunction-sections
 
+define rule_elf
+	$(call cmd,elf__,$(*F))
+	$(call cmd,prelink__)
+endef
+
 $(obj)/%.pbl: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(BAREBOX_PIGGY_OBJS) FORCE
-	$(call if_changed,elf__,$(*F))
-	$(call if_changed,prelink__)
+	$(call if_changed_rule,elf)
 
 $(obj)/%.elf: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(BAREBOX_PIGGY_OBJS) FORCE
-	$(call if_changed,elf__,$(*F))
-	$(call if_changed,prelink__)
+	$(call if_changed_rule,elf)
 
-$(obj)/%.pblb: $(obj)/%.pbl FORCE
-	$(call if_changed,objcopy_bin,$(*F))
-	$(call if_changed,check_missing_fw,$@,$<)
-	$(call if_changed,check_file_size,$@,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
 
+# Convert the ELF into a linear binary, check for missing firmware
+# and verify file sizes:
 #
 # For each start symbol create three variables containing the
 # relevant sizes in the image:
@@ -91,6 +92,13 @@ $(obj)/%.pblb: $(obj)/%.pbl FORCE
 # PBL_IMAGE_SIZE_$(symbol)  - contains the full image size including the
 #                             compressed payload
 #
+# if MAX_PBL_xxx_SIZE_$(symbol) is defined it contains the maximum size the
+# code/memory/image for this PBL may get. Check these values.
+define rule_pblb
+	$(call cmd,objcopy_bin,$(*F))
+	$(call cmd,check_missing_fw,$@,$<)
+	$(call cmd,check_file_size,$@,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
+
 	$(eval PBL_CODE_SIZE_$* = \
 		$(shell $(srctree)/scripts/extract_symbol_offset pbl_code_size $^))
 	$(eval PBL_MEMORY_SIZE_$*= \
@@ -98,21 +106,21 @@ $(obj)/%.pblb: $(obj)/%.pbl FORCE
 	$(eval PBL_IMAGE_SIZE_$*= \
 		$(shell $(srctree)/scripts/extract_symbol_offset pbl_image_size $^))
 
-#
-# if MAX_PBL_xxx_SIZE_$(symbol) is defined it contains the maximum size the
-# code/memory/image for this PBL may get. Check these values.
-#
 	$(if $(MAX_PBL_CODE_SIZE_$*), \
-		$(call if_changed,check_size,$(PBL_CODE_SIZE_$*),$(MAX_PBL_CODE_SIZE_$*)) \
+		$(call cmd,check_size,$(PBL_CODE_SIZE_$*),$(MAX_PBL_CODE_SIZE_$*)) \
 	)
 
 	$(if $(MAX_PBL_MEMORY_SIZE_$*), \
-		$(call if_changed,check_size,$(PBL_MEMORY_SIZE_$*),$(MAX_PBL_MEMORY_SIZE_$*)) \
+		$(call cmd,check_size,$(PBL_MEMORY_SIZE_$*),$(MAX_PBL_MEMORY_SIZE_$*)) \
 	)
 
 	$(if $(MAX_PBL_IMAGE_SIZE_$*), \
-		$(call if_changed,check_size,$(PBL_IMAGE_SIZE_$*),$(MAX_PBL_IMAGE_SIZE_$*)) \
+		$(call cmd,check_size,$(PBL_IMAGE_SIZE_$*),$(MAX_PBL_IMAGE_SIZE_$*)) \
 	)
+endef
+
+$(obj)/%.pblb: $(obj)/%.pbl FORCE
+	$(call if_changed_rule,pblb)
 
 $(obj)/%.s: $(obj)/% FORCE
 	$(call if_changed,disasm)
-- 
2.39.5




             reply	other threads:[~2025-08-14 20:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14 20:22 Ahmad Fatoum [this message]
2025-08-14 20:22 ` [PATCH master 2/2] RISC-V: stacktrace: add missing header for eprintf Ahmad Fatoum

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=20250814202254.344010-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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