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