diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2019-03-26 14:57:54 -0700 |
---|---|---|
committer | Vadim Bendebury <vbendeb@chromium.org> | 2019-09-21 19:11:24 -0700 |
commit | d2aa31110c2a73883be465e4b591404f41711189 (patch) | |
tree | 60d007d64bcbb0f278eacef718784e06caac4077 | |
parent | f6bea2fc727b39073cdaac079896b6c00284a427 (diff) | |
download | chrome-ec-d2aa31110c2a73883be465e4b591404f41711189.tar.gz |
cr50: rebuild board image if essential make variables change
When building Cr50 board image, some make variables get converted into
compilation flags, which affect image composition. Changes of these
variables go unnoticed as they do not directly affect make
dependencies.
Let's define the set of essential variables in ENV_VARS, and save the
state of these variables at build time in a generated .h file,
updating it only if any of the variables' values changed since the
previous make run.
The generated .h file is included in board.h, which guarantees that
files dependent on board.h are recompiled if the generated .h file
changes.
BRANCH=cr50
BUG=none
TEST=verified that changing of CR50_DEV and/or H1_RED_BOARD or
CR50_SQA values triggers full rebuild of the Cr50 image.
Verified that 'emerge-atlas ec-utils' also succeeds.
Change-Id: Id0589a3b6a66fe4da90a9aea894bc83eb6337c8c
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/707915
Reviewed-by: Keith Short <keithshort@chromium.org>
(cherry picked from commit 22b1008446791f31d8841b8ae43bbbc0f4d9f143)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1657316
(cherry picked from commit 3d79ec33402e658cb1d43cdd28fa7f2290b01c41)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1705731
(cherry picked from commit de69550b8be74e76fd30216f8dce588b9d5e64f4)
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | board/cr50/build.mk | 5 | ||||
-rw-r--r-- | include/config.h | 8 | ||||
-rwxr-xr-x | util/env_changed.sh | 23 |
4 files changed, 49 insertions, 0 deletions
@@ -45,6 +45,14 @@ all: include $(BDIR)/build.mk include chip/$(CHIP)/build.mk +ifneq ($(ENV_VARS),) +# Let's make sure $(out)/env_config.h changes if value any of the above +# variables has changed since the prvious make invocation. This in turn will +# make sure that relevant object files are re-built. +current_set = $(foreach env_flag, $(ENV_VARS), $(env_flag)=$($(env_flag))) +$(shell util/env_changed.sh "$(out)/env_config.h" "$(current_set)") +endif + # Create uppercase config variants, to avoid mixed case constants. # Also translate '-' to '_', so 'cortex-m' turns into 'CORTEX_M'. This must # be done before evaluating config.h. @@ -94,6 +102,11 @@ CPPFLAGS_RO+=$(foreach t,$(_tsk_cfg_ro),-D$(t)) CPPFLAGS_RW+=$(foreach t,$(_tsk_cfg_rw),-D$(t)) CPPFLAGS+=$(foreach t,$(_tsk_cfg),-D$(t)) +ifneq ($(ENV_VARS),) +CPPFLAGS += -DINCLUDE_ENV_CONFIG +CFLAGS += -I$(realpath $(out)) +endif + _flag_cfg_ro:=$(shell $(CPP) $(CPPFLAGS) -P -dM -Ichip/$(CHIP) \ -I$(BDIR) -DSECTION_IS_RO include/config.h | \ grep -o "\#define CONFIG_[A-Z0-9_]*" | cut -c9- | sort) diff --git a/board/cr50/build.mk b/board/cr50/build.mk index d065b01b5f..b6fe1e4768 100644 --- a/board/cr50/build.mk +++ b/board/cr50/build.mk @@ -15,6 +15,11 @@ CHIP_VARIANT ?= cr50_fpga # a guard so that recipe definitions and variable extensions only happen the # second time. ifeq ($(BOARD_MK_INCLUDED_ONCE),) + +# List of variables which can be defined in the environment or set in the make +# command line. +ENV_VARS := CR50_DEV CR50_SQA H1_RED_BOARD + BOARD_MK_INCLUDED_ONCE=1 SIG_EXTRA = --cros else diff --git a/include/config.h b/include/config.h index a7cbe7b8fc..ae499553a7 100644 --- a/include/config.h +++ b/include/config.h @@ -18,6 +18,14 @@ #ifndef __CROS_EC_CONFIG_H #define __CROS_EC_CONFIG_H +#ifdef INCLUDE_ENV_CONFIG +/* + * When building for an EC target, pick up the .h file which allows to + * keep track of changing make variables. + */ +#include "env_config.h" +#endif + /* * All config options are listed alphabetically and described here. * diff --git a/util/env_changed.sh b/util/env_changed.sh new file mode 100755 index 0000000000..5bab64760d --- /dev/null +++ b/util/env_changed.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This script accepts two parameters: a file name and a string. +# +# If the file does not exist, or does not contain the passed in string wrapped +# in '/*... */, the file is written with the wrapped passed in string. + +h_file="$1" +current_set="/* $2 */" + +if [[ -f "${h_file}" ]]; then + old_set="$(cat "${h_file}")" + if [[ "${current_set}" == "${old_set}" ]]; then + exit 0 + fi +else + dest_dir="$(dirname "${h_file}")" + [[ -d "${dest_dir}" ]] || mkdir -p "${dest_dir}" +fi +printf "${current_set}" > "${h_file}" |