[PATCH v2 2/2] Makefile: Only build dtc if needed
Heinrich Schuchardt
xypron.glpk at gmx.de
Mon Apr 27 02:58:28 CEST 2020
Am April 27, 2020 12:29:29 AM UTC schrieb Simon Glass <sjg at chromium.org>:
>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 2.5 seconds of elapsed time on a clean build for me.
>
>- Add a patch to bring back the dtc-version.sh script
>- Update the check to make sure libfdt is available if needed
U -Boot has been set up to create reproducible builds. With this patch dtc will have to be made a build dependency to provide reproducibility. Cf. https://www.debian.org/doc/debian-policy/ch-source.html#reproducibility
This may require changes in the packaging of U-Boot in Linux distributions. Nothing to stop this patch, just something to keep in mind.
You presume that future versions of dtc will always be backward compatible with U-Boot. Ok, we do the same for other tools like gcc too (with surprises at each new major release).
Cc: Vagrant
Best regards
Heinrich
>
>Signed-off-by: Simon Glass <sjg at chromium.org>
>---
>
> Makefile | 21 ++++++++++++++++++---
> dts/Kconfig | 4 ----
> scripts/Kbuild.include | 5 ++++-
> scripts/Makefile | 1 -
> scripts/dtc-version.sh | 36 +++++++++++++++++++++++++++++++-----
> 5 files changed, 53 insertions(+), 14 deletions(-)
>
>diff --git a/Makefile b/Makefile
>index b8a4b5058a..90cb83ed32 100644
>--- a/Makefile
>+++ b/Makefile
>@@ -410,7 +410,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__ \
>@@ -1797,12 +1802,12 @@ include/config/uboot.release:
>include/config/auto.conf FORCE
> # version.h and scripts_basic is processed / created.
>
> # Listed in dependency order
>-PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
>+PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
>prepare4
>
># prepare3 is used to check if we are building in a separate output
>directory,
> # and if so do:
># 1) Check that make has not been executed in the kernel src $(srctree)
>-prepare3: include/config/uboot.release
>+prepare4: include/config/uboot.release
> ifneq ($(KBUILD_SRC),)
> @$(kecho) ' Using $(srctree) as source for U-Boot'
> $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then
>\
>@@ -1812,6 +1817,14 @@ ifneq ($(KBUILD_SRC),)
> fi;
> endif
>
>+# Checks for dtc and builds it if needed
>+prepare3: prepare4
>+ $(eval DTC := $(call
>dtc-version,010406,$(build_dtc),$(CONFIG_PYLIBFDT)))
>+ echo here $(DTC) $(build_dtc)
>+ if test "$(DTC)" = "$(build_dtc)"; then \
>+ $(MAKE) $(build)=scripts/dtc; \
>+ fi
>+
> # prepare2 creates a makefile if using a separate output directory
> prepare2: prepare3 outputmakefile cfg
>
>@@ -1963,6 +1976,8 @@ SYSTEM_MAP = \
> System.map: u-boot
> @$(call SYSTEM_MAP,$<) > $@
>
>+build_dtc := $(objtree)/scripts/dtc/dtc
>+
>#########################################################################
>
> # ARM relocations should all be R_ARM_RELATIVE (32-bit) or
>diff --git a/dts/Kconfig b/dts/Kconfig
>index 046a54a173..f8b808606c 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
> select OF_LIBFDT if !OF_PLATDATA
> help
> This feature provides for run-time configuration of U-Boot
>diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
>index b34dedade7..8c167cef2d 100644
>--- a/scripts/Kbuild.include
>+++ b/scripts/Kbuild.include
>@@ -151,8 +151,11 @@ cc-fullversion = $(shell $(CONFIG_SHELL) \
>cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo
>$(4))
>
> # added for U-Boot
>+# $1: min_version
>+# 32: build_dtc
>+# $3: need_pylibfdt
>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 $3)
>
> # cc-ldoption
> # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
>diff --git a/scripts/Makefile b/scripts/Makefile
>index e7b353f77f..cfe9fef804 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 0744c39eb0..75ba82830d 100755
>--- a/scripts/dtc-version.sh
>+++ b/scripts/dtc-version.sh
>@@ -1,12 +1,26 @@
> #!/bin/sh
> #
>-# dtc-version dtc-command
>+# dtc-version dtc_command min_version build_dtc need_pylibfdt
> #
>-# 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 need_pylibfdt is non-empty then the script first checks that the
>Python
>+# libfdt library is available. If not it outputs $build_dtc and exits
>+#
>+# Otherwise, 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"
>+need_pylibfdt="$4"
>
> if [ ${#dtc} -eq 0 ]; then
> echo "Error: No dtc command specified."
>@@ -14,8 +28,20 @@ if [ ${#dtc} -eq 0 ]; then
> exit 1
> fi
>
>+if [ -n "${need_pylibfdt}" ]; then
>+ if ! echo "import libfdt" | python3 2>/dev/null; then
>+ echo $build_dtc
>+ exit 0
>+ fi
>+fi
>+
> 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
More information about the U-Boot
mailing list