[PATCH 2/4] build: Respect CONFIG_SPL_BUILD in DT sources
Marek Vasut
marex at denx.de
Fri Nov 22 02:58:13 CET 2024
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.
Signed-off-by: Marek Vasut <marex at denx.de>
---
Cc: "NXP i.MX U-Boot Team" <uboot-imx at nxp.com>
Cc: Bryan Brattlof <bb at ti.com>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: Greg Malysa <greg.malysa at timesys.com>
Cc: Ian Roberts <ian.roberts at timesys.com>
Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
Cc: Jonathan Humphreys <j-humphreys at ti.com>
Cc: Masahisa Kojima <kojima.masahisa at socionext.com>
Cc: Nathan Barrett-Morrison <nathan.morrison at timesys.com>
Cc: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
Cc: Simon Glass <sjg at chromium.org>
Cc: Stefano Babic <sbabic at denx.de>
Cc: Sumit Garg <sumit.garg at linaro.org>
Cc: Tim Harvey <tharvey at gateworks.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: u-boot at lists.denx.de
---
NOTE: For v2025.04
---
dts/Makefile | 5 ++++-
scripts/Makefile.lib | 11 +++++++++++
scripts/Makefile.xpl | 7 ++++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/dts/Makefile b/dts/Makefile
index 86bf8dc2156..53cab9a37a4 100644
--- a/dts/Makefile
+++ b/dts/Makefile
@@ -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)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 54403040f00..a42965edc6f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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__
diff --git a/scripts/Makefile.xpl b/scripts/Makefile.xpl
index dca5f4539d0..c0bd8dd7f97 100644
--- a/scripts/Makefile.xpl
+++ b/scripts/Makefile.xpl
@@ -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)
--
2.45.2
More information about the U-Boot
mailing list