Debian Codegraph @

3rdparty/vboot/Makefile

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # Copyright 2013 The ChromiumOS Authors
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 BUILD = ${SRCDIR}/build
41 export BUILD
42
43 # Stuff for 'make install'
44 INSTALL = install
45 DESTDIR = /
46 LIBDIR ?= lib
47
48 # Default values
49 DEV_DEBUG_FORCE=
50
51 # Where exactly do the pieces go?
52 # UB_DIR = utility binary directory
53 # ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
54 # UI_DIR = include directory for library headers
55 # US_DIR = shared data directory (for static content like devkeys)
56 # DF_DIR = utility defaults directory
57 # VB_DIR = vboot binary directory for dev-mode-only scripts
58 # DUT_TEST_DIR = vboot dut tests binary directory
59 UB_DIR=${DESTDIR}/usr/bin
60 UL_DIR=${DESTDIR}/usr/${LIBDIR}
61 ULP_DIR=${UL_DIR}/pkgconfig
62 UI_DIR=${DESTDIR}/usr/include/vboot
63 US_DIR=${DESTDIR}/usr/share/vboot
64 DF_DIR=${DESTDIR}/etc/default
65 VB_DIR=${US_DIR}/bin
66 DUT_TEST_DIR=${US_DIR}/tests
67
68 # Where to install the (exportable) executables for testing?
69 TEST_INSTALL_DIR = ${BUILD}/install_for_test
70
71 # Set when installing into the SDK instead of building for a board sysroot.
72 SDK_BUILD ?=
73
74 # Verbose? Use V=1
75 ifeq ($(filter-out 0,${V}),)
76 Q := @
77 endif
78
79 # Quiet? Use QUIET=1
80 ifeq ($(filter-out 0,${QUIET}),)
81 PRINTF := printf
82 else
83 PRINTF := :
84 endif
85
86 # ARCH and/or FIRMWARE_ARCH are defined by the ChromiumOS ebuild.
87 # Pick a valid target architecture if none is defined.
88 ifeq (${ARCH},)
89 ARCH := $(shell uname -m)
90 endif
91
92 ifeq (${ARCH},armv7l)
93 override ARCH := arm
94 else ifeq (${ARCH},aarch64)
95 override ARCH := arm64
96 else ifeq (${ARCH},i386)
97 override ARCH := x86
98 else ifeq (${ARCH},i686)
99 override ARCH := x86
100 else ifeq (${ARCH},amd64)
101 override ARCH := x86_64
102 endif
103
104 ifneq (,$(filter arm arm64,${ARCH}))
105 ARCH_DIR := arm
106 else ifneq (,$(filter x86 x86_64,${ARCH}))
107 ARCH_DIR := x86
108 else
109 ARCH_DIR := stub
110 endif
111
112 # Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
113 # please add them after this point (e.g., -DVBOOT_DEBUG).
114 DEBUG_FLAGS := $(if $(filter-out 0,${DEBUG}),-g -Og,-g -Os)
115 WERROR := -Werror
116 FIRMWARE_FLAGS := -nostdinc -ffreestanding -fno-builtin -fno-stack-protector
117 COMMON_FLAGS := -pipe ${WERROR} -Wall -Wstrict-prototypes -Wtype-limits \
118 -Wundef -Wmissing-prototypes -Wno-trigraphs -Wredundant-decls -Wshadow \
119 -Wwrite-strings -Wstrict-aliasing -Wdate-time \
120 -Wint-conversion -ffunction-sections -fdata-sections \
121 -Wformat -Wno-format-security -std=gnu11 ${DEBUG_FLAGS} ${CPPFLAGS}
122
123 # test_ccflag
124 # $(1): compiler flags to test
125 # $(2): code to insert into test snippet
126 # returns: $(1) if compiler was successful, empty string otherwise
127 test_ccflag = $(shell \
128 printf "$(2)\nvoid _start(void) {}\n" | \
129 $(CC) -nostdlib -Werror $(1) -xc -c - -o /dev/null \
130 >/dev/null 2>&1 && echo "$(1)")
131
132 COMMON_FLAGS += $(call test_ccflag,-Wimplicit-fallthrough)
133 COMMON_FLAGS += $(call test_ccflag,-Wno-address-of-packed-member)
134 COMMON_FLAGS += $(call test_ccflag,-Wno-unknown-warning)
135 COMMON_FLAGS += $(call test_ccflag,-Wincompatible-function-pointer-types)
136
137 TEST_FLAGS := $(call test_ccflag,-Wno-address-of-packed-member)
138
139 # FIRMWARE_ARCH is only defined by the ChromiumOS ebuild if compiling
140 # for a firmware target (coreboot or depthcharge). It must map to the same
141 # consistent set of architectures as the host.
142 ifeq (${FIRMWARE_ARCH},i386)
143 override FIRMWARE_ARCH := x86
144 else ifeq (${FIRMWARE_ARCH},amd64)
145 override FIRMWARE_ARCH := x86_64
146 else ifneq ($(filter arm64 armv7 armv8 armv8_64,${FIRMWARE_ARCH}),)
147 override FIRMWARE_ARCH := arm
148 endif
149
150 ifeq (${FIRMWARE_ARCH},arm)
151 CC ?= armv7a-cros-linux-gnueabihf-gcc
152 CFLAGS ?= -march=armv5 -fno-common -ffixed-r8 -mfloat-abi=hard -marm
153 -mabi=aapcs-linux -mno-thumb-interwork ${FIRMWARE_FLAGS} ${COMMON_FLAGS}
154 else ifeq (${FIRMWARE_ARCH},x86)
155 CC ?= i686-pc-linux-gnu-gcc
156 # Drop -march=i386 to permit use of SSE instructions
157 CFLAGS ?= -fvisibility=hidden -fomit-frame-pointer \
158 -fno-toplevel-reorder -fno-dwarf2-cfi-asm -mpreferred-stack-boundary=2 \
159 ${FIRMWARE_FLAGS} ${COMMON_FLAGS}
160 else ifeq (${FIRMWARE_ARCH},x86_64)
161 CFLAGS ?= ${FIRMWARE_FLAGS} ${COMMON_FLAGS} -fvisibility=hidden \
162 -fomit-frame-pointer
163 else ifeq (${FIRMWARE_ARCH},riscv)
164 CC ?= riscv64-linux-gnu-gcc
165 else ifeq (${FIRMWARE_ARCH},mock)
166 FIRMWARE_STUB := 1
167 CFLAGS += ${TEST_FLAGS}
168 else ifneq (${FIRMWARE_ARCH},)
169 $(error Unexpected FIRMWARE_ARCH ${FIRMWARE_ARCH})
170 else
171 # FIRMWARE_ARCH not defined; assuming local compile.
172 FIRMWARE_STUB := 1
173 CC ?= gcc
174 CFLAGS += -DCHROMEOS_ENVIRONMENT ${COMMON_FLAGS}
175 endif
176
177 # Needs -Wl because LD is actually set to CC by default.
178 LDFLAGS += -Wl,--gc-sections
179
180 ifneq ($(filter-out 0,${DEBUG})$(filter-out 0,${TEST_PRINT}),)
181 CFLAGS += -DVBOOT_DEBUG
182 endif
183
184 ifneq ($(filter-out 0,${NDEBUG}),)
185 CFLAGS += -DNDEBUG
186 endif
187
188 ifneq ($(filter-out 0,${TPM2_MODE}),)
189 CFLAGS += -DTPM2_MODE
190 endif
191
192 # Support devices with GPT in SPI-NOR (for nand device)
193 # TODO(b:184812319): Consider removing this code if nobody uses it.
194 ifneq ($(filter-out 0,${GPT_SPI_NOR}),)
195 CFLAGS += -DGPT_SPI_NOR
196 endif
197
198 # Enable EC early firmware selection.
199 ifneq ($(filter-out 0,${EC_EFS}),)
200 CFLAGS += -DEC_EFS=1
201 else
202 CFLAGS += -DEC_EFS=0
203 endif
204
205 # Some tests need to be disabled when using mocked_secdata_tpm.
206 ifneq ($(filter-out 0,${MOCK_TPM}),)
207 CFLAGS += -DMOCK_TPM
208 endif
209
210 # EXTERNAL_TPM_CLEAR_REQUEST indicates whether we want to use the external
211 # tpm_clear_request tool or not.
212 ifneq ($(filter-out 0,${EXTERNAL_TPM_CLEAR_REQUEST}),)
213 CFLAGS += -DEXTERNAL_TPM_CLEAR_REQUEST=1
214 else
215 CFLAGS += -DEXTERNAL_TPM_CLEAR_REQUEST=0
216 endif
217
218 # Configurable temporary directory for host tools
219 VBOOT_TMP_DIR := /tmp
220 CFLAGS += -DVBOOT_TMP_DIR=\"${VBOOT_TMP_DIR}\"
221
222 # Directory used by crossystem to create a lock file
223 CROSSYSTEM_LOCK_DIR := /run/lock
224 CFLAGS += -DCROSSYSTEM_LOCK_DIR=\"${CROSSYSTEM_LOCK_DIR}\"
225
226 # NOTE: We don't use these files but they are useful for other packages to
227 # query about required compiling/linking flags.
228 PC_IN_FILES = vboot_host.pc.in
229
230 # Create / use dependency files
231 CFLAGS += -MMD -MF [email protected]
232
233 ifeq (${FIRMWARE_ARCH},)
234 # Creates position independent code for non firmware target.
235 CFLAGS += -fPIC
236 endif
237
238 CFLAGS += -D_GNU_SOURCE
239
240 # This is required to access large disks and files on 32-bit systems,
241 # but if the environment doesn't support it, at least compile support
242 # for what is possible.
243 # Pass through cflags_use_64bits to evaluate it only once, here.
244 HASH_CONST := \#
245 cflags_use_64bits := $(call test_ccflag,$\
246 -D_FILE_OFFSET_BITS=64,$\
247 ${HASH_CONST}include <fts.h>)
248 CFLAGS += $(cflags_use_64bits)
249
250 # Code coverage
251 ifneq ($(filter-out 0,${COV}),)
252 COV_FLAGS = -Og --coverage -DCOVERAGE
253 CFLAGS += ${COV_FLAGS}
254 LDFLAGS += ${COV_FLAGS}
255 COV_INFO = ${BUILD}/coverage.info
256 endif
257
258 ifdef HAVE_MACOS
259 CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
260 endif
261
262 # Musl doesn't have execinfo.h.
263 ifndef HAVE_MUSL
264 CFLAGS += -DHAVE_EXECINFO_H
265 endif
266
267 # And a few more default utilities
268 LD = ${CC}
269 CXX ?= g++
270 PKG_CONFIG ?= pkg-config
271
272 # Static?
273 ifneq ($(filter-out 0,${STATIC}),)
274 LDFLAGS += -static
275 PKG_CONFIG += --static
276 endif
277
278 ifneq (${FUZZ_FLAGS},)
279 CFLAGS += ${FUZZ_FLAGS}
280 endif
281
282 # Optional Libraries
283 LIBZIP_VERSION := $(shell ${PKG_CONFIG} --modversion libzip 2>/dev/null)
284 HAVE_LIBZIP := $(if ${LIBZIP_VERSION},1)
285 ifneq ($(filter-out 0,${HAVE_LIBZIP}),)
286 CFLAGS += -DHAVE_LIBZIP $(shell ${PKG_CONFIG} --cflags libzip)
287 LIBZIP_LIBS := $(shell ${PKG_CONFIG} --libs libzip)
288 endif
289
290 LIBARCHIVE_VERSION := $(shell ${PKG_CONFIG} --modversion libarchive 2>/dev/null)
291 HAVE_LIBARCHIVE := $(if ${LIBARCHIVE_VERSION},1)
292 ifneq ($(filter-out 0,${HAVE_LIBARCHIVE}),)
293 CFLAGS += -DHAVE_LIBARCHIVE $(shell ${PKG_CONFIG} --cflags libarchive)
294 LIBARCHIVE_LIBS := $(shell ${PKG_CONFIG} --libs libarchive)
295 endif
296
297 HAVE_CROSID := $(shell ${PKG_CONFIG} --exists crosid && echo 1)
298 ifeq ($(HAVE_CROSID),1)
299 CFLAGS += -DHAVE_CROSID $(shell ${PKG_CONFIG} --cflags crosid)
300 CROSID_LIBS := $(shell ${PKG_CONFIG} --libs crosid)
301 endif
302
303 HAVE_NSS := $(shell ${PKG_CONFIG} --exists nss && echo 1)
304 ifeq ($(HAVE_NSS),1)
305 CFLAGS += -DHAVE_NSS $(shell ${PKG_CONFIG} --cflags nss)
306 # The LIBS is not needed because we only use the header.
307 else
308 $(warning Missing NSS. PKCS11 signing not supported. Install libnss3 to enable this feature.)
309 endif
310
311 # Get major version of openssl (e.g. version 3.0.5 -> "3")
312 OPENSSL_VERSION := $(shell ${PKG_CONFIG} --modversion openssl | cut -d. -f1)
313
314 # A test wrapper can be specified. Tests are run inside the wrapper eg:
315 # make RUNTEST=env runtests
316 RUNTEST =
317 # The Path to the $BUILD inside the runtest wrapper, used by the test scripts.
318 # The top of the chroot for RUNTEST must be passed in via the SYSROOT
319 # environment variable. In the ChromiumOS chroot, this is done automatically by
320 # the ebuild.
321 export BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
322 # Path to the $SRCDIR inside the wrapper, the test scripts rederive this.
323 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
324
325 ##############################################################################
326 # The default target is here, to allow dependencies to be expressed below
327 # without accidentally changing the default target.
328
329 # Default target.
330 .PHONY: all
331 all: fwlib futil utillib hostlib cgpt tlcl util_files \
332 $(if $(filter x86_64,${ARCH}),$(if $(filter clang,${CC}),fuzzers)) \
333 $(if $(filter-out 0,${COV}),coverage)
334
335 ##############################################################################
336 # Now we need to describe everything we might want or need to build
337
338 # Everything wants these headers.
339 INCLUDES += \
340 -Ifirmware/include \
341 -Ifirmware/lib/include \
342 -Ifirmware/lib/cgptlib/include \
343 -Ifirmware/lib/tpm_lite/include \
344 -Ifirmware/2lib/include
345
346 # If we're not building for a specific target, just stub out things like the
347 # TPM commands and various external functions that are provided by the BIOS.
348 ifneq (${FIRMWARE_STUB},)
349 INCLUDES += -Ihost/include -Ihost/lib/include
350 INCLUDES += -Ihost/lib21/include
351 ifeq ($(shell uname -s), OpenBSD)
352 INCLUDES += -I/usr/local/include
353 endif
354 endif
355
356 # Firmware library, used by the other firmware components (depthcharge,
357 # coreboot, etc.). It doesn't need exporting to some other place; they'll build
358 # this source tree locally and link to it directly.
359 FWLIB = ${BUILD}/vboot_fw.a
360
361 # Separate TPM lightweight command library (TLCL)
362 TLCL = ${BUILD}/tlcl.a
363
364 FWLIB_SRCS = \
365 firmware/2lib/2api.c \
366 firmware/2lib/2auxfw_sync.c \
367 firmware/2lib/2common.c \
368 firmware/2lib/2context.c \
369 firmware/2lib/2crc8.c \
370 firmware/2lib/2crypto.c \
371 firmware/2lib/2ec_sync.c \
372 firmware/2lib/2firmware.c \
373 firmware/2lib/2gbb.c \
374 firmware/2lib/2hmac.c \
375 firmware/2lib/2kernel.c \
376 firmware/2lib/2load_kernel.c \
377 firmware/2lib/2misc.c \
378 firmware/2lib/2nvstorage.c \
379 firmware/2lib/2packed_key.c \
380 firmware/2lib/2recovery_reasons.c \
381 firmware/2lib/2rsa.c \
382 firmware/2lib/2secdata_firmware.c \
383 firmware/2lib/2secdata_fwmp.c \
384 firmware/2lib/2secdata_kernel.c \
385 firmware/2lib/2sha1.c \
386 firmware/2lib/2sha256.c \
387 firmware/2lib/2sha512.c \
388 firmware/2lib/2sha_utility.c \
389 firmware/2lib/2struct.c \
390 firmware/2lib/2stub_hwcrypto.c \
391 firmware/2lib/2tpm_bootmode.c \
392 firmware/lib/cgptlib/cgptlib.c \
393 firmware/lib/cgptlib/cgptlib_internal.c \
394 firmware/lib/cgptlib/crc32.c \
395 firmware/lib/gpt_misc.c \
396 firmware/lib20/api_kernel.c \
397 firmware/lib20/kernel.c
398
399 # TPM lightweight command library
400 ifeq ($(filter-out 0,${TPM2_MODE}),)
401 TLCL_SRCS = \
402 firmware/lib/tpm_lite/tlcl.c
403 else
404 # TODO(apronin): tests for TPM2 case?
405 TLCL_SRCS = \
406 firmware/lib/tpm2_lite/tlcl.c \
407 firmware/lib/tpm2_lite/marshaling.c
408 endif
409
410 # Support real TPM unless MOCK_TPM is set
411 ifneq ($(filter-out 0,${MOCK_TPM}),)
412 FWLIB_SRCS += \
413 firmware/lib/tpm_lite/mocked_tlcl.c
414 endif
415
416 ifneq ($(filter-out 0,${X86_SHA_EXT}),)
417 CFLAGS += -DX86_SHA_EXT
418 FWLIB_SRCS += \
419 firmware/2lib/2hwcrypto.c \
420 firmware/2lib/2sha256_x86.c
421 endif
422
423 ifneq ($(filter-out 0,${ARMV8_CRYPTO_EXT}),)
424 CFLAGS += -DARMV8_CRYPTO_EXT
425 FWLIB_SRCS += \
426 firmware/2lib/2hwcrypto.c \
427 firmware/2lib/2sha256_arm.c
428 FWLIB_ASMS += \
429 firmware/2lib/sha256_armv8a_ce_a64.S
430 endif
431
432 ifneq ($(filter-out 0,${ARM64_RSA_ACCELERATION}),)
433 CFLAGS += -DARM64_RSA_ACCELERATION
434 FWLIB_SRCS += \
435 firmware/2lib/2modpow_neon.c
436 endif
437
438 ifneq ($(filter-out 0,${VB2_X86_RSA_ACCELERATION}),)
439 CFLAGS += -DVB2_X86_RSA_ACCELERATION
440 FWLIB_SRCS += \
441 firmware/2lib/2modpow_sse2.c
442 endif
443
444 ifneq (,$(filter arm64 x86 x86_64,${ARCH}))
445 ENABLE_HWCRYPTO_RSA_TESTS := 1
446 endif
447
448 # Even if X86_SHA_EXT is 0 we need cflags since this will be compiled for tests
449 ${BUILD}/firmware/2lib/2sha256_x86.o: CFLAGS += -mssse3 -mno-avx -msha
450
451 ${BUILD}/firmware/2lib/2modpow_sse2.o: CFLAGS += -msse2 -mno-avx
452
453 ifneq (${FIRMWARE_STUB},)
454 # Include BIOS stubs in the firmware library when compiling for host
455 # TODO: split out other stub funcs too
456 FWLIB_SRCS += \
457 firmware/stub/tpm_lite_stub.c \
458 firmware/stub/vboot_api_stub_disk.c \
459 firmware/stub/vboot_api_stub_stream.c \
460 firmware/2lib/2stub.c
461 endif
462
463 FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o} ${FWLIB_ASMS:%.S=${BUILD}/%.o}
464 TLCL_OBJS = ${TLCL_SRCS:%.c=${BUILD}/%.o}
465 ALL_OBJS += ${FWLIB_OBJS} ${TLCL_OBJS}
466
467 # Maintain behaviour of default on.
468 USE_FLASHROM ?= 1
469
470 ifneq ($(filter-out 0,${USE_FLASHROM}),)
471 $(info building with libflashrom support)
472 FLASHROM_LIBS := $(shell ${PKG_CONFIG} --libs flashrom)
473 COMMONLIB_SRCS += \
474 host/lib/flashrom.c \
475 host/lib/flashrom_drv.c
476 CFLAGS += -DUSE_FLASHROM
477 endif
478 COMMONLIB_SRCS += \
479 host/lib/subprocess.c \
480 host/lib/cbfstool.c
481
482 # Intermediate library for the vboot_reference utilities to link against.
483 UTILLIB = ${BUILD}/libvboot_util.a
484
485 # Avoid build failures outside the chroot on Ubuntu 2022.04
486 # e.g.:
487 # host/lib/host_key2.c:103:17: error: ‘RSA_free’ is deprecated: Since OpenSSL 3.0
488 # [-Werror=deprecated-declarations]
489 ifeq ($(OPENSSL_VERSION),3)
490 ${UTILLIB}: CFLAGS += -Wno-error=deprecated-declarations
491 endif
492
493 UTILLIB_SRCS = \
494 cgpt/cgpt_add.c \
495 cgpt/cgpt_boot.c \
496 cgpt/cgpt_common.c \
497 cgpt/cgpt_create.c \
498 cgpt/cgpt_edit.c \
499 cgpt/cgpt_prioritize.c \
500 cgpt/cgpt_repair.c \
501 cgpt/cgpt_show.c \
502 futility/dump_kernel_config_lib.c \
503 host/arch/${ARCH_DIR}/lib/crossystem_arch.c \
504 host/lib/chromeos_config.c \
505 host/lib/crossystem.c \
506 host/lib/crypto.c \
507 host/lib/file_keys.c \
508 $(COMMONLIB_SRCS) \
509 host/lib/fmap.c \
510 host/lib/host_common.c \
511 host/lib/host_key2.c \
512 host/lib/host_keyblock.c \
513 host/lib/host_misc.c \
514 host/lib/host_signature.c \
515 host/lib/host_signature2.c \
516 host/lib/signature_digest.c \
517 host/lib/util_misc.c \
518 host/lib21/host_common.c \
519 host/lib21/host_key.c \
520 host/lib21/host_misc.c \
521 host/lib21/host_signature.c
522
523 ifeq ($(HAVE_NSS),1)
524 UTILLIB_SRCS += \
525 host/lib/host_p11.c
526 else
527 UTILLIB_SRCS += \
528 host/lib/host_p11_stub.c
529 endif
530
531 UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
532 ALL_OBJS += ${UTILLIB_OBJS}
533
534 # Externally exported library for some target userspace apps to link with
535 # (cryptohome, updater, etc.)
536 HOSTLIB = ${BUILD}/libvboot_host.so
537 HOSTLIB_STATIC = ${BUILD}/libvboot_host.a
538
539 # For testing purposes files contianing some libvboot_host symbols.
540 HOSTLIB_DEF = ${BUILD}/tests/libvboot_host_def.txt
541 HOSTLIB_UNDEF = ${BUILD}/tests/libvboot_host_undef.txt
542
543 HOSTLIB_SRCS = \
544 cgpt/cgpt_add.c \
545 cgpt/cgpt_boot.c \
546 cgpt/cgpt_common.c \
547 cgpt/cgpt_create.c \
548 cgpt/cgpt_edit.c \
549 cgpt/cgpt_find.c \
550 cgpt/cgpt_prioritize.c \
551 cgpt/cgpt_repair.c \
552 cgpt/cgpt_show.c \
553 firmware/2lib/2common.c \
554 firmware/2lib/2context.c \
555 firmware/2lib/2crc8.c \
556 firmware/2lib/2crypto.c \
557 firmware/2lib/2hmac.c \
558 firmware/2lib/2nvstorage.c \
559 firmware/2lib/2recovery_reasons.c \
560 firmware/2lib/2rsa.c \
561 firmware/2lib/2sha1.c \
562 firmware/2lib/2sha256.c \
563 firmware/2lib/2sha512.c \
564 firmware/2lib/2sha_utility.c \
565 firmware/2lib/2struct.c \
566 firmware/2lib/2stub.c \
567 firmware/2lib/2stub_hwcrypto.c \
568 firmware/lib/cgptlib/cgptlib_internal.c \
569 firmware/lib/cgptlib/crc32.c \
570 firmware/lib/gpt_misc.c \
571 firmware/stub/tpm_lite_stub.c \
572 firmware/stub/vboot_api_stub_disk.c \
573 futility/dump_kernel_config_lib.c \
574 host/arch/${ARCH_DIR}/lib/crossystem_arch.c \
575 host/lib/chromeos_config.c \
576 host/lib/crossystem.c \
577 host/lib/crypto.c \
578 host/lib/extract_vmlinuz.c \
579 $(COMMONLIB_SRCS) \
580 host/lib/fmap.c \
581 host/lib/host_misc.c \
582 host/lib21/host_misc.c \
583 ${TLCL_SRCS}
584
585 ifneq ($(filter-out 0,${GPT_SPI_NOR}),)
586 HOSTLIB_SRCS += cgpt/cgpt_nor.c
587 endif
588
589 HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
590 ALL_OBJS += ${HOSTLIB_OBJS}
591
592 # ----------------------------------------------------------------------------
593 # Now for the userspace binaries
594
595 CGPT = ${BUILD}/cgpt/cgpt
596
597 CGPT_SRCS = \
598 cgpt/cgpt.c \
599 cgpt/cgpt_add.c \
600 cgpt/cgpt_boot.c \
601 cgpt/cgpt_common.c \
602 cgpt/cgpt_create.c \
603 cgpt/cgpt_edit.c \
604 cgpt/cgpt_find.c \
605 cgpt/cgpt_legacy.c \
606 cgpt/cgpt_prioritize.c \
607 cgpt/cgpt_repair.c \
608 cgpt/cgpt_show.c \
609 cgpt/cmd_add.c \
610 cgpt/cmd_boot.c \
611 cgpt/cmd_create.c \
612 cgpt/cmd_edit.c \
613 cgpt/cmd_find.c \
614 cgpt/cmd_legacy.c \
615 cgpt/cmd_prioritize.c \
616 cgpt/cmd_repair.c \
617 cgpt/cmd_show.c
618
619 ifneq ($(filter-out 0,${GPT_SPI_NOR}),)
620 CGPT_SRCS += cgpt/cgpt_nor.c
621 endif
622
623 CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
624
625 ALL_OBJS += ${CGPT_OBJS}
626
627 CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
628
629 CGPT_WRAPPER_SRCS = \
630 cgpt/cgpt_nor.c \
631 cgpt/cgpt_wrapper.c
632
633 CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
634
635 ALL_OBJS += ${CGPT_WRAPPER_OBJS}
636
637 # Utility defaults
638 UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
639
640 # Scripts to install directly (not compiled)
641 UTIL_SCRIPT_NAMES_SDK = \
642 utility/dev_make_keypair \
643 utility/vbutil_what_keys
644 UTIL_SCRIPT_NAMES_BOARD = \
645 utility/chromeos-tpm-recovery \
646 utility/dev_debug_vboot \
647 utility/enable_dev_usb_boot \
648 utility/tpm-nvsize
649
650 UTIL_BIN_NAMES_SDK = \
651 utility/dumpRSAPublicKey \
652 utility/load_kernel_test \
653 utility/pad_digest_utility \
654 utility/signature_digest_utility \
655 utility/verify_data
656 UTIL_BIN_NAMES_BOARD = \
657 utility/dumpRSAPublicKey \
658 utility/tpmc
659
660 ifneq ($(filter-out 0,${USE_FLASHROM}),)
661 UTIL_BIN_NAMES_BOARD += utility/crossystem
662 endif
663
664 UTIL_SCRIPTS_SDK = $(addprefix ${BUILD}/,${UTIL_SCRIPT_NAMES_SDK})
665 UTIL_SCRIPTS_BOARD = $(addprefix ${BUILD}/,${UTIL_SCRIPT_NAMES_BOARD})
666 UTIL_BINS_SDK = $(addprefix ${BUILD}/,${UTIL_BIN_NAMES_SDK})
667 UTIL_BINS_BOARD = $(addprefix ${BUILD}/,${UTIL_BIN_NAMES_BOARD})
668 UTIL_FILES_SDK = ${UTIL_BINS_SDK} ${UTIL_SCRIPTS_SDK}
669 UTIL_FILES_BOARD = ${UTIL_BINS_BOARD} ${UTIL_SCRIPTS_BOARD}
670 ALL_OBJS += $(addsuffix .o,${UTIL_BINS_SDK})
671 ALL_OBJS += $(addsuffix .o,${UTIL_BINS_BOARD})
672
673
674 # Signing scripts that are also useful on DUTs.
675 SIGNING_SCRIPTS_BOARD = \
676 scripts/image_signing/make_dev_firmware.sh \
677 scripts/image_signing/make_dev_ssd.sh \
678 scripts/image_signing/resign_firmwarefd.sh \
679 scripts/image_signing/common_minimal.sh
680
681 # SDK installations have some extra scripts.
682 SIGNING_SCRIPTS_SDK = \
683 scripts/image_signing/make_dev_firmware.sh \
684 scripts/image_signing/make_dev_ssd.sh \
685 scripts/image_signing/resign_firmwarefd.sh \
686 scripts/image_signing/swap_ec_rw \
687 scripts/image_signing/common_minimal.sh
688
689 # Unified firmware utility.
690 FUTIL_BIN = ${BUILD}/futility/futility
691
692 # These are the executables that are now built in to futility. We'll create
693 # symlinks for these so the old names will still work.
694 FUTIL_SYMLINKS = \
695 dump_fmap \
696 dump_kernel_config \
697 gbb_utility \
698 vbutil_firmware \
699 vbutil_kernel \
700 vbutil_key \
701 vbutil_keyblock
702
703 FUTIL_SRCS = \
704 futility/futility.c \
705 futility/cmd_create.c \
706 futility/cmd_dump_fmap.c \
707 futility/cmd_dump_kernel_config.c \
708 futility/cmd_flash_util.c \
709 futility/cmd_gbb_utility.c \
710 futility/cmd_gscvd.c \
711 futility/cmd_load_fmap.c \
712 futility/cmd_pcr.c \
713 futility/cmd_read.c \
714 futility/cmd_show.c \
715 futility/cmd_sign.c \
716 futility/cmd_update.c \
717 futility/cmd_vbutil_firmware.c \
718 futility/cmd_vbutil_kernel.c \
719 futility/cmd_vbutil_key.c \
720 futility/cmd_vbutil_keyblock.c \
721 futility/file_type_bios.c \
722 futility/file_type.c \
723 futility/file_type_rwsig.c \
724 futility/file_type_usbpd1.c \
725 futility/flash_helpers.c \
726 futility/platform_csme.c \
727 futility/misc.c \
728 futility/vb1_helper.c \
729 futility/vb2_helper.c
730
731 ifneq ($(filter-out 0,${USE_FLASHROM}),)
732 FUTIL_SRCS += host/lib/flashrom_drv.c \
733 futility/updater_archive.c \
734 futility/updater_dut.c \
735 futility/updater_manifest.c \
736 futility/updater_quirks.c \
737 futility/updater_utils.c \
738 futility/updater.c
739 endif
740
741 # List of commands built in futility.
742 FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
743
744 FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
745
746 ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include
747
748 # Avoid build failures outside the chroot on Ubuntu 2022.04
749 # e.g.:
750 # futility/cmd_create.c:161:9: warning: ‘RSA_free’ is deprecated: Since OpenSSL 3.0
751 # [-Wdeprecated-declarations]
752 ifeq ($(OPENSSL_VERSION),3)
753 ${FUTIL_OBJS}: CFLAGS += -Wno-error=deprecated-declarations
754 endif
755
756 ALL_OBJS += ${FUTIL_OBJS}
757
758
759 # Library of handy test functions.
760 TESTLIB = ${BUILD}/tests/test.a
761
762 TEST_COMMON_DIR = tests/common
763
764 TESTLIB_SRCS += $(wildcard $(TEST_COMMON_DIR)/*.c)
765 TESTLIB_SRCS += tests/crc32_test.c
766
767 TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
768 TEST_OBJS += ${TESTLIB_OBJS}
769
770
771 # And some compiled tests.
772 TEST_NAMES = \
773 tests/cbfstool_tests \
774 tests/cgptlib_test \
775 tests/chromeos_config_tests \
776 tests/gpt_misc_tests \
777 tests/sha_benchmark \
778 tests/subprocess_tests \
779 tests/verify_kernel
780
781 ifeq ($(filter-out 0,${MOCK_TPM})$(filter-out 0,${TPM2_MODE}),)
782 # tlcl_tests only works when MOCK_TPM is disabled
783 # TODO(apronin): tests for TPM2 case?
784 TEST_NAMES += \
785 tests/tlcl_tests
786 endif
787
788 TEST_FUTIL_NAMES = \
789 tests/futility/binary_editor \
790 tests/futility/test_file_types \
791 tests/futility/test_not_really
792
793 TEST_NAMES += ${TEST_FUTIL_NAMES}
794
795 TEST2X_NAMES = \
796 tests/vb2_api_tests \
797 tests/vb2_auxfw_sync_tests \
798 tests/vb2_common_tests \
799 tests/vb2_common2_tests \
800 tests/vb2_common3_tests \
801 tests/vb2_crypto_tests \
802 tests/vb2_ec_sync_tests \
803 tests/vb2_firmware_tests \
804 tests/vb2_gbb_init_tests \
805 tests/vb2_gbb_tests \
806 tests/vb2_host_flashrom_tests \
807 tests/vb2_host_key_tests \
808 tests/vb2_host_nvdata_flashrom_tests \
809 tests/vb2_inject_kernel_subkey_tests \
810 tests/vb2_kernel_tests \
811 tests/vb2_load_kernel_tests \
812 tests/vb2_load_kernel2_tests \
813 tests/vb2_misc_tests \
814 tests/vb2_misc2_tests \
815 tests/vb2_nvstorage_tests \
816 tests/vb2_rsa_utility_tests \
817 tests/vb2_recovery_reasons_tests \
818 tests/vb2_secdata_firmware_tests \
819 tests/vb2_secdata_fwmp_tests \
820 tests/vb2_secdata_kernel_tests \
821 tests/vb2_sha_api_tests \
822 tests/vb2_sha_tests \
823 tests/hmac_test
824
825 TEST20_NAMES = \
826 tests/vb20_api_kernel_tests \
827 tests/vb20_kernel_tests \
828 tests/vb20_rsa_padding_tests \
829 tests/vb20_verify_fw
830
831 TEST21_NAMES = \
832 tests/vb21_host_common2_tests \
833 tests/vb21_host_common_tests \
834 tests/vb21_host_key_tests \
835 tests/vb21_host_misc_tests \
836 tests/vb21_host_sig_tests
837
838 TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
839
840 # Tests which should be run on dut
841 ifeq (${ARCH}, x86_64)
842 DUT_TEST_NAMES += tests/vb2_sha256_x86_tests
843 endif
844
845 HWCRYPTO_RSA_TESTS = \
846 tests/vb20_hwcrypto_rsa_padding_tests \
847 tests/vb20_hwcrypto_verify_fw
848
849 TEST_NAMES += ${DUT_TEST_NAMES}
850
851 ifeq (${ENABLE_HWCRYPTO_RSA_TESTS},1)
852 TEST20_NAMES += ${HWCRYPTO_RSA_TESTS}
853 endif
854
855 # And a few more...
856 ifeq ($(filter-out 0,${TPM2_MODE}),)
857 TLCL_TEST_NAMES = \
858 tests/tpm_lite/tpmtest_earlyextend \
859 tests/tpm_lite/tpmtest_earlynvram \
860 tests/tpm_lite/tpmtest_earlynvram2 \
861 tests/tpm_lite/tpmtest_enable \
862 tests/tpm_lite/tpmtest_fastenable \
863 tests/tpm_lite/tpmtest_globallock \
864 tests/tpm_lite/tpmtest_redefine_unowned \
865 tests/tpm_lite/tpmtest_spaceperm \
866 tests/tpm_lite/tpmtest_testsetup \
867 tests/tpm_lite/tpmtest_timing \
868 tests/tpm_lite/tpmtest_writelimit
869 else
870 # TODO(apronin): tests for TPM2 case?
871 TLCL_TEST_NAMES =
872 endif
873
874 TEST_NAMES += ${TLCL_TEST_NAMES}
875
876 # Finally
877 TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
878 TEST_OBJS += $(addsuffix .o,${TEST_BINS})
879
880 TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES})
881 TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
882 TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
883 TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
884
885 # Directory containing test keys
886 TEST_KEYS = ${SRC_RUN}/tests/testkeys
887
888 # ----------------------------------------------------------------------------
889 # Fuzzing binaries
890
891 FUZZ_TEST_NAMES = \
892 tests/cgpt_fuzzer \
893 tests/vb2_keyblock_fuzzer \
894 tests/vb2_preamble_fuzzer
895
896 FUZZ_TEST_BINS = $(addprefix ${BUILD}/,${FUZZ_TEST_NAMES})
897
898 ##############################################################################
899 # Finally, some targets. High-level ones first.
900
901 # Create output directories if necessary. Do this via explicit shell commands
902 # so it happens before trying to generate/include dependencies.
903 SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
904 _dir_create := $(foreach d, \
905 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
906 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
907
908 .PHONY: clean
909 clean:
910 ${Q}/bin/rm -rf ${BUILD}
911
912 .PHONY: install
913 install: cgpt_install signing_install futil_install pc_files_install \
914 lib_install $(if ${SDK_BUILD},,util_install_defaults) \
915 $(foreach f,$(if ${SDK_BUILD},${UTIL_FILES_SDK},${UTIL_FILES_BOARD}), \
916 util_install-$(patsubst ${BUILD}/%,%,${f}))
917
918 .PHONY: install_dev
919 install_dev: devkeys_install headers_install
920
921 .PHONY: install_mtd
922 install_mtd: install cgpt_wrapper_install
923
924 .PHONY: install_for_test
925 install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
926 install_for_test: test_setup install \
927 $(foreach f,${UTIL_FILES_SDK} ${UTIL_FILES_BOARD}, \
928 util_install-$(patsubst ${BUILD}/%,%,${f}))
929
930 # Don't delete intermediate object files
931 .SECONDARY:
932
933 # ----------------------------------------------------------------------------
934 # Firmware library
935
936 # TPM-specific flags. These depend on the particular TPM we're targeting for.
937 # They are needed here only for compiling parts of the firmware code into
938 # user-level tests.
939
940 # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
941 # the self test has completed.
942
943 ${TLCL_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
944
945 # TPM_MANUAL_SELFTEST is defined if the self test must be started manually
946 # (with a call to TPM_ContinueSelfTest) instead of starting automatically at
947 # power on.
948 #
949 # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
950 # are not both defined at the same time. (See comment in code.)
951
952 # CFLAGS += -DTPM_MANUAL_SELFTEST
953
954 # NOTE: UNROLL_LOOPS *only* affects SHA256, *not* SHA512. This seems to have
955 # been a conscious decision at some point (see b/35501356) but whether it still
956 # holds up in all situations on all architectures today might need to be
957 # reevaluated. For now, since we currently always use SHA256 for (non-recovery)
958 # kernel bodies and don't unroll loops for firmware verification, it's not very
959 # relevant in practice. To unroll SHA512, UNROLL_LOOPS_SHA512 would need to be
960 # defined.
961 ifneq ($(filter-out 0,$(UNROLL_LOOPS)),)
962 $(info vboot SHA256 built with unrolled loops (faster, larger code size))
963 CFLAGS += -DUNROLL_LOOPS
964 else
965 $(info vboot SHA256 built with tight loops (slower, smaller code size))
966 endif
967
968 .PHONY: fwlib
969 fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},)
970
971 ${FWLIB}: ${FWLIB_OBJS}
972 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
973 ${Q}rm -f $@
974 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
975 ${Q}ar qcT $@ $^
976
977 .PHONY: tlcl
978 tlcl: ${TLCL}
979
980 ${TLCL}: ${TLCL_OBJS}
981 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
982 ${Q}rm -f $@
983 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
984 ${Q}ar qcT $@ $^
985
986 # ----------------------------------------------------------------------------
987 # Host library(s)
988
989 # Some UTILLIB files need dlopen(), doesn't hurt to just link it everywhere.
990 LDLIBS += -ldl
991 ifneq ($(filter-out 0,${USE_FLASHROM}),)
992 ${HOSTLIB}: LDLIBS += ${FLASHROM_LIBS}
993 endif
994
995 .PHONY: utillib
996 utillib: ${UTILLIB}
997
998 # TODO: better way to make .a than duplicating this recipe each time?
999 ${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} ${TLCL_OBJS}
1000 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1001 ${Q}rm -f $@
1002 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1003 ${Q}ar qcT $@ $^
1004
1005 .PHONY: hostlib
1006 hostlib: ${HOSTLIB} ${HOSTLIB_STATIC}
1007
1008 # TODO: better way to make .a than duplicating this recipe each time?
1009 ${HOSTLIB_STATIC}: ${HOSTLIB_OBJS}
1010 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1011 ${Q}rm -f $@
1012 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1013 ${Q}ar qcT $@ $^
1014
1015 ${HOSTLIB}: ${HOSTLIB_OBJS}
1016 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1017 ${Q}rm -f $@
1018 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1019 ${Q}${LD} ${LDFLAGS} ${LDLIBS} -shared -Wl,-soname,$(subst ${BUILD}/,,$@) $^ -o $@
1020
1021 ${HOSTLIB_DEF}: ${HOSTLIB_STATIC}
1022 @${PRINTF} " NMd $(subst ${BUILD}/,,$@)\n"
1023 ${Q}nm --defined-only --format=just-symbols $^ > $@
1024
1025 ${HOSTLIB_UNDEF}: ${HOSTLIB_STATIC}
1026 @${PRINTF} " NMu $(subst ${BUILD}/,,$@)\n"
1027 ${Q}nm --undefined-only --format=just-symbols $^ > $@
1028
1029
1030 .PHONY: headers_install
1031 headers_install:
1032 @${PRINTF} " INSTALL HEADERS\n"
1033 ${Q}mkdir -p ${UI_DIR}
1034 ${Q}${INSTALL} -t ${UI_DIR} -m644 \
1035 host/include/* \
1036 firmware/2lib/include/2crypto.h \
1037 firmware/2lib/include/2recovery_reasons.h \
1038 firmware/2lib/include/2sysincludes.h \
1039 firmware/include/gpt.h \
1040 firmware/include/tlcl.h \
1041 firmware/include/tss_constants.h \
1042 firmware/include/tpm1_tss_constants.h \
1043 firmware/include/tpm2_tss_constants.h
1044
1045 .PHONY: lib_install
1046 lib_install: ${HOSTLIB} ${HOSTLIB_STATIC}
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 \
1056 `find tests/devkeys -type f -maxdepth 1`
1057
1058 # ----------------------------------------------------------------------------
1059 # CGPT library and utility
1060
1061 .PHONY: cgpt_wrapper
1062 cgpt_wrapper: ${CGPT_WRAPPER}
1063
1064 ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
1065 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
1066 ${Q}${LD} -o ${CGPT_WRAPPER} ${LDFLAGS} $^ ${LDLIBS}
1067
1068 .PHONY: cgpt
1069 cgpt: ${CGPT} $(if $(filter-out 0,${GPT_SPI_NOR}),cgpt_wrapper)
1070
1071 # on FreeBSD: install misc/e2fsprogs-libuuid from ports,
1072 # or e2fsprogs-libuuid from its binary package system.
1073 # on OpenBSD: install sysutils/e2fsprogs from ports,
1074 # or e2fsprogs from its binary package system, to install uuid/uid.h
1075 ${CGPT}: LDLIBS += -luuid
1076
1077 ${CGPT}: ${CGPT_OBJS} ${UTILLIB}
1078 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
1079 ${Q}${LD} -o ${CGPT} ${LDFLAGS} $^ ${LDLIBS}
1080
1081 .PHONY: cgpt_install
1082 cgpt_install: ${CGPT}
1083 @${PRINTF} " INSTALL CGPT\n"
1084 ${Q}mkdir -p ${UB_DIR}
1085 ${Q}${INSTALL} -t ${UB_DIR} $^
1086
1087 .PHONY: cgpt_wrapper_install
1088 cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
1089 @$(PRINTF) " INSTALL cgpt_wrapper\n"
1090 ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
1091 ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
1092 ${UB_DIR}/$(notdir ${CGPT}).bin
1093 ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
1094 ${UB_DIR}/$(notdir ${CGPT})
1095
1096 # ----------------------------------------------------------------------------
1097 # Utilities
1098
1099 .PHONY: util_files
1100 util_files: $(if ${SDK_BUILD},${UTIL_FILES_SDK},${UTIL_FILES_BOARD})
1101
1102 # These have their own headers too.
1103 ${BUILD}/utility/%: INCLUDES += -Iutility/include
1104
1105 # Avoid build failures outside the chroot on Ubuntu 2022.04
1106 ifeq ($(OPENSSL_VERSION),3)
1107 ${BUILD}/utility/%: CFLAGS += -Wno-error=deprecated-declarations
1108 endif
1109
1110 ${UTIL_BINS_SDK}: ${UTILLIB}
1111 ${UTIL_BINS_SDK}: LIBS = ${UTILLIB}
1112 ${UTIL_BINS_BOARD}: ${UTILLIB}
1113 ${UTIL_BINS_BOARD}: LIBS = ${UTILLIB}
1114
1115 ${UTIL_SCRIPTS_SDK} ${UTIL_SCRIPTS_BOARD}: ${BUILD}/%: %
1116 ${Q}cp -f $< $@
1117 ${Q}chmod a+rx $@
1118
1119 define UTIL_INSTALL_template
1120 .PHONY: util_install-$(1)
1121 util_install-$(1): $$(addprefix $${BUILD}/,$(1))
1122 @${PRINTF} " INSTALL $(1)\n"
1123 ${Q}mkdir -p $${UB_DIR}
1124 ${Q}${INSTALL} -t $${UB_DIR} $$<
1125 endef
1126
1127 $(foreach f, $(sort ${UTIL_FILES_SDK} ${UTIL_FILES_BOARD}), \
1128 $(eval $(call UTIL_INSTALL_template,$(patsubst ${BUILD}/%,%,${f}))))
1129
1130 .PHONY: util_install_defaults
1131 util_install_defaults: ${UTIL_DEFAULTS}
1132 ${Q}mkdir -p ${DF_DIR}
1133 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
1134
1135 # And some signing stuff for the target
1136 .PHONY: signing_install
1137 signing_install: $(if ${SDK_BUILD},\
1138 ${SIGNING_SCRIPTS_SDK},${SIGNING_SCRIPTS_BOARD})
1139 @${PRINTF} " INSTALL SIGNING\n"
1140 ${Q}mkdir -p ${VB_DIR}
1141 ${Q}${INSTALL} -t ${VB_DIR} $^
1142
1143 # ----------------------------------------------------------------------------
1144 # Firmware Utility
1145
1146 .PHONY: futil
1147 futil: ${FUTIL_BIN}
1148
1149 # FUTIL_LIBS is shared by FUTIL_BIN and TEST_FUTIL_BINS.
1150 FUTIL_LIBS = ${CROSID_LIBS} ${CRYPTO_LIBS} ${LIBZIP_LIBS} ${LIBARCHIVE_LIBS} \
1151 ${FLASHROM_LIBS}
1152
1153 ${FUTIL_BIN}: LDLIBS += ${FUTIL_LIBS}
1154 ${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
1155 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1156 ${Q}${LD} -o $@ ${LDFLAGS} $^ ${LDLIBS}
1157
1158 .PHONY: futil_install
1159 futil_install: ${FUTIL_BIN}
1160 @${PRINTF} " INSTALL futility\n"
1161 ${Q}mkdir -p ${UB_DIR}
1162 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN}
1163 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
1164 ln -sf futility "${UB_DIR}/$$prog"; done
1165
1166 # ----------------------------------------------------------------------------
1167 # Utility to generate TLCL structure definition header file.
1168
1169 ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1170
1171 STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1172 STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1173
1174 .PHONY: update_tlcl_structures
1175 update_tlcl_structures: ${BUILD}/utility/tlcl_generator
1176 @${PRINTF} " Rebuilding TLCL structures\n"
1177 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1178 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1179 ( echo "%% Updating structures.h %%" && \
1180 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1181
1182 # ----------------------------------------------------------------------------
1183 # Tests
1184
1185 .PHONY: tests
1186 tests: ${TEST_BINS}
1187
1188 ${TEST_BINS}: ${UTILLIB} ${TESTLIB}
1189 ${TEST_BINS}: INCLUDES += -Itests
1190 ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
1191
1192 # Futility tests need almost everything that futility needs.
1193 ${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB}
1194 ${TEST_FUTIL_BINS}: INCLUDES += -Ifutility
1195 ${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB}
1196 ${TEST_FUTIL_BINS}: LDLIBS += ${FUTIL_LIBS}
1197
1198 ${TEST2X_BINS}: ${FWLIB}
1199 ${TEST2X_BINS}: LIBS += ${FWLIB}
1200
1201 ${TEST20_BINS}: ${FWLIB}
1202 ${TEST20_BINS}: LIBS += ${FWLIB}
1203 ${TEST20_BINS}: LDLIBS += ${CRYPTO_LIBS}
1204
1205 ${TESTLIB}: ${TESTLIB_OBJS}
1206 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
1207 ${Q}rm -f $@
1208 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
1209 ${Q}ar qcT $@ $^
1210
1211 DUT_TEST_BINS = $(addprefix ${BUILD}/,${DUT_TEST_NAMES})
1212
1213 # Special build for sha256_x86 test
1214 ${BUILD}/tests/vb2_sha256_x86_tests: \
1215 ${BUILD}/firmware/2lib/2sha256_x86.o ${BUILD}/firmware/2lib/2hwcrypto.o
1216 ${BUILD}/tests/vb2_sha256_x86_tests: \
1217 LIBS += ${BUILD}/firmware/2lib/2sha256_x86.o ${BUILD}/firmware/2lib/2hwcrypto.o
1218
1219 ifeq (${ENABLE_HWCRYPTO_RSA_TESTS},1)
1220 define enable_hwcrypto_rsa_tests
1221 ${BUILD}/$(1): CFLAGS += -DENABLE_HWCRYPTO_RSA_TESTS
1222 ifeq (${ARCH},arm64)
1223 ${BUILD}/$(1): CFLAGS += -DARM64_RSA_ACCELERATION
1224 ${BUILD}/$(1): ${BUILD}/firmware/2lib/2modpow_neon.o
1225 ${BUILD}/$(1): LIBS += ${BUILD}/firmware/2lib/2modpow_neon.o
1226 else
1227 ${BUILD}/$(1): CFLAGS += -DVB2_X86_RSA_ACCELERATION
1228 ${BUILD}/$(1): ${BUILD}/firmware/2lib/2modpow_sse2.o
1229 ${BUILD}/$(1): LIBS += ${BUILD}/firmware/2lib/2modpow_sse2.o
1230 endif
1231 endef
1232
1233 $(foreach test, ${HWCRYPTO_RSA_TESTS}, \
1234 $(eval $(call enable_hwcrypto_rsa_tests,${test})))
1235 endif
1236
1237 .PHONY: install_dut_test
1238 install_dut_test: ${DUT_TEST_BINS}
1239 ifneq ($(strip ${DUT_TEST_BINS}),)
1240 @${PRINTF} " INSTALL DUT TESTS\n"
1241 ${Q}mkdir -p ${DUT_TEST_DIR}
1242 ${Q}${INSTALL} -t ${DUT_TEST_DIR} $^
1243 endif
1244
1245 # ----------------------------------------------------------------------------
1246 # Fuzzers
1247
1248 .PHONY: fuzzers
1249 fuzzers: ${FUZZ_TEST_BINS}
1250
1251 ${FUZZ_TEST_BINS}: ${FWLIB}
1252 ${FUZZ_TEST_BINS}: LIBS = ${FWLIB}
1253 ${FUZZ_TEST_BINS}: LDFLAGS += -fsanitize=fuzzer
1254
1255 # ----------------------------------------------------------------------------
1256 # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1257 # rules for specific targets.
1258
1259 ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
1260 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
1261 ${Q}${LD} -o $@ ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
1262
1263 ${BUILD}/%.o: %.c
1264 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
1265 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1266
1267 ${BUILD}/%.o: ${BUILD}/%.c
1268 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
1269 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1270
1271 ${BUILD}/%.o: %.S
1272 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
1273 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1274
1275 # ----------------------------------------------------------------------------
1276 # Here are the special tweaks to the generic rules.
1277
1278 # Always create the defaults file, since it depends on input variables
1279 .PHONY: ${UTIL_DEFAULTS}
1280 ${UTIL_DEFAULTS}:
1281 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
1282 ${Q}rm -f $@
1283 ${Q}mkdir -p $(dir $@)
1284 ${Q}echo '# Generated file. Do not edit.' > [email protected]
1285 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> [email protected]
1286 ${Q}mv -f [email protected] $@
1287
1288 # Some utilities need external crypto functions
1289 CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1290 ifeq ($(shell uname -s), FreeBSD)
1291 CRYPTO_LIBS += -lcrypto
1292 endif
1293 ifeq ($(shell uname -s), OpenBSD)
1294 LDFLAGS += -Wl,-z,notext
1295 endif
1296
1297 ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1298 ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1299 ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1300 ${BUILD}/utility/verify_data: LDLIBS += ${CRYPTO_LIBS}
1301
1302 ${BUILD}/tests/vb2_host_key_tests: LDLIBS += ${CRYPTO_LIBS}
1303 ${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1304 ${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1305 ${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
1306 ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
1307
1308 ${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
1309
1310 ${BUILD}/tests/%: LDLIBS += -lrt -luuid
1311 ${BUILD}/tests/%: LIBS += ${TESTLIB}
1312
1313 ifeq ($(filter-out 0,${TPM2_MODE}),)
1314 # TODO(apronin): tests for TPM2 case?
1315 TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1316 ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1317 ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
1318 TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1319 endif
1320
1321 # ----------------------------------------------------------------------------
1322 # Here are the special rules that don't fit in the generic rules.
1323
1324 # Generates the list of commands defined in futility by running grep in the
1325 # source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1326 ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1327 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
1328 ${Q}rm -f $@ $@_t $@_commands
1329 ${Q}mkdir -p ${BUILD}/gen
1330 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
1331 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1332 | sort >>$@_commands
1333 ${Q}./scripts/getversion.sh >> $@_t
1334 ${Q}echo '#define _CMD(NAME) extern const struct' \
1335 'futil_cmd_t __cmd_##NAME;' >> $@_t
1336 ${Q}cat $@_commands >> $@_t
1337 ${Q}echo '#undef _CMD' >> $@_t
1338 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1339 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1340 ${Q}cat $@_commands >> $@_t
1341 ${Q}echo '0}; /* null-terminated */' >> $@_t
1342 ${Q}echo '#undef _CMD' >> $@_t
1343 ${Q}mv $@_t $@
1344 ${Q}rm -f $@_commands
1345
1346 ##############################################################################
1347 # Targets that exist just to run tests
1348
1349 .PHONY: test_setup
1350 test_setup:: cgpt ${UTIL_FILES_SDK} ${UTIL_FILES_BOARD} futil tests
1351
1352 # Generate test keys
1353 .PHONY: genkeys
1354 genkeys: install_for_test
1355 ${RUNTEST} ${SRC_RUN}/tests/gen_test_keys.sh
1356
1357 # Generate test cases
1358 .PHONY: gentestcases
1359 gentestcases: install_for_test
1360 ${RUNTEST} ${SRC_RUN}/tests/gen_test_cases.sh
1361
1362 # Generate test cases for fuzzing
1363 .PHONY: genfuzztestcases
1364 genfuzztestcases: install_for_test
1365 ${RUNTEST} ${SRC_RUN}/tests/gen_fuzz_test_cases.sh
1366
1367 .PHONY: runcgpttests
1368 runcgpttests: install_for_test
1369 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
1370
1371 .PHONY: runtestscripts
1372 runtestscripts: install_for_test ${HOSTLIB_DEF} ${HOSTLIB_UNDEF}
1373 ${RUNTEST} ${SRC_RUN}/scripts/image_signing/sign_android_unittests.sh
1374 ${RUNTEST} ${SRC_RUN}/scripts/image_signing/sign_uefi_unittest.py
1375 ${RUNTEST} $(SRC_RUN)/scripts/image_signing/lib/generate_android_cloud_config_unittest.py
1376 ${RUNTEST} ${SRC_RUN}/tests/load_kernel_tests.sh
1377 ${RUNTEST} ${SRC_RUN}/tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
1378 ${RUNTEST} ${SRC_RUN}/tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
1379 ${RUNTEST} ${SRC_RUN}/tests/run_preamble_tests.sh
1380 ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_kernel_arg_tests.sh
1381 ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_tests.sh
1382 ${RUNTEST} ${SRC_RUN}/tests/swap_ec_rw_tests.sh
1383 ${RUNTEST} ${SRC_RUN}/tests/vb2_rsa_tests.sh
1384 ${RUNTEST} ${SRC_RUN}/tests/vb2_firmware_tests.sh
1385 ${RUNTEST} ${SRC_RUN}/tests/vhost_reference.sh ${HOSTLIB_DEF} ${HOSTLIB_UNDEF}
1386
1387 .PHONY: runmisctests
1388 runmisctests: install_for_test
1389 ${RUNTEST} ${BUILD_RUN}/tests/cbfstool_tests
1390 ${RUNTEST} ${BUILD_RUN}/tests/gpt_misc_tests
1391 ${RUNTEST} ${BUILD_RUN}/tests/subprocess_tests
1392 ifeq ($(filter-out 0,${MOCK_TPM})$(filter-out 0,${TPM2_MODE}),)
1393 # tlcl_tests only works when MOCK_TPM is disabled
1394 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1395 endif
1396
1397 .PHONY: run2tests
1398 run2tests: install_for_test
1399 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
1400 ${RUNTEST} ${BUILD_RUN}/tests/vb2_auxfw_sync_tests
1401 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
1402 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1403 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
1404 ${RUNTEST} ${BUILD_RUN}/tests/vb2_crypto_tests
1405 ${RUNTEST} ${BUILD_RUN}/tests/vb2_ec_sync_tests
1406 ${RUNTEST} ${BUILD_RUN}/tests/vb2_firmware_tests
1407 ${RUNTEST} ${BUILD_RUN}/tests/vb2_gbb_init_tests
1408 ${RUNTEST} ${BUILD_RUN}/tests/vb2_gbb_tests
1409 ${RUNTEST} ${BUILD_RUN}/tests/vb2_host_key_tests
1410 ${RUNTEST} ${BUILD_RUN}/tests/vb2_inject_kernel_subkey_tests
1411 ${RUNTEST} ${BUILD_RUN}/tests/vb2_load_kernel_tests
1412 ${RUNTEST} ${BUILD_RUN}/tests/vb2_load_kernel2_tests
1413 ${RUNTEST} ${BUILD_RUN}/tests/vb2_kernel_tests
1414 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1415 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
1416 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1417 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
1418 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_firmware_tests
1419 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_fwmp_tests
1420 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_kernel_tests
1421 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_api_tests
1422 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
1423 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_kernel_tests
1424 ${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
1425 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common_tests
1426 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common2_tests ${TEST_KEYS}
1427 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD_RUN}
1428 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD_RUN}
1429 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
1430 ${RUNTEST} ${BUILD_RUN}/tests/hmac_test
1431
1432 .PHONY: runfutiltests
1433 runfutiltests: install_for_test
1434 ${RUNTEST} ${SRC_RUN}/tests/futility/run_test_scripts.sh
1435 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
1436 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1437
1438 # Test all permutations of encryption keys, instead of just the ones we use.
1439 # Not run by automated build.
1440 .PHONY: runlongtests
1441 runlongtests: install_for_test genkeys genfuzztestcases
1442 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1443 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1444 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common2_tests ${TEST_KEYS} --all
1445 ${RUNTEST} ${SRC_RUN}/tests/run_preamble_tests.sh --all
1446 ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_tests.sh --all
1447
1448 .PHONY: rununittests
1449 rununittests: runcgpttests runmisctests run2tests
1450
1451 # Print a big green success message at the end of all tests. If you don't see
1452 # that, you know there was an error somewhere further up.
1453 .PHONY: runtests
1454 runtests: rununittests runtestscripts runfutiltests
1455 ${Q}echo -e "\nruntests: \E[32;1mALL TESTS PASSED SUCCESSFULLY!\E[0;m\n"
1456
1457 # Code coverage
1458 .PHONY: coverage
1459 ifeq ($(filter-out 0,${COV}),)
1460 coverage:
1461 $(error Build coverage like this: make clean && COV=1 make coverage)
1462 else
1463 .PHONY: coverage_init
1464 coverage_init: install_for_test
1465 rm -f ${COV_INFO}*
1466 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1467
1468 .PHONY: coverage_html
1469 coverage_html: coverage_init runtests
1470 lcov -c -d . -b . -o ${COV_INFO}.tests
1471 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1472 lcov -r ${COV_INFO}.total '/usr/*' -o ${COV_INFO}.local
1473 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1474 # Generate addtional coverage stats just for firmware subdir, because the stats
1475 # for the whole project don't include subdirectory summaries. This will print
1476 # the summary for just the firmware sources.
1477 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1478 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
1479 -o ${COV_INFO}.firmware
1480
1481 coverage: coverage_init runtests coverage_html
1482 endif
1483
1484 # Include generated dependencies
1485 ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1486 TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1487 -include ${ALL_DEPS}
1488 -include ${TEST_DEPS}
1489
1490 # We want to use only relative paths in cscope.files, especially since the
1491 # paths inside and outside the chroot are different.
1492 SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1493
1494 # Note: vboot 2.0 is deprecated, so don't index those files
1495 ${BUILD}/cscope.files: all install_for_test
1496 ${Q}rm -f $@
1497 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1498 grep -v /lib20/ | \
1499 sed -e "s/${SRCDIRPAT}//" | \
1500 egrep '\.[chS]$$' | sort | uniq > $@
1501
1502 cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1503 cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1504 run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1505
1506 .PHONY: tags TAGS xrefs
1507 tags TAGS xrefs: ${BUILD}/cscope.files
1508 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1509 ${Q}$(call run_if_prog,etags,${cmd_etags})
1510 ${Q}$(call run_if_prog,ctags,${cmd_ctags})
1511
1512 PC_FILES = ${PC_IN_FILES:%.pc.in=${BUILD}/%.pc}
1513 ${PC_FILES}: ${PC_IN_FILES}
1514 ${Q}sed \
1515 -e 's:@LDLIBS@:${LDLIBS}:' \
1516 -e 's:@LIBDIR@:${LIBDIR}:' \
1517 $< > $@
1518
1519 .PHONY: pc_files_install
1520 pc_files_install: ${PC_FILES}
1521 ${Q}mkdir -p ${ULP_DIR}
1522 ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$(notdir $<)