Debian Codegraph @

3rdparty/vboot/Makefile

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