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