Skip to contentSkip to conversation

build: Respect CONFIG_SPL_BUILD in DT sources

PATCH In review Fabio Estevam 4 participants 10 messages Apr 25, 2025

Subsystems (3)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/4 build: Respect CONFIG_SPL_BUILD in DT sources

From: Marek Vasut <[email protected]>

Currently the U-Boot SPL build uses the same DTBs that were generated during U-Boot proper build, and calls 'fdtgrep' on those DTBs to filter out uninteresting nodes and properties. Those U-Boot proper DTBs are built from DTS which are first preprocessed by CPP, but that CPP is invoked in U-Boot proper build context and effectively ignores the CONFIG_SPL_BUILD macro. In case the CONFIG_SPL_BUILD macro is used in any .dts file, the content of the macro is removed by CPP.

Fix this by building a separate set of DTBs for the SPL, which are preprocessed by CPP with -DCONFIG_SPL_BUILD set. Use the same way for the other PLs.

---
 dts/Makefile         |  5 ++++-
 scripts/Makefile.lib | 11 +++++++++++
 scripts/Makefile.xpl |  7 ++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)
dts/Makefile +4 -1
index 86bf8dc2156..53cab9a37a4 100644
@@ -32,7 +32,10 @@ else
 DTB := $(dt_dir)/$(DEVICE_TREE).dtb
 endif
 
-$(obj)/dt-$(SPL_NAME).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE
+$(obj)/dt-$(SPL_NAME).tmp.dtb: $(patsubst %.dtb,%.dts,$(DTB)) FORCE
+	$(call if_changed,dtc)
+
+$(obj)/dt-$(SPL_NAME).dtb: $(obj)/dt-$(SPL_NAME).tmp.dtb $(objtree)/tools/fdtgrep FORCE
 	mkdir -p $(dir $@)
 	$(call if_changed,fdtgrep)
 
scripts/Makefile.lib +11 -0
index 83fd5ff6c31..8d6f67caee2 100644
@@ -202,6 +202,16 @@ endif
 dtsi_include_list = $(strip $(u_boot_dtsi_options_debug) \
 	$(notdir $(firstword $(u_boot_dtsi_options))))
 
