[PATCH v2 1/2] Makefile: Add environment variable DEVICE_TREE to header

Michal Simek michal.simek at xilinx.com
Mon Mar 9 14:29:46 CET 2020

Users have option to overwrite default device tree
(CONFIG_DEFAULT_DEVICE_TREE) via environment variable DEVICE_TREE.

Feature has been added long time ago by commit 74de8c9a1672
("dts/Makefile: Build the user specified dts") for a little bit different

But this variable can be also used for different purpose like choosing
proper configuration from FIT image in SPL.
And this is the functionality I would like to use on Xilinx Zynq devices
that current u-boot.img can be composed in the same way based on OF_LIST
and different configuration is taken based on platform specific SPL.
SPL requires low level ps7_init_gpl configuration that's why different
boards require different SPL with fixed board_fit_config_name_match().

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
Reviewed-by: Tom Rini <trini at konsulko.com>
Reviewed-by: Simon Glass <sjg at chromium.org>

Changes in v2:
- Add tags from Tom and Simon

I have done it in this way but maybe there is any smarter way how this can
be done. Also macro name can change if you want.

 Makefile                 | 14 +++++++++++++-
 arch/arm/mach-zynq/spl.c |  8 ++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 55aa90cf17fa..97166aefbf50 100644
--- a/Makefile
+++ b/Makefile
@@ -483,6 +483,7 @@ endif
 version_h := include/generated/version_autogenerated.h
 timestamp_h := include/generated/timestamp_autogenerated.h
 defaultenv_h := include/generated/defaultenv_autogenerated.h
+dt_h := include/generated/dt.h
 no-dot-config-targets := clean clobber mrproper distclean \
 			 help %docs check% coccicheck \
@@ -1768,7 +1769,7 @@ endif
 # prepare2 creates a makefile if using a separate output directory
 prepare2: prepare3 outputmakefile cfg
-prepare1: prepare2 $(version_h) $(timestamp_h) \
+prepare1: prepare2 $(version_h) $(timestamp_h) $(dt_h) \
 ifeq ($(wildcard $(LDSCRIPT)),)
 	@echo >&2 "  Could not find linker script."
@@ -1834,12 +1835,23 @@ define filechk_defaultenv.h
 	 xxd -i ; echo ", 0x00" ; )
+define filechk_dt.h
+	(if test -n "$${DEVICE_TREE}"; then \
+		echo \#define DEVICE_TREE \"$(DEVICE_TREE)\"; \
+	else \
+	fi)
 $(version_h): include/config/uboot.release FORCE
 	$(call filechk,version.h)
 $(timestamp_h): $(srctree)/Makefile FORCE
 	$(call filechk,timestamp.h)
+$(dt_h): $(srctree)/Makefile FORCE
+	$(call filechk,dt.h)
 $(defaultenv_h): $(CONFIG_DEFAULT_ENV_FILE:"%"=%) FORCE
 	$(call filechk,defaultenv.h)
diff --git a/arch/arm/mach-zynq/spl.c b/arch/arm/mach-zynq/spl.c
index 96ba90fb7a76..e89e46c1038d 100644
--- a/arch/arm/mach-zynq/spl.c
+++ b/arch/arm/mach-zynq/spl.c
@@ -6,6 +6,7 @@
 #include <debug_uart.h>
 #include <hang.h>
 #include <spl.h>
+#include <generated/dt.h>
 #include <asm/io.h>
 #include <asm/spl.h>
@@ -89,8 +90,11 @@ void spl_board_prepare_for_boot(void)
 int board_fit_config_name_match(const char *name)
 	/* Just empty function now - can't decide what to choose */
-	debug("%s: %s\n", __func__, name);
+	debug("%s: Check %s, default %s\n", __func__, name, DEVICE_TREE);
-	return 0;
+	if (!strcmp(name, DEVICE_TREE))
+		return 0;
+	return -1;

More information about the U-Boot mailing list