1 # Copyright 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.
5 # This Makefile normally builds in a 'build' subdir, but use
9 # to put the output somewhere else.
11 ##############################################################################
12 # Make variables come in two flavors, immediate or deferred.
14 # Variable definitions are parsed like this:
16 # IMMEDIATE = DEFERRED
18 # IMMEDIATE := IMMEDIATE
20 # Rules are parsed this way:
22 # IMMEDIATE : IMMEDIATE
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.
29 # So we'll try to define all the variables first. Then the rules.
32 ##############################################################################
33 # Configuration variables come first.
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.
38 # We should only run pwd once, not every time we refer to ${BUILD}.
39 SRCDIR := $(shell pwd)
41 BUILD = ${SRCDIR}/build
44 # Stuff for 'make install'
52 # Where exactly do the pieces go?
53 # UB_DIR = utility binary directory
54 # ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
55 # UI_DIR = include directory for library headers
56 # US_DIR = shared data directory (for static content like devkeys)
57 # DF_DIR = utility defaults directory
58 # VB_DIR = vboot binary directory for dev-mode-only scripts
60 # Host install just puts everything where it's told
62 UL_DIR=${DESTDIR}/${LIBDIR}
63 ULP_DIR=${UL_DIR}/pkgconfig
64 UI_DIR=${DESTDIR}/include/vboot
65 US_DIR=${DESTDIR}/share/vboot
66 DF_DIR=${DESTDIR}/default
69 # Target install puts things into different places
70 UB_DIR=${DESTDIR}/usr/bin
71 UL_DIR=${DESTDIR}/usr/${LIBDIR}
72 ULP_DIR=${UL_DIR}/pkgconfig
73 UI_DIR=${DESTDIR}/usr/include/vboot
74 US_DIR=${DESTDIR}/usr/share/vboot
75 DF_DIR=${DESTDIR}/etc/default
79 # Where to install the (exportable) executables for testing?
80 TEST_INSTALL_DIR = ${BUILD}/install_for_test
94 # Architecture detection
95 _machname := $(shell uname -m)
96 HOST_ARCH ?= ${_machname}
98 # ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
99 # Pick a sane target architecture if none is defined.
102 else ifeq (${ARCH},i386)
104 else ifeq (${ARCH},amd64)
105 override ARCH := x86_64
108 # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
109 # for a firmware target (such as u-boot or depthcharge). It must map
110 # to the same consistent set of architectures as the host.
111 ifeq (${FIRMWARE_ARCH},i386)
112 override FIRMWARE_ARCH := x86
113 else ifeq (${FIRMWARE_ARCH},amd64)
114 override FIRMWARE_ARCH := x86_64
115 else ifeq (${FIRMWARE_ARCH},armv7)
116 override FIRMWARE_ARCH := arm
119 # Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
120 # please add them after this point (e.g., -DVBOOT_DEBUG).
122 # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
123 # temporarily. As we are still investigating which flags are necessary for
124 # maintaining a compatible ABI, etc. between u-boot and vboot_reference.
126 # As a first step, this makes the setting of CC and CFLAGS here optional, to
127 # permit a calling script or Makefile to set these.
129 # Flag ordering: arch, then -f, then -m, then -W
130 DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
132 COMMON_FLAGS := -nostdinc -pipe \
133 -ffreestanding -fno-builtin -fno-stack-protector \
134 ${WERROR} -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
136 # Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
137 ifeq (${FIRMWARE_ARCH}, arm)
138 CC ?= armv7a-cros-linux-gnueabi-gcc
139 CFLAGS ?= -march=armv5 \
140 -fno-common -ffixed-r8 \
141 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
143 else ifeq (${FIRMWARE_ARCH}, x86)
144 CC ?= i686-pc-linux-gnu-gcc
145 # Drop -march=i386 to permit use of SSE instructions
147 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
148 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
149 -mpreferred-stack-boundary=2 \
151 else ifeq (${FIRMWARE_ARCH}, x86_64)
152 CFLAGS ?= ${COMMON_FLAGS} \
153 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
155 # FIRMWARE_ARCH not defined; assuming local compile.
157 CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall ${WERROR} ${DEBUG_FLAGS}
160 ifneq (${CUSTOM_MUSIC},)
161 CFLAGS += -DCUSTOM_MUSIC
165 CFLAGS += -DVBOOT_DEBUG
168 ifeq (${DISABLE_NDEBUG},)
172 ifneq (${FORCE_LOGGING_ON},)
173 CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
185 # NOTE: We don't use these files but they are useful for other packages to
186 # query about required compiling/linking flags.
187 PC_IN_FILES = vboot_host.pc.in
189 # Create / use dependency files
190 CFLAGS += -MMD -MF $@.d
192 ifeq (${FIRMWARE_ARCH},)
193 # Creates position independent code for non firmware target.
197 # These are required to access large disks and files on 32-bit systems.
198 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
202 COV_FLAGS = -O0 --coverage -DCOVERAGE
203 CFLAGS += ${COV_FLAGS}
204 LDFLAGS += ${COV_FLAGS}
205 COV_INFO = ${BUILD}/coverage.info
209 CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
212 # Musl doesn't have execinfo.h.
214 CFLAGS += -DHAVE_EXECINFO_H
217 # And a few more default utilities
220 PKG_CONFIG ?= pkg-config
225 PKG_CONFIG += --static
228 # Determine QEMU architecture needed, if any
229 ifeq (${ARCH},${HOST_ARCH})
230 # Same architecture; no need for QEMU
232 else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
233 # 64-bit host can run 32-bit targets directly
239 # The top of the chroot for qemu must be passed in via the SYSROOT environment
240 # variable. In the Chromium OS chroot, this is done automatically by the
244 # Path to build output for running tests is same as for building
248 $(info Using qemu for testing.)
249 # Path to build output for running tests is different in the chroot
250 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
251 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
253 QEMU_BIN = qemu-${QEMU_ARCH}
254 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
257 RUNTEST = tests/test_using_qemu.sh
262 ##############################################################################
263 # The default target is here, to allow dependencies to be expressed below
264 # without accidentally changing the default target.
268 all: fwlib fwlib2x fwlib20 fwlib21 \
269 $(if ${FIRMWARE_ARCH},,host_stuff) \
270 $(if ${COV},coverage)
272 ##############################################################################
273 # Now we need to describe everything we might want or need to build
275 # Everything wants these headers.
278 -Ifirmware/lib/include \
279 -Ifirmware/lib/cgptlib/include \
280 -Ifirmware/lib/cryptolib/include \
281 -Ifirmware/lib/tpm_lite/include \
282 -Ifirmware/2lib/include
284 # If we're not building for a specific target, just stub out things like the
285 # TPM commands and various external functions that are provided by the BIOS.
286 ifeq (${FIRMWARE_ARCH},)
287 INCLUDES += -Ihost/include -Ihost/lib/include
290 # Firmware library, used by the other firmware components (depthcharge,
291 # coreboot, etc.). It doesn't need exporting to some other place; they'll build
292 # this source tree locally and link to it directly.
293 FWLIB = ${BUILD}/vboot_fw.a
295 # Smaller firmware library common to all vboot 2.x, used only for
296 # 1) compile-time tests of the public API or
297 # 2) linking with an actual 2.0 or 2.1 implementation
298 FWLIB2X = ${BUILD}/vboot_fw2x.a
300 # Vboot 2.0 (deprecated - see firmware/README)
301 FWLIB20 = ${BUILD}/vboot_fw20.a
302 # Vboot 2.1 (not yet ready - see firmware/README)
303 FWLIB21 = ${BUILD}/vboot_fw21.a
305 BDBLIB = ${BUILD}/bdb.a
307 # Firmware library sources needed by VbInit() call
309 firmware/lib/crc8.c \
310 firmware/lib/utility.c \
311 firmware/lib/vboot_api_init.c \
312 firmware/lib/vboot_common_init.c \
313 firmware/lib/vboot_nvstorage.c \
314 firmware/lib/vboot_nvstorage_rollback.c \
315 firmware/lib/region-init.c \
317 # Additional firmware library sources needed by VbSelectFirmware() call
319 firmware/lib/cryptolib/padding.c \
320 firmware/lib/cryptolib/rsa.c \
321 firmware/lib/cryptolib/rsa_utility.c \
322 firmware/lib/cryptolib/sha1.c \
323 firmware/lib/cryptolib/sha256.c \
324 firmware/lib/cryptolib/sha512.c \
325 firmware/lib/cryptolib/sha_utility.c \
326 firmware/lib/stateful_util.c \
327 firmware/lib/vboot_api_firmware.c \
328 firmware/lib/vboot_common.c \
329 firmware/lib/vboot_firmware.c \
330 firmware/lib/region-fw.c \
332 # Additional firmware library sources needed by VbSelectAndLoadKernel() call
334 firmware/lib/cgptlib/cgptlib.c \
335 firmware/lib/cgptlib/cgptlib_internal.c \
336 firmware/lib/cgptlib/crc32.c \
337 firmware/lib/gpt_misc.c \
338 firmware/lib/utility_string.c \
339 firmware/lib/vboot_api_kernel.c \
340 firmware/lib/vboot_audio.c \
341 firmware/lib/vboot_display.c \
342 firmware/lib/vboot_kernel.c \
343 firmware/lib/region-kernel.c \
345 # Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
347 firmware/2lib/2api.c \
348 firmware/2lib/2common.c \
349 firmware/2lib/2crc8.c \
350 firmware/2lib/2misc.c \
351 firmware/2lib/2nvstorage.c \
352 firmware/2lib/2rsa.c \
353 firmware/2lib/2secdata.c \
354 firmware/2lib/2secdatak.c \
355 firmware/2lib/2sha1.c \
356 firmware/2lib/2sha256.c \
357 firmware/2lib/2sha512.c \
358 firmware/2lib/2sha_utility.c \
359 firmware/2lib/2tpm_bootmode.c
362 firmware/lib20/api.c \
363 firmware/lib20/api_kernel.c \
364 firmware/lib20/common.c \
365 firmware/lib20/kernel.c \
366 firmware/lib20/misc.c \
367 firmware/lib20/packed_key.c
370 firmware/lib21/api.c \
371 firmware/lib21/common.c \
372 firmware/lib21/misc.c \
373 firmware/lib21/packed_key.c
380 # Support real TPM unless BIOS sets MOCK_TPM
383 firmware/lib/rollback_index.c \
384 firmware/lib/tpm_lite/tlcl.c
387 firmware/lib/tpm_bootmode.c
390 firmware/lib/mocked_rollback_index.c \
391 firmware/lib/tpm_lite/mocked_tlcl.c
394 firmware/lib/mocked_tpm_bootmode.c
397 ifeq (${FIRMWARE_ARCH},)
398 # Include BIOS stubs in the firmware library when compiling for host
399 # TODO: split out other stub funcs too
401 firmware/stub/tpm_lite_stub.c \
402 firmware/stub/utility_stub.c \
403 firmware/stub/vboot_api_stub_init.c \
404 firmware/stub/vboot_api_stub_region.c
407 firmware/stub/vboot_api_stub_sf.c
410 firmware/stub/vboot_api_stub.c \
411 firmware/stub/vboot_api_stub_disk.c \
412 firmware/stub/vboot_api_stub_stream.c
415 firmware/2lib/2stub.c
419 VBSF_SRCS += ${VBINIT_SRCS}
420 FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
422 VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
423 VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
424 ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
426 FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
427 FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
428 FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
429 FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
430 BDBLIB_OBJS = ${BDBLIB_SRCS:%.c=${BUILD}/%.o}
431 ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS} \
434 # Intermediate library for the vboot_reference utilities to link against.
435 UTILLIB = ${BUILD}/libvboot_util.a
436 UTILLIB21 = ${BUILD}/libvboot_util21.a
437 UTILBDB = ${BUILD}/libvboot_utilbdb.a
445 cgpt/cgpt_prioritize.c \
447 futility/dump_kernel_config_lib.c \
448 host/arch/${ARCH}/lib/crossystem_arch.c \
449 host/lib/crossystem.c \
450 host/lib/file_keys.c \
452 host/lib/host_common.c \
453 host/lib/host_key.c \
454 host/lib/host_keyblock.c \
455 host/lib/host_misc.c \
456 host/lib/util_misc.c \
457 host/lib/host_signature.c \
458 host/lib/signature_digest.c
460 UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
461 ALL_OBJS += ${UTILLIB_OBJS}
464 host/lib21/host_fw_preamble.c \
465 host/lib21/host_key.c \
466 host/lib21/host_keyblock.c \
467 host/lib21/host_misc.c \
468 host/lib21/host_signature.c
470 UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
471 ALL_OBJS += ${UTILLIB21_OBJS}
476 UTILBDB_OBJS = ${UTILBDB_SRCS:%.c=${BUILD}/%.o}
477 ALL_OBJS += ${UTILBDB_OBJS}
479 # Externally exported library for some target userspace apps to link with
480 # (cryptohome, updater, etc.)
481 HOSTLIB = ${BUILD}/libvboot_host.a
488 cgpt/cgpt_prioritize.c \
489 firmware/lib/cgptlib/cgptlib_internal.c \
490 firmware/lib/cgptlib/crc32.c \
491 firmware/lib/crc8.c \
492 firmware/lib/gpt_misc.c \
493 firmware/lib/tpm_lite/tlcl.c \
494 firmware/lib/utility_string.c \
495 firmware/lib/vboot_nvstorage.c \
496 firmware/stub/tpm_lite_stub.c \
497 firmware/stub/utility_stub.c \
498 firmware/stub/vboot_api_stub.c \
499 firmware/stub/vboot_api_stub_disk.c \
500 firmware/stub/vboot_api_stub_init.c \
501 firmware/stub/vboot_api_stub_sf.c \
502 futility/dump_kernel_config_lib.c \
503 host/arch/${ARCH}/lib/crossystem_arch.c \
504 host/lib/crossystem.c \
505 host/lib/extract_vmlinuz.c \
509 HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
510 ALL_OBJS += ${HOSTLIB_OBJS}
512 # Sigh. For historical reasons, the autoupdate installer must sometimes be a
513 # 32-bit executable, even when everything else is 64-bit. But it only needs a
514 # few functions, so let's just build those.
515 TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
522 cgpt/cgpt_prioritize.c \
523 firmware/lib/cgptlib/cgptlib_internal.c \
524 firmware/lib/cgptlib/crc32.c \
525 firmware/lib/gpt_misc.c \
526 firmware/lib/utility_string.c \
527 firmware/stub/vboot_api_stub.c \
528 firmware/stub/vboot_api_stub_disk.c \
529 firmware/stub/vboot_api_stub_sf.c \
530 firmware/stub/utility_stub.c \
531 futility/dump_kernel_config_lib.c \
532 host/lib/extract_vmlinuz.c
534 TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
536 # ----------------------------------------------------------------------------
537 # Now for the userspace binaries
539 CGPT = ${BUILD}/cgpt/cgpt
550 cgpt/cgpt_prioritize.c \
558 cgpt/cmd_prioritize.c \
562 CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
564 ALL_OBJS += ${CGPT_OBJS}
566 CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
568 CGPT_WRAPPER_SRCS = \
572 CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
574 ALL_OBJS += ${CGPT_WRAPPER_OBJS}
577 UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
579 # Scripts to install directly (not compiled)
581 utility/dev_debug_vboot \
582 utility/enable_dev_usb_boot
586 utility/dev_make_keypair \
587 utility/vbutil_what_keys
590 # These utilities should be linked statically.
591 UTIL_NAMES_STATIC = \
594 UTIL_NAMES = ${UTIL_NAMES_STATIC} \
595 utility/tpm_init_temp_fix \
596 utility/dumpRSAPublicKey \
599 # TODO: Do we still need eficompress and efidecompress for anything?
602 utility/bmpblk_font \
603 utility/bmpblk_utility \
604 utility/eficompress \
605 utility/efidecompress \
606 utility/load_kernel_test \
607 utility/pad_digest_utility \
608 utility/signature_digest_utility \
612 UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
613 UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
614 ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
617 # Scripts for signing stuff.
620 utility/chromeos-tpm-recovery
622 # These go in a different place.
623 SIGNING_SCRIPTS_DEV = \
624 scripts/image_signing/resign_firmwarefd.sh \
625 scripts/image_signing/make_dev_firmware.sh \
626 scripts/image_signing/make_dev_ssd.sh \
627 scripts/image_signing/set_gbb_flags.sh
629 # Installed, but not made executable.
630 SIGNING_COMMON = scripts/image_signing/common_minimal.sh
633 # The unified firmware utility will eventually replace all the others
634 FUTIL_BIN = ${BUILD}/futility/futility
635 # But we still need both static (tiny) and dynamic (with openssl) versions.
636 FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
638 # These are the executables that are now built in to futility. We'll create
639 # symlinks for these so the old names will still work.
649 FUTIL_STATIC_SRCS = \
650 futility/futility.c \
651 futility/cmd_dump_fmap.c \
652 futility/cmd_gbb_utility.c \
654 futility/ryu_root_header.c
657 ${FUTIL_STATIC_SRCS} \
658 futility/cmd_create.c \
659 futility/cmd_dump_kernel_config.c \
660 futility/cmd_load_fmap.c \
662 futility/cmd_show.c \
663 futility/cmd_sign.c \
664 futility/cmd_vbutil_firmware.c \
665 futility/cmd_vbutil_kernel.c \
666 futility/cmd_vbutil_key.c \
667 futility/cmd_vbutil_keyblock.c \
668 futility/file_type.c \
669 futility/file_type_bios.c \
670 futility/file_type_rwsig.c \
671 futility/file_type_usbpd1.c \
672 futility/vb1_helper.c \
673 futility/vb2_helper.c
675 # List of commands built in futility and futility_s.
676 FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
677 FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
679 # Workaround for TODO(crbug.com/437107).
680 FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
682 FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
683 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
684 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
685 FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
687 ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
688 ${FUTIL_BIN}: ${UTILLIB21}
689 ${FUTIL_BIN}: LIBS += ${UTILLIB21}
691 ALL_OBJS += ${FUTIL_OBJS}
694 # Library of handy test functions.
695 TESTLIB = ${BUILD}/tests/test.a
698 tests/test_common.c \
699 tests/timer_utils.c \
702 TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
703 TEST_OBJS += ${TESTLIB_OBJS}
706 # And some compiled tests.
709 tests/rollback_index2_tests \
710 tests/rollback_index3_tests \
711 tests/rsa_padding_test \
712 tests/rsa_utility_tests \
713 tests/rsa_verify_benchmark \
714 tests/sha_benchmark \
716 tests/stateful_util_tests \
718 tests/tpm_bootmode_tests \
719 tests/utility_string_tests \
720 tests/utility_tests \
721 tests/vboot_api_init_tests \
722 tests/vboot_api_devmode_tests \
723 tests/vboot_api_firmware_tests \
724 tests/vboot_api_kernel_tests \
725 tests/vboot_api_kernel2_tests \
726 tests/vboot_api_kernel3_tests \
727 tests/vboot_api_kernel4_tests \
728 tests/vboot_api_kernel5_tests \
729 tests/vboot_api_kernel6_tests \
730 tests/vboot_audio_tests \
731 tests/vboot_common_tests \
732 tests/vboot_common2_tests \
733 tests/vboot_common3_tests \
734 tests/vboot_display_tests \
735 tests/vboot_firmware_tests \
736 tests/vboot_kernel_tests \
737 tests/vboot_nvstorage_test \
741 TEST_NAMES += tests/vboot_region_tests
745 tests/futility/binary_editor \
746 tests/futility/test_file_types \
747 tests/futility/test_not_really
749 TEST_NAMES += ${TEST_FUTIL_NAMES}
752 tests/vb2_api_tests \
753 tests/vb2_common_tests \
754 tests/vb2_misc_tests \
755 tests/vb2_nvstorage_tests \
756 tests/vb2_rsa_utility_tests \
757 tests/vb2_secdata_tests \
758 tests/vb2_secdatak_tests \
762 tests/vb20_api_tests \
763 tests/vb20_api_kernel_tests \
764 tests/vb20_common_tests \
765 tests/vb20_common2_tests \
766 tests/vb20_verify_fw.c \
767 tests/vb20_common3_tests \
768 tests/vb20_kernel_tests \
769 tests/vb20_misc_tests \
770 tests/vb20_rsa_padding_tests \
774 tests/vb21_api_tests \
775 tests/vb21_common_tests \
776 tests/vb21_common2_tests \
777 tests/vb21_misc_tests \
778 tests/vb21_host_fw_preamble_tests \
779 tests/vb21_host_key_tests \
780 tests/vb21_host_keyblock_tests \
781 tests/vb21_host_misc_tests \
782 tests/vb21_host_sig_tests
787 TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES} ${TESTBDB_NAMES}
791 tests/tpm_lite/tpmtest_earlyextend \
792 tests/tpm_lite/tpmtest_earlynvram \
793 tests/tpm_lite/tpmtest_earlynvram2 \
794 tests/tpm_lite/tpmtest_enable \
795 tests/tpm_lite/tpmtest_fastenable \
796 tests/tpm_lite/tpmtest_globallock \
797 tests/tpm_lite/tpmtest_redefine_unowned \
798 tests/tpm_lite/tpmtest_spaceperm \
799 tests/tpm_lite/tpmtest_testsetup \
800 tests/tpm_lite/tpmtest_timing \
801 tests/tpm_lite/tpmtest_writelimit
803 TEST_NAMES += ${TLCL_TEST_NAMES}
806 TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
807 TEST_OBJS += $(addsuffix .o,${TEST_BINS})
809 TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES})
810 TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
811 TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
812 TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
813 TESTBDB_BINS = $(addprefix ${BUILD}/,${TESTBDB_NAMES})
815 # Directory containing test keys
816 TEST_KEYS = ${SRC_RUN}/tests/testkeys
819 ##############################################################################
820 # Finally, some targets. High-level ones first.
822 # Create output directories if necessary. Do this via explicit shell commands
823 # so it happens before trying to generate/include dependencies.
824 SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
825 _dir_create := $(foreach d, \
826 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
827 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
831 host_stuff: utillib hostlib cgpt utils futil tests utillib21
835 ${Q}/bin/rm -rf ${BUILD}
838 install: cgpt_install utils_install signing_install futil_install \
842 install_dev: headers_install lib_install
845 install_mtd: install cgpt_wrapper_install
847 .PHONY: install_for_test
848 install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
849 install_for_test: install
851 # Don't delete intermediate object files
854 # ----------------------------------------------------------------------------
857 # TPM-specific flags. These depend on the particular TPM we're targeting for.
858 # They are needed here only for compiling parts of the firmware code into
861 # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
862 # the self test has completed.
864 ${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
866 # TPM_MANUAL_SELFTEST is defined if the self test must be started manually
867 # (with a call to TPM_ContinueSelfTest) instead of starting automatically at
870 # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
871 # are not both defined at the same time. (See comment in code.)
873 # CFLAGS += -DTPM_MANUAL_SELFTEST
875 ifeq (${FIRMWARE_ARCH},i386)
876 # Unrolling loops in cryptolib makes it faster
877 ${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
878 ${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
879 ${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
880 ${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
881 ${BDBLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
883 # Workaround for coreboot on x86, which will power off asynchronously
884 # without giving us a chance to react. This is not an example of the Right
885 # Way to do things. See chrome-os-partner:7689, and the commit message
886 # that made this change.
887 ${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
889 # On x86 we don't actually read the GBB data into RAM until it is needed.
890 # Therefore it makes sense to cache it rather than reading it each time.
891 # Enable this feature.
892 ${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
896 ${FWLIB_OBJS}: CFLAGS += -DREGION_READ
899 ifeq (${FIRMWARE_ARCH},)
900 # Disable rollback TPM when compiling locally, since otherwise
901 # load_kernel_test attempts to talk to the TPM.
902 ${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
905 ${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
906 ${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
907 ${BDBLIB_OBJS}: INCLUDES += -Ifirmware/bdb
909 # Linktest ensures firmware lib doesn't rely on outside libraries
910 ${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
911 ${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
912 TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
913 ${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
914 ${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
915 TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
916 ${BUILD}/firmware/linktest/main: ${FWLIB}
917 ${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
918 TEST_OBJS += ${BUILD}/firmware/linktest/main.o
922 ${BUILD}/firmware/linktest/main_vbinit \
923 ${BUILD}/firmware/linktest/main_vbsf \
924 ${BUILD}/firmware/linktest/main
927 fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
929 ${FWLIB}: ${FWLIB_OBJS}
930 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
932 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
938 ${FWLIB2X}: ${FWLIB2X_OBJS}
939 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
941 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
947 ${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
948 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
950 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
956 ${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
957 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
959 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
965 ${BDBLIB}: ${BDBLIB_OBJS}
966 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
968 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
971 # ----------------------------------------------------------------------------
974 # Link tests for local utilities
975 ${BUILD}/host/linktest/main: ${UTILLIB}
976 ${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
977 TEST_OBJS += ${BUILD}/host/linktest/main.o
980 utillib: ${UTILLIB} \
981 ${BUILD}/host/linktest/main
983 # TODO: better way to make .a than duplicating this recipe each time?
984 ${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
985 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
987 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
991 utillib21: ${UTILLIB21}
993 ${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
994 ${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
995 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
997 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1000 ${UTILBDB}: ${UTILBDB_OBJS} ${BDBLIB_OBJS}
1001 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1003 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1006 # Link tests for external repos
1007 ${BUILD}/host/linktest/extern: ${HOSTLIB}
1008 ${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
1009 ${BUILD}/host/linktest/extern: LDLIBS += -static
1010 TEST_OBJS += ${BUILD}/host/linktest/extern.o
1013 hostlib: ${HOSTLIB} \
1014 ${BUILD}/host/linktest/extern
1016 # TODO: better way to make .a than duplicating this recipe each time?
1017 ${HOSTLIB}: ${HOSTLIB_OBJS}
1018 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1020 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1024 # Ugh. This is a very cut-down version of HOSTLIB just for the installer.
1026 tinyhostlib: ${TINYHOSTLIB}
1027 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
1029 ${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
1030 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1032 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1035 .PHONY: headers_install
1037 @${PRINTF} " INSTALL HEADERS\n"
1038 ${Q}mkdir -p ${UI_DIR}
1039 ${Q}${INSTALL} -t ${UI_DIR} -m644 \
1041 firmware/include/gpt.h \
1042 firmware/include/tlcl.h \
1043 firmware/include/tss_constants.h
1046 lib_install: ${HOSTLIB}
1047 @${PRINTF} " INSTALL HOSTLIB\n"
1048 ${Q}mkdir -p ${UL_DIR}
1049 ${Q}${INSTALL} -t ${UL_DIR} -m644 $^
1051 .PHONY: devkeys_install
1053 @${PRINTF} " INSTALL DEVKEYS\n"
1054 ${Q}mkdir -p ${US_DIR}/devkeys
1055 ${Q}${INSTALL} -t ${US_DIR}/devkeys -m644 tests/devkeys/*
1057 # ----------------------------------------------------------------------------
1058 # CGPT library and utility
1060 .PHONY: cgpt_wrapper
1061 cgpt_wrapper: ${CGPT_WRAPPER}
1063 ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
1064 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
1065 ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
1068 cgpt: ${CGPT} ${CGPT_WRAPPER}
1070 ${CGPT}: LDLIBS += -luuid
1072 ${CGPT}: ${CGPT_OBJS} ${UTILLIB}
1073 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
1074 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1076 .PHONY: cgpt_install
1077 cgpt_install: ${CGPT}
1078 @${PRINTF} " INSTALL CGPT\n"
1079 ${Q}mkdir -p ${UB_DIR}
1080 ${Q}${INSTALL} -t ${UB_DIR} $^
1082 .PHONY: cgpt_wrapper_install
1083 cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
1084 @$(PRINTF) " INSTALL cgpt_wrapper\n"
1085 ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
1086 ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
1087 ${UB_DIR}/$(notdir ${CGPT}).bin
1088 ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
1089 ${UB_DIR}/$(notdir ${CGPT})
1091 # ----------------------------------------------------------------------------
1094 # These have their own headers too.
1095 ${BUILD}/utility/%: INCLUDES += -Iutility/include
1097 ${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
1098 ${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
1100 # Utilities for auto-update toolkits must be statically linked.
1101 ${UTIL_BINS_STATIC}: LDFLAGS += -static
1105 utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
1106 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
1107 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
1109 .PHONY: utils_install
1110 utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
1111 @${PRINTF} " INSTALL UTILS\n"
1112 ${Q}mkdir -p ${UB_DIR}
1113 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
1114 ${Q}mkdir -p ${DF_DIR}
1115 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
1117 # And some signing stuff for the target
1118 .PHONY: signing_install
1119 signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
1120 @${PRINTF} " INSTALL SIGNING\n"
1121 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
1122 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
1123 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1124 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
1126 # ----------------------------------------------------------------------------
1127 # new Firmware Utility
1130 futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1132 ${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
1133 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1134 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
1136 ${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
1137 ${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
1138 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1139 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1141 .PHONY: futil_install
1142 futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1143 @${PRINTF} " INSTALL futility\n"
1144 ${Q}mkdir -p ${UB_DIR}
1145 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1146 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
1147 ln -sf futility "${UB_DIR}/$$prog"; done
1149 # ----------------------------------------------------------------------------
1150 # Utility to generate TLCL structure definition header file.
1152 ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1154 STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1155 STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1157 .PHONY: update_tlcl_structures
1158 update_tlcl_structures: ${BUILD}/utility/tlcl_generator
1159 @${PRINTF} " Rebuilding TLCL structures\n"
1160 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1161 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1162 ( echo "%% Updating structures.h %%" && \
1163 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1165 # ----------------------------------------------------------------------------
1171 ${TEST_BINS}: ${UTILLIB} ${TESTLIB}
1172 ${TEST_BINS}: INCLUDES += -Itests
1173 ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
1175 # Futility tests need almost everything that futility needs.
1176 ${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21}
1177 ${TEST_FUTIL_BINS}: INCLUDES += -Ifutility
1178 ${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21}
1179 ${TEST_FUTIL_BINS}: LDLIBS += ${CRYPTO_LIBS}
1181 ${TEST2X_BINS}: ${FWLIB2X}
1182 ${TEST2X_BINS}: LIBS += ${FWLIB2X}
1184 ${TEST20_BINS}: ${FWLIB20}
1185 ${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
1186 ${TEST20_BINS}: LIBS += ${FWLIB20}
1188 ${TEST21_BINS}: ${UTILLIB21}
1189 ${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1190 ${TEST21_BINS}: LIBS += ${UTILLIB21}
1192 ${TESTBDB_BINS}: ${UTILBDB}
1193 ${TESTBDB_BINS}: INCLUDES += -Ifirmware/bdb
1194 ${TESTBDB_BINS}: LIBS += ${UTILBDB_OBJS} ${BDBLIB_OBJS}
1196 ${TESTLIB}: ${TESTLIB_OBJS}
1197 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1199 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1203 # ----------------------------------------------------------------------------
1204 # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1205 # rules for specific targets.
1207 ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
1208 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1209 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
1212 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
1213 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1215 ${BUILD}/%.o: ${BUILD}/%.c
1216 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
1217 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1219 # Rules to recompile a single source file for library and test
1220 # TODO: is there a tidier way to do this?
1221 ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1222 ${BUILD}/%_for_lib.o: %.c
1223 @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
1224 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1226 ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1227 ${BUILD}/%_for_test.o: %.c
1228 @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
1229 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1231 # TODO: C++ files don't belong in vboot reference at all. Convert to C.
1233 @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
1234 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1236 # ----------------------------------------------------------------------------
1237 # Here are the special tweaks to the generic rules.
1239 # Always create the defaults file, since it depends on input variables
1240 .PHONY: ${UTIL_DEFAULTS}
1242 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
1244 ${Q}mkdir -p $(dir $@)
1245 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1246 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1249 # Some utilities need external crypto functions
1250 CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1252 ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1253 ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1254 ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1256 ${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1257 ${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1258 ${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1259 ${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1260 ${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1261 ${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
1262 ${BUILD}/tests/bdb_test: LDLIBS += ${CRYPTO_LIBS}
1264 ${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
1266 LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1267 YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1269 ${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1270 ${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
1272 BMPBLK_UTILITY_DEPS = \
1273 ${BUILD}/utility/bmpblk_util.o \
1274 ${BUILD}/utility/image_types.o \
1275 ${BUILD}/utility/eficompress_for_lib.o \
1276 ${BUILD}/utility/efidecompress_for_lib.o
1278 ${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1279 ${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
1280 ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
1282 ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1283 ${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
1284 ALL_OBJS += ${BUILD}/utility/image_types.o
1286 # Allow multiple definitions, so tests can mock functions from other libraries
1287 ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
1288 ${BUILD}/tests/%: LDLIBS += -lrt -luuid
1289 ${BUILD}/tests/%: LIBS += ${TESTLIB}
1291 ${BUILD}/tests/rollback_index2_tests: OBJS += \
1292 ${BUILD}/firmware/lib/rollback_index_for_test.o
1293 ${BUILD}/tests/rollback_index2_tests: \
1294 ${BUILD}/firmware/lib/rollback_index_for_test.o
1295 TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
1297 ${BUILD}/tests/tlcl_tests: OBJS += \
1298 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1299 ${BUILD}/tests/tlcl_tests: \
1300 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1301 TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1303 ${BUILD}/tests/vboot_audio_tests: OBJS += \
1304 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1305 ${BUILD}/tests/vboot_audio_tests: \
1306 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1307 TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
1309 TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1310 ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1311 ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
1312 TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1314 # ----------------------------------------------------------------------------
1315 # Here are the special rules that don't fit in the generic rules.
1317 # Generates the list of commands defined in futility by running grep in the
1318 # source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1319 ${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1320 ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1321 ${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1322 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
1323 ${Q}rm -f $@ $@_t $@_commands
1324 ${Q}mkdir -p ${BUILD}/gen
1325 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
1326 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1327 | sort >>$@_commands
1328 ${Q}./scripts/getversion.sh >> $@_t
1329 ${Q}echo '#define _CMD(NAME) extern const struct' \
1330 'futil_cmd_t __cmd_##NAME;' >> $@_t
1331 ${Q}cat $@_commands >> $@_t
1332 ${Q}echo '#undef _CMD' >> $@_t
1333 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1334 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1335 ${Q}cat $@_commands >> $@_t
1336 ${Q}echo '0}; /* null-terminated */' >> $@_t
1337 ${Q}echo '#undef _CMD' >> $@_t
1339 ${Q}rm -f $@_commands
1341 ##############################################################################
1342 # Targets that exist just to run tests
1344 # Frequently-run tests
1345 .PHONY: test_targets
1346 test_targets:: runcgpttests runmisctests run2tests runbdbtests
1349 # Bitmap utility isn't compiled for minimal variant
1350 test_targets:: runbmptests runfutiltests
1351 # Scripts don't work under qemu testing
1352 # TODO: convert scripts to makefile so they can be called directly
1353 test_targets:: runtestscripts
1357 test_setup:: cgpt utils futil tests install_for_test
1359 # Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1361 ifneq (${QEMU_ARCH},)
1362 test_setup:: qemu_install
1364 .PHONY: qemu_install
1367 $(error SYSROOT must be set to the top of the target-specific root \
1368 when cross-compiling for qemu-based tests to run properly.)
1370 @${PRINTF} " Copying qemu binary.\n"
1371 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1372 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
1376 runtests: test_setup test_targets
1378 # Generate test keys
1380 genkeys: utils test_setup
1381 tests/gen_test_keys.sh
1383 # Generate test cases for fuzzing
1384 .PHONY: genfuzztestcases
1385 genfuzztestcases: utils test_setup
1386 tests/gen_fuzz_test_cases.sh
1389 runbmptests: test_setup
1390 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
1391 ./TestBmpBlock.py -v
1393 .PHONY: runcgpttests
1394 runcgpttests: test_setup
1395 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
1397 .PHONY: runtestscripts
1398 runtestscripts: test_setup genfuzztestcases
1399 tests/load_kernel_tests.sh
1400 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
1401 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
1402 tests/run_preamble_tests.sh
1403 tests/run_rsa_tests.sh
1404 tests/run_vbutil_kernel_arg_tests.sh
1405 tests/run_vbutil_tests.sh
1406 tests/vb2_rsa_tests.sh
1407 tests/vb2_firmware_tests.sh
1409 .PHONY: runmisctests
1410 runmisctests: test_setup
1411 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
1412 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
1413 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1414 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1415 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
1416 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1417 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1418 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1419 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1420 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
1421 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
1422 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1423 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
1424 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1425 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1426 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
1427 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel5_tests
1428 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
1429 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
1430 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1431 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1432 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
1433 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
1434 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
1435 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
1436 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
1439 run2tests: test_setup
1440 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
1441 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
1442 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1443 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1444 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
1445 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
1446 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdatak_tests
1447 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
1448 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1449 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_kernel_tests
1450 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1451 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1452 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1453 ${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
1454 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
1455 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1456 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1457 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1458 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1459 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1460 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
1461 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1462 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
1463 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
1466 runbdbtests: test_setup
1467 ${RUNTEST} ${BUILD_RUN}/tests/bdb_test ${TEST_KEYS}
1469 .PHONY: runfutiltests
1470 runfutiltests: test_setup
1471 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
1472 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
1473 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1475 # Run long tests, including all permutations of encryption keys (instead of
1476 # just the ones we use) and tests of currently-unused code.
1477 # Not run by automated build.
1478 .PHONY: runlongtests
1479 runlongtests: test_setup genkeys genfuzztestcases
1480 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1481 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
1482 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1483 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
1484 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
1485 tests/run_preamble_tests.sh --all
1486 tests/run_vbutil_tests.sh --all
1488 # TODO: There were a number of ancient tests that hadn't been run in years.
1489 # They were removed with https://chromium-review.googlesource.com/#/c/214610/
1490 # Some day it might be nice to see what they were supposed to do.
1493 runalltests: runtests runfutiltests runlongtests
1496 .PHONY: coverage_init
1497 coverage_init: test_setup
1499 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1501 .PHONY: coverage_html
1503 lcov -c -d . -b . -o ${COV_INFO}.tests
1504 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1505 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1506 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1507 # Generate addtional coverage stats just for firmware subdir, because the stats
1508 # for the whole project don't include subdirectory summaries. This will print
1509 # the summary for just the firmware sources.
1510 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1511 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
1512 -o ${COV_INFO}.firmware
1517 $(error Build coverage like this: make clean && COV=1 make coverage)
1519 coverage: coverage_init runtests coverage_html
1522 # Include generated dependencies
1523 ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1524 TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1525 -include ${ALL_DEPS}
1526 -include ${TEST_DEPS}
1528 # We want to use only relative paths in cscope.files, especially since the
1529 # paths inside and outside the chroot are different.
1530 SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1532 # Note: vboot 2.0 is deprecated, so don't index those files
1533 ${BUILD}/cscope.files: all test_setup
1535 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1537 sed -e "s/${SRCDIRPAT}//" | \
1538 egrep '\.[chS]$$' | sort | uniq > $@
1540 cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1541 cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1542 run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1544 .PHONY: tags TAGS xrefs
1545 tags TAGS xrefs: ${BUILD}/cscope.files
1546 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1547 ${Q}$(call run_if_prog,etags,${cmd_etags})
1548 ${Q}$(call run_if_prog,ctags,${cmd_ctags})
1550 PC_FILES = ${PC_IN_FILES:%.pc.in=${BUILD}/%.pc}
1551 ${PC_FILES}: ${PC_IN_FILES}
1553 -e 's:@LDLIBS@:${LDLIBS}:' \
1554 -e 's:@LIBDIR@:${LIBDIR}:' \
1557 .PHONY: pc_files_install
1558 pc_files_install: ${PC_FILES}
1559 ${Q}mkdir -p ${ULP_DIR}
1560 ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$(notdir $<)