Proper armv7l host arch detection
[vboot.git] / Makefile
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.
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}.
39 SRCDIR := $(shell pwd)
40 export SRCDIR
41 BUILD = ${SRCDIR}/build
42 export BUILD
43
44 # Stuff for 'make install'
45 INSTALL = install
46 DESTDIR = /usr/local
47 LIBDIR ?= lib
48
49 # Default values
50 DEV_DEBUG_FORCE=
51
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
59 ifeq (${MINIMAL},)
60 # Host install just puts everything where it's told
61 UB_DIR=${DESTDIR}/bin
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
67 VB_DIR=${DESTDIR}/bin
68 else
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
76 VB_DIR=${US_DIR}/bin
77 endif
78
79 # Where to install the (exportable) executables for testing?
80 TEST_INSTALL_DIR = ${BUILD}/install_for_test
81
82 # Verbose? Use V=1
83 ifeq (${V},)
84 Q := @
85 endif
86
87 # Quiet? Use QUIET=1
88 ifeq (${QUIET},)
89 PRINTF := printf
90 else
91 PRINTF := :
92 endif
93
94 # Architecture detection
95 _machname := $(shell uname -m)
96 HOST_ARCH ?= ${_machname}
97
98 # ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
99 # Pick a sane target architecture if none is defined.
100 ifeq (${ARCH},)
101   ARCH := ${HOST_ARCH}
102 endif
103
104 ifeq (${ARCH},armv7l)
105   override ARCH := arm
106 else ifeq (${ARCH},i386)
107   override ARCH := x86
108 else ifeq (${ARCH},amd64)
109   override ARCH := x86_64
110 endif
111
112 # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
113 # for a firmware target (such as u-boot or depthcharge). It must map
114 # to the same consistent set of architectures as the host.
115 ifeq (${FIRMWARE_ARCH},i386)
116   override FIRMWARE_ARCH := x86
117 else ifeq (${FIRMWARE_ARCH},amd64)
118   override FIRMWARE_ARCH := x86_64
119 else ifeq (${FIRMWARE_ARCH},armv7)
120   override FIRMWARE_ARCH := arm
121 endif
122
123 # Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
124 # please add them after this point (e.g., -DVBOOT_DEBUG).
125 #
126 # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
127 # temporarily. As we are still investigating which flags are necessary for
128 # maintaining a compatible ABI, etc. between u-boot and vboot_reference.
129 #
130 # As a first step, this makes the setting of CC and CFLAGS here optional, to
131 # permit a calling script or Makefile to set these.
132 #
133 # Flag ordering: arch, then -f, then -m, then -W
134 DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
135 WERROR := -Werror
136 COMMON_FLAGS := -nostdinc -pipe \
137         -ffreestanding -fno-builtin -fno-stack-protector \
138         ${WERROR} -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
139
140 # Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
141 ifeq (${FIRMWARE_ARCH}, arm)
142 CC ?= armv7a-cros-linux-gnueabi-gcc
143 CFLAGS ?= -march=armv5 \
144         -fno-common -ffixed-r8 \
145         -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
146         ${COMMON_FLAGS}
147 else ifeq (${FIRMWARE_ARCH}, x86)
148 CC ?= i686-pc-linux-gnu-gcc
149 # Drop -march=i386 to permit use of SSE instructions
150 CFLAGS ?= \
151         -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
152         -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
153         -mpreferred-stack-boundary=2 \
154         ${COMMON_FLAGS}
155 else ifeq (${FIRMWARE_ARCH}, x86_64)
156 CFLAGS ?= ${COMMON_FLAGS} \
157         -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
158 else
159 # FIRMWARE_ARCH not defined; assuming local compile.
160 CC ?= gcc
161 CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall ${WERROR} ${DEBUG_FLAGS}
162 endif
163
164 ifneq (${CUSTOM_MUSIC},)
165 CFLAGS += -DCUSTOM_MUSIC
166 endif
167
168 ifneq (${DEBUG},)
169 CFLAGS += -DVBOOT_DEBUG
170 endif
171
172 ifeq (${DISABLE_NDEBUG},)
173 CFLAGS += -DNDEBUG
174 endif
175
176 ifneq (${FORCE_LOGGING_ON},)
177 CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
178 endif
179
180 ifneq (${PD_SYNC},)
181 CFLAGS += -DPD_SYNC
182 endif
183
184 ifneq (${USE_MTD},)
185 CFLAGS += -DUSE_MTD
186 LDLIBS += -lmtdutils
187 endif
188
189 ifneq (${TPM2_MODE},)
190 CFLAGS += -DTPM2_MODE
191 endif
192
193 # NOTE: We don't use these files but they are useful for other packages to
194 # query about required compiling/linking flags.
195 PC_IN_FILES = vboot_host.pc.in
196
197 # Create / use dependency files
198 CFLAGS += -MMD -MF $@.d
199
200 ifeq (${FIRMWARE_ARCH},)
201 # Creates position independent code for non firmware target.
202 CFLAGS += -fPIE
203 endif
204
205 # These are required to access large disks and files on 32-bit systems.
206 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
207
208 # Code coverage
209 ifneq (${COV},)
210   COV_FLAGS = -O0 --coverage -DCOVERAGE
211   CFLAGS += ${COV_FLAGS}
212   LDFLAGS += ${COV_FLAGS}
213   COV_INFO = ${BUILD}/coverage.info
214 endif
215
216 ifdef HAVE_MACOS
217   CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
218 endif
219
220 # Musl doesn't have execinfo.h.
221 ifndef HAVE_MUSL
222   CFLAGS += -DHAVE_EXECINFO_H
223 endif
224
225 # And a few more default utilities
226 LD = ${CC}
227 CXX ?= g++
228 PKG_CONFIG ?= pkg-config
229
230 # Static?
231 ifneq (${STATIC},)
232 LDFLAGS += -static
233 PKG_CONFIG += --static
234 endif
235
236 # Determine QEMU architecture needed, if any
237 ifeq (${ARCH},${HOST_ARCH})
238   # Same architecture; no need for QEMU
239   QEMU_ARCH :=
240 else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
241   # 64-bit host can run 32-bit targets directly
242   QEMU_ARCH :=
243 else
244   QEMU_ARCH := ${ARCH}
245 endif
246
247 # The top of the chroot for qemu must be passed in via the SYSROOT environment
248 # variable.  In the Chromium OS chroot, this is done automatically by the
249 # ebuild.
250
251 ifeq (${QEMU_ARCH},)
252   # Path to build output for running tests is same as for building
253   BUILD_RUN = ${BUILD}
254   SRC_RUN = ${SRCDIR}
255 else
256   $(info Using qemu for testing.)
257   # Path to build output for running tests is different in the chroot
258   BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
259   SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
260
261   QEMU_BIN = qemu-${QEMU_ARCH}
262   QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
263   export QEMU_RUN
264
265   RUNTEST = tests/test_using_qemu.sh
266 endif
267
268 export BUILD_RUN
269
270 ##############################################################################
271 # The default target is here, to allow dependencies to be expressed below
272 # without accidentally changing the default target.
273
274 # Default target.
275 .PHONY: all
276 all: fwlib fwlib2x fwlib20 fwlib21 \
277         $(if ${FIRMWARE_ARCH},,host_stuff) \
278         $(if ${COV},coverage)
279
280 ##############################################################################
281 # Now we need to describe everything we might want or need to build
282
283 # Everything wants these headers.
284 INCLUDES += \
285         -Ifirmware/include \
286         -Ifirmware/lib/include \
287         -Ifirmware/lib/cgptlib/include \
288         -Ifirmware/lib/cryptolib/include \
289         -Ifirmware/lib/tpm_lite/include \
290         -Ifirmware/2lib/include
291
292 # If we're not building for a specific target, just stub out things like the
293 # TPM commands and various external functions that are provided by the BIOS.
294 ifeq (${FIRMWARE_ARCH},)
295 INCLUDES += -Ihost/include -Ihost/lib/include
296 endif
297
298 # Firmware library, used by the other firmware components (depthcharge,
299 # coreboot, etc.). It doesn't need exporting to some other place; they'll build
300 # this source tree locally and link to it directly.
301 FWLIB = ${BUILD}/vboot_fw.a
302
303 # Smaller firmware library common to all vboot 2.x, used only for
304 # 1) compile-time tests of the public API or
305 # 2) linking with an actual 2.0 or 2.1 implementation
306 FWLIB2X = ${BUILD}/vboot_fw2x.a
307
308 # Vboot 2.0 (deprecated - see firmware/README)
309 FWLIB20 = ${BUILD}/vboot_fw20.a
310 # Vboot 2.1 (not yet ready - see firmware/README)
311 FWLIB21 = ${BUILD}/vboot_fw21.a
312
313 BDBLIB = ${BUILD}/bdb.a
314
315 # Firmware library sources needed by VbInit() call
316 VBINIT_SRCS = \
317         firmware/lib/crc8.c \
318         firmware/lib/utility.c \
319         firmware/lib/vboot_api_init.c \
320         firmware/lib/vboot_common_init.c \
321         firmware/lib/vboot_nvstorage.c \
322         firmware/lib/vboot_nvstorage_rollback.c \
323         firmware/lib/region-init.c \
324
325 # Additional firmware library sources needed by VbSelectFirmware() call
326 VBSF_SRCS = \
327         firmware/lib/cryptolib/padding.c \
328         firmware/lib/cryptolib/rsa.c \
329         firmware/lib/cryptolib/rsa_utility.c \
330         firmware/lib/cryptolib/sha1.c \
331         firmware/lib/cryptolib/sha256.c \
332         firmware/lib/cryptolib/sha512.c \
333         firmware/lib/cryptolib/sha_utility.c \
334         firmware/lib/stateful_util.c \
335         firmware/lib/vboot_api_firmware.c \
336         firmware/lib/vboot_common.c \
337         firmware/lib/vboot_firmware.c \
338         firmware/lib/region-fw.c \
339
340 # Additional firmware library sources needed by VbSelectAndLoadKernel() call
341 VBSLK_SRCS = \
342         firmware/lib/cgptlib/cgptlib.c \
343         firmware/lib/cgptlib/cgptlib_internal.c \
344         firmware/lib/cgptlib/crc32.c \
345         firmware/lib/gpt_misc.c \
346         firmware/lib/utility_string.c \
347         firmware/lib/vboot_api_kernel.c \
348         firmware/lib/vboot_audio.c \
349         firmware/lib/vboot_display.c \
350         firmware/lib/vboot_kernel.c \
351         firmware/lib/region-kernel.c \
352
353 # Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
354 FWLIB2X_SRCS = \
355         firmware/2lib/2api.c \
356         firmware/2lib/2common.c \
357         firmware/2lib/2crc8.c \
358         firmware/2lib/2misc.c \
359         firmware/2lib/2nvstorage.c \
360         firmware/2lib/2rsa.c \
361         firmware/2lib/2secdata.c \
362         firmware/2lib/2secdatak.c \
363         firmware/2lib/2sha1.c \
364         firmware/2lib/2sha256.c \
365         firmware/2lib/2sha512.c \
366         firmware/2lib/2sha_utility.c \
367         firmware/2lib/2tpm_bootmode.c \
368         firmware/2lib/2hmac.c
369
370 FWLIB20_SRCS = \
371         firmware/lib20/api.c \
372         firmware/lib20/api_kernel.c \
373         firmware/lib20/common.c \
374         firmware/lib20/kernel.c \
375         firmware/lib20/misc.c \
376         firmware/lib20/packed_key.c
377
378 FWLIB21_SRCS = \
379         firmware/lib21/api.c \
380         firmware/lib21/common.c \
381         firmware/lib21/misc.c \
382         firmware/lib21/packed_key.c
383
384 BDBLIB_SRCS = \
385         firmware/bdb/bdb.c \
386         firmware/bdb/misc.c \
387         firmware/bdb/rsa.c \
388         firmware/bdb/secrets.c \
389         firmware/bdb/stub.c \
390         firmware/bdb/nvm.c
391
392 # TPM lightweight command library
393 ifeq (${TPM2_MODE},)
394 TLCL_SRCS = \
395         firmware/lib/tpm_lite/tlcl.c
396 else
397 TLCL_SRCS = \
398         firmware/lib/tpm2_lite/tlcl.c \
399         firmware/lib/tpm2_lite/marshaling.c
400 endif
401 TLCL_OBJS_FOR_TEST = $(TLCL_SRCS:%.c=${BUILD}/%_for_test.o)
402
403 # Support real TPM unless BIOS sets MOCK_TPM
404 ifeq (${MOCK_TPM},)
405 VBINIT_SRCS += \
406         firmware/lib/rollback_index.c \
407         ${TLCL_SRCS}
408
409 VBSF_SRCS += \
410         firmware/lib/tpm_bootmode.c
411 else
412 VBINIT_SRCS += \
413         firmware/lib/mocked_rollback_index.c \
414         firmware/lib/tpm_lite/mocked_tlcl.c
415
416 VBSF_SRCS += \
417         firmware/lib/mocked_tpm_bootmode.c
418 endif
419
420 ifeq (${FIRMWARE_ARCH},)
421 # Include BIOS stubs in the firmware library when compiling for host
422 # TODO: split out other stub funcs too
423 VBINIT_SRCS += \
424         firmware/stub/tpm_lite_stub.c \
425         firmware/stub/utility_stub.c \
426         firmware/stub/vboot_api_stub_init.c \
427         firmware/stub/vboot_api_stub_region.c
428
429 VBSF_SRCS += \
430         firmware/stub/vboot_api_stub_sf.c
431
432 VBSLK_SRCS += \
433         firmware/stub/vboot_api_stub.c \
434         firmware/stub/vboot_api_stub_disk.c \
435         firmware/stub/vboot_api_stub_stream.c
436
437 FWLIB2X_SRCS += \
438         firmware/2lib/2stub.c
439
440 endif
441
442 VBSF_SRCS += ${VBINIT_SRCS}
443 FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
444
445 VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
446 VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
447 ALL_OBJS +=  ${VBINIT_OBJS} ${VBSF_OBJS}
448
449 FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
450 FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
451 FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
452 FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
453 BDBLIB_OBJS = ${BDBLIB_SRCS:%.c=${BUILD}/%.o}
454 ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS} \
455         $(BDBLIB_OBJS}
456
457 # Intermediate library for the vboot_reference utilities to link against.
458 UTILLIB = ${BUILD}/libvboot_util.a
459 UTILLIB21 = ${BUILD}/libvboot_util21.a
460 UTILBDB = ${BUILD}/libvboot_utilbdb.a
461
462 UTILLIB_SRCS = \
463         cgpt/cgpt_create.c \
464         cgpt/cgpt_add.c \
465         cgpt/cgpt_boot.c \
466         cgpt/cgpt_show.c \
467         cgpt/cgpt_repair.c \
468         cgpt/cgpt_prioritize.c \
469         cgpt/cgpt_common.c \
470         futility/dump_kernel_config_lib.c \
471         host/arch/${ARCH}/lib/crossystem_arch.c \
472         host/lib/crossystem.c \
473         host/lib/file_keys.c \
474         host/lib/fmap.c \
475         host/lib/host_common.c \
476         host/lib/host_key.c \
477         host/lib/host_keyblock.c \
478         host/lib/host_misc.c \
479         host/lib/util_misc.c \
480         host/lib/host_signature.c \
481         host/lib/signature_digest.c
482
483 UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
484 ALL_OBJS += ${UTILLIB_OBJS}
485
486 UTILLIB21_SRCS += \
487         host/lib21/host_fw_preamble.c \
488         host/lib21/host_key.c \
489         host/lib21/host_keyblock.c \
490         host/lib21/host_misc.c \
491         host/lib21/host_signature.c
492
493 UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
494 ALL_OBJS += ${UTILLIB21_OBJS}
495
496 UTILBDB_SRCS += \
497         firmware/bdb/host.c
498
499 UTILBDB_OBJS = ${UTILBDB_SRCS:%.c=${BUILD}/%.o}
500 ALL_OBJS += ${UTILBDB_OBJS}
501
502 # Externally exported library for some target userspace apps to link with
503 # (cryptohome, updater, etc.)
504 HOSTLIB = ${BUILD}/libvboot_host.a
505
506 HOSTLIB_SRCS = \
507         cgpt/cgpt_add.c \
508         cgpt/cgpt_boot.c \
509         cgpt/cgpt_common.c \
510         cgpt/cgpt_create.c \
511         cgpt/cgpt_prioritize.c \
512         firmware/lib/cgptlib/cgptlib_internal.c \
513         firmware/lib/cgptlib/crc32.c \
514         firmware/lib/crc8.c \
515         firmware/lib/gpt_misc.c \
516         ${TLCL_SRCS} \
517         firmware/lib/utility_string.c \
518         firmware/lib/vboot_nvstorage.c \
519         firmware/stub/tpm_lite_stub.c \
520         firmware/stub/utility_stub.c \
521         firmware/stub/vboot_api_stub.c \
522         firmware/stub/vboot_api_stub_disk.c \
523         firmware/stub/vboot_api_stub_init.c \
524         firmware/stub/vboot_api_stub_sf.c \
525         futility/dump_kernel_config_lib.c \
526         host/arch/${ARCH}/lib/crossystem_arch.c \
527         host/lib/crossystem.c \
528         host/lib/extract_vmlinuz.c \
529         host/lib/fmap.c \
530         host/lib/host_misc.c
531
532 HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
533 ALL_OBJS += ${HOSTLIB_OBJS}
534
535 # Sigh. For historical reasons, the autoupdate installer must sometimes be a
536 # 32-bit executable, even when everything else is 64-bit. But it only needs a
537 # few functions, so let's just build those.
538 TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
539
540 TINYHOSTLIB_SRCS = \
541         cgpt/cgpt_add.c \
542         cgpt/cgpt_boot.c \
543         cgpt/cgpt_common.c \
544         cgpt/cgpt_create.c \
545         cgpt/cgpt_prioritize.c \
546         firmware/lib/cgptlib/cgptlib_internal.c \
547         firmware/lib/cgptlib/crc32.c \
548         firmware/lib/gpt_misc.c \
549         firmware/lib/utility_string.c \
550         firmware/stub/vboot_api_stub.c \
551         firmware/stub/vboot_api_stub_disk.c \
552         firmware/stub/vboot_api_stub_sf.c \
553         firmware/stub/utility_stub.c \
554         futility/dump_kernel_config_lib.c \
555         host/lib/extract_vmlinuz.c
556
557 TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
558
559 # ----------------------------------------------------------------------------
560 # Now for the userspace binaries
561
562 CGPT = ${BUILD}/cgpt/cgpt
563
564 CGPT_SRCS = \
565         cgpt/cgpt.c \
566         cgpt/cgpt_add.c \
567         cgpt/cgpt_boot.c \
568         cgpt/cgpt_common.c \
569         cgpt/cgpt_create.c \
570         cgpt/cgpt_find.c \
571         cgpt/cgpt_legacy.c \
572         cgpt/cgpt_nor.c \
573         cgpt/cgpt_prioritize.c \
574         cgpt/cgpt_repair.c \
575         cgpt/cgpt_show.c \
576         cgpt/cmd_add.c \
577         cgpt/cmd_boot.c \
578         cgpt/cmd_create.c \
579         cgpt/cmd_find.c \
580         cgpt/cmd_legacy.c \
581         cgpt/cmd_prioritize.c \
582         cgpt/cmd_repair.c \
583         cgpt/cmd_show.c
584
585 CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
586
587 ALL_OBJS += ${CGPT_OBJS}
588
589 CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
590
591 CGPT_WRAPPER_SRCS = \
592         cgpt/cgpt_nor.c \
593         cgpt/cgpt_wrapper.c
594
595 CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
596
597 ALL_OBJS += ${CGPT_WRAPPER_OBJS}
598
599 # Utility defaults
600 UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
601
602 # Scripts to install directly (not compiled)
603 UTIL_SCRIPTS = \
604         utility/dev_debug_vboot \
605         utility/enable_dev_usb_boot
606
607 ifeq (${MINIMAL},)
608 UTIL_SCRIPTS += \
609         utility/dev_make_keypair \
610         utility/vbutil_what_keys
611 endif
612
613 # These utilities should be linked statically.
614 UTIL_NAMES_STATIC = \
615         utility/crossystem
616
617 UTIL_NAMES = ${UTIL_NAMES_STATIC} \
618         utility/dumpRSAPublicKey \
619         utility/tpmc
620
621 ifeq (${TPM2_MODE},)
622 UTIL_NAMES += utility/tpm_init_temp_fix
623 endif
624
625 # TODO: Do we still need eficompress and efidecompress for anything?
626 ifeq (${MINIMAL},)
627 UTIL_NAMES += \
628         utility/bmpblk_font \
629         utility/bmpblk_utility \
630         utility/eficompress \
631         utility/efidecompress \
632         utility/load_kernel_test \
633         utility/pad_digest_utility \
634         utility/signature_digest_utility \
635         utility/verify_data
636 endif
637
638 UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
639 UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
640 ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
641
642
643 # Scripts for signing stuff.
644 SIGNING_SCRIPTS = \
645         utility/tpm-nvsize \
646         utility/chromeos-tpm-recovery
647
648 # These go in a different place.
649 SIGNING_SCRIPTS_DEV = \
650         scripts/image_signing/resign_firmwarefd.sh \
651         scripts/image_signing/make_dev_firmware.sh \
652         scripts/image_signing/make_dev_ssd.sh \
653         scripts/image_signing/set_gbb_flags.sh
654
655 # Installed, but not made executable.
656 SIGNING_COMMON = scripts/image_signing/common_minimal.sh
657
658
659 # The unified firmware utility will eventually replace all the others
660 FUTIL_BIN = ${BUILD}/futility/futility
661 # But we still need both static (tiny) and dynamic (with openssl) versions.
662 FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
663
664 # These are the executables that are now built in to futility. We'll create
665 # symlinks for these so the old names will still work.
666 FUTIL_SYMLINKS = \
667         dump_fmap \
668         dump_kernel_config \
669         gbb_utility \
670         vbutil_firmware \
671         vbutil_kernel \
672         vbutil_key \
673         vbutil_keyblock
674
675 FUTIL_STATIC_SRCS = \
676         futility/futility.c \
677         futility/cmd_dump_fmap.c \
678         futility/cmd_gbb_utility.c \
679         futility/misc.c \
680         futility/ryu_root_header.c
681
682 FUTIL_SRCS = \
683         ${FUTIL_STATIC_SRCS} \
684         futility/cmd_create.c \
685         futility/cmd_dump_kernel_config.c \
686         futility/cmd_load_fmap.c \
687         futility/cmd_pcr.c \
688         futility/cmd_show.c \
689         futility/cmd_sign.c \
690         futility/cmd_vbutil_firmware.c \
691         futility/cmd_vbutil_kernel.c \
692         futility/cmd_vbutil_key.c \
693         futility/cmd_vbutil_keyblock.c \
694         futility/file_type.c \
695         futility/file_type_bios.c \
696         futility/file_type_rwsig.c \
697         futility/file_type_usbpd1.c \
698         futility/vb1_helper.c \
699         futility/vb2_helper.c
700
701 # List of commands built in futility and futility_s.
702 FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
703 FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
704
705 # Workaround for TODO(crbug.com/437107).
706 FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
707
708 FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
709         ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
710         ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
711 FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
712
713 ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
714 ${FUTIL_BIN}: ${UTILLIB21}
715 ${FUTIL_BIN}: LIBS += ${UTILLIB21}
716
717 ALL_OBJS += ${FUTIL_OBJS}
718
719
720 # Library of handy test functions.
721 TESTLIB = ${BUILD}/tests/test.a
722
723 TESTLIB_SRCS = \
724         tests/test_common.c \
725         tests/timer_utils.c \
726         tests/crc32_test.c
727
728 TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
729 TEST_OBJS += ${TESTLIB_OBJS}
730
731
732 # And some compiled tests.
733 TEST_NAMES = \
734         tests/cgptlib_test \
735         tests/rollback_index3_tests \
736         tests/rsa_padding_test \
737         tests/rsa_utility_tests \
738         tests/rsa_verify_benchmark \
739         tests/sha_benchmark \
740         tests/sha_tests \
741         tests/stateful_util_tests \
742         tests/tpm_bootmode_tests \
743         tests/utility_string_tests \
744         tests/utility_tests \
745         tests/vboot_api_init_tests \
746         tests/vboot_api_devmode_tests \
747         tests/vboot_api_firmware_tests \
748         tests/vboot_api_kernel_tests \
749         tests/vboot_api_kernel2_tests \
750         tests/vboot_api_kernel3_tests \
751         tests/vboot_api_kernel4_tests \
752         tests/vboot_api_kernel5_tests \
753         tests/vboot_api_kernel6_tests \
754         tests/vboot_audio_tests \
755         tests/vboot_common_tests \
756         tests/vboot_common2_tests \
757         tests/vboot_common3_tests \
758         tests/vboot_display_tests \
759         tests/vboot_firmware_tests \
760         tests/vboot_kernel_tests \
761         tests/vboot_nvstorage_test \
762         tests/verify_kernel
763
764 ifeq (${TPM2_MODE},)
765 # TODO(apronin): tests for TPM2 case?
766 TEST_NAMES += \
767         tests/tlcl_tests \
768         tests/rollback_index2_tests
769 endif
770
771 ifdef REGION_READ
772 TEST_NAMES += tests/vboot_region_tests
773 endif
774
775 TEST_FUTIL_NAMES  = \
776         tests/futility/binary_editor \
777         tests/futility/test_file_types \
778         tests/futility/test_not_really
779
780 TEST_NAMES += ${TEST_FUTIL_NAMES}
781
782 TEST2X_NAMES = \
783         tests/vb2_api_tests \
784         tests/vb2_common_tests \
785         tests/vb2_misc_tests \
786         tests/vb2_nvstorage_tests \
787         tests/vb2_rsa_utility_tests \
788         tests/vb2_secdata_tests \
789         tests/vb2_secdatak_tests \
790         tests/vb2_sha_tests \
791         tests/hmac_test
792
793 TEST20_NAMES = \
794         tests/vb20_api_tests \
795         tests/vb20_api_kernel_tests \
796         tests/vb20_common_tests \
797         tests/vb20_common2_tests \
798         tests/vb20_verify_fw.c \
799         tests/vb20_common3_tests \
800         tests/vb20_kernel_tests \
801         tests/vb20_misc_tests \
802         tests/vb20_rsa_padding_tests \
803         tests/vb20_verify_fw
804
805 TEST21_NAMES = \
806         tests/vb21_api_tests \
807         tests/vb21_common_tests \
808         tests/vb21_common2_tests \
809         tests/vb21_misc_tests \
810         tests/vb21_host_fw_preamble_tests \
811         tests/vb21_host_key_tests \
812         tests/vb21_host_keyblock_tests \
813         tests/vb21_host_misc_tests \
814         tests/vb21_host_sig_tests
815
816 TESTBDB_NAMES = \
817         tests/bdb_test \
818         tests/bdb_nvm_test \
819         tests/bdb_sprw_test
820
821 TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES} ${TESTBDB_NAMES}
822
823 # And a few more...
824 ifeq (${TPM2_MODE},)
825 TLCL_TEST_NAMES = \
826         tests/tpm_lite/tpmtest_earlyextend \
827         tests/tpm_lite/tpmtest_earlynvram \
828         tests/tpm_lite/tpmtest_earlynvram2 \
829         tests/tpm_lite/tpmtest_enable \
830         tests/tpm_lite/tpmtest_fastenable \
831         tests/tpm_lite/tpmtest_globallock \
832         tests/tpm_lite/tpmtest_redefine_unowned \
833         tests/tpm_lite/tpmtest_spaceperm \
834         tests/tpm_lite/tpmtest_testsetup \
835         tests/tpm_lite/tpmtest_timing \
836         tests/tpm_lite/tpmtest_writelimit
837 else
838 # TODO(apronin): tests for TPM2 case?
839 TLCL_TEST_NAMES =
840 endif
841
842 TEST_NAMES += ${TLCL_TEST_NAMES}
843
844 # Finally
845 TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
846 TEST_OBJS += $(addsuffix .o,${TEST_BINS})
847
848 TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES})
849 TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
850 TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
851 TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
852 TESTBDB_BINS = $(addprefix ${BUILD}/,${TESTBDB_NAMES})
853
854 # Directory containing test keys
855 TEST_KEYS = ${SRC_RUN}/tests/testkeys
856
857
858 ##############################################################################
859 # Finally, some targets. High-level ones first.
860
861 # Create output directories if necessary.  Do this via explicit shell commands
862 # so it happens before trying to generate/include dependencies.
863 SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
864 _dir_create := $(foreach d, \
865         $(shell find ${SUBDIRS} -name '*.c' -exec  dirname {} \; | sort -u), \
866         $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
867
868 # Host targets
869 .PHONY: host_stuff
870 host_stuff: utillib hostlib cgpt utils futil tests utillib21
871
872 .PHONY: clean
873 clean:
874         ${Q}/bin/rm -rf ${BUILD}
875
876 .PHONY: install
877 install: cgpt_install utils_install signing_install futil_install \
878         pc_files_install
879
880 .PHONY: install_dev
881 install_dev: headers_install lib_install
882
883 .PHONY: install_mtd
884 install_mtd: install cgpt_wrapper_install
885
886 .PHONY: install_for_test
887 install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
888 install_for_test: install
889
890 # Don't delete intermediate object files
891 .SECONDARY:
892
893 # ----------------------------------------------------------------------------
894 # Firmware library
895
896 # TPM-specific flags.  These depend on the particular TPM we're targeting for.
897 # They are needed here only for compiling parts of the firmware code into
898 # user-level tests.
899
900 # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
901 # the self test has completed.
902
903 ${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
904
905 # TPM_MANUAL_SELFTEST is defined if the self test must be started manually
906 # (with a call to TPM_ContinueSelfTest) instead of starting automatically at
907 # power on.
908 #
909 # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
910 # are not both defined at the same time.  (See comment in code.)
911
912 # CFLAGS += -DTPM_MANUAL_SELFTEST
913
914 ifeq (${FIRMWARE_ARCH},i386)
915 # Unrolling loops in cryptolib makes it faster
916 ${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
917 ${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
918 ${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
919 ${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
920 ${BDBLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
921
922 # Workaround for coreboot on x86, which will power off asynchronously
923 # without giving us a chance to react. This is not an example of the Right
924 # Way to do things. See chrome-os-partner:7689, and the commit message
925 # that made this change.
926 ${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
927
928 # On x86 we don't actually read the GBB data into RAM until it is needed.
929 # Therefore it makes sense to cache it rather than reading it each time.
930 # Enable this feature.
931 ${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
932 endif
933
934 ifdef REGION_READ
935 ${FWLIB_OBJS}: CFLAGS += -DREGION_READ
936 endif
937
938 ifeq (${FIRMWARE_ARCH},)
939 # Disable rollback TPM when compiling locally, since otherwise
940 # load_kernel_test attempts to talk to the TPM.
941 ${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
942 endif
943
944 ${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
945 ${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
946 ${BDBLIB_OBJS}: INCLUDES += -Ifirmware/bdb
947
948 # Linktest ensures firmware lib doesn't rely on outside libraries
949 ${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
950 ${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
951 TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
952 ${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
953 ${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
954 TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
955 ${BUILD}/firmware/linktest/main: ${FWLIB}
956 ${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
957 TEST_OBJS += ${BUILD}/firmware/linktest/main.o
958
959 .PHONY: fwlinktest
960 fwlinktest: \
961         ${BUILD}/firmware/linktest/main_vbinit \
962         ${BUILD}/firmware/linktest/main_vbsf \
963         ${BUILD}/firmware/linktest/main
964
965 .PHONY: fwlib
966 fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
967
968 ${FWLIB}: ${FWLIB_OBJS}
969         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
970         ${Q}rm -f $@
971         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
972         ${Q}ar qc $@ $^
973
974 .PHONY: fwlib2x
975 fwlib2x: ${FWLIB2X}
976
977 ${FWLIB2X}: ${FWLIB2X_OBJS}
978         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
979         ${Q}rm -f $@
980         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
981         ${Q}ar qc $@ $^
982
983 .PHONY: fwlib20
984 fwlib20: ${FWLIB20}
985
986 ${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
987         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
988         ${Q}rm -f $@
989         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
990         ${Q}ar qc $@ $^
991
992 .PHONY: fwlib21
993 fwlib21: ${FWLIB21}
994
995 ${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
996         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
997         ${Q}rm -f $@
998         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
999         ${Q}ar qc $@ $^
1000
1001 .PHONY: bdblib
1002 bdblib: ${BDBLIB}
1003
1004 ${BDBLIB}: ${FWLIB2X_OBJS} ${BDBLIB_OBJS}
1005         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1006         ${Q}rm -f $@
1007         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1008         ${Q}ar qc $@ $^
1009
1010 # ----------------------------------------------------------------------------
1011 # Host library(s)
1012
1013 # Link tests for local utilities
1014 ${BUILD}/host/linktest/main: ${UTILLIB}
1015 ${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
1016 TEST_OBJS += ${BUILD}/host/linktest/main.o
1017
1018 .PHONY: utillib
1019 utillib: ${UTILLIB} \
1020         ${BUILD}/host/linktest/main
1021
1022 # TODO: better way to make .a than duplicating this recipe each time?
1023 ${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
1024         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1025         ${Q}rm -f $@
1026         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1027         ${Q}ar qc $@ $^
1028
1029 .PHONY: utillib21
1030 utillib21: ${UTILLIB21}
1031
1032 ${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1033 ${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
1034         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1035         ${Q}rm -f $@
1036         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1037         ${Q}ar qc $@ $^
1038
1039 ${UTILBDB}: ${UTILBDB_OBJS} ${BDBLIB_OBJS}
1040         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1041         ${Q}rm -f $@
1042         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1043         ${Q}ar qc $@ $^
1044
1045 # Link tests for external repos
1046 ${BUILD}/host/linktest/extern: ${HOSTLIB}
1047 ${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
1048 ${BUILD}/host/linktest/extern: LDLIBS += -static
1049 TEST_OBJS += ${BUILD}/host/linktest/extern.o
1050
1051 .PHONY: hostlib
1052 hostlib: ${HOSTLIB} \
1053         ${BUILD}/host/linktest/extern
1054
1055 # TODO: better way to make .a than duplicating this recipe each time?
1056 ${HOSTLIB}: ${HOSTLIB_OBJS}
1057         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1058         ${Q}rm -f $@
1059         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1060         ${Q}ar qc $@ $^
1061
1062
1063 # Ugh. This is a very cut-down version of HOSTLIB just for the installer.
1064 .PHONY: tinyhostlib
1065 tinyhostlib: ${TINYHOSTLIB}
1066         ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
1067
1068 ${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
1069         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1070         ${Q}rm -f $@
1071         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1072         ${Q}ar qc $@ $^
1073
1074 .PHONY: headers_install
1075 headers_install:
1076         @${PRINTF} "    INSTALL       HEADERS\n"
1077         ${Q}mkdir -p ${UI_DIR}
1078         ${Q}${INSTALL} -t ${UI_DIR} -m644 \
1079                 host/include/* \
1080                 firmware/include/gpt.h \
1081                 firmware/include/tlcl.h \
1082                 firmware/include/tss_constants.h
1083
1084 .PHONY: lib_install
1085 lib_install: ${HOSTLIB}
1086         @${PRINTF} "    INSTALL       HOSTLIB\n"
1087         ${Q}mkdir -p ${UL_DIR}
1088         ${Q}${INSTALL} -t ${UL_DIR} -m644 $^
1089
1090 .PHONY: devkeys_install
1091 devkeys_install:
1092         @${PRINTF} "    INSTALL       DEVKEYS\n"
1093         ${Q}mkdir -p ${US_DIR}/devkeys
1094         ${Q}${INSTALL} -t ${US_DIR}/devkeys -m644 tests/devkeys/*
1095
1096 # ----------------------------------------------------------------------------
1097 # CGPT library and utility
1098
1099 .PHONY: cgpt_wrapper
1100 cgpt_wrapper: ${CGPT_WRAPPER}
1101
1102 ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
1103         @$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
1104         ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
1105
1106 .PHONY: cgpt
1107 cgpt: ${CGPT} ${CGPT_WRAPPER}
1108
1109 ${CGPT}: LDLIBS += -luuid
1110
1111 ${CGPT}: ${CGPT_OBJS} ${UTILLIB}
1112         @${PRINTF} "    LDcgpt        $(subst ${BUILD}/,,$@)\n"
1113         ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1114
1115 .PHONY: cgpt_install
1116 cgpt_install: ${CGPT}
1117         @${PRINTF} "    INSTALL       CGPT\n"
1118         ${Q}mkdir -p ${UB_DIR}
1119         ${Q}${INSTALL} -t ${UB_DIR} $^
1120
1121 .PHONY: cgpt_wrapper_install
1122 cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
1123         @$(PRINTF) "    INSTALL       cgpt_wrapper\n"
1124         ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
1125         ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
1126                 ${UB_DIR}/$(notdir ${CGPT}).bin
1127         ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
1128                 ${UB_DIR}/$(notdir ${CGPT})
1129
1130 # ----------------------------------------------------------------------------
1131 # Utilities
1132
1133 # These have their own headers too.
1134 ${BUILD}/utility/%: INCLUDES += -Iutility/include
1135
1136 ${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
1137 ${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
1138
1139 # Utilities for auto-update toolkits must be statically linked.
1140 ${UTIL_BINS_STATIC}: LDFLAGS += -static
1141
1142
1143 .PHONY: utils
1144 utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
1145         ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
1146         ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
1147
1148 .PHONY: utils_install
1149 utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
1150         @${PRINTF} "    INSTALL       UTILS\n"
1151         ${Q}mkdir -p ${UB_DIR}
1152         ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
1153         ${Q}mkdir -p ${DF_DIR}
1154         ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
1155
1156 # And some signing stuff for the target
1157 .PHONY: signing_install
1158 signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
1159         @${PRINTF} "    INSTALL       SIGNING\n"
1160         ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
1161         ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
1162         ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1163         ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
1164
1165 # ----------------------------------------------------------------------------
1166 # new Firmware Utility
1167
1168 .PHONY: futil
1169 futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1170
1171 ${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
1172         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1173         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
1174
1175 ${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
1176 ${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
1177         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1178         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1179
1180 .PHONY: futil_install
1181 futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1182         @${PRINTF} "    INSTALL       futility\n"
1183         ${Q}mkdir -p ${UB_DIR}
1184         ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1185         ${Q}for prog in ${FUTIL_SYMLINKS}; do \
1186                 ln -sf futility "${UB_DIR}/$$prog"; done
1187
1188 # ----------------------------------------------------------------------------
1189 # Utility to generate TLCL structure definition header file.
1190
1191 ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1192
1193 STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1194 STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1195
1196 .PHONY: update_tlcl_structures
1197 update_tlcl_structures: ${BUILD}/utility/tlcl_generator
1198         @${PRINTF} "    Rebuilding TLCL structures\n"
1199         ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1200         ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1201                 ( echo "%% Updating structures.h %%" && \
1202                   cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1203
1204 # ----------------------------------------------------------------------------
1205 # Tests
1206
1207 .PHONY: tests
1208 tests: ${TEST_BINS}
1209
1210 ${TEST_BINS}: ${UTILLIB} ${TESTLIB}
1211 ${TEST_BINS}: INCLUDES += -Itests
1212 ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
1213
1214 # Futility tests need almost everything that futility needs.
1215 ${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21}
1216 ${TEST_FUTIL_BINS}: INCLUDES += -Ifutility
1217 ${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21}
1218 ${TEST_FUTIL_BINS}: LDLIBS += ${CRYPTO_LIBS}
1219
1220 ${TEST2X_BINS}: ${FWLIB2X}
1221 ${TEST2X_BINS}: LIBS += ${FWLIB2X}
1222
1223 ${TEST20_BINS}: ${FWLIB20}
1224 ${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
1225 ${TEST20_BINS}: LIBS += ${FWLIB20}
1226
1227 ${TEST21_BINS}: ${UTILLIB21}
1228 ${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1229 ${TEST21_BINS}: LIBS += ${UTILLIB21}
1230
1231 ${TESTBDB_BINS}: ${FWLIB2X} ${UTILBDB}
1232 ${TESTBDB_BINS}: INCLUDES += -Ifirmware/bdb
1233 ${TESTBDB_BINS}: LIBS += ${UTILBDB_OBJS} ${BDBLIB_OBJS} ${FWLIB2X}
1234
1235 ${TESTLIB}: ${TESTLIB_OBJS}
1236         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1237         ${Q}rm -f $@
1238         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1239         ${Q}ar qc $@ $^
1240
1241
1242 # ----------------------------------------------------------------------------
1243 # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1244 # rules for specific targets.
1245
1246 ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
1247         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1248         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
1249
1250 ${BUILD}/%.o: %.c
1251         @${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1252         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1253
1254 ${BUILD}/%.o: ${BUILD}/%.c
1255         @${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1256         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1257
1258 # Rules to recompile a single source file for library and test
1259 # TODO: is there a tidier way to do this?
1260 ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1261 ${BUILD}/%_for_lib.o: %.c
1262         @${PRINTF} "    CC-for-lib    $(subst ${BUILD}/,,$@)\n"
1263         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1264
1265 ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1266 ${BUILD}/%_for_test.o: %.c
1267         @${PRINTF} "    CC-for-test   $(subst ${BUILD}/,,$@)\n"
1268         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1269
1270 # TODO: C++ files don't belong in vboot reference at all.  Convert to C.
1271 ${BUILD}/%.o: %.cc
1272         @${PRINTF} "    CXX           $(subst ${BUILD}/,,$@)\n"
1273         ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1274
1275 # ----------------------------------------------------------------------------
1276 # Here are the special tweaks to the generic rules.
1277
1278 # Always create the defaults file, since it depends on input variables
1279 .PHONY: ${UTIL_DEFAULTS}
1280 ${UTIL_DEFAULTS}:
1281         @${PRINTF} "    CREATE        $(subst ${BUILD}/,,$@)\n"
1282         ${Q}rm -f $@
1283         ${Q}mkdir -p $(dir $@)
1284         ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1285         ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1286         ${Q}mv -f $@.tmp $@
1287
1288 # Some utilities need external crypto functions
1289 CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1290
1291 ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1292 ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1293 ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1294
1295 ${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1296 ${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1297 ${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1298 ${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1299 ${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1300 ${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
1301 ${BUILD}/tests/bdb_test: LDLIBS += ${CRYPTO_LIBS}
1302 ${BUILD}/tests/bdb_nvm_test: LDLIBS += ${CRYPTO_LIBS}
1303 ${BUILD}/tests/bdb_sprw_test: LDLIBS += ${CRYPTO_LIBS}
1304 ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
1305
1306 ${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
1307
1308 LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1309 YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1310
1311 ${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1312 ${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
1313
1314 BMPBLK_UTILITY_DEPS = \
1315         ${BUILD}/utility/bmpblk_util.o \
1316         ${BUILD}/utility/image_types.o \
1317         ${BUILD}/utility/eficompress_for_lib.o \
1318         ${BUILD}/utility/efidecompress_for_lib.o
1319
1320 ${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1321 ${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
1322 ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
1323
1324 ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1325 ${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
1326 ALL_OBJS += ${BUILD}/utility/image_types.o
1327
1328 # Allow multiple definitions, so tests can mock functions from other libraries
1329 ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
1330 ${BUILD}/tests/%: LDLIBS += -lrt -luuid
1331 ${BUILD}/tests/%: LIBS += ${TESTLIB}
1332
1333 ifeq (${TPM2_MODE},)
1334 # TODO(apronin): tests for TPM2 case?
1335 ${BUILD}/tests/rollback_index2_tests: OBJS += \
1336         ${BUILD}/firmware/lib/rollback_index_for_test.o
1337 ${BUILD}/tests/rollback_index2_tests: \
1338         ${BUILD}/firmware/lib/rollback_index_for_test.o
1339 TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
1340 endif
1341
1342 ${BUILD}/tests/tlcl_tests: OBJS += \
1343         ${TLCL_OBJS_FOR_TEST}
1344 ${BUILD}/tests/tlcl_tests: \
1345         ${TLCL_OBJS_FOR_TEST}
1346 TEST_OBJS += ${TLCL_OBJS_FOR_TEST}
1347
1348 ${BUILD}/tests/vboot_audio_tests: OBJS += \
1349         ${BUILD}/firmware/lib/vboot_audio_for_test.o
1350 ${BUILD}/tests/vboot_audio_tests: \
1351         ${BUILD}/firmware/lib/vboot_audio_for_test.o
1352 TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
1353
1354 ifeq (${TPM2_MODE},)
1355 # TODO(apronin): tests for TPM2 case?
1356 TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1357 ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1358 ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
1359 TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1360 endif
1361
1362 # ----------------------------------------------------------------------------
1363 # Here are the special rules that don't fit in the generic rules.
1364
1365 # Generates the list of commands defined in futility by running grep in the
1366 # source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1367 ${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1368 ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1369 ${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1370         @${PRINTF} "    GEN           $(subst ${BUILD}/,,$@)\n"
1371         ${Q}rm -f $@ $@_t $@_commands
1372         ${Q}mkdir -p ${BUILD}/gen
1373         ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
1374                 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1375                 | sort >>$@_commands
1376         ${Q}./scripts/getversion.sh >> $@_t
1377         ${Q}echo '#define _CMD(NAME) extern const struct' \
1378                 'futil_cmd_t __cmd_##NAME;' >> $@_t
1379         ${Q}cat $@_commands >> $@_t
1380         ${Q}echo '#undef _CMD' >> $@_t
1381         ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1382         ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1383         ${Q}cat $@_commands >> $@_t
1384         ${Q}echo '0};  /* null-terminated */' >> $@_t
1385         ${Q}echo '#undef _CMD' >> $@_t
1386         ${Q}mv $@_t $@
1387         ${Q}rm -f $@_commands
1388
1389 ##############################################################################
1390 # Targets that exist just to run tests
1391
1392 # Frequently-run tests
1393 .PHONY: test_targets
1394 test_targets:: runcgpttests runmisctests run2tests runbdbtests
1395
1396 ifeq (${MINIMAL},)
1397 # Bitmap utility isn't compiled for minimal variant
1398 test_targets:: runbmptests runfutiltests
1399 # Scripts don't work under qemu testing
1400 # TODO: convert scripts to makefile so they can be called directly
1401 test_targets:: runtestscripts
1402 endif
1403
1404 .PHONY: test_setup
1405 test_setup:: cgpt utils futil tests install_for_test
1406
1407 # Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
1408 # sysroot.
1409 ifneq (${QEMU_ARCH},)
1410 test_setup:: qemu_install
1411
1412 .PHONY: qemu_install
1413 qemu_install:
1414 ifeq (${SYSROOT},)
1415         $(error SYSROOT must be set to the top of the target-specific root \
1416 when cross-compiling for qemu-based tests to run properly.)
1417 endif
1418         @${PRINTF} "    Copying qemu binary.\n"
1419         ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1420         ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
1421 endif
1422
1423 .PHONY: runtests
1424 runtests: test_setup test_targets
1425
1426 # Generate test keys
1427 .PHONY: genkeys
1428 genkeys: utils test_setup
1429         tests/gen_test_keys.sh
1430
1431 # Generate test cases for fuzzing
1432 .PHONY: genfuzztestcases
1433 genfuzztestcases: utils test_setup
1434         tests/gen_fuzz_test_cases.sh
1435
1436 .PHONY: runbmptests
1437 runbmptests: test_setup
1438         cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
1439                 ./TestBmpBlock.py -v
1440
1441 .PHONY: runcgpttests
1442 runcgpttests: test_setup
1443         ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
1444
1445 .PHONY: runtestscripts
1446 runtestscripts: test_setup genfuzztestcases
1447         tests/load_kernel_tests.sh
1448         tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
1449         tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
1450         tests/run_preamble_tests.sh
1451         tests/run_rsa_tests.sh
1452         tests/run_vbutil_kernel_arg_tests.sh
1453         tests/run_vbutil_tests.sh
1454         tests/vb2_rsa_tests.sh
1455         tests/vb2_firmware_tests.sh
1456
1457 .PHONY: runmisctests
1458 runmisctests: test_setup
1459         ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
1460         ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
1461         ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1462         ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1463         ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
1464         ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1465         ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1466         ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1467         ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1468         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
1469         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
1470         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1471         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
1472         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1473         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1474         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
1475         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel5_tests
1476         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
1477         ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
1478         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1479         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1480         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
1481         ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
1482         ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
1483         ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
1484         ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
1485
1486 .PHONY: run2tests
1487 run2tests: test_setup
1488         ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
1489         ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
1490         ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1491         ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1492         ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
1493         ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
1494         ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdatak_tests
1495         ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
1496         ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1497         ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_kernel_tests
1498         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1499         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1500         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1501         ${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
1502         ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
1503         ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1504         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1505         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1506         ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1507         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1508         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
1509         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1510         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
1511         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
1512         ${RUNTEST} ${BUILD_RUN}/tests/hmac_test
1513
1514 .PHONY: runbdbtests
1515 runbdbtests: test_setup
1516         ${RUNTEST} ${BUILD_RUN}/tests/bdb_test ${TEST_KEYS}
1517         ${RUNTEST} ${BUILD_RUN}/tests/bdb_sprw_test ${TEST_KEYS}
1518
1519 .PHONY: runfutiltests
1520 runfutiltests: test_setup
1521         tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
1522         ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
1523         ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1524
1525 # Run long tests, including all permutations of encryption keys (instead of
1526 # just the ones we use) and tests of currently-unused code.
1527 # Not run by automated build.
1528 .PHONY: runlongtests
1529 runlongtests: test_setup genkeys genfuzztestcases
1530         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1531         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
1532         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1533         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
1534         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
1535         tests/run_preamble_tests.sh --all
1536         tests/run_vbutil_tests.sh --all
1537
1538 # TODO: There were a number of ancient tests that hadn't been run in years.
1539 # They were removed with https://chromium-review.googlesource.com/#/c/214610/
1540 # Some day it might be nice to see what they were supposed to do.
1541
1542 .PHONY: runalltests
1543 runalltests: runtests runfutiltests runlongtests
1544
1545 # Code coverage
1546 .PHONY: coverage_init
1547 coverage_init: test_setup
1548         rm -f ${COV_INFO}*
1549         lcov -c -i -d . -b . -o ${COV_INFO}.initial
1550
1551 .PHONY: coverage_html
1552 coverage_html:
1553         lcov -c -d . -b . -o ${COV_INFO}.tests
1554         lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1555         lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1556         genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1557 # Generate addtional coverage stats just for firmware subdir, because the stats
1558 # for the whole project don't include subdirectory summaries. This will print
1559 # the summary for just the firmware sources.
1560         lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1561         lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
1562                 -o ${COV_INFO}.firmware
1563
1564 .PHONY: coverage
1565 ifeq (${COV},)
1566 coverage:
1567         $(error Build coverage like this: make clean && COV=1 make coverage)
1568 else
1569 coverage: coverage_init runtests coverage_html
1570 endif
1571
1572 # Include generated dependencies
1573 ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1574 TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1575 -include ${ALL_DEPS}
1576 -include ${TEST_DEPS}
1577
1578 # We want to use only relative paths in cscope.files, especially since the
1579 # paths inside and outside the chroot are different.
1580 SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1581
1582 # Note: vboot 2.0 is deprecated, so don't index those files
1583 ${BUILD}/cscope.files: all test_setup
1584         ${Q}rm -f $@
1585         ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1586                 grep -v /lib20/ | \
1587                 sed -e "s/${SRCDIRPAT}//" | \
1588                 egrep '\.[chS]$$' | sort | uniq > $@
1589
1590 cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1591 cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1592 run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1593
1594 .PHONY: tags TAGS xrefs
1595 tags TAGS xrefs: ${BUILD}/cscope.files
1596         ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1597         ${Q}$(call run_if_prog,etags,${cmd_etags})
1598         ${Q}$(call run_if_prog,ctags,${cmd_ctags})
1599
1600 PC_FILES = ${PC_IN_FILES:%.pc.in=${BUILD}/%.pc}
1601 ${PC_FILES}: ${PC_IN_FILES}
1602         ${Q}sed \
1603                 -e 's:@LDLIBS@:${LDLIBS}:' \
1604                 -e 's:@LIBDIR@:${LIBDIR}:' \
1605                 $< > $@
1606
1607 .PHONY: pc_files_install
1608 pc_files_install: ${PC_FILES}
1609         ${Q}mkdir -p ${ULP_DIR}
1610         ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$(notdir $<)