Skip to contentSkip to conversation

scripts/Makefile.lib: increase detail for dtsi debug output

PATCH In review E Shattow 1 participant 2 messages Sep 1, 2025 – Sep 3, 2025 Kbuild

lore
Share & tools
lore

E Shattow

author
#0 lore raw

PATCH v2 1/1 scripts/Makefile.lib: increase detail for dtsi debug output

Skip automatic dtsi selection if ARCH is not defined and introduce u_boot_dtsi_search for use with foreach method to implement the automatic dtsi inclusion. Increase code re-use and detail for debug output.

Detailed dtsi automatic selection debug output when DEVICE_TREE_DEBUG=1
- Indicate when key is undefined and skip undefined search pattern
- Indicate when search pattern is found or not found, and the pattern
- Show values of defined keys

---
 scripts/Makefile.lib | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
scripts/Makefile.lib +23 -11
index 5db2fbc418a..0d70868a339 100644
@@ -195,21 +195,33 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
 ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
 
 # Try these files in order to find the U-Boot-specific .dtsi include file
+ifneq ($(strip $(ARCH)),)
+
 u_boot_dtsi_loc = $(srctree)/arch/$(ARCH)/dts/
 
-u_boot_dtsi_options = $(strip $(wildcard $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi) \
+u_boot_dtsi_search = $(<) \
+	$(CONFIG_SYS_SOC) $(CONFIG_SYS_CPU) $(CONFIG_SYS_VENDOR)
+
+u_boot_dtsi_pattern = $(eval x=$$(patsubst "%",%,$(i)))$(strip \
+	$(and $(x),$(wildcard \
+	$(u_boot_dtsi_loc)$(basename $(notdir $(x)))-u-boot.dtsi)))
+
+u_boot_dtsi_options = $(strip \
+	$(foreach i,$(value u_boot_dtsi_search),$(u_boot_dtsi_pattern)) \
 	$(wildcard $(u_boot_dtsi_loc)u-boot.dtsi))
 
-u_boot_dtsi_options_raw = $(warning Automatic .dtsi inclusion: options: \
-	$(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)u-boot.dtsi ... \
-	found: $(if $(u_boot_dtsi_options),"$(u_boot_dtsi_options)",nothing!))
+u_boot_dtsi_pattern_raw = $(eval x=$$(patsubst "%",%,$(i))) \
+	$(i)=$(if $(x),$(and $(x),$(x) $(if $(u_boot_dtsi_pattern),,not) \
+	found @ $(u_boot_dtsi_loc)$(basename $(notdir $(x)))-u-boot.dtsi),(undefined)) ||
+
+u_boot_dtsi_options_raw = $(strip \
+	Automatic inclusion \
+	$(or $(u_boot_dtsi_options),(undefined)) from search: \
+	$(foreach i,$(value u_boot_dtsi_search),$(u_boot_dtsi_pattern_raw)) \
+	u-boot.dtsi $(if $(wildcard $(u_boot_dtsi_loc)u-boot.dtsi),,not) \
+	found @ $(u_boot_dtsi_loc)u-boot.dtsi)
+
+endif
 
 # Uncomment for debugging
 # This shows all the files that were considered and the one that we chose.

base-commit: e4c8b32d03d7ecffd586b7d33336603ad639d7c0

Signature · 1 line
2.50.0
author
#1 lore raw
Quoted 19 lines · E Shattow

Skip automatic dtsi selection if ARCH is not defined and introduce u_boot_dtsi_search for use with foreach method to implement the automatic dtsi inclusion. Increase code re-use and detail for debug output.

Detailed dtsi automatic selection debug output when DEVICE_TREE_DEBUG=1
- Indicate when key is undefined and skip undefined search pattern
- Indicate when search pattern is found or not found, and the pattern
- Show values of defined keys

---
 scripts/Makefile.lib | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
scripts/Makefile.lib +0 -0
index 5db2fbc418a..0d70868a339 100644

scripts/Makefile.lib cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \ · line 199

Quoted 5 lines
scripts/Makefile.lib +1 -0
@@ -195,21 +195,33 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
 ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
 
 
 # Try these files in order to find the U-Boot-specific .dtsi include file
+ifneq ($(strip $(ARCH)),)

I think this guarding for non-empty $(ARCH) could be changed to become:

ifneq ($(filter $(obj),dts/upstream/src/$(ARCH) arch/$(ARCH)/dts),)

it could be $(obj) or $(src) I am not sure if either is correct, but they do seem to compile for OF_UPSTREAM and non-OF_UPSTREAM target. This avoids the work and debug output unless actually compiling in the dts target directory. Am I missing any detail here?

Quoted 28 lines
scripts/Makefile.lib +13 -11
+
 u_boot_dtsi_loc = $(srctree)/arch/$(ARCH)/dts/
 
-u_boot_dtsi_options = $(strip $(wildcard $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi) \
-	$(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi) \
+u_boot_dtsi_search = $(<) \
+	$(CONFIG_SYS_SOC) $(CONFIG_SYS_CPU) $(CONFIG_SYS_VENDOR)
+
+u_boot_dtsi_pattern = $(eval x=$$(patsubst "%",%,$(i)))$(strip \
+	$(and $(x),$(wildcard \
+	$(u_boot_dtsi_loc)$(basename $(notdir $(x)))-u-boot.dtsi)))
+
+u_boot_dtsi_options = $(strip \
+	$(foreach i,$(value u_boot_dtsi_search),$(u_boot_dtsi_pattern)) \
 	$(wildcard $(u_boot_dtsi_loc)u-boot.dtsi))
 
-u_boot_dtsi_options_raw = $(warning Automatic .dtsi inclusion: options: \
-	$(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi \
-	$(u_boot_dtsi_loc)u-boot.dtsi ... \
-	found: $(if $(u_boot_dtsi_options),"$(u_boot_dtsi_options)",nothing!))
+u_boot_dtsi_pattern_raw = $(eval x=$$(patsubst "%",%,$(i))) \
+	$(i)=$(if $(x),$(and $(x),$(x) $(if $(u_boot_dtsi_pattern),,not) \
+	found @ $(u_boot_dtsi_loc)$(basename $(notdir $(x)))-u-boot.dtsi),(undefined)) ||

scripts/Makefile.lib cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \

Quoted 10 lines
scripts/Makefile.lib +9 -0
+
+u_boot_dtsi_options_raw = $(strip \
+	Automatic inclusion \
+	$(or $(u_boot_dtsi_options),(undefined)) from search: \
+	$(foreach i,$(value u_boot_dtsi_search),$(u_boot_dtsi_pattern_raw)) \
+	u-boot.dtsi $(if $(wildcard $(u_boot_dtsi_loc)u-boot.dtsi),,not) \
+	found @ $(u_boot_dtsi_loc)u-boot.dtsi)
+
 
+endif

And move this endif later down to insert above the 'dtc_cpp_flags ='... line, to encompass debugging and avoid adding dtc_cpp_flags with an invalid generated path.

Quoted 5 lines
scripts/Makefile.lib +0 -0
 # Uncomment for debugging

# This shows all the files that were considered and the one that we chose.

base-commit: e4c8b32d03d7ecffd586b7d33336603ad639d7c0

Tested at least with starfive_visionfive2_defconfig from v2025.01 (before OF_UPSTREAM) and v2025.07 (adopted OF_UPSTREAM).

-E