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