diff options
author | Vadim Bendebury <vbendeb@google.com> | 2020-12-29 19:18:25 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-31 06:23:14 +0000 |
commit | 8b5a703f7b605cf22af5669c6fef9eb2d3bc2f7d (patch) | |
tree | d21e8c7a764eea4064aac7acfef548d84ad14147 | |
parent | dbc7c310f5babec6fd2b6a382b8a49b011296a12 (diff) | |
download | chrome-ec-8b5a703f7b605cf22af5669c6fef9eb2d3bc2f7d.tar.gz |
make: fix no change remake behavior
This patch was inspired by crrev.com/c/2593881, it is extended to
cover both cryptoc and tpm2 libraries. Cherry-picking across the
branches is pointless as the branches have drifted apart and the patch
applied to completely different files.
The below was copied from the original patch description and edited
and augmented to match the Cr50 case.
Currently, the cryptoc and tpm2 targets are marked as
.PHONY. That means that any project that depends on cryptoc or tpm2
will always rebuild ec.bin on make invocations.
For example, running make for cr50 will show the following build steps
on each make invocation, even though nothing in cryptoc or tpm2
changed:
make obj=/mnt/host/source/src/platform/cr50/build/cr50/cryptoc \
SUPPORT_UNALIGNED=1 \
CONFIG_UPTO_SHA512=y -C /mnt/host/source/src/third_party/cryptoc
make obj=/mnt/host/source/src/platform/cr50/build/cr50/tpm2 \
EMBEDDED_MODE=1 \
-C /mnt/host/source/src/third_party/tpm2 copied_objs
make[1]: Entering directory '/mnt/host/source/src/third_party/cryptoc'
make[1]: '/mnt/host/.../build/cr50/cryptoc/libcryptoc.a' is up to date.
make[1]: Leaving directory '/mnt/host/source/src/third_party/cryptoc'
make[1]: Entering directory '/mnt/host/source/src/third_party/tpm2'
make[1]: Nothing to be done for 'copied_objs'.
make[1]: Leaving directory '/mnt/host/source/src/third_party/tpm2'
LD RO/ec.RO.elf
LD RW/ec.RW.elf
.
.
.
This fix brings the dirty/clean state of cryptoc and tpm2 into the
main Cr50 make process, so that it can assess if libcryptoc.a or tpm
objects (and later ec.bin) actually need to be remade.
We do something similar for the ec version header file that is generated
by the build system itself (see crrev.com/c/227211)
Instead of relying on shell globbing, the tpm2 Makefile is now used to
determine the exact set of the tpm object files to be linked in.
This change was only possible with the fix to cryptoc's Makefile
crrev.com/c/2091999 and to the tpm2 Makefile in crrev.com/c/2606746.
With this change, building Cr50 does not force an unnecessary
recompilation, so the above make example looks like the following
after the initial build:
$ make BOARD=cr50 -j
*** 8044 bytes in flash...
*** 14116 bytes in flash...
BUG=none
TEST=verified that cryptolib and tpm2 libraries are rebuilt when some
.c or .h file in the respective directories it touched, but not
unnecessarily, like before this patch.
Change-Id: Ic7c55e6f779559e082afdd18c7368e5115afabdf
Signed-off-by: Vadim Bendebury <vbendeb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2606810
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Craig Hesling <hesling@chromium.org>
Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r-- | board/cr50/build.mk | 29 | ||||
-rw-r--r-- | common/build.mk | 13 |
2 files changed, 32 insertions, 10 deletions
diff --git a/board/cr50/build.mk b/board/cr50/build.mk index 46871c7ec8..a06bcd3065 100644 --- a/board/cr50/build.mk +++ b/board/cr50/build.mk @@ -109,16 +109,31 @@ CFLAGS += -DEMBEDDED_MODE=1 # Configure cryptoc headers to handle unaligned accesses. CFLAGS += -DSUPPORT_UNALIGNED=1 -TPM2_OBJS = $(shell find $(out)/tpm2 -name '*.cp.o') +# Use absolute path as the destination to ensure that TPM2 makefile finds the +# place for output. +outdir := $(realpath $(out))/tpm2 +cmd_tpm2_base = $(MAKE) obj=$(outdir) EMBEDDED_MODE=1 \ + -C $(EXTLIB) --no-print-directory + +TPM2_OBJS := $(shell $(cmd_tpm2_base) list_copied_objs) + +TPM2_TARGET := $(outdir)/.copied_objs + # Add dependencies on that library $(out)/RW/ec.RW.elf $(out)/RW/ec.RW_B.elf: LDFLAGS_EXTRA += $(TPM2_OBJS) -$(out)/RW/ec.RW.elf $(out)/RW/ec.RW_B.elf: copied_objs +$(out)/RW/ec.RW.elf $(out)/RW/ec.RW_B.elf: $(TPM2_TARGET) + +cmd_tpm2lib = $(cmd_tpm2_base) $(TPM2_TARGET) + +tpm2lib_check_clean = $(cmd_tpm2lib) -q && echo clean + +ifneq ($(shell $(tpm2lib_check_clean)),clean) +# Force the external build only if it is needed. +.PHONY: $(TPM2_TARGET) +endif -# Force the external build each time, so it can look for changed sources. -.PHONY: copied_objs -copied_objs: - $(MAKE) obj=$(realpath $(out))/tpm2 EMBEDDED_MODE=1 \ - -C $(EXTLIB) copied_objs +$(TPM2_TARGET): + $(call quiet,tpm2lib,TPM2 ) endif # BOARD_MK_INCLUDED_ONCE is nonempty diff --git a/common/build.mk b/common/build.mk index f0a55ccb61..ec592b8f9f 100644 --- a/common/build.mk +++ b/common/build.mk @@ -257,11 +257,18 @@ endif CPPFLAGS += -I$(CRYPTOCLIB)/include CRYPTOC_LDFLAGS := -L$(out)/cryptoc -lcryptoc -# Force the external build each time, so it can look for changed sources. +cmd_cryptolib = $(MAKE) obj=$(realpath $(out))/cryptoc SUPPORT_UNALIGNED=1 \ + CONFIG_UPTO_SHA512=$(CONFIG_UPTO_SHA512) -C $(CRYPTOCLIB) + +cryptolib_check_clean = $(cmd_cryptolib) -q && echo clean + +ifneq ($(shell $(cryptolib_check_clean)),clean) +# Force the external build only if it is needed. .PHONY: $(out)/cryptoc/libcryptoc.a +endif + $(out)/cryptoc/libcryptoc.a: - $(MAKE) obj=$(realpath $(out))/cryptoc SUPPORT_UNALIGNED=1 \ - CONFIG_UPTO_SHA512=$(CONFIG_UPTO_SHA512) -C $(CRYPTOCLIB) + $(call quiet,cryptolib,CRYPTOLIB) # Link RO and RW against cryptoc. $(out)/RO/ec.RO.elf $(out)/RO/ec.RO_B.elf: LDFLAGS_EXTRA += $(CRYPTOC_LDFLAGS) |