Makefile revision 49cb0d3471e768da11fe76b65769bd57dca38bd7
1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# This Makefile normally builds in a 'build' subdir, but use 6# 7# make BUILD=<dir> 8# 9# to put the output somewhere else. 10 11############################################################################## 12# Make variables come in two flavors, immediate or deferred. 13# 14# Variable definitions are parsed like this: 15# 16# IMMEDIATE = DEFERRED 17# or 18# IMMEDIATE := IMMEDIATE 19# 20# Rules are parsed this way: 21# 22# IMMEDIATE : IMMEDIATE 23# DEFERRED 24# 25# So you can assign variables in any order if they're only to be used in 26# actions, but if you use a variable in either the target or prerequisite of a 27# rule, the rule will be constructed using only the top-down, immediate value. 28# 29# So we'll try to define all the variables first. Then the rules. 30# 31 32############################################################################## 33# Configuration variables come first. 34# 35# Our convention is that we only use := for variables that will never be 36# changed or appended. They must be defined before being used anywhere. 37 38# we should only run pwd once, not every time we refer to ${BUILD}. 39SRCDIR := $(shell pwd) 40BUILD ?= $(SRCDIR)/build 41export BUILD 42 43# Target for 'make install' 44DESTDIR ?= /usr/bin 45INSTALL ?= install 46 47# Where to install the (exportable) executables for testing? 48TEST_INSTALL_DIR = ${BUILD}/install_for_test 49 50# Verbose? Use V=1 51ifeq (${V},) 52Q := @ 53endif 54 55# Architecture detection 56_machname := $(shell uname -m) 57HOST_ARCH ?= ${_machname} 58 59# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild. 60# Pick a sane target architecture if none is defined. 61ifeq (${ARCH},) 62 ARCH := ${HOST_ARCH} 63else ifeq (${ARCH},i386) 64 override ARCH := x86 65else ifeq (${ARCH},amd64) 66 override ARCH := x86_64 67endif 68 69# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling 70# for a firmware target (such as u-boot or depthcharge). It must map 71# to the same consistent set of architectures as the host. 72ifeq (${FIRMWARE_ARCH},i386) 73 override FIRMWARE_ARCH := x86 74else ifeq (${FIRMWARE_ARCH},amd64) 75 override FIRMWARE_ARCH := x86_64 76endif 77 78# Provide default CC and CFLAGS for firmware builds; if you have any -D flags, 79# please add them after this point (e.g., -DVBOOT_DEBUG). 80# 81# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just 82# temporarily. As we are still investigating which flags are necessary for 83# maintaining a compatible ABI, etc. between u-boot and vboot_reference. 84# 85# As a first step, this makes the setting of CC and CFLAGS here optional, to 86# permit a calling script or Makefile to set these. 87# 88# Flag ordering: arch, then -f, then -m, then -W 89DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os) 90COMMON_FLAGS := -nostdinc -pipe \ 91 -ffreestanding -fno-builtin -fno-stack-protector \ 92 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS} 93 94# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild. 95ifeq (${FIRMWARE_ARCH}, arm) 96CC ?= armv7a-cros-linux-gnueabi-gcc 97CFLAGS ?= -march=armv5 \ 98 -fno-common -ffixed-r8 \ 99 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \ 100 ${COMMON_FLAGS} 101else ifeq (${FIRMWARE_ARCH}, x86) 102CC ?= i686-pc-linux-gnu-gcc 103# Drop -march=i386 to permit use of SSE instructions 104CFLAGS ?= \ 105 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \ 106 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \ 107 -mpreferred-stack-boundary=2 -mregparm=3 \ 108 ${COMMON_FLAGS} 109else ifeq (${FIRMWARE_ARCH}, x86_64) 110CFLAGS ?= ${COMMON_FLAGS} \ 111 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer 112else 113# FIRMWARE_ARCH not defined; assuming local compile. 114CC ?= gcc 115CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two? 116endif 117 118ifneq (${DEBUG},) 119CFLAGS += -DVBOOT_DEBUG 120endif 121 122ifeq (${DISABLE_NDEBUG},) 123CFLAGS += -DNDEBUG 124endif 125 126# Create / use dependency files 127CFLAGS += -MMD -MF $@.d 128 129# Code coverage 130ifneq (${COV},) 131 COV_FLAGS = -O0 --coverage 132 CFLAGS += ${COV_FLAGS} 133 LDFLAGS += ${COV_FLAGS} 134 COV_INFO = ${BUILD}/coverage.info 135endif 136 137# And a few more default utilities 138LD = ${CC} 139CXX ?= g++ # HEY: really? 140PKG_CONFIG ?= pkg-config 141 142# Determine QEMU architecture needed, if any 143ifeq (${ARCH},${HOST_ARCH}) 144 # Same architecture; no need for QEMU 145 QEMU_ARCH := 146else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86) 147 # 64-bit host can run 32-bit targets directly 148 QEMU_ARCH := 149else 150 QEMU_ARCH := ${ARCH} 151endif 152 153# The top of the chroot for qemu must be passed in via the SYSROOT environment 154# variable. In the Chromium OS chroot, this is done automatically by the 155# ebuild. 156 157ifeq (${QEMU_ARCH},) 158 # Path to build output for running tests is same as for building 159 BUILD_RUN = ${BUILD} 160 SRC_RUN = ${SRCDIR} 161else 162 $(info Using qemu for testing.) 163 # Path to build output for running tests is different in the chroot 164 BUILD_RUN = $(subst ${SYSROOT},,${BUILD}) 165 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR}) 166 167 QEMU_BIN = qemu-${QEMU_ARCH} 168 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN} 169 export QEMU_RUN 170 171 RUNTEST = tests/test_using_qemu.sh 172endif 173 174export BUILD_RUN 175 176# Some things only compile inside the Chromium OS chroot. 177# TODO: Those things should be in their own repo, not part of vboot_reference 178# TODO: Is there a better way to detect this? 179ifneq (${CROS_WORKON_SRCROOT},) 180IN_CHROOT := yes 181endif 182 183# TODO: Move to separate repo. 184ifneq (${IN_CHROOT},) 185PC_BASE_VER ?= 125070 186PC_DEPS := libchrome-${PC_BASE_VER} 187PC_CFLAGS := $(shell ${PKG_CONFIG} --cflags ${PC_DEPS}) 188PC_LDLIBS := $(shell ${PKG_CONFIG} --libs ${PC_DEPS}) 189endif 190 191 192############################################################################## 193# Now we need to describe everything we might want or need to build 194 195# TODO: This should go in its own repo. 196AU_CGPTLIB = ${BUILD}/cgpt/libcgpt-cc.a 197# This is just ... Gah. There's no good place for it. 198DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a 199 200# Everything wants these headers. 201INCLUDES += \ 202 -Ifirmware/include \ 203 -Ifirmware/lib/include \ 204 -Ifirmware/lib/cgptlib/include \ 205 -Ifirmware/lib/cryptolib/include \ 206 -Ifirmware/lib/tpm_lite/include 207 208# If we're not building for a specific target, just stub out things like the 209# TPM commands and various external functions that are provided by the BIOS. 210ifeq (${FIRMWARE_ARCH},) 211INCLUDES += -Ifirmware/stub/include 212else 213INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include 214endif 215 216# Firmware library. TODO: Do we still need to export this? 217FWLIB = ${BUILD}/vboot_fw.a 218 219# find lib -iname '*.c' | sort 220FWLIB_SRCS = \ 221 firmware/lib/cgptlib/cgptlib.c \ 222 firmware/lib/cgptlib/cgptlib_internal.c \ 223 firmware/lib/cgptlib/crc32.c \ 224 firmware/lib/crc8.c \ 225 firmware/lib/cryptolib/padding.c \ 226 firmware/lib/cryptolib/rsa.c \ 227 firmware/lib/cryptolib/rsa_utility.c \ 228 firmware/lib/cryptolib/sha1.c \ 229 firmware/lib/cryptolib/sha256.c \ 230 firmware/lib/cryptolib/sha512.c \ 231 firmware/lib/cryptolib/sha_utility.c \ 232 firmware/lib/stateful_util.c \ 233 firmware/lib/utility.c \ 234 firmware/lib/utility_string.c \ 235 firmware/lib/vboot_api_init.c \ 236 firmware/lib/vboot_api_firmware.c \ 237 firmware/lib/vboot_api_kernel.c \ 238 firmware/lib/vboot_audio.c \ 239 firmware/lib/vboot_common.c \ 240 firmware/lib/vboot_display.c \ 241 firmware/lib/vboot_firmware.c \ 242 firmware/lib/vboot_kernel.c \ 243 firmware/lib/vboot_nvstorage.c 244 245# Support real TPM unless BIOS sets MOCK_TPM 246ifeq (${MOCK_TPM},) 247FWLIB_SRCS += \ 248 firmware/lib/rollback_index.c \ 249 firmware/lib/tpm_bootmode.c \ 250 firmware/lib/tpm_lite/tlcl.c 251else 252FWLIB_SRCS += \ 253 firmware/lib/mocked_rollback_index.c \ 254 firmware/lib/mocked_tpm_bootmode.c \ 255 firmware/lib/tpm_lite/mocked_tlcl.c 256endif 257 258ifeq (${FIRMWARE_ARCH},) 259# Include BIOS stubs in the firmware library when compiling for host 260FWLIB_SRCS += \ 261 firmware/stub/tpm_lite_stub.c \ 262 firmware/stub/utility_stub.c \ 263 firmware/stub/vboot_api_stub.c \ 264 firmware/stub/vboot_api_stub_disk.c 265endif 266 267FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o} 268ALL_OBJS += ${FWLIB_OBJS} 269 270 271# Library to build the utilities. "HOST" mostly means "userspace". 272HOSTLIB = ${BUILD}/vboot_host.a 273 274HOSTLIB_SRCS = \ 275 host/arch/${ARCH}/lib/crossystem_arch.c \ 276 host/lib/crossystem.c \ 277 host/lib/file_keys.c \ 278 host/lib/fmap.c \ 279 host/lib/host_common.c \ 280 host/lib/host_key.c \ 281 host/lib/host_keyblock.c \ 282 host/lib/host_misc.c \ 283 host/lib/host_signature.c \ 284 host/lib/signature_digest.c 285 286HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o} 287ALL_OBJS += ${HOSTLIB_OBJS} 288 289 290# Link with hostlib by default 291LIBS = $(HOSTLIB) 292 293# Might need this too. 294CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto) 295 296 297# ---------------------------------------------------------------------------- 298# Now for the userspace binaries 299 300CGPT = ${BUILD}/cgpt/cgpt 301 302CGPT_SRCS = \ 303 cgpt/cgpt.c \ 304 cgpt/cgpt_add.c \ 305 cgpt/cgpt_boot.c \ 306 cgpt/cgpt_common.c \ 307 cgpt/cgpt_create.c \ 308 cgpt/cgpt_find.c \ 309 cgpt/cgpt_legacy.c \ 310 cgpt/cgpt_prioritize.c \ 311 cgpt/cgpt_repair.c \ 312 cgpt/cgpt_show.c \ 313 cgpt/cmd_add.c \ 314 cgpt/cmd_boot.c \ 315 cgpt/cmd_create.c \ 316 cgpt/cmd_find.c \ 317 cgpt/cmd_legacy.c \ 318 cgpt/cmd_prioritize.c \ 319 cgpt/cmd_repair.c \ 320 cgpt/cmd_show.c 321 322CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o} 323ALL_OBJS += ${CGPT_OBJS} 324 325C_DESTDIR = ${DESTDIR} 326 327 328# Scripts to install directly (not compiled) 329UTIL_SCRIPTS = \ 330 utility/dev_debug_vboot \ 331 utility/dev_make_keypair \ 332 utility/enable_dev_usb_boot \ 333 utility/vbutil_what_keys 334 335# These utilities should be linked statically. 336UTIL_NAMES_STATIC = \ 337 crossystem \ 338 dump_fmap \ 339 gbb_utility 340 341UTIL_NAMES = ${UTIL_NAMES_STATIC} \ 342 dev_sign_file \ 343 dump_kernel_config \ 344 dumpRSAPublicKey \ 345 load_kernel_test \ 346 pad_digest_utility \ 347 signature_digest_utility \ 348 tpm_init_temp_fix \ 349 tpmc \ 350 vbutil_firmware \ 351 vbutil_kernel \ 352 vbutil_key \ 353 vbutil_keyblock \ 354 verify_data 355 356ifneq (${IN_CHROOT},) 357UTIL_NAMES += mount-encrypted 358endif 359 360ifeq (${MINIMAL},) 361UTIL_NAMES += \ 362 bmpblk_font \ 363 bmpblk_utility \ 364 eficompress \ 365 efidecompress 366endif 367 368UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC}) 369UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES}) 370ALL_DEPS += $(addsuffix .d,${UTIL_BINS}) 371 372U_DESTDIR = ${DESTDIR} 373 374 375# The unified firmware utility will eventually replace all the others 376FUTIL_BIN = ${BUILD}/futility/futility 377 378FUTIL_SRCS = \ 379 futility/IGNOREME.c 380 381FUTIL_LDS = futility/futility.lds 382 383FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} 384 385ALL_DEPS += $(addsuffix .d,${FUTIL_BIN}) 386ALL_OBJS += ${FUTIL_OBJS} 387 388F_DESTDIR = ${DESTDIR} 389 390 391# Library of handy test functions. 392TESTLIB = ${BUILD}/tests/test.a 393 394TESTLIB_SRCS = \ 395 tests/test_common.c \ 396 tests/timer_utils.c \ 397 tests/crc32_test.c 398 399TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o} 400ALL_OBJS += ${TESTLIB_OBJS} 401 402 403# And some compiled tests. 404TEST_NAMES = \ 405 cgptlib_test \ 406 rollback_index2_tests \ 407 rollback_index3_tests \ 408 rsa_padding_test \ 409 rsa_utility_tests \ 410 rsa_verify_benchmark \ 411 sha_benchmark \ 412 sha_tests \ 413 stateful_util_tests \ 414 tlcl_tests \ 415 tpm_bootmode_tests \ 416 utility_string_tests \ 417 utility_tests \ 418 vboot_api_init_tests \ 419 vboot_api_devmode_tests \ 420 vboot_api_firmware_tests \ 421 vboot_api_kernel_tests \ 422 vboot_audio_tests \ 423 vboot_common_tests \ 424 vboot_common2_tests \ 425 vboot_common3_tests \ 426 vboot_display_tests \ 427 vboot_firmware_tests \ 428 vboot_kernel_tests \ 429 vboot_nvstorage_test 430 431# Grrr 432ifneq (${IN_CHROOT},) 433TEST_NAMES += CgptManagerTests 434endif 435 436# TODO: port these tests to new API, if not already eqivalent 437# functionality in other tests. These don't even compile at present. 438# 439# big_firmware_tests 440# big_kernel_tests 441# firmware_image_tests 442# firmware_rollback_tests 443# firmware_splicing_tests 444# firmware_verify_benchmark 445# kernel_image_tests 446# kernel_rollback_tests 447# kernel_splicing_tests 448# kernel_verify_benchmark 449# rollback_index_test 450# verify_firmware_fuzz_driver 451# verify_kernel_fuzz_driver 452# utility/load_firmware_test 453 454# And a few more... 455TLCL_TESTS = \ 456 tpmtest_earlyextend \ 457 tpmtest_earlynvram \ 458 tpmtest_earlynvram2 \ 459 tpmtest_enable \ 460 tpmtest_fastenable \ 461 tpmtest_globallock \ 462 tpmtest_redefine_unowned \ 463 tpmtest_spaceperm \ 464 tpmtest_testsetup \ 465 tpmtest_timing \ 466 tpmtest_writelimit 467TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS}) 468TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES}) 469 470TEST_NAMES += ${TLCL_TEST_NAMES} 471 472TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES}) 473ALL_DEPS += $(addsuffix .d,${TEST_BINS}) 474 475# Directory containing test keys 476TEST_KEYS = ${SRC_RUN}/tests/testkeys 477 478# ---------------------------------------------------------------------------- 479# TODO: why not make this include *all* the cgpt files, and simply have 480# cgpt link against it? 481# TODO: CgptManager.cc should move to the installer project. Shouldn't be 482# in libcgpt-cc.a. 483AU_CGPTLIB_SRCS = \ 484 cgpt/CgptManager.cc \ 485 cgpt/cgpt_create.c \ 486 cgpt/cgpt_add.c \ 487 cgpt/cgpt_boot.c \ 488 cgpt/cgpt_show.c \ 489 cgpt/cgpt_repair.c \ 490 cgpt/cgpt_prioritize.c \ 491 cgpt/cgpt_common.c \ 492 firmware/lib/cgptlib/crc32.c \ 493 firmware/lib/cgptlib/cgptlib_internal.c \ 494 firmware/stub/utility_stub.c 495 496AU_CGPTLIB_OBJS = $(filter %.o, \ 497 ${AU_CGPTLIB_SRCS:%.c=${BUILD}/%.o} \ 498 ${AU_CGPTLIB_SRCS:%.cc=${BUILD}/%.o}) 499ALL_OBJS += ${AU_CGPTLIB_OBJS} 500 501 502############################################################################## 503# Finally, some targets. High-level ones first. 504 505# Create output directories if necessary. Do this via explicit shell commands 506# so it happens before trying to generate/include dependencies. 507SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite 508_dir_create := $(foreach d, \ 509 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \ 510 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d})) 511 512 513# Default target. 514.PHONY: all 515all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage) 516 517# Host targets 518.PHONY: host_stuff 519host_stuff: hostlib cgpt utils futil tests 520 521# AU targets 522.PHONY: au_stuff 523au_stuff: libcgpt_cc libdump_kernel_config cgptmanager_tests 524 525.PHONY: clean 526clean: 527 ${Q}/bin/rm -rf ${BUILD} 528 529.PHONY: install 530install: cgpt_install utils_install futil_install 531 532# Don't delete intermediate object files 533.SECONDARY: 534 535# TODO: I suspect this is missing some object files. Make a temp 536# target which cleans all known obj/exe's and see what's left; those 537# are the files which need deps. 538ALL_DEPS += ${ALL_OBJS:%.o=%.o.d} 539-include ${ALL_DEPS} 540 541# ---------------------------------------------------------------------------- 542# Firmware library 543 544# TPM-specific flags. These depend on the particular TPM we're targeting for. 545# They are needed here only for compiling parts of the firmware code into 546# user-level tests. 547 548# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until 549# the self test has completed. 550 551${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST 552 553# TPM_MANUAL_SELFTEST is defined if the self test must be started manually 554# (with a call to TPM_ContinueSelfTest) instead of starting automatically at 555# power on. 556# 557# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST 558# are not both defined at the same time. (See comment in code.) 559 560# CFLAGS += -DTPM_MANUAL_SELFTEST 561 562ifeq (${FIRMWARE_ARCH},i386) 563# Unrolling loops in cryptolib makes it faster 564${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS 565 566# Workaround for coreboot on x86, which will power off asynchronously 567# without giving us a chance to react. This is not an example of the Right 568# Way to do things. See chrome-os-partner:7689, and the commit message 569# that made this change. 570${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY 571 572# On x86 we don't actually read the GBB data into RAM until it is needed. 573# Therefore it makes sense to cache it rather than reading it each time. 574# Enable this feature. 575${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA 576endif 577 578ifeq (${FIRMWARE_ARCH},) 579# Disable rollback TPM when compiling locally, since otherwise 580# load_kernel_test attempts to talk to the TPM. 581${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM 582endif 583 584.PHONY: fwlib 585fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,${BUILD}/firmware/linktest/main) 586 587${FWLIB}: ${FWLIB_OBJS} 588 @printf " RM $(subst ${BUILD}/,,$@)\n" 589 ${Q}rm -f $@ 590 @printf " AR $(subst ${BUILD}/,,$@)\n" 591 ${Q}ar qc $@ $^ 592 593# ---------------------------------------------------------------------------- 594# Host library 595 596.PHONY: hostlib 597hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main 598 599${BUILD}/host/% ${HOSTLIB}: INCLUDES += \ 600 -Ihost/include\ 601 -Ihost/arch/${ARCH}/include 602 603# TODO: better way to make .a than duplicating this recipe each time? 604${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} 605 @printf " RM $(subst ${BUILD}/,,$@)\n" 606 ${Q}rm -f $@ 607 @printf " AR $(subst ${BUILD}/,,$@)\n" 608 ${Q}ar qc $@ $^ 609 610# ---------------------------------------------------------------------------- 611# CGPT library and utility 612 613.PHONY: cgpt 614cgpt: ${CGPT} 615 616${CGPT}: LDFLAGS += -static 617${CGPT}: LDLIBS += -luuid 618 619${CGPT}: ${CGPT_OBJS} ${LIBS} 620 @printf " LDcgpt $(subst ${BUILD}/,,$@)\n" 621 ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS} 622 623.PHONY: cgpt_install 624cgpt_install: ${CGPT} 625 @printf " INSTALL CGPT\n" 626 ${Q}mkdir -p ${C_DESTDIR} 627 ${Q}${INSTALL} -t ${C_DESTDIR} $^ 628 629# ---------------------------------------------------------------------------- 630# Utilities 631 632# These have their own headers too. 633${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include 634 635# Utilities for auto-update toolkits must be statically linked. 636${UTIL_BINS_STATIC}: LDFLAGS += -static 637 638.PHONY: utils 639utils: ${UTIL_BINS} ${UTIL_SCRIPTS} 640# TODO: change ebuild to pull scripts directly out of utility dir 641 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility 642 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS}) 643 644.PHONY: utils_install 645utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} 646 @printf " INSTALL UTILS\n" 647 ${Q}mkdir -p ${U_DESTDIR} 648 ${Q}${INSTALL} -t ${U_DESTDIR} $^ 649 650# ---------------------------------------------------------------------------- 651# new Firmware Utility 652 653.PHONY: futil 654futil: ${FUTIL_BIN} 655 656${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} 657 @printf " LD $(subst ${BUILD}/,,$@)\n" 658 ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS} 659 660.PHONY: futil_install 661futil_install: ${FUTIL_BIN} 662 @printf " INSTALL futility\n" 663 ${Q}mkdir -p ${F_DESTDIR} 664 ${Q}${INSTALL} -t ${F_DESTDIR} $^ 665 666 667# ---------------------------------------------------------------------------- 668# Mount-encrypted utility for cryptohome 669 670# TODO: mount-encrypted should move to cryptohome and just link against 671# vboot-host.a for tlcl and crossystem. 672 673# The embedded libcrypto conflicts with the shipped openssl, 674# so mount-* builds without the common CFLAGS (and those includes). 675 676${BUILD}/utility/mount-helpers.o: \ 677 utility/mount-helpers.c \ 678 utility/mount-helpers.h \ 679 utility/mount-encrypted.h 680 @printf " CCm-e $(subst ${BUILD}/,,$@)\n" 681 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ 682 ${COV_FLAGS} \ 683 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \ 684 -c $< -o $@ 685 686${BUILD}/utility/mount-encrypted: \ 687 utility/mount-encrypted.c \ 688 utility/mount-encrypted.h \ 689 ${BUILD}/utility/mount-helpers.o ${LIBS} 690 @printf " CCm-exe $(subst ${BUILD}/,,$@)\n" 691 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ 692 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \ 693 -Ifirmware/include \ 694 -Ihost/include \ 695 ${COV_FLAGS} \ 696 ${LDFLAGS} \ 697 $< -o $@ \ 698 ${BUILD}/utility/mount-helpers.o ${LIBS} \ 699 $(shell ${PKG_CONFIG} --libs glib-2.0 openssl) \ 700 -lm 701ifneq (${COV},) 702 ${Q}mv -f mount-encrypted.gcno ${BUILD}/utility 703endif 704 705# ---------------------------------------------------------------------------- 706# Utility to generate TLCL structure definition header file. 707 708${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct 709 710STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp 711STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h 712 713.PHONY: update_tlcl_structures 714update_tlcl_structures: ${BUILD}/utility/tlcl_generator 715 @printf " Rebuilding TLCL structures\n" 716 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP} 717 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \ 718 ( echo "%% Updating structures.h %%" && \ 719 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} ) 720 721# ---------------------------------------------------------------------------- 722# Library to dump kernel config 723# Used by platform/installer, as well as standalone utility. 724 725.PHONY: libdump_kernel_config 726libdump_kernel_config: ${DUMPKERNELCONFIGLIB} 727 728${DUMPKERNELCONFIGLIB}: ${BUILD}/utility/dump_kernel_config_lib.o 729 @printf " RM $(subst ${BUILD}/,,$@)\n" 730 ${Q}rm -f $@ 731 @printf " AR $(subst ${BUILD}/,,$@)\n" 732 ${Q}ar qc $@ $^ 733 734# ---------------------------------------------------------------------------- 735# And this thing. 736 737.PHONY: libcgpt_cc 738libcgpt_cc: ${AU_CGPTLIB} 739 740${AU_CGPTLIB}: INCLUDES += -Ifirmware/lib/cgptlib/include 741${AU_CGPTLIB}: ${AU_CGPTLIB_OBJS} 742 @printf " RM $(subst ${BUILD}/,,$@)\n" 743 ${Q}rm -f $@ 744 @printf " AR $(subst ${BUILD}/,,$@)\n" 745 ${Q}ar qc $@ $^ 746 747# ---------------------------------------------------------------------------- 748# Tests 749 750.PHONY: tests 751tests: ${TEST_BINS} 752 753${TEST_BINS}: ${TESTLIB} 754 755${TESTLIB}: ${TESTLIB_OBJS} 756 @printf " RM $(subst ${BUILD}/,,$@)\n" 757 ${Q}rm -f $@ 758 @printf " AR $(subst ${BUILD}/,,$@)\n" 759 ${Q}ar qc $@ $^ 760 761 762# ---------------------------------------------------------------------------- 763# Generic build rules. LIBS and OBJS can be overridden to tweak the generic 764# rules for specific targets. 765 766${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS} 767 @printf " LD $(subst ${BUILD}/,,$@)\n" 768 ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS} 769 770${BUILD}/%.o: %.c 771 @printf " CC $(subst ${BUILD}/,,$@)\n" 772 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 773 774# Rules to recompile a single source file for library and test 775# TODO: is there a tidier way to do this? 776${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY 777${BUILD}/%_for_lib.o: %.c 778 @printf " CC-for-lib $(subst ${BUILD}/,,$@)\n" 779 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 780 781${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST 782${BUILD}/%_for_test.o: %.c 783 @printf " CC-for-test $(subst ${BUILD}/,,$@)\n" 784 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 785 786# TODO: C++ files don't belong in vboot reference at all. Convert to C. 787${BUILD}/%.o: %.cc 788 @printf " CXX $(subst ${BUILD}/,,$@)\n" 789 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $< 790 791# ---------------------------------------------------------------------------- 792# Here are the special tweaks to the generic rules. 793 794# Linktest ensures firmware lib doesn't rely on outside libraries 795${BUILD}/firmware/linktest/main: LIBS = ${FWLIB} 796 797# Specific dependency here. 798${BUILD}/utility/dump_kernel_config: LIBS += ${DUMPKERNELCONFIGLIB} 799${BUILD}/utility/dump_kernel_config: ${DUMPKERNELCONFIGLIB} 800 801# GBB utility needs C++ linker. TODO: It shouldn't. 802${BUILD}/utility/gbb_utility: LD = ${CXX} 803 804# Some utilities need external crypto functions 805${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS} 806${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS} 807${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS} 808${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS} 809${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS} 810${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS} 811${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS} 812${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS} 813 814${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS} 815${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS} 816${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS} 817 818${BUILD}/utility/bmpblk_utility: LD = ${CXX} 819${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml 820 821BMPBLK_UTILITY_DEPS = \ 822 ${BUILD}/utility/bmpblk_util.o \ 823 ${BUILD}/utility/image_types.o \ 824 ${BUILD}/utility/eficompress_for_lib.o \ 825 ${BUILD}/utility/efidecompress_for_lib.o 826${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS} 827${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS} 828 829${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o 830${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o 831 832# Allow multiple definitions, so tests can mock functions from other libraries 833${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition 834${BUILD}/tests/%: INCLUDES += -Ihost/include 835${BUILD}/tests/%: LDLIBS += -lrt -luuid 836${BUILD}/tests/%: LIBS += ${TESTLIB} 837 838${BUILD}/tests/rollback_index2_tests: OBJS += \ 839 ${BUILD}/firmware/lib/rollback_index_for_test.o 840${BUILD}/tests/rollback_index2_tests: \ 841 ${BUILD}/firmware/lib/rollback_index_for_test.o 842 843${BUILD}/tests/tlcl_tests: OBJS += \ 844 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o 845${BUILD}/tests/tlcl_tests: \ 846 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o 847 848${BUILD}/tests/vboot_audio_tests: OBJS += \ 849 ${BUILD}/firmware/lib/vboot_audio_for_test.o 850${BUILD}/tests/vboot_audio_tests: \ 851 ${BUILD}/firmware/lib/vboot_audio_for_test.o 852 853.PHONY: cgptmanager_tests 854cgptmanager_tests: ${BUILD}/tests/CgptManagerTests 855 856${BUILD}/tests/CgptManagerTests: CFLAGS += ${PC_CFLAGS} 857${BUILD}/tests/CgptManagerTests: LD = ${CXX} 858${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags ${PC_LDLIBS} 859${BUILD}/tests/CgptManagerTests: LIBS = ${AU_CGPTLIB} 860${BUILD}/tests/CgptManagerTests: ${AU_CGPTLIB} 861 862${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include 863${BUILD}/tests/rollback_index_test: LIBS += -ltlcl 864 865${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o 866${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o 867 868############################################################################## 869# Targets that exist just to run tests 870 871# Frequently-run tests 872.PHONY: test_targets 873test_targets:: runcgpttests runmisctests 874 875ifeq (${MINIMAL},) 876# Bitmap utility isn't compiled for minimal variant 877test_targets:: runbmptests 878# Scripts don't work under qemu testing 879# TODO: convert scripts to makefile so they can be called directly 880test_targets:: runtestscripts 881endif 882 883.PHONY: test_setup 884test_setup:: cgpt utils futil tests 885 886# Qemu setup for cross-compiled tests. Need to copy qemu binary into the 887# sysroot. 888ifneq (${QEMU_ARCH},) 889test_setup:: qemu_install 890 891.PHONY: qemu_install 892qemu_install: 893ifeq (${SYSROOT},) 894 $(error SYSROOT must be set to the top of the target-specific root \ 895when cross-compiling for qemu-based tests to run properly.) 896endif 897 @printf " Copying qemu binary.\n" 898 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN} 899 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN} 900endif 901 902.PHONY: runtests 903runtests: test_targets 904 905# Generate test keys 906.PHONY: genkeys 907genkeys: utils 908 tests/gen_test_keys.sh 909 910# Generate test cases for fuzzing 911.PHONY: genfuzztestcases 912genfuzztestcases: utils 913 tests/gen_fuzz_test_cases.sh 914 915.PHONY: runbmptests 916runbmptests: test_setup 917 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \ 918 ./TestBmpBlock.py -v 919 920.PHONY: runcgpttests 921runcgpttests: test_setup 922 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test 923# HEY - elsewhere 924ifneq (${IN_CHROOT},) 925 ${RUNTEST} ${BUILD_RUN}/tests/CgptManagerTests --v=1 926endif 927 928.PHONY: runtestscripts 929runtestscripts: test_setup genfuzztestcases 930 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt 931 tests/run_preamble_tests.sh 932 tests/run_rsa_tests.sh 933 tests/run_vbutil_kernel_arg_tests.sh 934 tests/run_vbutil_tests.sh 935 936.PHONY: runmisctests 937runmisctests: test_setup 938 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests 939 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests 940 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests 941 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests 942 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests 943 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests 944 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests 945 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests 946 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests 947 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests 948 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests 949 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests 950 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests 951 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests 952 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} 953 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} 954 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests 955 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests 956 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests 957 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test 958 959.PHONY: runfutiltests 960runfutiltests: DESTDIR := ${TEST_INSTALL_DIR} 961runfutiltests: test_setup install 962 @echo "$@ passed" 963 964# Run long tests, including all permutations of encryption keys (instead of 965# just the ones we use) and tests of currently-unused code. 966# Not run by automated build. 967.PHONY: runlongtests 968runlongtests: test_setup genkeys genfuzztestcases 969 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all 970 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all 971 tests/run_preamble_tests.sh --all 972 tests/run_vbutil_tests.sh --all 973 974# TODO: tests to run when ported to new API 975# ./run_image_verification_tests.sh 976# # Splicing tests 977# ${BUILD}/tests/firmware_splicing_tests 978# ${BUILD}/tests/kernel_splicing_tests 979# # Rollback Tests 980# ${BUILD}/tests/firmware_rollback_tests 981# ${BUILD}/tests/kernel_rollback_tests 982 983# Code coverage 984.PHONY: coverage_init 985coverage_init: test_setup 986 rm -f ${COV_INFO}* 987 lcov -c -i -d . -b . -o ${COV_INFO}.initial 988 989.PHONY: coverage_html 990coverage_html: 991 lcov -c -d . -b . -o ${COV_INFO}.tests 992 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total 993 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local 994 genhtml ${COV_INFO}.local -o ${BUILD}/coverage 995 996# Generate addtional coverage stats just for firmware subdir, because the 997# per-directory stats for the whole project don't include their own subdirs. 998 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub 999 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \ 1000 -o ${COV_INFO}.firmware 1001 1002.PHONY: coverage 1003ifeq (${COV},) 1004coverage: 1005 $(error Build coverage like this: make clean && COV=1 make) 1006else 1007coverage: coverage_init runtests coverage_html 1008endif 1009 1010