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