From patchwork Mon Apr 27 00:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1277268 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=JhaaCxJp; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499QfH0BDcz9sRY for ; Mon, 27 Apr 2020 10:30:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5FFE181DA0; Mon, 27 Apr 2020 02:29:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="JhaaCxJp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1635781D8B; Mon, 27 Apr 2020 02:29:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 259EE81D87 for ; Mon, 27 Apr 2020 02:29:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd41.google.com with SMTP id k23so1772920ios.5 for ; Sun, 26 Apr 2020 17:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HXx7mDamG5WNiNMyCthxFOy59baDzAthCLPbUl4+u9c=; b=JhaaCxJpB8CeE5xD0lXe6kZqYLSHy0s1EgGMalwV3nGRgPLCr8ha3+RcjUnUyJ456e 47hS91VWJUGgNjpUiUgHrJUlZx44ienB26EuMMQYXgyTXp+iccSIxrvLCevsm4Ze/KMF bXISzWHXpa1z4wf3R3b93kmHtCqPswginktu4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HXx7mDamG5WNiNMyCthxFOy59baDzAthCLPbUl4+u9c=; b=RjTcGElxjqrKyzg2X7dfeTQ30A+qYXS/qSob04AzVlXF9jC5skzHqXOgiwImDXNTdb s3QvPXuTaAwY/uageb4tRK7DH1+wKyggV7s9Z3OEZ6fC4lJobCmaznNanCWNDzz4+KOa tW2f7hGfLOgz/TikUzCzNY8YgC2k3tKcCMTKbreKQTW0nKx3QsHfBcrzhvSb78zAz5Ci zRQizIfmzSc/fKYKIz/Gv1GpCkd2VWqLj2pL+8sK6xcp91Ns+Vqd1yR24KRmjknJCj1m PDUWzkTb2v/F2l7jx6F7WeZAUhnGHqI8wXzXUFjBVW78cIJ7wbYtrkTeWLFDh+kToq7s wYGw== X-Gm-Message-State: AGi0PuZkrbxOAAE5beITWCQRTtMPeCJu0fFVaFDetPUcb3ZksOstJp0y Zatv9FUwrvIB0lXz00Tt99Lxvw== X-Google-Smtp-Source: APiQypKX/Sn33Yv1Pu2t76AfR0wX5Gg06M4URCSDBssD/LU94PGMQysH5Pfm4oqgOROjIdlyx3BkLg== X-Received: by 2002:a5e:8616:: with SMTP id z22mr18936185ioj.130.1587947378175; Sun, 26 Apr 2020 17:29:38 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id y3sm4855076ila.70.2020.04.26.17.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 17:29:37 -0700 (PDT) From: Simon Glass To: Tom Rini Cc: Marek Vasut , Masahiro Yamada , Simon Glass , Anatolij Gustschin , Baruch Siach , Bin Meng , Fabio Estevam , Heinrich Schuchardt , Jagan Teki , Jean-Jacques Hiblot , Kever Yang , Masahiro Yamada , Sean Anderson , Walter Lozano , u-boot@lists.denx.de Subject: [PATCH v2 2/2] Makefile: Only build dtc if needed Date: Sun, 26 Apr 2020 18:29:29 -0600 Message-Id: <20200427002929.239379-2-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200427002929.239379-1-sjg@chromium.org> References: <20200427002929.239379-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean 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 Signed-off-by: Simon Glass --- 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