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