[Concept,01/17] kbuild: Use relative paths in generated .incbin directives

Message ID 20260316183050.3855921-2-sjg@u-boot.org
State New
Headers
Series Add automatic memory-leak detection to U-Boot tests |

Commit Message

Simon Glass March 16, 2026, 6:30 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

The generated .S files for fonts, images, splash screens, signer
binaries and EFI apps use .incbin with the full prerequisite path.
When building with O= this bakes an absolute path into the .S file.
If the build directory is later used on a different machine (e.g. in a
container), the assembler cannot find the source file.

Use $(src)/$(notdir $<) instead of $< so the .incbin directive contains
a source-relative path like drivers/video/images/u_boot.bmp rather than
an absolute one. Add -Wa,-I$(srctree) to the assembler flags so the
assembler can resolve these paths.

The DTB and DTBO rules are left unchanged since their prerequisites are
generated files in the build directory.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 scripts/Makefile.lib | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
  

Patch

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e2d0cb78bc9..8ccab5444cd 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -174,6 +174,7 @@  c_flags        = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude)     \
 		 $(basename_flags) $(modname_flags)
 
 a_flags        = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude)     \
+		 -Wa,-I$(srctree)                                   \
 		 $(__a_flags) $(modkern_aflags)
 
 cpp_flags      = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude)     \
@@ -494,7 +495,7 @@  cmd_S_ttf=						\
 	echo '.balign 16';				\
 	echo '.global __ttf_$(*F)_begin';		\
 	echo '__ttf_$(*F)_begin:';			\
-	echo '.incbin "$<" ';				\
+	echo '.incbin "$(src)/$(notdir $<)" ';				\
 	echo '__ttf_$(*F)_end:';			\
 	echo '.global __ttf_$(*F)_end';			\
 	echo '.balign 16';				\
@@ -514,7 +515,7 @@  cmd_S_signer=						\
 	echo '.balign 16';				\
 	echo '.global __signer_$(subst .,_,$(*F))_begin';		\
 	echo '__signer_$(subst .,_,$(*F))_begin:';			\
-	echo '.incbin "$<" ';				\
+	echo '.incbin "$(src)/$(notdir $<)" ';				\
 	echo '__signer_$(subst .,_,$(*F))_end:';			\
 	echo '.global __signer_$(subst .,_,$(*F))_end';		\
 	echo '.balign 16';				\
@@ -535,7 +536,7 @@  cmd_S_splash=						\
 	echo '.balign 16';				\
 	echo '.global __splash_$(*F)_logo_begin';		\
 	echo '__splash_$(*F)_logo_begin:';			\
-	echo '.incbin "$<" ';				\
+	echo '.incbin "$(src)/$(notdir $<)" ';				\
 	echo '__splash_$(*F)_logo_end:';			\
 	echo '.global __splash_$(*F)_logo_end';			\
 	echo '.balign 16';				\
@@ -554,7 +555,7 @@  cmd_S_image=						\
 	echo '.balign 16';				\
 	echo '.global __image_$(*F)_begin';		\
 	echo '__image_$(*F)_begin:';			\
-	echo '.incbin "$<" ';				\
+	echo '.incbin "$(src)/$(notdir $<)" ';				\
 	echo '__image_$(*F)_end:';			\
 	echo '.global __image_$(*F)_end';		\
 	echo '.balign 16';				\
@@ -594,7 +595,7 @@  cmd_S_efi=					\
 	echo '.balign 16';			\
 	echo '.global __efi_$*_begin';		\
 	echo '__efi_$*_begin:';			\
-	echo '.incbin "$<" ';			\
+	echo '.incbin "$(src)/$(notdir $<)" ';			\
 	echo '__efi_$*_end:';			\
 	echo '.global __efi_$*_end';		\
 	echo '.balign 16';			\