[U-Boot] [PATCH] 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.
Signed-off-by: Simon Glass sjg@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

On 11/13/2018 11:43 PM, Simon Glass wrote:
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 !
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Marek Vasut marek.vasut@gmail.com

Hi Tom,
On Wed, 14 Nov 2018 at 12:51, Marek Vasut marek.vasut@gmail.com wrote:
On 11/13/2018 11:43 PM, Simon Glass wrote:
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 !
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Marek Vasut marek.vasut@gmail.com
Should we pick this one up? It is assigned to you in patchwork.
Regards, Simon

On Tue, Nov 13, 2018 at 03:43:07PM -0700, Simon Glass wrote:
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@chromium.org Reviewed-by: Marek Vasut marek.vasut@gmail.com
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.

Hi Tom,
On Sat, 26 Jan 2019 at 20:51, Tom Rini trini@konsulko.com wrote:
On Tue, Nov 13, 2018 at 03:43:07PM -0700, Simon Glass wrote:
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@chromium.org Reviewed-by: Marek Vasut marek.vasut@gmail.com
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

On Sun, Apr 26, 2020 at 06:34:48PM -0600, Simon Glass wrote:
Hi Tom,
On Sat, 26 Jan 2019 at 20:51, Tom Rini trini@konsulko.com wrote:
On Tue, Nov 13, 2018 at 03:43:07PM -0700, Simon Glass wrote:
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@chromium.org Reviewed-by: Marek Vasut marek.vasut@gmail.com
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".

Hi Tom,
On Mon, 27 Apr 2020 at 12:59, Tom Rini trini@konsulko.com wrote:
On Sun, Apr 26, 2020 at 06:34:48PM -0600, Simon Glass wrote:
Hi Tom,
On Sat, 26 Jan 2019 at 20:51, Tom Rini trini@konsulko.com wrote:
On Tue, Nov 13, 2018 at 03:43:07PM -0700, Simon Glass wrote:
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@chromium.org Reviewed-by: Marek Vasut marek.vasut@gmail.com
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".
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

On Mon, Apr 27, 2020 at 04:25:10PM -0600, Simon Glass wrote:
Hi Tom,
On Mon, 27 Apr 2020 at 12:59, Tom Rini trini@konsulko.com wrote:
On Sun, Apr 26, 2020 at 06:34:48PM -0600, Simon Glass wrote:
Hi Tom,
On Sat, 26 Jan 2019 at 20:51, Tom Rini trini@konsulko.com wrote:
On Tue, Nov 13, 2018 at 03:43:07PM -0700, Simon Glass wrote:
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@chromium.org Reviewed-by: Marek Vasut marek.vasut@gmail.com
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".
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.
participants (3)
-
Marek Vasut
-
Simon Glass
-
Tom Rini