blob: 438ab0683daccaebcede4a98148631dd6ba26b1b [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# 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
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill Richardson64ddad72014-08-29 23:49:23 -070040export SRCDIR
Mike Frysingerc8c87b32015-01-15 17:04:40 -050041BUILD = ${SRCDIR}/build
Randall Spangler844bce52013-01-15 16:16:43 -080042export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080043
Bill Richardsonc9bf3482013-02-13 14:38:29 -080044# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080045INSTALL = install
Bill Richardsonefa87562014-09-11 10:41:51 -070046DESTDIR = /usr/local
Nam T. Nguyen07d90432015-02-17 13:26:44 -080047LIBDIR ?= lib
Bill Richardsonc9bf3482013-02-13 14:38:29 -080048
Bill Richardsoncfe83a82014-12-04 11:29:57 -080049# Default values
50DEV_DEBUG_FORCE=
51
Bill Richardsonfeb25182013-03-07 12:54:29 -080052# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070053# UB_DIR = utility binary directory
Nam T. Nguyen07d90432015-02-17 13:26:44 -080054# ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080055# DF_DIR = utility defaults directory
Bill Richardson6f396152014-07-15 12:52:19 -070056# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080057ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070058# Host install just puts everything where it's told
Bill Richardsonefa87562014-09-11 10:41:51 -070059UB_DIR=${DESTDIR}/bin
Nam T. Nguyen07d90432015-02-17 13:26:44 -080060ULP_DIR=${DESTDIR}/${LIBDIR}/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080061DF_DIR=${DESTDIR}/default
Bill Richardsonefa87562014-09-11 10:41:51 -070062VB_DIR=${DESTDIR}/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080063else
Bill Richardsonefa87562014-09-11 10:41:51 -070064# Target install puts things into different places
Bill Richardson6f396152014-07-15 12:52:19 -070065UB_DIR=${DESTDIR}/usr/bin
Nam T. Nguyen07d90432015-02-17 13:26:44 -080066ULP_DIR=${DESTDIR}/usr/${LIBDIR}/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080067DF_DIR=${DESTDIR}/etc/default
Bill Richardsonc9bf3482013-02-13 14:38:29 -080068VB_DIR=${DESTDIR}/usr/share/vboot/bin
69endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080070
Bill Richardsoneecc18f2013-01-17 15:28:17 -080071# Where to install the (exportable) executables for testing?
72TEST_INSTALL_DIR = ${BUILD}/install_for_test
73
74# Verbose? Use V=1
75ifeq (${V},)
76Q := @
77endif
78
Simon Glass661ae9e2013-03-26 11:39:21 -070079# Quiet? Use QUIET=1
Mike Frysingerc8c87b32015-01-15 17:04:40 -050080ifeq (${QUIET},)
Simon Glass661ae9e2013-03-26 11:39:21 -070081PRINTF := printf
82else
83PRINTF := :
84endif
85
Randall Spangler61a2eb32013-01-23 10:20:16 -080086# Architecture detection
87_machname := $(shell uname -m)
88HOST_ARCH ?= ${_machname}
89
90# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
91# Pick a sane target architecture if none is defined.
92ifeq (${ARCH},)
93 ARCH := ${HOST_ARCH}
94else ifeq (${ARCH},i386)
95 override ARCH := x86
96else ifeq (${ARCH},amd64)
97 override ARCH := x86_64
98endif
99
100# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
101# for a firmware target (such as u-boot or depthcharge). It must map
102# to the same consistent set of architectures as the host.
103ifeq (${FIRMWARE_ARCH},i386)
104 override FIRMWARE_ARCH := x86
105else ifeq (${FIRMWARE_ARCH},amd64)
106 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -0700107else ifeq (${FIRMWARE_ARCH},armv7)
108 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -0800109endif
110
Simon Glassb265c342011-11-16 15:09:51 -0800111# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
112# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700113#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800114# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
115# temporarily. As we are still investigating which flags are necessary for
116# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700117#
Simon Glassb265c342011-11-16 15:09:51 -0800118# As a first step, this makes the setting of CC and CFLAGS here optional, to
119# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700120#
Simon Glassb265c342011-11-16 15:09:51 -0800121# Flag ordering: arch, then -f, then -m, then -W
122DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
123COMMON_FLAGS := -nostdinc -pipe \
124 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800125 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800126
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800127# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
128ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800129CC ?= armv7a-cros-linux-gnueabi-gcc
130CFLAGS ?= -march=armv5 \
131 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700132 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800133 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800134else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800135CC ?= i686-pc-linux-gnu-gcc
136# Drop -march=i386 to permit use of SSE instructions
137CFLAGS ?= \
138 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
139 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800140 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800141 ${COMMON_FLAGS}
142else ifeq (${FIRMWARE_ARCH}, x86_64)
143CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800144 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800145else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800146# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800147CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700148CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800149endif
150
151ifneq (${DEBUG},)
152CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700153endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800154
vbendebb2b0fcc2010-07-15 15:09:47 -0700155ifeq (${DISABLE_NDEBUG},)
156CFLAGS += -DNDEBUG
157endif
158
Bill Richardsonfeb25182013-03-07 12:54:29 -0800159ifneq (${FORCE_LOGGING_ON},)
160CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
161endif
162
Randall Spangler6014c042014-07-22 14:42:58 -0700163ifneq (${PD_SYNC},)
164CFLAGS += -DPD_SYNC
165endif
166
Nam T. Nguyenf44ebbe2015-02-12 11:10:35 -0800167ifneq (${USE_MTD},)
168CFLAGS += -DUSE_MTD
169LDLIBS += -lmtdutils
170endif
171
Nam T. Nguyen07d90432015-02-17 13:26:44 -0800172# NOTE: We don't use these files but they are useful for other packages to
173# query about required compiling/linking flags.
174PC_IN_FILES = vboot_host.pc.in
175
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800176# Create / use dependency files
177CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800178
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700179ifeq (${FIRMWARE_ARCH},)
180# Creates position independent code for non firmware target.
181CFLAGS += -fPIE
182endif
183
Bill Richardson0c3ba242013-03-29 11:09:30 -0700184# These are required to access large disks and files on 32-bit systems.
185CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
186
Randall Spangler59d75082013-01-23 09:29:54 -0800187# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800188ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700189 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800190 CFLAGS += ${COV_FLAGS}
191 LDFLAGS += ${COV_FLAGS}
192 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800193endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800194
David Riley05987b12015-02-05 19:22:49 -0800195ifdef HAVE_MACOS
196 CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
197endif
198
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800199# And a few more default utilities
200LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700201CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800202PKG_CONFIG ?= pkg-config
203
Mike Frysinger0b789c52015-01-15 15:37:59 -0500204# Static?
205ifneq (${STATIC},)
206LDFLAGS += -static
207PKG_CONFIG += --static
208endif
209
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210# Determine QEMU architecture needed, if any
211ifeq (${ARCH},${HOST_ARCH})
212 # Same architecture; no need for QEMU
213 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800214else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800215 # 64-bit host can run 32-bit targets directly
216 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800217else
218 QEMU_ARCH := ${ARCH}
219endif
220
221# The top of the chroot for qemu must be passed in via the SYSROOT environment
222# variable. In the Chromium OS chroot, this is done automatically by the
223# ebuild.
224
225ifeq (${QEMU_ARCH},)
226 # Path to build output for running tests is same as for building
227 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800228 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800229else
230 $(info Using qemu for testing.)
231 # Path to build output for running tests is different in the chroot
232 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800233 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800234
235 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800236 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
237 export QEMU_RUN
238
239 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800240endif
241
Randall Spanglere061a252013-01-22 15:34:07 -0800242export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800243
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800244##############################################################################
245# Now we need to describe everything we might want or need to build
246
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800247# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800248INCLUDES += \
249 -Ifirmware/include \
250 -Ifirmware/lib/include \
251 -Ifirmware/lib/cgptlib/include \
252 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700253 -Ifirmware/lib/tpm_lite/include \
254 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700255
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800256# If we're not building for a specific target, just stub out things like the
257# TPM commands and various external functions that are provided by the BIOS.
258ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700259INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800260endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800261
Bill Richardson78299022014-06-20 14:33:00 -0700262# Firmware library, used by the other firmware components (depthcharge,
263# coreboot, etc.). It doesn't need exporting to some other place; they'll build
264# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800265FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800266
Bill Richardson06eb78c2015-01-27 15:01:51 -0800267# Smaller firmware library common to all vboot 2.x, used only for
268# 1) compile-time tests of the public API or
269# 2) linking with an actual 2.0 or 2.1 implementation
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800270FWLIB2X = ${BUILD}/vboot_fw2x.a
Bill Richardson06eb78c2015-01-27 15:01:51 -0800271
272# Vboot 2.0 (deprecated - see firmware/README)
273FWLIB20 = ${BUILD}/vboot_fw20.a
274# Vboot 2.1 (not yet ready - see firmware/README)
Randall Spanglera5b69b02014-12-02 13:41:29 -0800275FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700276
Randall Spangler93943262013-02-26 11:03:57 -0800277# Firmware library sources needed by VbInit() call
278VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800279 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800280 firmware/lib/utility.c \
281 firmware/lib/vboot_api_init.c \
282 firmware/lib/vboot_common_init.c \
283 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700284 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600285 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800286
287# Additional firmware library sources needed by VbSelectFirmware() call
288VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800289 firmware/lib/cryptolib/padding.c \
290 firmware/lib/cryptolib/rsa.c \
291 firmware/lib/cryptolib/rsa_utility.c \
292 firmware/lib/cryptolib/sha1.c \
293 firmware/lib/cryptolib/sha256.c \
294 firmware/lib/cryptolib/sha512.c \
295 firmware/lib/cryptolib/sha_utility.c \
296 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800297 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800298 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600299 firmware/lib/vboot_firmware.c \
300 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800301
302# Additional firmware library sources needed by VbSelectAndLoadKernel() call
303VBSLK_SRCS = \
304 firmware/lib/cgptlib/cgptlib.c \
305 firmware/lib/cgptlib/cgptlib_internal.c \
306 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700307 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800308 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800309 firmware/lib/vboot_api_kernel.c \
310 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800311 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600312 firmware/lib/vboot_kernel.c \
313 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800314
Bill Richardson06eb78c2015-01-27 15:01:51 -0800315# Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
316FWLIB2X_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700317 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700318 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700319 firmware/2lib/2crc8.c \
320 firmware/2lib/2misc.c \
321 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700322 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700323 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700324 firmware/2lib/2sha1.c \
325 firmware/2lib/2sha256.c \
326 firmware/2lib/2sha512.c \
Daisuke Nojiri62d482e2015-01-29 14:37:25 -0800327 firmware/2lib/2sha_utility.c \
328 firmware/2lib/2tpm_bootmode.c
Randall Spanglera5b69b02014-12-02 13:41:29 -0800329
Randall Spangler108d9912014-12-02 15:55:56 -0800330FWLIB20_SRCS = \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800331 firmware/lib20/api.c \
332 firmware/lib20/common.c \
333 firmware/lib20/misc.c \
334 firmware/lib20/packed_key.c
Randall Spangler108d9912014-12-02 15:55:56 -0800335
Randall Spanglera5b69b02014-12-02 13:41:29 -0800336FWLIB21_SRCS = \
337 firmware/lib21/api.c \
338 firmware/lib21/common.c \
339 firmware/lib21/misc.c \
340 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700341
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800342# Support real TPM unless BIOS sets MOCK_TPM
343ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800344VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800345 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800346 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800347
348VBSF_SRCS += \
349 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800350else
Randall Spangler93943262013-02-26 11:03:57 -0800351VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800352 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800353 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800354
355VBSF_SRCS += \
356 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800357endif
358
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800359ifeq (${FIRMWARE_ARCH},)
360# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800361# TODO: split out other stub funcs too
362VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800363 firmware/stub/tpm_lite_stub.c \
364 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600365 firmware/stub/vboot_api_stub_init.c \
366 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800367
368VBSF_SRCS += \
369 firmware/stub/vboot_api_stub_sf.c
370
371VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800372 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700373 firmware/stub/vboot_api_stub_disk.c \
374 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700375
Bill Richardson06eb78c2015-01-27 15:01:51 -0800376FWLIB2X_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700377 firmware/2lib/2stub.c
378
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800379endif
380
Randall Spangler93943262013-02-26 11:03:57 -0800381VBSF_SRCS += ${VBINIT_SRCS}
382FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
383
384VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
385VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800386ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800387
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800388FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800389FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800390FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800391FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800392ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800393
Bill Richardson78299022014-06-20 14:33:00 -0700394# Intermediate library for the vboot_reference utilities to link against.
395UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800396UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800397
Bill Richardson78299022014-06-20 14:33:00 -0700398UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800399 cgpt/cgpt_create.c \
400 cgpt/cgpt_add.c \
401 cgpt/cgpt_boot.c \
402 cgpt/cgpt_show.c \
403 cgpt/cgpt_repair.c \
404 cgpt/cgpt_prioritize.c \
405 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700406 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800407 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800408 host/lib/crossystem.c \
409 host/lib/file_keys.c \
410 host/lib/fmap.c \
411 host/lib/host_common.c \
412 host/lib/host_key.c \
413 host/lib/host_keyblock.c \
414 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700415 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800416 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700417 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800418
Randall Spangleraaaff862014-12-01 15:40:08 -0800419UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
420ALL_OBJS += ${UTILLIB_OBJS}
421
Randall Spanglera5b69b02014-12-02 13:41:29 -0800422UTILLIB21_SRCS += \
423 host/lib21/host_fw_preamble.c \
424 host/lib21/host_key.c \
425 host/lib21/host_keyblock.c \
426 host/lib21/host_misc.c \
427 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800428
Randall Spanglera5b69b02014-12-02 13:41:29 -0800429UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
430ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700431
432# Externally exported library for some target userspace apps to link with
433# (cryptohome, updater, etc.)
434HOSTLIB = ${BUILD}/libvboot_host.a
435
436HOSTLIB_SRCS = \
437 cgpt/cgpt_add.c \
438 cgpt/cgpt_boot.c \
439 cgpt/cgpt_common.c \
440 cgpt/cgpt_create.c \
441 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700442 firmware/lib/cgptlib/cgptlib_internal.c \
443 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700444 firmware/lib/crc8.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800445 firmware/lib/gpt_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700446 firmware/lib/tpm_lite/tlcl.c \
447 firmware/lib/utility_string.c \
448 firmware/lib/vboot_nvstorage.c \
449 firmware/stub/tpm_lite_stub.c \
450 firmware/stub/utility_stub.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800451 firmware/stub/vboot_api_stub_disk.c \
Bill Richardson78299022014-06-20 14:33:00 -0700452 firmware/stub/vboot_api_stub_init.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800453 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700454 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700455 host/arch/${ARCH}/lib/crossystem_arch.c \
456 host/lib/crossystem.c \
Zach Reizner317bb492015-02-20 14:55:02 -0800457 host/lib/extract_vmlinuz.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700458 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700459 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700460
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800461HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462ALL_OBJS += ${HOSTLIB_OBJS}
463
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800464# Sigh. For historical reasons, the autoupdate installer must sometimes be a
465# 32-bit executable, even when everything else is 64-bit. But it only needs a
466# few functions, so let's just build those.
467TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
468
469TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800470 cgpt/cgpt_add.c \
471 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800472 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700473 cgpt/cgpt_create.c \
474 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700475 firmware/lib/cgptlib/cgptlib_internal.c \
476 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800477 firmware/lib/gpt_misc.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800478 firmware/lib/utility_string.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800479 firmware/stub/vboot_api_stub_disk.c \
480 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson78299022014-06-20 14:33:00 -0700481 firmware/stub/utility_stub.c \
Zach Reizner317bb492015-02-20 14:55:02 -0800482 futility/dump_kernel_config_lib.c \
483 host/lib/extract_vmlinuz.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800484
485TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800486
487# ----------------------------------------------------------------------------
488# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800489
490CGPT = ${BUILD}/cgpt/cgpt
491
492CGPT_SRCS = \
493 cgpt/cgpt.c \
494 cgpt/cgpt_add.c \
495 cgpt/cgpt_boot.c \
496 cgpt/cgpt_common.c \
497 cgpt/cgpt_create.c \
498 cgpt/cgpt_find.c \
499 cgpt/cgpt_legacy.c \
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800500 cgpt/cgpt_nor.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800501 cgpt/cgpt_prioritize.c \
502 cgpt/cgpt_repair.c \
503 cgpt/cgpt_show.c \
504 cgpt/cmd_add.c \
505 cgpt/cmd_boot.c \
506 cgpt/cmd_create.c \
507 cgpt/cmd_find.c \
508 cgpt/cmd_legacy.c \
509 cgpt/cmd_prioritize.c \
510 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800511 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800512
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800513CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800514
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800515ALL_OBJS += ${CGPT_OBJS}
516
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800517CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
518
519CGPT_WRAPPER_SRCS = \
520 cgpt/cgpt_nor.c \
521 cgpt/cgpt_wrapper.c
522
523CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
524
525ALL_OBJS += ${CGPT_WRAPPER_OBJS}
526
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800527# Utility defaults
528UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800529
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800530# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800531UTIL_SCRIPTS = \
532 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700533 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800534
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800535ifeq (${MINIMAL},)
536UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700537 utility/dev_make_keypair \
538 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800539endif
540
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800541# These utilities should be linked statically.
542UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700543 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800544
545UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700546 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700547 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700548 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800549
Bill Richardson6f396152014-07-15 12:52:19 -0700550# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800551ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800552UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700553 utility/bmpblk_font \
554 utility/bmpblk_utility \
555 utility/eficompress \
556 utility/efidecompress \
557 utility/load_kernel_test \
558 utility/pad_digest_utility \
559 utility/signature_digest_utility \
560 utility/verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800561endif
562
Bill Richardson339f7e02013-04-05 09:49:24 -0700563UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
564UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700565ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800566
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800567
568# Scripts for signing stuff.
569SIGNING_SCRIPTS = \
570 utility/tpm-nvsize \
571 utility/chromeos-tpm-recovery
572
573# These go in a different place.
574SIGNING_SCRIPTS_DEV = \
575 scripts/image_signing/resign_firmwarefd.sh \
576 scripts/image_signing/make_dev_firmware.sh \
577 scripts/image_signing/make_dev_ssd.sh \
578 scripts/image_signing/set_gbb_flags.sh
579
580# Installed, but not made executable.
581SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800582
Bill Richardson826db092013-01-14 12:37:15 -0800583
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800584# The unified firmware utility will eventually replace all the others
585FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700586# But we still need both static (tiny) and dynamic (with openssl) versions.
587FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800588
Bill Richardson6f396152014-07-15 12:52:19 -0700589# These are the executables that are now built in to futility. We'll create
590# symlinks for these so the old names will still work.
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700591FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700592 dump_fmap \
593 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700594 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700595 vbutil_firmware \
596 vbutil_kernel \
597 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700598 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800599
Bill Richardson6db8c752013-04-05 13:30:43 -0700600FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800601 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700602 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700603 futility/cmd_gbb_utility.c \
604 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800605
Bill Richardson6db8c752013-04-05 13:30:43 -0700606FUTIL_SRCS = \
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500607 ${FUTIL_STATIC_SRCS} \
Bill Richardson6f396152014-07-15 12:52:19 -0700608 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700609 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700610 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700611 futility/cmd_show.c \
612 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700613 futility/cmd_vbutil_firmware.c \
614 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700615 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700616 futility/cmd_vbutil_keyblock.c \
Bill Richardson25593382015-01-30 12:22:28 -0800617 futility/file_type.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700618 futility/traversal.c \
619 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700620
Alex Deymoe08ee282014-08-29 01:07:48 -0700621# List of commands built in futility and futility_s.
622FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
623FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800624
Bill Richardson91852e72014-11-28 12:28:04 -0800625# Workaround for TODO(crbug.com/437107).
626FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
627
Alex Deymoe08ee282014-08-29 01:07:48 -0700628FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800629 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700630 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
631FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800632
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800633ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800634
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800635
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800636# Library of handy test functions.
637TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800638
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800639TESTLIB_SRCS = \
640 tests/test_common.c \
641 tests/timer_utils.c \
642 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800643
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800644TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700645TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800646
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800647
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800648# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800649TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700650 tests/cgptlib_test \
651 tests/rollback_index2_tests \
652 tests/rollback_index3_tests \
653 tests/rsa_padding_test \
654 tests/rsa_utility_tests \
655 tests/rsa_verify_benchmark \
656 tests/sha_benchmark \
657 tests/sha_tests \
658 tests/stateful_util_tests \
659 tests/tlcl_tests \
660 tests/tpm_bootmode_tests \
661 tests/utility_string_tests \
662 tests/utility_tests \
663 tests/vboot_api_init_tests \
664 tests/vboot_api_devmode_tests \
665 tests/vboot_api_firmware_tests \
666 tests/vboot_api_kernel_tests \
667 tests/vboot_api_kernel2_tests \
668 tests/vboot_api_kernel3_tests \
669 tests/vboot_api_kernel4_tests \
670 tests/vboot_audio_tests \
671 tests/vboot_common_tests \
672 tests/vboot_common2_tests \
673 tests/vboot_common3_tests \
674 tests/vboot_display_tests \
675 tests/vboot_firmware_tests \
676 tests/vboot_kernel_tests \
677 tests/vboot_nvstorage_test \
Bill Richardsona77541f2014-12-04 19:06:35 -0800678 tests/verify_kernel \
Bill Richardson6f396152014-07-15 12:52:19 -0700679 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700680 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800681
Simon Glass527ba812013-07-25 08:48:47 -0600682ifdef REGION_READ
683TEST_NAMES += tests/vboot_region_tests
684endif
685
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800686TEST2X_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700687 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700688 tests/vb2_common_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700689 tests/vb2_misc_tests \
690 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700691 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700692 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800693 tests/vb2_sha_tests
694
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800695TEST20_NAMES = \
696 tests/vb20_api_tests \
697 tests/vb20_common_tests \
698 tests/vb20_common2_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800699 tests/vb20_verify_fw.c \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800700 tests/vb20_common3_tests \
701 tests/vb20_misc_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800702 tests/vb20_rsa_padding_tests \
703 tests/vb20_verify_fw
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800704
Randall Spangler108d9912014-12-02 15:55:56 -0800705TEST21_NAMES = \
706 tests/vb21_api_tests \
707 tests/vb21_common_tests \
708 tests/vb21_common2_tests \
709 tests/vb21_misc_tests \
710 tests/vb21_host_fw_preamble_tests \
711 tests/vb21_host_key_tests \
712 tests/vb21_host_keyblock_tests \
713 tests/vb21_host_misc_tests \
714 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700715
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800716TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700717
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800718# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700719TLCL_TEST_NAMES = \
720 tests/tpm_lite/tpmtest_earlyextend \
721 tests/tpm_lite/tpmtest_earlynvram \
722 tests/tpm_lite/tpmtest_earlynvram2 \
723 tests/tpm_lite/tpmtest_enable \
724 tests/tpm_lite/tpmtest_fastenable \
725 tests/tpm_lite/tpmtest_globallock \
726 tests/tpm_lite/tpmtest_redefine_unowned \
727 tests/tpm_lite/tpmtest_spaceperm \
728 tests/tpm_lite/tpmtest_testsetup \
729 tests/tpm_lite/tpmtest_timing \
730 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800731
732TEST_NAMES += ${TLCL_TEST_NAMES}
733
Bill Richardson339f7e02013-04-05 09:49:24 -0700734# Finally
735TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700736TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800737
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800738TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800739TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800740TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800741
Randall Spanglere061a252013-01-22 15:34:07 -0800742# Directory containing test keys
743TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800744
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800745
746##############################################################################
747# Finally, some targets. High-level ones first.
748
749# Create output directories if necessary. Do this via explicit shell commands
750# so it happens before trying to generate/include dependencies.
751SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
752_dir_create := $(foreach d, \
753 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
754 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
755
756
757# Default target.
758.PHONY: all
Bill Richardson06eb78c2015-01-27 15:01:51 -0800759all: fwlib fwlib2x fwlib20 fwlib21 \
Randall Spangleraaaff862014-12-01 15:40:08 -0800760 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700761 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800762
763# Host targets
764.PHONY: host_stuff
Bill Richardson06eb78c2015-01-27 15:01:51 -0800765host_stuff: utillib hostlib cgpt utils futil tests utillib21
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800767.PHONY: clean
768clean:
769 ${Q}/bin/rm -rf ${BUILD}
770
771.PHONY: install
Nam T. Nguyen07d90432015-02-17 13:26:44 -0800772install: cgpt_install utils_install signing_install futil_install \
773 pc_files_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800774
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800775.PHONY: install_mtd
776install_mtd: install cgpt_wrapper_install
777
Bill Richardson3e3790d2014-07-14 15:05:54 -0700778.PHONY: install_for_test
779install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
780install_for_test: install
781
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800782# Don't delete intermediate object files
783.SECONDARY:
784
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800785# ----------------------------------------------------------------------------
786# Firmware library
787
788# TPM-specific flags. These depend on the particular TPM we're targeting for.
789# They are needed here only for compiling parts of the firmware code into
790# user-level tests.
791
792# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
793# the self test has completed.
794
Randall Spangler45cc0f22013-01-25 09:34:26 -0800795${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800796
797# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
798# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
799# power on.
800#
801# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
802# are not both defined at the same time. (See comment in code.)
803
804# CFLAGS += -DTPM_MANUAL_SELFTEST
805
806ifeq (${FIRMWARE_ARCH},i386)
807# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800808${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardson06eb78c2015-01-27 15:01:51 -0800809${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800810${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800811${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800812
813# Workaround for coreboot on x86, which will power off asynchronously
814# without giving us a chance to react. This is not an example of the Right
815# Way to do things. See chrome-os-partner:7689, and the commit message
816# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800817${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800818
819# On x86 we don't actually read the GBB data into RAM until it is needed.
820# Therefore it makes sense to cache it rather than reading it each time.
821# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800822${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800823endif
824
Simon Glass527ba812013-07-25 08:48:47 -0600825ifdef REGION_READ
826${FWLIB_OBJS}: CFLAGS += -DREGION_READ
827endif
828
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800829ifeq (${FIRMWARE_ARCH},)
830# Disable rollback TPM when compiling locally, since otherwise
831# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800832${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800833endif
834
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800835${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -0800836${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
837
Bill Richardsona130e0b2013-04-04 18:16:39 -0700838# Linktest ensures firmware lib doesn't rely on outside libraries
839${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800840${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700841TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700842${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800843${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700844TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700845${BUILD}/firmware/linktest/main: ${FWLIB}
846${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700847TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800848
Bill Richardsond2d08b22014-07-08 16:31:40 -0700849.PHONY: fwlinktest
850fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800851 ${BUILD}/firmware/linktest/main_vbinit \
852 ${BUILD}/firmware/linktest/main_vbsf \
853 ${BUILD}/firmware/linktest/main
854
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800855.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700856fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800857
858${FWLIB}: ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500859 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800860 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500861 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800862 ${Q}ar qc $@ $^
863
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800864.PHONY: fwlib2x
865fwlib2x: ${FWLIB2X}
866
Bill Richardson06eb78c2015-01-27 15:01:51 -0800867${FWLIB2X}: ${FWLIB2X_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500868 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800869 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500870 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800871 ${Q}ar qc $@ $^
872
Bill Richardson06eb78c2015-01-27 15:01:51 -0800873.PHONY: fwlib20
874fwlib20: ${FWLIB20}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800875
Bill Richardson06eb78c2015-01-27 15:01:51 -0800876${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500877 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700878 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500879 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700880 ${Q}ar qc $@ $^
881
Randall Spanglera5b69b02014-12-02 13:41:29 -0800882.PHONY: fwlib21
883fwlib21: ${FWLIB21}
884
Bill Richardson06eb78c2015-01-27 15:01:51 -0800885${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500886 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800887 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500888 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800889 ${Q}ar qc $@ $^
890
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800891# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700892# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800893
Bill Richardson78299022014-06-20 14:33:00 -0700894# Link tests for local utilities
895${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700896${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700897TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700898
899.PHONY: utillib
900utillib: ${UTILLIB} \
901 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800902
903# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800904${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500905 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800906 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500907 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800908 ${Q}ar qc $@ $^
909
Randall Spanglera5b69b02014-12-02 13:41:29 -0800910.PHONY: utillib21
911utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800912
Randall Spangler108d9912014-12-02 15:55:56 -0800913${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Bill Richardson06eb78c2015-01-27 15:01:51 -0800914${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500915 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700916 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500917 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700918 ${Q}ar qc $@ $^
919
920
921# Link tests for external repos
922${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700923${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
924${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700925TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700926
927.PHONY: hostlib
928hostlib: ${HOSTLIB} \
929 ${BUILD}/host/linktest/extern
930
931# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700932${HOSTLIB}: ${HOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500933 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800934 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500935 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800936 ${Q}ar qc $@ $^
937
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800938
939# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
940.PHONY: tinyhostlib
941tinyhostlib: ${TINYHOSTLIB}
942 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
943
944${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500945 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800946 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500947 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800948 ${Q}ar qc $@ $^
949
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800950# ----------------------------------------------------------------------------
951# CGPT library and utility
952
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800953.PHONY: cgpt_wrapper
954cgpt_wrapper: ${CGPT_WRAPPER}
955
956${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
957 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
958 ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
959
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800960.PHONY: cgpt
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800961cgpt: ${CGPT} ${CGPT_WRAPPER}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800962
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800963${CGPT}: LDLIBS += -luuid
964
Bill Richardson78299022014-06-20 14:33:00 -0700965${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500966 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700967 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800968
969.PHONY: cgpt_install
970cgpt_install: ${CGPT}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500971 @${PRINTF} " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800972 ${Q}mkdir -p ${UB_DIR}
973 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800974
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800975.PHONY: cgpt_wrapper_install
976cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
977 @$(PRINTF) " INSTALL cgpt_wrapper\n"
978 ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
979 ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
980 ${UB_DIR}/$(notdir ${CGPT}).bin
981 ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
982 ${UB_DIR}/$(notdir ${CGPT})
983
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800984# ----------------------------------------------------------------------------
985# Utilities
986
987# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700988${BUILD}/utility/%: INCLUDES += -Iutility/include
989
990${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
991${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800992
993# Utilities for auto-update toolkits must be statically linked.
994${UTIL_BINS_STATIC}: LDFLAGS += -static
995
Bill Richardsona130e0b2013-04-04 18:16:39 -0700996
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800997.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800998utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800999 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
1000 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
1001
1002.PHONY: utils_install
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001003utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001004 @${PRINTF} " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001005 ${Q}mkdir -p ${UB_DIR}
1006 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001007 ${Q}mkdir -p ${DF_DIR}
1008 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001009
1010# And some signing stuff for the target
1011.PHONY: signing_install
1012signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001013 @${PRINTF} " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -07001014 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001015 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -07001016 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1017 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001018
1019# ----------------------------------------------------------------------------
1020# new Firmware Utility
1021
1022.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -07001023futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1024
Bill Richardson06eb78c2015-01-27 15:01:51 -08001025${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001026 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001027 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001028
Bill Richardsonb84b81d2014-07-14 14:48:31 -07001029${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson06eb78c2015-01-27 15:01:51 -08001030${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001031 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001032 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001033
1034.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -07001035futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001036 @${PRINTF} " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -07001037 ${Q}mkdir -p ${UB_DIR}
1038 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -07001039 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -07001040 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001041
1042# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001043# Utility to generate TLCL structure definition header file.
1044
1045${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1046
1047STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1048STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1049
1050.PHONY: update_tlcl_structures
1051update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001052 @${PRINTF} " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001053 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1054 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1055 ( echo "%% Updating structures.h %%" && \
1056 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1057
1058# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001059# Tests
1060
1061.PHONY: tests
1062tests: ${TEST_BINS}
1063
Bill Richardson78299022014-06-20 14:33:00 -07001064${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -07001065${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001066${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001067
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001068${TEST2X_BINS}: ${FWLIB2X}
1069${TEST2X_BINS}: LIBS += ${FWLIB2X}
1070
Randall Spangler108d9912014-12-02 15:55:56 -08001071${TEST20_BINS}: ${FWLIB20}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001072${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -08001073${TEST20_BINS}: LIBS += ${FWLIB20}
1074
1075${TEST21_BINS}: ${UTILLIB21}
1076${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1077${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -08001078
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001079${TESTLIB}: ${TESTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001080 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001081 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001082 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001083 ${Q}ar qc $@ $^
1084
1085
1086# ----------------------------------------------------------------------------
1087# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1088# rules for specific targets.
1089
1090${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001091 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001092 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001093
1094${BUILD}/%.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001095 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001096 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1097
Alex Deymoe08ee282014-08-29 01:07:48 -07001098${BUILD}/%.o: ${BUILD}/%.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001099 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001100 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1101
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001102# Rules to recompile a single source file for library and test
1103# TODO: is there a tidier way to do this?
1104${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1105${BUILD}/%_for_lib.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001106 @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001107 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1108
1109${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1110${BUILD}/%_for_test.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001111 @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001112 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1113
1114# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1115${BUILD}/%.o: %.cc
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001116 @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001117 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1118
1119# ----------------------------------------------------------------------------
1120# Here are the special tweaks to the generic rules.
1121
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001122# Always create the defaults file, since it depends on input variables
1123.PHONY: ${UTIL_DEFAULTS}
1124${UTIL_DEFAULTS}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001125 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001126 ${Q}rm -f $@
1127 ${Q}mkdir -p $(dir $@)
1128 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1129 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1130 ${Q}mv -f $@.tmp $@
1131
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001132# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001133CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1134
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001135${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1136${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1137${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001138
1139${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1140${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1141${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001142${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1143${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsona77541f2014-12-04 19:06:35 -08001144${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001145
1146${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001147
Mike Frysinger0b789c52015-01-15 15:37:59 -05001148LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1149YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1150
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001151${BUILD}/utility/bmpblk_utility: LD = ${CXX}
Mike Frysinger0b789c52015-01-15 15:37:59 -05001152${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001153
1154BMPBLK_UTILITY_DEPS = \
1155 ${BUILD}/utility/bmpblk_util.o \
1156 ${BUILD}/utility/image_types.o \
1157 ${BUILD}/utility/eficompress_for_lib.o \
1158 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001159
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001160${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1161${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001162ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001163
1164${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1165${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001166ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001167
1168# Allow multiple definitions, so tests can mock functions from other libraries
1169${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001170${BUILD}/tests/%: LDLIBS += -lrt -luuid
1171${BUILD}/tests/%: LIBS += ${TESTLIB}
1172
1173${BUILD}/tests/rollback_index2_tests: OBJS += \
1174 ${BUILD}/firmware/lib/rollback_index_for_test.o
1175${BUILD}/tests/rollback_index2_tests: \
1176 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001177TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001178
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001179${BUILD}/tests/tlcl_tests: OBJS += \
1180 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1181${BUILD}/tests/tlcl_tests: \
1182 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001183TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001184
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001185${BUILD}/tests/vboot_audio_tests: OBJS += \
1186 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1187${BUILD}/tests/vboot_audio_tests: \
1188 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001189TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001190
Bill Richardson339f7e02013-04-05 09:49:24 -07001191TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001192${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1193${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001194TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001195
Alex Deymoe08ee282014-08-29 01:07:48 -07001196# ----------------------------------------------------------------------------
1197# Here are the special rules that don't fit in the generic rules.
1198
1199# Generates the list of commands defined in futility by running grep in the
1200# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1201${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1202${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1203${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001204 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001205 ${Q}rm -f $@ $@_t $@_commands
1206 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001207 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001208 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1209 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001210 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001211 ${Q}echo '#define _CMD(NAME) extern const struct' \
1212 'futil_cmd_t __cmd_##NAME;' >> $@_t
1213 ${Q}cat $@_commands >> $@_t
1214 ${Q}echo '#undef _CMD' >> $@_t
1215 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1216 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1217 ${Q}cat $@_commands >> $@_t
1218 ${Q}echo '0}; /* null-terminated */' >> $@_t
1219 ${Q}echo '#undef _CMD' >> $@_t
1220 ${Q}mv $@_t $@
1221 ${Q}rm -f $@_commands
1222
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001223##############################################################################
1224# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001225
1226# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001227.PHONY: test_targets
Bill Richardson06eb78c2015-01-27 15:01:51 -08001228test_targets:: runcgpttests runmisctests run2tests
Randall Spangler844bce52013-01-15 16:16:43 -08001229
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001230ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001231# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001232test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001233# Scripts don't work under qemu testing
1234# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001235test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001236endif
1237
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001238.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001239test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001240
Randall Spangler844bce52013-01-15 16:16:43 -08001241# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1242# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001243ifneq (${QEMU_ARCH},)
1244test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001245
1246.PHONY: qemu_install
1247qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001248ifeq (${SYSROOT},)
1249 $(error SYSROOT must be set to the top of the target-specific root \
1250when cross-compiling for qemu-based tests to run properly.)
1251endif
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001252 @${PRINTF} " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001253 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1254 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001255endif
1256
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001257.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001258runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001259
1260# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001261.PHONY: genkeys
Bill Richardson0840b842015-02-05 12:39:02 -08001262genkeys: utils test_setup
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001263 tests/gen_test_keys.sh
1264
1265# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001266.PHONY: genfuzztestcases
Bill Richardson0840b842015-02-05 12:39:02 -08001267genfuzztestcases: utils test_setup
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001268 tests/gen_fuzz_test_cases.sh
1269
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001270.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001271runbmptests: test_setup
1272 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001273 ./TestBmpBlock.py -v
1274
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001275.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001276runcgpttests: test_setup
1277 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001278
Randall Spangler844bce52013-01-15 16:16:43 -08001279.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001280runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001281 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001282 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001283 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001284 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001285 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001286 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001287 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001288 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001289 tests/vb2_firmware_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001290
Randall Spangler844bce52013-01-15 16:16:43 -08001291.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001292runmisctests: test_setup
1293 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001294 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001295 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1296 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1297 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001298 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001299 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1300 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1301 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1302 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001303 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001304 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1305 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001306 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1307 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1308 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001309 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001310 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1311 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1312 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001313 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001314 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001315 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001316 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001317
Randall Spangler786acda2014-05-22 13:27:07 -07001318.PHONY: run2tests
1319run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001320 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001321 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001322 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1323 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001324 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001325 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001326 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001327 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1328 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1329 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1330 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1331 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001332 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1333 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1334 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1335 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1336 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1337 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1338 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1339 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1340 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001341
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001342.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001343runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001344 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001345 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001346
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001347# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001348# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001349# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001350.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001351runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001352 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1353 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001354 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1355 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001356 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001357 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001358 tests/run_vbutil_tests.sh --all
1359
Bill Richardson78d59bf2014-08-27 16:17:04 -07001360# TODO: There were a number of ancient tests that hadn't been run in years.
1361# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1362# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001363
Bill Richardson78299022014-06-20 14:33:00 -07001364.PHONY: runalltests
1365runalltests: runtests runfutiltests runlongtests
1366
Randall Spangler59d75082013-01-23 09:29:54 -08001367# Code coverage
1368.PHONY: coverage_init
1369coverage_init: test_setup
1370 rm -f ${COV_INFO}*
1371 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1372
1373.PHONY: coverage_html
1374coverage_html:
1375 lcov -c -d . -b . -o ${COV_INFO}.tests
1376 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1377 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1378 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001379# Generate addtional coverage stats just for firmware subdir, because the stats
1380# for the whole project don't include subdirectory summaries. This will print
1381# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001382 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1383 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001384 -o ${COV_INFO}.firmware
1385
1386.PHONY: coverage
1387ifeq (${COV},)
1388coverage:
1389 $(error Build coverage like this: make clean && COV=1 make)
1390else
1391coverage: coverage_init runtests coverage_html
1392endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001393
1394# Include generated dependencies
1395ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001396TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
Bill Richardson04d98e32015-01-31 01:14:39 -08001397-include ${ALL_DEPS}
1398-include ${TEST_DEPS}
Bill Richardson80872db2014-10-03 10:26:11 -07001399
1400# We want to use only relative paths in cscope.files, especially since the
1401# paths inside and outside the chroot are different.
1402SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1403
Bill Richardson8db64da2015-01-29 21:46:58 -08001404# Note: vboot 2.0 is deprecated, so don't index those files
Bill Richardson80872db2014-10-03 10:26:11 -07001405${BUILD}/cscope.files: test_setup
1406 ${Q}rm -f $@
1407 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
Bill Richardson8db64da2015-01-29 21:46:58 -08001408 grep -v /lib20/ | \
Bill Richardson80872db2014-10-03 10:26:11 -07001409 sed -e "s/${SRCDIRPAT}//" | \
1410 egrep '\.[chS]$$' | sort | uniq > $@
1411
1412cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1413cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1414run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1415
1416.PHONY: tags TAGS xrefs
1417tags TAGS xrefs: ${BUILD}/cscope.files
1418 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1419 ${Q}$(call run_if_prog,etags,${cmd_etags})
1420 ${Q}$(call run_if_prog,ctags,${cmd_ctags})
Nam T. Nguyen07d90432015-02-17 13:26:44 -08001421
1422PC_FILES = ${PC_IN_FILES:%.pc.in=%.pc}
1423${PC_FILES}: ${PC_IN_FILES}
1424 ${Q}sed \
1425 -e 's:@LDLIBS@:${LDLIBS}:' \
1426 -e 's:@LIBDIR@:${LIBDIR}:' \
1427 $< > $@
1428
1429.PHONY: pc_files_install
1430pc_files_install: ${PC_FILES}
1431 ${Q}mkdir -p ${ULP_DIR}
1432 ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$<