From 708bce40ba1a3539acff50ea73b737f75dbe5918 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Tue, 21 Jan 2020 19:15:31 +0800 Subject: vboot: get rid of MINIMAL in Makefile - Clean up install paths. The ebuild was adding /usr in the MINIMAL=1 case, making it look virtually exactly the same as the non-MINIMAL case. Just unify the two. - Introduce SDK_BUILD variable to take over part of the functionality previously implemented by MINIMAL. - One may now use rununittests for quick test runs instead of setting MINIMAL=1. - runtestscripts is added to the default test set under "runtests". runfutiltests is not yet enabled due to flakiness (see chromium:1048048). - Remove unused LZMA_LIBS and YAML_LIBS. - Stop installing dev-mode-only scripts into /usr/bin for an SDK build (VB_DIR). Presumably this was meant for board builds, but since everyone is used to these scripts living in /usr/share/vboot/bin, we may as well keep them there. - Stop installing crossystem for an SDK build. - Group SIGNING_SCRIPTS into UTIL_SCRIPTS_BOARD. - Have install_for_test depend on test_setup instead of vice versa. Targets which run tests should depend on install_for_test. BUG=b:124141368, chromium:605348, chromium:1048048 TEST=make clean && make runtests TEST=make clean && make rununittests TEST=sudo emerge vboot_reference, check installed files TEST=emerge-eve vboot_reference, check installed files TEST=USE=fuzzer emerge-eve vboot_reference TEST=FEATURES=test USE=fuzzer emerge-eve vboot_reference BRANCH=none Change-Id: I203e69143e40ee42729488bf0ab59f5120649bd1 Cq-Depend: chromium:2012183 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2012182 Reviewed-by: Joel Kitching Tested-by: Joel Kitching Commit-Queue: Joel Kitching --- Makefile | 189 +++++++++++++++++++++++--------------------------------- tests/common.sh | 2 +- 2 files changed, 77 insertions(+), 114 deletions(-) diff --git a/Makefile b/Makefile index 0c075e06..762aa116 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ export BUILD # Stuff for 'make install' INSTALL = install -DESTDIR = /usr/local +DESTDIR = / LIBDIR ?= lib # Default values @@ -56,17 +56,6 @@ DEV_DEBUG_FORCE= # US_DIR = shared data directory (for static content like devkeys) # DF_DIR = utility defaults directory # VB_DIR = vboot binary directory for dev-mode-only scripts -ifeq (${MINIMAL},) -# Host install just puts everything where it's told -UB_DIR=${DESTDIR}/bin -UL_DIR=${DESTDIR}/${LIBDIR} -ULP_DIR=${UL_DIR}/pkgconfig -UI_DIR=${DESTDIR}/include/vboot -US_DIR=${DESTDIR}/share/vboot -DF_DIR=${DESTDIR}/default -VB_DIR=${DESTDIR}/bin -else -# Target install puts things into different places UB_DIR=${DESTDIR}/usr/bin UL_DIR=${DESTDIR}/usr/${LIBDIR} ULP_DIR=${UL_DIR}/pkgconfig @@ -74,11 +63,13 @@ UI_DIR=${DESTDIR}/usr/include/vboot US_DIR=${DESTDIR}/usr/share/vboot DF_DIR=${DESTDIR}/etc/default VB_DIR=${US_DIR}/bin -endif # Where to install the (exportable) executables for testing? TEST_INSTALL_DIR = ${BUILD}/install_for_test +# Set when installing into the SDK instead of building for a board sysroot. +SDK_BUILD ?= + # Verbose? Use V=1 ifeq (${V},) Q := @ @@ -114,8 +105,8 @@ else ifeq (${ARCH},amd64) endif # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling -# for a firmware target (such as u-boot or depthcharge). It must map -# to the same consistent set of architectures as the host. +# for a firmware target (coreboot or depthcharge). It must map to the same +# consistent set of architectures as the host. ifeq (${FIRMWARE_ARCH},i386) override FIRMWARE_ARCH := x86 else ifeq (${FIRMWARE_ARCH},amd64) @@ -126,15 +117,6 @@ endif # Provide default CC and CFLAGS for firmware builds; if you have any -D flags, # please add them after this point (e.g., -DVBOOT_DEBUG). -# -# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just -# temporarily. As we are still investigating which flags are necessary for -# maintaining a compatible ABI, etc. between u-boot and vboot_reference. -# -# As a first step, this makes the setting of CC and CFLAGS here optional, to -# permit a calling script or Makefile to set these. -# -# Flag ordering: arch, then -f, then -m, then -W DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-g -Os) WERROR := -Werror FIRMWARE_FLAGS := -nostdinc -ffreestanding -fno-builtin -fno-stack-protector @@ -144,7 +126,8 @@ COMMON_FLAGS := -pipe ${WERROR} -Wall -Wstrict-prototypes -Wtype-limits \ -Wno-address-of-packed-member -ffunction-sections -fdata-sections \ -Wimplicit-fallthrough -Wformat -Wno-format-security ${DEBUG_FLAGS} -# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild. +# FIRMWARE_ARCH is defined if compiling for a firmware target +# (coreboot or depthcharge). ifeq (${FIRMWARE_ARCH},arm) CC ?= armv7a-cros-linux-gnueabihf-gcc CFLAGS ?= -march=armv5 -fno-common -ffixed-r8 -mfloat-abi=hard -marm @@ -325,8 +308,9 @@ export BUILD_RUN # Default target. .PHONY: all -all: $(if ${NO_BUILD_TOOLS},,fwlib fwlib2x fwlib20 fwlib21 tlcl) \ - $(if ${FIRMWARE_ARCH},,host_stuff) \ +all: fwlib fwlib2x fwlib20 fwlib21 futil utillib hostlib cgpt tlcl \ + $(if ${SDK_BUILD},utils_sdk,utils_board) \ + $(if $(filter x86_64,${ARCH}),fuzzers) \ $(if ${COV},coverage) ############################################################################## @@ -589,42 +573,32 @@ ALL_OBJS += ${CGPT_WRAPPER_OBJS} UTIL_DEFAULTS = ${BUILD}/default/vboot_reference # Scripts to install directly (not compiled) -UTIL_SCRIPTS = \ - utility/dev_debug_vboot \ - utility/enable_dev_usb_boot - -ifeq (${MINIMAL},) -UTIL_SCRIPTS += \ +UTIL_SCRIPTS_SDK = \ utility/dev_make_keypair \ utility/vbutil_what_keys -endif +UTIL_SCRIPTS_BOARD = \ + utility/chromeos-tpm-recovery \ + utility/dev_debug_vboot \ + utility/enable_dev_usb_boot \ + utility/tpm-nvsize -UTIL_NAMES = \ - utility/crossystem \ +UTIL_NAMES_SDK = \ utility/dumpRSAPublicKey \ - utility/tpmc - -ifeq (${MINIMAL},) -UTIL_NAMES += \ utility/load_kernel_test \ utility/pad_digest_utility \ utility/signature_digest_utility \ utility/verify_data +UTIL_NAMES_BOARD = \ + utility/crossystem \ + utility/tpmc -LZMA_LIBS = $(shell ${PKG_CONFIG} --libs liblzma) -YAML_LIBS = $(shell ${PKG_CONFIG} --libs yaml-0.1) -endif - -UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES}) -ALL_OBJS += $(addsuffix .o,${UTIL_BINS}) +UTIL_BINS_SDK = $(addprefix ${BUILD}/,${UTIL_NAMES_SDK}) +UTIL_BINS_BOARD = $(addprefix ${BUILD}/,${UTIL_NAMES_BOARD}) +ALL_OBJS += $(addsuffix .o,${UTIL_BINS_SDK}) +ALL_OBJS += $(addsuffix .o,${UTIL_BINS_BOARD}) # Scripts for signing stuff. -SIGNING_SCRIPTS = \ - utility/tpm-nvsize \ - utility/chromeos-tpm-recovery - -# These go in a different place. SIGNING_SCRIPTS_DEV = \ scripts/image_signing/resign_firmwarefd.sh \ scripts/image_signing/make_dev_firmware.sh \ @@ -637,7 +611,7 @@ SIGNING_SCRIPTS_DEV = \ SIGNING_COMMON = scripts/image_signing/common_minimal.sh -# The unified firmware utility will eventually replace all the others +# Unified firmware utility. FUTIL_BIN = ${BUILD}/futility/futility # These are the executables that are now built in to futility. We'll create @@ -815,7 +789,6 @@ FUZZ_TEST_NAMES = \ tests/vb2_preamble_fuzzer FUZZ_TEST_BINS = $(addprefix ${BUILD}/,${FUZZ_TEST_NAMES}) -FUZZ_TEST_OBJS += $(addsuffix .o,${FUZZ_TEST_BINS}) ############################################################################## # Finally, some targets. High-level ones first. @@ -827,35 +800,24 @@ _dir_create := $(foreach d, \ $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \ $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d})) -# Host targets - -.PHONY: host_tools -host_tools: utils futil tests - -.PHONY: host_stuff -host_stuff: utillib hostlib \ - $(if $(filter x86_64,${ARCH}),fuzzers) \ - $(if ${NO_BUILD_TOOLS},,cgpt host_tools) - .PHONY: clean clean: ${Q}/bin/rm -rf ${BUILD} .PHONY: install -install: $(if ${NO_BUILD_TOOLS},,cgpt_install) \ - utils_install signing_install futil_install \ - pc_files_install +install: cgpt_install signing_install futil_install pc_files_install \ + $(if ${SDK_BUILD},utils_install_sdk,utils_install_board) .PHONY: install_dev install_dev: headers_install lib_install .PHONY: install_mtd -install_mtd: install \ - $(if ${NO_BUILD_TOOLS},,cgpt_wrapper_install) +install_mtd: install cgpt_wrapper_install .PHONY: install_for_test install_for_test: override DESTDIR = ${TEST_INSTALL_DIR} -install_for_test: install +install_for_test: test_setup +install_for_test: install utils_install_sdk utils_install_board # Don't delete intermediate object files .SECONDARY: @@ -1021,33 +983,45 @@ cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER} # These have their own headers too. ${BUILD}/utility/%: INCLUDES += -Iutility/include -${UTIL_BINS}: ${UTILLIB} -${UTIL_BINS}: LIBS = ${UTILLIB} +${UTIL_BINS_SDK}: ${UTILLIB} +${UTIL_BINS_SDK}: LIBS = ${UTILLIB} +${UTIL_BINS_BOARD}: ${UTILLIB} +${UTIL_BINS_BOARD}: LIBS = ${UTILLIB} + +.PHONY: utils_sdk +utils_sdk: ${UTIL_BINS_SDK} ${UTIL_SCRIPTS_SDK} + ${Q}cp -f ${UTIL_SCRIPTS_SDK} ${BUILD}/utility + ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS_SDK}) -.PHONY: utils -utils: ${UTIL_BINS} ${UTIL_SCRIPTS} - ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility - ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS}) +.PHONY: utils_board +utils_board: ${UTIL_BINS_BOARD} ${UTIL_SCRIPTS_BOARD} + ${Q}cp -f ${UTIL_SCRIPTS_BOARD} ${BUILD}/utility + ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS_BOARD}) -.PHONY: utils_install -utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS} +.PHONY: utils_install_sdk +utils_install_sdk: utils_sdk @${PRINTF} " INSTALL UTILS\n" ${Q}mkdir -p ${UB_DIR} - ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS} + ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS_SDK} ${UTIL_SCRIPTS_SDK} + +.PHONY: utils_install_board +utils_install_board: utils_board ${UTIL_DEFAULTS} + @${PRINTF} " INSTALL UTILS\n" + ${Q}mkdir -p ${UB_DIR} + ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS_BOARD} ${UTIL_SCRIPTS_BOARD} ${Q}mkdir -p ${DF_DIR} ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS} # And some signing stuff for the target .PHONY: signing_install -signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON} +signing_install: ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON} @${PRINTF} " INSTALL SIGNING\n" ${Q}mkdir -p ${UB_DIR} ${VB_DIR} - ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS} ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV} ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON} # ---------------------------------------------------------------------------- -# new Firmware Utility +# Firmware Utility .PHONY: futil futil: ${FUTIL_BIN} @@ -1209,20 +1183,8 @@ ${FUTIL_CMD_LIST}: ${FUTIL_SRCS} ############################################################################## # Targets that exist just to run tests -# Frequently-run tests -.PHONY: test_targets -test_targets:: runcgpttests runmisctests run2tests - -ifeq (${MINIMAL},) -# Bitmap utility isn't compiled for minimal variant -test_targets:: runfutiltests -# Scripts don't work under qemu testing -# TODO: convert scripts to makefile so they can be called directly -test_targets:: runtestscripts -endif - .PHONY: test_setup -test_setup:: cgpt utils futil tests install_for_test +test_setup:: cgpt utils_sdk utils_board futil tests # Qemu setup for cross-compiled tests. Need to copy qemu binary into the # sysroot. @@ -1240,30 +1202,27 @@ endif ${Q}chmod a+rx ${BUILD}/${QEMU_BIN} endif -.PHONY: runtests -runtests: test_setup test_targets - # Generate test keys .PHONY: genkeys -genkeys: utils test_setup +genkeys: install_for_test tests/gen_test_keys.sh # Generate test cases .PHONY: gentestcases -gentestcases: utils test_setup +gentestcases: install_for_test tests/gen_test_cases.sh # Generate test cases for fuzzing .PHONY: genfuzztestcases -genfuzztestcases: utils test_setup +genfuzztestcases: install_for_test tests/gen_fuzz_test_cases.sh .PHONY: runcgpttests -runcgpttests: test_setup +runcgpttests: install_for_test ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test .PHONY: runtestscripts -runtestscripts: test_setup genfuzztestcases +runtestscripts: install_for_test genfuzztestcases scripts/image_signing/sign_android_unittests.sh tests/load_kernel_tests.sh tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt @@ -1275,7 +1234,7 @@ runtestscripts: test_setup genfuzztestcases tests/vb2_firmware_tests.sh .PHONY: runmisctests -runmisctests: test_setup +runmisctests: install_for_test ${RUNTEST} ${BUILD_RUN}/tests/subprocess_tests ifeq (${MOCK_TPM}${TPM2_MODE},) # tlcl_tests only works when MOCK_TPM is disabled @@ -1291,7 +1250,7 @@ endif ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests .PHONY: run2tests -run2tests: test_setup +run2tests: install_for_test ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests ${RUNTEST} ${BUILD_RUN}/tests/vb2_auxfw_sync_tests ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests @@ -1323,28 +1282,32 @@ run2tests: test_setup ${RUNTEST} ${BUILD_RUN}/tests/hmac_test .PHONY: runfutiltests -runfutiltests: test_setup - tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin +runfutiltests: install_for_test + tests/futility/run_test_scripts.sh ${UB_DIR} ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really -# Run long tests, including all permutations of encryption keys (instead of -# just the ones we use) and tests of currently-unused code. +# Test all permutations of encryption keys, instead of just the ones we use. # Not run by automated build. .PHONY: runlongtests -runlongtests: test_setup genkeys genfuzztestcases +runlongtests: install_for_test genkeys genfuzztestcases ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all tests/run_preamble_tests.sh --all tests/run_vbutil_tests.sh --all -.PHONY: runalltests -runalltests: runtests runfutiltests runlongtests +.PHONY: rununittests +rununittests: runcgpttests runmisctests run2tests + +# chromium(1048048): Not including runfutiltests due to flakiness. +# Add back when this issue has been resolved. +.PHONY: runtests +runtests: rununittests runtestscripts # Code coverage .PHONY: coverage_init -coverage_init: test_setup +coverage_init: install_for_test rm -f ${COV_INFO}* lcov -c -i -d . -b . -o ${COV_INFO}.initial @@ -1380,7 +1343,7 @@ TEST_DEPS += ${TEST_OBJS:%.o=%.o.d} SRCDIRPAT=$(subst /,\/,${SRCDIR}/) # Note: vboot 2.0 is deprecated, so don't index those files -${BUILD}/cscope.files: all test_setup +${BUILD}/cscope.files: all install_for_test ${Q}rm -f $@ ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \ grep -v /lib20/ | \ diff --git a/tests/common.sh b/tests/common.sh index 70743fc7..4da9e443 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -12,7 +12,7 @@ BUILD="${BUILD:-${ROOT_DIR}/build}" BUILD_RUN="${BUILD_RUN:-${BUILD}}" SRC_RUN="${SRC_RUN:-${SRCDIR}}" BUILD_DIR="${BUILD}" -BIN_DIR=${BUILD_DIR}/install_for_test/bin +BIN_DIR=${BUILD_DIR}/install_for_test/usr/bin FUTILITY=${BIN_DIR}/futility TEST_DIR="${BUILD_DIR}/tests" TESTKEY_DIR=${SCRIPT_DIR}/testkeys -- cgit v1.2.1