Skip to contentSkip to conversation

Makefile: Only build dtc if needed

PATCH In review Simon Glass 3 participants 8 messages Nov 13, 2018 – Apr 28, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Only build dtc if needed

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.

---

 Makefile               | 17 +++++++++++++++--
 dts/Kconfig            |  4 ----
 scripts/Kbuild.include |  4 +++-
 scripts/Makefile       |  1 -
 scripts/dtc-version.sh | 25 ++++++++++++++++++++-----
 5 files changed, 38 insertions(+), 13 deletions(-)
Makefile +15 -2
index 250eb6c3c39..fec2b2d8fb5 100644
@@ -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
dts/Kconfig +0 -4
index 8917f424445..7e600e28f6c 100644
@@ -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.
scripts/Kbuild.include +3 -1
index 13ebddda65c..82be40cbe78 100644
@@ -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)
scripts/Makefile +0 -1
index e7b353f77f4..cfe9fef8044 100644
@@ -10,4 +10,3 @@ always		:= $(hostprogs-y)
 
 # Let clean descend into subdirs
 subdir-	+= basic kconfig
-subdir-$(CONFIG_DTC)	+= dtc
scripts/dtc-version.sh +20 -5
index 0744c39eb04..ec988e18daf 100755
@@ -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
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog
#1 lore raw

PATCH 1/1 Makefile: Only build dtc if needed

Quoted 7 lines · Simon Glass

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.

Nice !

Quoted 1 line
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 Makefile: Only build dtc if needed

Hi Tom,

Quoted 8 lines · Marek Vasut
Quoted 6 lines · Simon Glass

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.

Quoted 7 lines
Quoted 1 line

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

Nice !

Quoted 1 line

Should we pick this one up? It is assigned to you in patchwork.

Regards,
Simon

#3 lore raw
In reply to Simon Glass
Quoted 10 lines · Simon Glass

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.

In the case of new enough host dtc this then fails on sandbox_spl, chromebook_minnie and others where we need to build spl/dts/dt-platdata.c with a python import error over lacking _libfdt.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190126/b979520d/attachment.sig>
#4 lore raw

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · Simon Glass

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.

Quoted 8 lines
Quoted 4 lines

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

In the case of new enough host dtc this then fails on sandbox_spl, chromebook_minnie and others where we need to build spl/dts/dt-platdata.c with a python import error over lacking _libfdt.

I'm not sure if it has been long enough, but have the packages been updated to include pylibfdt?

I'm sending a new version of this patch that checks for that.

Regards,
SImon

#5 lore raw
Quoted 17 lines · Simon Glass

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 10 lines · Simon Glass

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.

Quoted 8 lines
Quoted 3 lines

In the case of new enough host dtc this then fails on sandbox_spl, chromebook_minnie and others where we need to build spl/dts/dt-platdata.c with a python import error over lacking _libfdt.

I'm not sure if it has been long enough, but have the packages been updated to include pylibfdt?

I'm sending a new version of this patch that checks for that.

I honestly don't know how far behind distributions lag here and then in turn how old something is before we say "sorry, you can't build there easily".

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200427/6137c54f/attachment.sig>
#6 lore raw

Hi Tom,

Quoted 23 lines · Tom Rini
Quoted 21 lines · Simon Glass

Hi Tom,

Quoted 17 lines · Tom Rini
Quoted 10 lines · Simon Glass

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.

In the case of new enough host dtc this then fails on sandbox_spl, chromebook_minnie and others where we need to build spl/dts/dt-platdata.c with a python import error over lacking _libfdt.

Quoted 8 lines
Quoted 4 lines

I'm not sure if it has been long enough, but have the packages been updated to include pylibfdt?

I'm sending a new version of this patch that checks for that.

I honestly don't know how far behind distributions lag here and then in turn how old something is before we say "sorry, you can't build there easily".

I think we should be able to deal with this with respect to dtc at least, since we can always build it if needed. We just need to get the conditions right.

Regards,
SImon

#7 lore raw
Quoted 31 lines · Simon Glass

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 25 lines · Simon Glass

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · Simon Glass

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.

Quoted 8 lines
Quoted 4 lines

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

In the case of new enough host dtc this then fails on sandbox_spl, chromebook_minnie and others where we need to build spl/dts/dt-platdata.c with a python import error over lacking _libfdt.

I'm not sure if it has been long enough, but have the packages been updated to include pylibfdt?

I'm sending a new version of this patch that checks for that.

Quoted 7 lines
Quoted 3 lines

I honestly don't know how far behind distributions lag here and then in turn how old something is before we say "sorry, you can't build there easily".

I think we should be able to deal with this with respect to dtc at least, since we can always build it if needed. We just need to get the conditions right.

To keep the threads in sync, I'm not sure it's worth diverging from the Linux kernel build in this regard.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200428/3ce0d765/attachment.sig>