[U-Boot] [PATCH] Makefile: Only build dtc if needed

Simon Glass sjg at chromium.org
Tue Nov 13 22:43:07 UTC 2018


At present U-Boot always builds dtc if CONFIG_OF_CONTROL is defined. This
is wasteful when the system already has a suitable version available.

Update the Makefile logic to build dtc only if the version available is
too old.

This saves about 3 seconds of CPU time on a clean build for me.

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

 Makefile               | 17 +++++++++++++++--
 dts/Kconfig            |  4 ----
 scripts/Kbuild.include |  4 +++-
 scripts/Makefile       |  1 -
 scripts/dtc-version.sh | 25 ++++++++++++++++++++-----
 5 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index 250eb6c3c39..fec2b2d8fb5 100644
--- a/Makefile
+++ b/Makefile
@@ -361,7 +361,12 @@ PERL		= perl
 PYTHON		?= python
 PYTHON2		= python2
 PYTHON3		= python3
-DTC		?= $(objtree)/scripts/dtc/dtc
+
+# DTC is automatically built if the version of $(DTC) is older that needed.
+# Use the system dtc if it is new enough.
+DTC		?= dtc
+DTC_MIN_VERSION	:= 010406
+
 CHECK		= sparse
 
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
@@ -926,7 +931,7 @@ endif
 PHONY += dtbs
 dtbs: dts/dt.dtb
 	@:
-dts/dt.dtb: u-boot
+dts/dt.dtb: checkdtc u-boot
 	$(Q)$(MAKE) $(build)=dts dtbs
 
 quiet_cmd_copy = COPY    $@
@@ -1579,6 +1584,14 @@ SYSTEM_MAP = \
 System.map:	u-boot
 		@$(call SYSTEM_MAP,$<) > $@
 
+build_dtc	:= $(objtree)/scripts/dtc/dtc
+
+checkdtc:
+	$(eval DTC := $(call dtc-version,010406,$(build_dtc)))
+	if test "$(DTC)" = "$(build_dtc)"; then \
+		$(MAKE) $(build)=scripts/dtc; \
+	fi
+
 #########################################################################
 
 # ARM relocations should all be R_ARM_RELATIVE (32-bit) or
diff --git a/dts/Kconfig b/dts/Kconfig
index 8917f424445..7e600e28f6c 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -5,9 +5,6 @@
 config SUPPORT_OF_CONTROL
 	bool
 
-config DTC
-	bool
-
 config PYLIBFDT
 	bool
 
@@ -24,7 +21,6 @@ menu "Device Tree Control"
 
 config OF_CONTROL
 	bool "Run-time configuration via Device Tree"
-	select DTC
 	help
 	  This feature provides for run-time configuration of U-Boot
 	  via a flattened device tree.
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 13ebddda65c..82be40cbe78 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -147,8 +147,10 @@ cc-fullversion = $(shell $(CONFIG_SHELL) \
 cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4))
 
 # added for U-Boot
+# $1: min_version
+# #2: build_dtc
 binutils-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/binutils-version.sh $(AS))
-dtc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/dtc-version.sh $(DTC))
+dtc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/dtc-version.sh $(DTC) $1 $2)
 
 # cc-ldoption
 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
diff --git a/scripts/Makefile b/scripts/Makefile
index e7b353f77f4..cfe9fef8044 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,4 +10,3 @@ always		:= $(hostprogs-y)
 
 # Let clean descend into subdirs
 subdir-	+= basic kconfig
-subdir-$(CONFIG_DTC)	+= dtc
diff --git a/scripts/dtc-version.sh b/scripts/dtc-version.sh
index 0744c39eb04..ec988e18daf 100755
--- a/scripts/dtc-version.sh
+++ b/scripts/dtc-version.sh
@@ -1,12 +1,22 @@
 #!/bin/sh
 #
-# dtc-version dtc-command
+# dtc-version dtc_command min_version build_dtc
 #
-# Prints the dtc version of `dtc-command' in a canonical 6-digit form
-# such as `010404'  for dtc 1.4.4
+# Selects which version of dtc to use
+#
+# If the version of dtc_command is < min_version, prints build_dtc else
+# prints dtc_command. The min_version is in the format MMmmpp where:
+#
+#   MM is the major version
+#   mm is the minor version
+#   pp is the patch level
+#
+# For example 010406 means 1.4.6
 #
 
-dtc="$*"
+dtc="$1"
+min_version="$2"
+build_dtc="$3"
 
 if [ ${#dtc} -eq 0 ]; then
 	echo "Error: No dtc command specified."
@@ -18,4 +28,9 @@ MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1)
 MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2)
 PATCH=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 3 | cut -d - -f 1)
 
-printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCH
+version="$(printf "%02d%02d%02d" $MAJOR $MINOR $PATCH)"
+if test $version -lt $min_version; then \
+	echo $build_dtc
+else
+	echo $dtc
+fi
-- 
2.19.1.930.g4563a0d9d0-goog



More information about the U-Boot mailing list