+ifeq ($(CONFIG_SPL_BUILD),y)
+dtc_cpp_xpl_flags = -DCONFIG_XPL_BUILD -DCONFIG_SPL_BUILD
+else ifeq ($(CONFIG_TPL_BUILD),y)
+dtc_cpp_xpl_flags = -DCONFIG_XPL_BUILD -DCONFIG_TPL_BUILD
+else ifeq ($(CONFIG_VPL_BUILD),y)
+dtc_cpp_xpl_flags = -DCONFIG_XPL_BUILD -DCONFIG_VPL_BUILD
+else
+dtc_cpp_xpl_flags =
+endif
+
 # Modified for U-Boot
 upstream_dtsi_include = $(addprefix -I, $(srctree)/dts/upstream/src/ \
 	$(sort $(dir $(wildcard $(srctree)/dts/upstream/src/$(ARCH)/*/*))) \
@@ -214,6 +224,7 @@ dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
 		 -I$(srctree)/arch/$(ARCH)/dts/include                   \
 		 -I$(srctree)/include                                    \
 		 $(upstream_dtsi_include)                                \
+		 $(dtc_cpp_xpl_flags)                                    \
 		 -D__ASSEMBLY__                                          \
 		 -undef -D__DTS__
 
scripts/Makefile.xpl +6 -1
index 43f27874f9f..ff19cb22f94 100644
@@ -590,11 +590,16 @@ endif
 
 SPL_OF_LIST_TARGETS = $(patsubst %,dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
 SHRUNK_ARCH_DTB = $(addprefix $(obj)/,$(SPL_OF_LIST_TARGETS))
+SPL_TMP_OF_LIST_TARGETS = $(patsubst %,dts/%.spl.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
+SHRUNK_ARCH_TMP_DTB = $(addprefix $(obj)/,$(SPL_TMP_OF_LIST_TARGETS))
 $(sort $(dir $(SHRUNK_ARCH_DTB))):
 	$(shell [ -d $@ ] || mkdir -p $@)
 
 .SECONDEXPANSION:
-$(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, $(dt_dir)/%, $$@) $(dir $(SHRUNK_ARCH_DTB))
+$(SHRUNK_ARCH_TMP_DTB): $$(patsubst %.spl.dtb,%.dts,$$(patsubst $(obj)/dts/%, $(dt_dir)/%, $$@)) $(dir $(SHRUNK_ARCH_TMP_DTB))
+	$(call if_changed,dtc)
+
+$(SHRUNK_ARCH_DTB): $$(patsubst %.dtb,%.spl.dtb,$$@)  $(dir $(SHRUNK_ARCH_DTB))
 	$(call if_changed,fdtgrep)
 
 targets += $(SPL_OF_LIST_TARGETS)
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH 2/4 arm64: dts: imx8mn: Remove unreferenced clock-controller clocks in SPL DTs

From: Marek Vasut <[email protected]>

Since 50cdd3f74af3 ("clk: imx: clk-imx8mn Fix nand and spi clock parent"), drivers/clk/imx/clk-imx8mn.c clk_get_by_name(dev, "osc_24m", &osc_24m_clk) fails with error -22 EINVAL in SPL. This is because clk_get_by_name() in the end calls fdtdec_parse_phandle_with_args(), which iterates over all phandles in clock-controller@30380000 { clocks = <&osc_32k>, <&osc_24m>, ... } node 'clocks' property in an attempt to find the "osc_24m" clock, but fails to resolve the &osc_32k phandle and returns with -EINVAL.

Remove the clocks property phandles which cannot be resolved because their matching nodes are removed from SPL DTs, so fdtdec_parse_phandle_with_args() can resolve all the remaining valid nodes and successfully look up the osc_24m clock.

Fixes 50cdd3f74af3 ("clk: imx: clk-imx8mn Fix nand and spi clock parent")
---
 arch/arm/dts/imx8mn-u-boot.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/imx8mn-u-boot.dtsi +4 -0
index 96a6df94c6c..bb0e5b4e31c 100644
@@ -51,6 +51,10 @@
 	/delete-property/ assigned-clocks;
 	/delete-property/ assigned-clock-parents;
 	/delete-property/ assigned-clock-rates;
+#ifdef CONFIG_SPL_BUILD
+	clocks = <&osc_24m>;
+	clock-names = "osc_24m";
+#endif
 };
 
 #ifdef CONFIG_FSL_CAAM
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/4] arm64: dts: imx8mn: Remove unreferenced clock-controller clocks in SPL DTs

Quoted 27 lines · Fabio Estevam

From: Marek Vasut <[email protected]>

Since 50cdd3f74af3 ("clk: imx: clk-imx8mn Fix nand and spi clock parent"), drivers/clk/imx/clk-imx8mn.c clk_get_by_name(dev, "osc_24m", &osc_24m_clk) fails with error -22 EINVAL in SPL. This is because clk_get_by_name() in the end calls fdtdec_parse_phandle_with_args(), which iterates over all phandles in clock-controller@30380000 { clocks = <&osc_32k>, <&osc_24m>, ... } node 'clocks' property in an attempt to find the "osc_24m" clock, but fails to resolve the &osc_32k phandle and returns with -EINVAL.

Remove the clocks property phandles which cannot be resolved because their matching nodes are removed from SPL DTs, so fdtdec_parse_phandle_with_args() can resolve all the remaining valid nodes and successfully look up the osc_24m clock.

Fixes 50cdd3f74af3 ("clk: imx: clk-imx8mn Fix nand and spi clock parent")
---
  arch/arm/dts/imx8mn-u-boot.dtsi | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/dts/imx8mn-u-boot.dtsi +0 -0
index 96a6df94c6c..bb0e5b4e31c 100644

arch/arm/dts/imx8mn-u-boot.dtsi line 58

Quoted 8 lines
arch/arm/dts/imx8mn-u-boot.dtsi +4 -0
@@ -51,6 +51,10 @@
  	/delete-property/ assigned-clocks;
  	/delete-property/ assigned-clock-parents;
  	/delete-property/ assigned-clock-rates;
+#ifdef CONFIG_SPL_BUILD
+	clocks = <&osc_24m>;
+	clock-names = "osc_24m";
+#endif
  };

See my comment on 4/4 .

author reviewer
#3 lore raw

PATCH 3/4 Revert "arm64: dts: imx8mn: Include 32kHz oscillator clock in SPL DTs"

In reply to Fabio Estevam

From: Marek Vasut <[email protected]>

The 32 kHz oscillator was included in DT as a temporary workaround for the v2025.01 release. With a more appropriate fix in place for v2025.04, the workaround can be reverted.

---
 arch/arm/dts/imx8mn-u-boot.dtsi | 5 -----
 1 file changed, 5 deletions(-)
arch/arm/dts/imx8mn-u-boot.dtsi +0 -5
index bb0e5b4e31c..8a9ef54c91d 100644
@@ -72,11 +72,6 @@
 	bootph-all;
 };
 
-&osc_32k {
-	bootph-pre-ram;
-	bootph-all;
-};
-
 #ifdef CONFIG_FSL_CAAM
 &sec_jr0 {
 	bootph-pre-ram;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 3/4] Revert "arm64: dts: imx8mn: Include 32kHz oscillator clock in SPL DTs"

Quoted 17 lines · Fabio Estevam

From: Marek Vasut <[email protected]>

The 32 kHz oscillator was included in DT as a temporary workaround for the v2025.01 release. With a more appropriate fix in place for v2025.04, the workaround can be reverted.

---
  arch/arm/dts/imx8mn-u-boot.dtsi | 5 -----
  1 file changed, 5 deletions(-)
arch/arm/dts/imx8mn-u-boot.dtsi +0 -0
index bb0e5b4e31c..8a9ef54c91d 100644

arch/arm/dts/imx8mn-u-boot.dtsi line 78

Quoted 7 lines
arch/arm/dts/imx8mn-u-boot.dtsi +0 -4
@@ -72,11 +72,6 @@
  	bootph-all;
  };
 
-&osc_32k {
-	bootph-pre-ram;
-	bootph-all;
-};

See my comment on 4/4 , no, let's keep this.

author reviewer
#5 lore raw

PATCH 4/4 arm64: dts: imx8mm: Allow osc_24m to be available in SPL

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

Align the osc_24m node with the imx8mn, so that it can be available in SPL.

This fixes a long pause in SPL when loading U-Boot proper.

---
 arch/arm/dts/imx8mm-u-boot.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/imx8mm-u-boot.dtsi +4 -0
index abb3aa5b635..a1ae2371773 100644
@@ -229,6 +229,10 @@
 	/delete-property/ assigned-clocks;
 	/delete-property/ assigned-clock-parents;
 	/delete-property/ assigned-clock-rates;
+#ifdef CONFIG_SPL_BUILD
+	clocks = <&osc_24m>;
+	clock-names = "osc_24m";
+#endif
 };
 
 &iomuxc {
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 4/4] arm64: dts: imx8mm: Allow osc_24m to be available in SPL

Quoted 16 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Align the osc_24m node with the imx8mn, so that it can be available in SPL.

This fixes a long pause in SPL when loading U-Boot proper.

---
  arch/arm/dts/imx8mm-u-boot.dtsi | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/dts/imx8mm-u-boot.dtsi +0 -0
index abb3aa5b635..a1ae2371773 100644

arch/arm/dts/imx8mm-u-boot.dtsi line 236

Quoted 8 lines
arch/arm/dts/imx8mm-u-boot.dtsi +4 -0
@@ -229,6 +229,10 @@
  	/delete-property/ assigned-clocks;
  	/delete-property/ assigned-clock-parents;
  	/delete-property/ assigned-clock-rates;
+#ifdef CONFIG_SPL_BUILD
+	clocks = <&osc_24m>;
+	clock-names = "osc_24m";
+#endif
  };

No SPL-specific ifdefs in DT please , sorry but NAK , I already did this last year and it was rejected, and that totally makes sense. Just include the 32kHz clock source in SPL DT and that's the right fix.

author reviewer
#7 lore raw

Re: [PATCH 4/4] arm64: dts: imx8mm: Allow osc_24m to be available in SPL

Quoted 3 lines · Marek Vasut

No SPL-specific ifdefs in DT please , sorry but NAK , I already did this last year and it was rejected, and that totally makes sense. Just include the 32kHz clock source in SPL DT and that's the right fix.

Ok, this works, thanks.

#8 lore raw
In reply to Fabio Estevam
Quoted 14 lines · Fabio Estevam

From: Marek Vasut <[email protected]>

Currently the U-Boot SPL build uses the same DTBs that were generated during U-Boot proper build, and calls 'fdtgrep' on those DTBs to filter out uninteresting nodes and properties. Those U-Boot proper DTBs are built from DTS which are first preprocessed by CPP, but that CPP is invoked in U-Boot proper build context and effectively ignores the CONFIG_SPL_BUILD macro. In case the CONFIG_SPL_BUILD macro is used in any .dts file, the content of the macro is removed by CPP.

Fix this by building a separate set of DTBs for the SPL, which are preprocessed by CPP with -DCONFIG_SPL_BUILD set. Use the same way for the other PLs.

Quoted 7 lines
---
 dts/Makefile         |  5 ++++-
 scripts/Makefile.lib | 11 +++++++++++
 scripts/Makefile.xpl |  7 ++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

There's already a thread here:
https://lore.kernel.org/u-boot/[email protected]/
saying that we shouldn't be doing what this patch adds.

Signature · 1 line
Tom
#9 lore raw

Hello,

Quoted 24 lines · Tom Rini
Quoted 14 lines · Fabio Estevam

From: Marek Vasut <[email protected]>

Currently the U-Boot SPL build uses the same DTBs that were generated during U-Boot proper build, and calls 'fdtgrep' on those DTBs to filter out uninteresting nodes and properties. Those U-Boot proper DTBs are built from DTS which are first preprocessed by CPP, but that CPP is invoked in U-Boot proper build context and effectively ignores the CONFIG_SPL_BUILD macro. In case the CONFIG_SPL_BUILD macro is used in any .dts file, the content of the macro is removed by CPP.

Fix this by building a separate set of DTBs for the SPL, which are preprocessed by CPP with -DCONFIG_SPL_BUILD set. Use the same way for the other PLs.

Quoted 7 lines
---
  dts/Makefile         |  5 ++++-
  scripts/Makefile.lib | 11 +++++++++++
  scripts/Makefile.xpl |  7 ++++++-
  3 files changed, 21 insertions(+), 2 deletions(-)
Quoted 4 lines

There's already a thread here:
https://lore.kernel.org/u-boot/[email protected]/
saying that we shouldn't be doing what this patch adds.

i was even asked to add a checkpatch.pl check for that:

https://lore.kernel.org/u-boot/[email protected]/

The original thread has been idle for a few weeks, i was about to ask how to move forward with the initial problem.

Regards,
Hendrik