blob: 12a27c7f924511f4351f5c316dbf2aebaa88486f [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
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsoncfe83a82014-12-04 11:29:57 -080048# Default values
49DEV_DEBUG_FORCE=
50
Bill Richardsonfeb25182013-03-07 12:54:29 -080051# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070052# UB_DIR = utility binary directory
Bill Richardsoncfe83a82014-12-04 11:29:57 -080053# DF_DIR = utility defaults directory
Bill Richardson6f396152014-07-15 12:52:19 -070054# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080055ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070056# Host install just puts everything where it's told
Bill Richardsonefa87562014-09-11 10:41:51 -070057UB_DIR=${DESTDIR}/bin
Bill Richardsoncfe83a82014-12-04 11:29:57 -080058DF_DIR=${DESTDIR}/default
Bill Richardsonefa87562014-09-11 10:41:51 -070059VB_DIR=${DESTDIR}/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080060else
Bill Richardsonefa87562014-09-11 10:41:51 -070061# Target install puts things into different places
Bill Richardson6f396152014-07-15 12:52:19 -070062UB_DIR=${DESTDIR}/usr/bin
Bill Richardsoncfe83a82014-12-04 11:29:57 -080063DF_DIR=${DESTDIR}/etc/default
Bill Richardsonc9bf3482013-02-13 14:38:29 -080064VB_DIR=${DESTDIR}/usr/share/vboot/bin
65endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080066
Bill Richardsoneecc18f2013-01-17 15:28:17 -080067# Where to install the (exportable) executables for testing?
68TEST_INSTALL_DIR = ${BUILD}/install_for_test
69
70# Verbose? Use V=1
71ifeq (${V},)
72Q := @
73endif
74
Simon Glass661ae9e2013-03-26 11:39:21 -070075# Quiet? Use QUIET=1
Mike Frysingerc8c87b32015-01-15 17:04:40 -050076ifeq (${QUIET},)
Simon Glass661ae9e2013-03-26 11:39:21 -070077PRINTF := printf
78else
79PRINTF := :
80endif
81
Randall Spangler61a2eb32013-01-23 10:20:16 -080082# Architecture detection
83_machname := $(shell uname -m)
84HOST_ARCH ?= ${_machname}
85
86# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
87# Pick a sane target architecture if none is defined.
88ifeq (${ARCH},)
89 ARCH := ${HOST_ARCH}
90else ifeq (${ARCH},i386)
91 override ARCH := x86
92else ifeq (${ARCH},amd64)
93 override ARCH := x86_64
94endif
95
96# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
97# for a firmware target (such as u-boot or depthcharge). It must map
98# to the same consistent set of architectures as the host.
99ifeq (${FIRMWARE_ARCH},i386)
100 override FIRMWARE_ARCH := x86
101else ifeq (${FIRMWARE_ARCH},amd64)
102 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -0700103else ifeq (${FIRMWARE_ARCH},armv7)
104 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -0800105endif
106
Simon Glassb265c342011-11-16 15:09:51 -0800107# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
108# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700109#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800110# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
111# temporarily. As we are still investigating which flags are necessary for
112# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700113#
Simon Glassb265c342011-11-16 15:09:51 -0800114# As a first step, this makes the setting of CC and CFLAGS here optional, to
115# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700116#
Simon Glassb265c342011-11-16 15:09:51 -0800117# Flag ordering: arch, then -f, then -m, then -W
118DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
119COMMON_FLAGS := -nostdinc -pipe \
120 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800121 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800122
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800123# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
124ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800125CC ?= armv7a-cros-linux-gnueabi-gcc
126CFLAGS ?= -march=armv5 \
127 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700128 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800129 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800130else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800131CC ?= i686-pc-linux-gnu-gcc
132# Drop -march=i386 to permit use of SSE instructions
133CFLAGS ?= \
134 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
135 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800136 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800137 ${COMMON_FLAGS}
138else ifeq (${FIRMWARE_ARCH}, x86_64)
139CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800140 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800141else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800142# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800143CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700144CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800145endif
146
147ifneq (${DEBUG},)
148CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700149endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800150
vbendebb2b0fcc2010-07-15 15:09:47 -0700151ifeq (${DISABLE_NDEBUG},)
152CFLAGS += -DNDEBUG
153endif
154
Bill Richardsonfeb25182013-03-07 12:54:29 -0800155ifneq (${FORCE_LOGGING_ON},)
156CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
157endif
158
Randall Spangler6014c042014-07-22 14:42:58 -0700159ifneq (${PD_SYNC},)
160CFLAGS += -DPD_SYNC
161endif
162
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800163# Create / use dependency files
164CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800165
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700166ifeq (${FIRMWARE_ARCH},)
167# Creates position independent code for non firmware target.
168CFLAGS += -fPIE
169endif
170
Bill Richardson0c3ba242013-03-29 11:09:30 -0700171# These are required to access large disks and files on 32-bit systems.
172CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
173
Randall Spangler59d75082013-01-23 09:29:54 -0800174# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800175ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700176 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800177 CFLAGS += ${COV_FLAGS}
178 LDFLAGS += ${COV_FLAGS}
179 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800180endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800181
David Riley05987b12015-02-05 19:22:49 -0800182ifdef HAVE_MACOS
183 CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
184endif
185
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186# And a few more default utilities
187LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700188CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800189PKG_CONFIG ?= pkg-config
190
Mike Frysinger0b789c52015-01-15 15:37:59 -0500191# Static?
192ifneq (${STATIC},)
193LDFLAGS += -static
194PKG_CONFIG += --static
195endif
196
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800197# Determine QEMU architecture needed, if any
198ifeq (${ARCH},${HOST_ARCH})
199 # Same architecture; no need for QEMU
200 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800201else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800202 # 64-bit host can run 32-bit targets directly
203 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800204else
205 QEMU_ARCH := ${ARCH}
206endif
207
208# The top of the chroot for qemu must be passed in via the SYSROOT environment
209# variable. In the Chromium OS chroot, this is done automatically by the
210# ebuild.
211
212ifeq (${QEMU_ARCH},)
213 # Path to build output for running tests is same as for building
214 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800215 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800216else
217 $(info Using qemu for testing.)
218 # Path to build output for running tests is different in the chroot
219 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800220 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800221
222 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800223 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
224 export QEMU_RUN
225
226 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227endif
228
Randall Spanglere061a252013-01-22 15:34:07 -0800229export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800230
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800231##############################################################################
232# Now we need to describe everything we might want or need to build
233
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800234# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800235INCLUDES += \
236 -Ifirmware/include \
237 -Ifirmware/lib/include \
238 -Ifirmware/lib/cgptlib/include \
239 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700240 -Ifirmware/lib/tpm_lite/include \
241 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700242
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800243# If we're not building for a specific target, just stub out things like the
244# TPM commands and various external functions that are provided by the BIOS.
245ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700246INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800247endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800248
Bill Richardson78299022014-06-20 14:33:00 -0700249# Firmware library, used by the other firmware components (depthcharge,
250# coreboot, etc.). It doesn't need exporting to some other place; they'll build
251# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800252FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800253
Bill Richardson06eb78c2015-01-27 15:01:51 -0800254# Smaller firmware library common to all vboot 2.x, used only for
255# 1) compile-time tests of the public API or
256# 2) linking with an actual 2.0 or 2.1 implementation
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800257FWLIB2X = ${BUILD}/vboot_fw2x.a
Bill Richardson06eb78c2015-01-27 15:01:51 -0800258
259# Vboot 2.0 (deprecated - see firmware/README)
260FWLIB20 = ${BUILD}/vboot_fw20.a
261# Vboot 2.1 (not yet ready - see firmware/README)
Randall Spanglera5b69b02014-12-02 13:41:29 -0800262FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700263
Randall Spangler93943262013-02-26 11:03:57 -0800264# Firmware library sources needed by VbInit() call
265VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800266 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800267 firmware/lib/utility.c \
268 firmware/lib/vboot_api_init.c \
269 firmware/lib/vboot_common_init.c \
270 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700271 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600272 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800273
274# Additional firmware library sources needed by VbSelectFirmware() call
275VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 firmware/lib/cryptolib/padding.c \
277 firmware/lib/cryptolib/rsa.c \
278 firmware/lib/cryptolib/rsa_utility.c \
279 firmware/lib/cryptolib/sha1.c \
280 firmware/lib/cryptolib/sha256.c \
281 firmware/lib/cryptolib/sha512.c \
282 firmware/lib/cryptolib/sha_utility.c \
283 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800284 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800285 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600286 firmware/lib/vboot_firmware.c \
287 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800288
289# Additional firmware library sources needed by VbSelectAndLoadKernel() call
290VBSLK_SRCS = \
291 firmware/lib/cgptlib/cgptlib.c \
292 firmware/lib/cgptlib/cgptlib_internal.c \
293 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700294 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800295 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800296 firmware/lib/vboot_api_kernel.c \
297 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800298 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600299 firmware/lib/vboot_kernel.c \
300 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800301
Bill Richardson06eb78c2015-01-27 15:01:51 -0800302# Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
303FWLIB2X_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700304 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700305 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700306 firmware/2lib/2crc8.c \
307 firmware/2lib/2misc.c \
308 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700309 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700310 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700311 firmware/2lib/2sha1.c \
312 firmware/2lib/2sha256.c \
313 firmware/2lib/2sha512.c \
Daisuke Nojiri62d482e2015-01-29 14:37:25 -0800314 firmware/2lib/2sha_utility.c \
315 firmware/2lib/2tpm_bootmode.c
Randall Spanglera5b69b02014-12-02 13:41:29 -0800316
Randall Spangler108d9912014-12-02 15:55:56 -0800317FWLIB20_SRCS = \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800318 firmware/lib20/api.c \
319 firmware/lib20/common.c \
320 firmware/lib20/misc.c \
321 firmware/lib20/packed_key.c
Randall Spangler108d9912014-12-02 15:55:56 -0800322
Randall Spanglera5b69b02014-12-02 13:41:29 -0800323FWLIB21_SRCS = \
324 firmware/lib21/api.c \
325 firmware/lib21/common.c \
326 firmware/lib21/misc.c \
327 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700328
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800329# Support real TPM unless BIOS sets MOCK_TPM
330ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800331VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800332 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800333 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800334
335VBSF_SRCS += \
336 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800337else
Randall Spangler93943262013-02-26 11:03:57 -0800338VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800339 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800340 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800341
342VBSF_SRCS += \
343 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800344endif
345
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800346ifeq (${FIRMWARE_ARCH},)
347# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800348# TODO: split out other stub funcs too
349VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800350 firmware/stub/tpm_lite_stub.c \
351 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600352 firmware/stub/vboot_api_stub_init.c \
353 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800354
355VBSF_SRCS += \
356 firmware/stub/vboot_api_stub_sf.c
357
358VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800359 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700360 firmware/stub/vboot_api_stub_disk.c \
361 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700362
Bill Richardson06eb78c2015-01-27 15:01:51 -0800363FWLIB2X_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700364 firmware/2lib/2stub.c
365
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800366endif
367
Randall Spangler93943262013-02-26 11:03:57 -0800368VBSF_SRCS += ${VBINIT_SRCS}
369FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
370
371VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
372VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800373ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800374
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800375FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800376FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800377FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800378FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800379ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800380
Bill Richardson78299022014-06-20 14:33:00 -0700381# Intermediate library for the vboot_reference utilities to link against.
382UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800383UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800384
Bill Richardson78299022014-06-20 14:33:00 -0700385UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800386 cgpt/cgpt_create.c \
387 cgpt/cgpt_add.c \
388 cgpt/cgpt_boot.c \
389 cgpt/cgpt_show.c \
390 cgpt/cgpt_repair.c \
391 cgpt/cgpt_prioritize.c \
392 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700393 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800394 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800395 host/lib/crossystem.c \
396 host/lib/file_keys.c \
397 host/lib/fmap.c \
398 host/lib/host_common.c \
399 host/lib/host_key.c \
400 host/lib/host_keyblock.c \
401 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700402 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800403 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700404 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800405
Randall Spangleraaaff862014-12-01 15:40:08 -0800406UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
407ALL_OBJS += ${UTILLIB_OBJS}
408
Randall Spanglera5b69b02014-12-02 13:41:29 -0800409UTILLIB21_SRCS += \
410 host/lib21/host_fw_preamble.c \
411 host/lib21/host_key.c \
412 host/lib21/host_keyblock.c \
413 host/lib21/host_misc.c \
414 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800415
Randall Spanglera5b69b02014-12-02 13:41:29 -0800416UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
417ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700418
419# Externally exported library for some target userspace apps to link with
420# (cryptohome, updater, etc.)
421HOSTLIB = ${BUILD}/libvboot_host.a
422
423HOSTLIB_SRCS = \
424 cgpt/cgpt_add.c \
425 cgpt/cgpt_boot.c \
426 cgpt/cgpt_common.c \
427 cgpt/cgpt_create.c \
428 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700429 firmware/lib/cgptlib/cgptlib_internal.c \
430 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700431 firmware/lib/crc8.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800432 firmware/lib/gpt_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700433 firmware/lib/tpm_lite/tlcl.c \
434 firmware/lib/utility_string.c \
435 firmware/lib/vboot_nvstorage.c \
436 firmware/stub/tpm_lite_stub.c \
437 firmware/stub/utility_stub.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800438 firmware/stub/vboot_api_stub_disk.c \
Bill Richardson78299022014-06-20 14:33:00 -0700439 firmware/stub/vboot_api_stub_init.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800440 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700441 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700442 host/arch/${ARCH}/lib/crossystem_arch.c \
443 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700444 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700445 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700446
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800447HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800448ALL_OBJS += ${HOSTLIB_OBJS}
449
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800450# Sigh. For historical reasons, the autoupdate installer must sometimes be a
451# 32-bit executable, even when everything else is 64-bit. But it only needs a
452# few functions, so let's just build those.
453TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
454
455TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800456 cgpt/cgpt_add.c \
457 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800458 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700459 cgpt/cgpt_create.c \
460 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700461 firmware/lib/cgptlib/cgptlib_internal.c \
462 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800463 firmware/lib/gpt_misc.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800464 firmware/lib/utility_string.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800465 firmware/stub/vboot_api_stub_disk.c \
466 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson78299022014-06-20 14:33:00 -0700467 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800468 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800469
470TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800471
472# ----------------------------------------------------------------------------
473# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800474
475CGPT = ${BUILD}/cgpt/cgpt
476
477CGPT_SRCS = \
478 cgpt/cgpt.c \
479 cgpt/cgpt_add.c \
480 cgpt/cgpt_boot.c \
481 cgpt/cgpt_common.c \
482 cgpt/cgpt_create.c \
483 cgpt/cgpt_find.c \
484 cgpt/cgpt_legacy.c \
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800485 cgpt/cgpt_nor.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800486 cgpt/cgpt_prioritize.c \
487 cgpt/cgpt_repair.c \
488 cgpt/cgpt_show.c \
489 cgpt/cmd_add.c \
490 cgpt/cmd_boot.c \
491 cgpt/cmd_create.c \
492 cgpt/cmd_find.c \
493 cgpt/cmd_legacy.c \
494 cgpt/cmd_prioritize.c \
495 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800496 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800497
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800498CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800499
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800500ALL_OBJS += ${CGPT_OBJS}
501
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800502CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
503
504CGPT_WRAPPER_SRCS = \
505 cgpt/cgpt_nor.c \
506 cgpt/cgpt_wrapper.c
507
508CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
509
510ALL_OBJS += ${CGPT_WRAPPER_OBJS}
511
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800512# Utility defaults
513UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800514
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800515# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800516UTIL_SCRIPTS = \
517 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700518 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800519
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800520ifeq (${MINIMAL},)
521UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700522 utility/dev_make_keypair \
523 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800524endif
525
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800526# These utilities should be linked statically.
527UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700528 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800529
530UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700531 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700532 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700533 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800534
Bill Richardson6f396152014-07-15 12:52:19 -0700535# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800536ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800537UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700538 utility/bmpblk_font \
539 utility/bmpblk_utility \
540 utility/eficompress \
541 utility/efidecompress \
542 utility/load_kernel_test \
543 utility/pad_digest_utility \
544 utility/signature_digest_utility \
545 utility/verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800546endif
547
Bill Richardson339f7e02013-04-05 09:49:24 -0700548UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
549UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700550ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800551
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800552
553# Scripts for signing stuff.
554SIGNING_SCRIPTS = \
555 utility/tpm-nvsize \
556 utility/chromeos-tpm-recovery
557
558# These go in a different place.
559SIGNING_SCRIPTS_DEV = \
560 scripts/image_signing/resign_firmwarefd.sh \
561 scripts/image_signing/make_dev_firmware.sh \
562 scripts/image_signing/make_dev_ssd.sh \
563 scripts/image_signing/set_gbb_flags.sh
564
565# Installed, but not made executable.
566SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800567
Bill Richardson826db092013-01-14 12:37:15 -0800568
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800569# The unified firmware utility will eventually replace all the others
570FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700571# But we still need both static (tiny) and dynamic (with openssl) versions.
572FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800573
Bill Richardson6f396152014-07-15 12:52:19 -0700574# These are the executables that are now built in to futility. We'll create
575# symlinks for these so the old names will still work.
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700576FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700577 dump_fmap \
578 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700579 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700580 vbutil_firmware \
581 vbutil_kernel \
582 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700583 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800584
Bill Richardson6db8c752013-04-05 13:30:43 -0700585FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800586 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700587 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700588 futility/cmd_gbb_utility.c \
589 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800590
Bill Richardson6db8c752013-04-05 13:30:43 -0700591FUTIL_SRCS = \
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500592 ${FUTIL_STATIC_SRCS} \
Bill Richardson6f396152014-07-15 12:52:19 -0700593 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700594 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700595 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700596 futility/cmd_show.c \
597 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700598 futility/cmd_vbutil_firmware.c \
599 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700600 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700601 futility/cmd_vbutil_keyblock.c \
Bill Richardson25593382015-01-30 12:22:28 -0800602 futility/file_type.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700603 futility/traversal.c \
604 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700605
Alex Deymoe08ee282014-08-29 01:07:48 -0700606# List of commands built in futility and futility_s.
607FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
608FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800609
Bill Richardson91852e72014-11-28 12:28:04 -0800610# Workaround for TODO(crbug.com/437107).
611FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
612
Alex Deymoe08ee282014-08-29 01:07:48 -0700613FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800614 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700615 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
616FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800617
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800618ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800619
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800620
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800621# Library of handy test functions.
622TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800623
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800624TESTLIB_SRCS = \
625 tests/test_common.c \
626 tests/timer_utils.c \
627 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800628
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800629TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700630TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800631
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800632
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800633# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800634TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700635 tests/cgptlib_test \
636 tests/rollback_index2_tests \
637 tests/rollback_index3_tests \
638 tests/rsa_padding_test \
639 tests/rsa_utility_tests \
640 tests/rsa_verify_benchmark \
641 tests/sha_benchmark \
642 tests/sha_tests \
643 tests/stateful_util_tests \
644 tests/tlcl_tests \
645 tests/tpm_bootmode_tests \
646 tests/utility_string_tests \
647 tests/utility_tests \
648 tests/vboot_api_init_tests \
649 tests/vboot_api_devmode_tests \
650 tests/vboot_api_firmware_tests \
651 tests/vboot_api_kernel_tests \
652 tests/vboot_api_kernel2_tests \
653 tests/vboot_api_kernel3_tests \
654 tests/vboot_api_kernel4_tests \
655 tests/vboot_audio_tests \
656 tests/vboot_common_tests \
657 tests/vboot_common2_tests \
658 tests/vboot_common3_tests \
659 tests/vboot_display_tests \
660 tests/vboot_firmware_tests \
661 tests/vboot_kernel_tests \
662 tests/vboot_nvstorage_test \
Bill Richardsona77541f2014-12-04 19:06:35 -0800663 tests/verify_kernel \
Bill Richardson6f396152014-07-15 12:52:19 -0700664 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700665 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800666
Simon Glass527ba812013-07-25 08:48:47 -0600667ifdef REGION_READ
668TEST_NAMES += tests/vboot_region_tests
669endif
670
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800671TEST2X_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700672 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700673 tests/vb2_common_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700674 tests/vb2_misc_tests \
675 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700676 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700677 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800678 tests/vb2_sha_tests
679
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800680TEST20_NAMES = \
681 tests/vb20_api_tests \
682 tests/vb20_common_tests \
683 tests/vb20_common2_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800684 tests/vb20_verify_fw.c \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800685 tests/vb20_common3_tests \
686 tests/vb20_misc_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800687 tests/vb20_rsa_padding_tests \
688 tests/vb20_verify_fw
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800689
Randall Spangler108d9912014-12-02 15:55:56 -0800690TEST21_NAMES = \
691 tests/vb21_api_tests \
692 tests/vb21_common_tests \
693 tests/vb21_common2_tests \
694 tests/vb21_misc_tests \
695 tests/vb21_host_fw_preamble_tests \
696 tests/vb21_host_key_tests \
697 tests/vb21_host_keyblock_tests \
698 tests/vb21_host_misc_tests \
699 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700700
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800701TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700702
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800703# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700704TLCL_TEST_NAMES = \
705 tests/tpm_lite/tpmtest_earlyextend \
706 tests/tpm_lite/tpmtest_earlynvram \
707 tests/tpm_lite/tpmtest_earlynvram2 \
708 tests/tpm_lite/tpmtest_enable \
709 tests/tpm_lite/tpmtest_fastenable \
710 tests/tpm_lite/tpmtest_globallock \
711 tests/tpm_lite/tpmtest_redefine_unowned \
712 tests/tpm_lite/tpmtest_spaceperm \
713 tests/tpm_lite/tpmtest_testsetup \
714 tests/tpm_lite/tpmtest_timing \
715 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800716
717TEST_NAMES += ${TLCL_TEST_NAMES}
718
Bill Richardson339f7e02013-04-05 09:49:24 -0700719# Finally
720TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700721TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800722
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800723TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800724TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800725TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800726
Randall Spanglere061a252013-01-22 15:34:07 -0800727# Directory containing test keys
728TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800729
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800730
731##############################################################################
732# Finally, some targets. High-level ones first.
733
734# Create output directories if necessary. Do this via explicit shell commands
735# so it happens before trying to generate/include dependencies.
736SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
737_dir_create := $(foreach d, \
738 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
739 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
740
741
742# Default target.
743.PHONY: all
Bill Richardson06eb78c2015-01-27 15:01:51 -0800744all: fwlib fwlib2x fwlib20 fwlib21 \
Randall Spangleraaaff862014-12-01 15:40:08 -0800745 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700746 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800747
748# Host targets
749.PHONY: host_stuff
Bill Richardson06eb78c2015-01-27 15:01:51 -0800750host_stuff: utillib hostlib cgpt utils futil tests utillib21
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800751
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800752.PHONY: clean
753clean:
754 ${Q}/bin/rm -rf ${BUILD}
755
756.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800757install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800758
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800759.PHONY: install_mtd
760install_mtd: install cgpt_wrapper_install
761
Bill Richardson3e3790d2014-07-14 15:05:54 -0700762.PHONY: install_for_test
763install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
764install_for_test: install
765
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766# Don't delete intermediate object files
767.SECONDARY:
768
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800769# ----------------------------------------------------------------------------
770# Firmware library
771
772# TPM-specific flags. These depend on the particular TPM we're targeting for.
773# They are needed here only for compiling parts of the firmware code into
774# user-level tests.
775
776# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
777# the self test has completed.
778
Randall Spangler45cc0f22013-01-25 09:34:26 -0800779${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800780
781# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
782# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
783# power on.
784#
785# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
786# are not both defined at the same time. (See comment in code.)
787
788# CFLAGS += -DTPM_MANUAL_SELFTEST
789
790ifeq (${FIRMWARE_ARCH},i386)
791# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800792${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardson06eb78c2015-01-27 15:01:51 -0800793${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800794${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800795${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800796
797# Workaround for coreboot on x86, which will power off asynchronously
798# without giving us a chance to react. This is not an example of the Right
799# Way to do things. See chrome-os-partner:7689, and the commit message
800# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800801${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800802
803# On x86 we don't actually read the GBB data into RAM until it is needed.
804# Therefore it makes sense to cache it rather than reading it each time.
805# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800806${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800807endif
808
Simon Glass527ba812013-07-25 08:48:47 -0600809ifdef REGION_READ
810${FWLIB_OBJS}: CFLAGS += -DREGION_READ
811endif
812
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800813ifeq (${FIRMWARE_ARCH},)
814# Disable rollback TPM when compiling locally, since otherwise
815# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800816${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800817endif
818
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800819${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -0800820${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
821
Bill Richardsona130e0b2013-04-04 18:16:39 -0700822# Linktest ensures firmware lib doesn't rely on outside libraries
823${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800824${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700825TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700826${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800827${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700828TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700829${BUILD}/firmware/linktest/main: ${FWLIB}
830${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700831TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800832
Bill Richardsond2d08b22014-07-08 16:31:40 -0700833.PHONY: fwlinktest
834fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800835 ${BUILD}/firmware/linktest/main_vbinit \
836 ${BUILD}/firmware/linktest/main_vbsf \
837 ${BUILD}/firmware/linktest/main
838
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800839.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700840fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800841
842${FWLIB}: ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500843 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800844 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500845 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800846 ${Q}ar qc $@ $^
847
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800848.PHONY: fwlib2x
849fwlib2x: ${FWLIB2X}
850
Bill Richardson06eb78c2015-01-27 15:01:51 -0800851${FWLIB2X}: ${FWLIB2X_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500852 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800853 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500854 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800855 ${Q}ar qc $@ $^
856
Bill Richardson06eb78c2015-01-27 15:01:51 -0800857.PHONY: fwlib20
858fwlib20: ${FWLIB20}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800859
Bill Richardson06eb78c2015-01-27 15:01:51 -0800860${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500861 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700862 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500863 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700864 ${Q}ar qc $@ $^
865
Randall Spanglera5b69b02014-12-02 13:41:29 -0800866.PHONY: fwlib21
867fwlib21: ${FWLIB21}
868
Bill Richardson06eb78c2015-01-27 15:01:51 -0800869${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500870 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800871 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500872 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800873 ${Q}ar qc $@ $^
874
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800875# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700876# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800877
Bill Richardson78299022014-06-20 14:33:00 -0700878# Link tests for local utilities
879${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700880${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700881TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700882
883.PHONY: utillib
884utillib: ${UTILLIB} \
885 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800886
887# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800888${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500889 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800890 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500891 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800892 ${Q}ar qc $@ $^
893
Randall Spanglera5b69b02014-12-02 13:41:29 -0800894.PHONY: utillib21
895utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800896
Randall Spangler108d9912014-12-02 15:55:56 -0800897${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Bill Richardson06eb78c2015-01-27 15:01:51 -0800898${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500899 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700900 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500901 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700902 ${Q}ar qc $@ $^
903
904
905# Link tests for external repos
906${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700907${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
908${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700909TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700910
911.PHONY: hostlib
912hostlib: ${HOSTLIB} \
913 ${BUILD}/host/linktest/extern
914
915# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700916${HOSTLIB}: ${HOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500917 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800918 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500919 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800920 ${Q}ar qc $@ $^
921
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800922
923# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
924.PHONY: tinyhostlib
925tinyhostlib: ${TINYHOSTLIB}
926 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
927
928${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500929 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800930 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500931 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800932 ${Q}ar qc $@ $^
933
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800934# ----------------------------------------------------------------------------
935# CGPT library and utility
936
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800937.PHONY: cgpt_wrapper
938cgpt_wrapper: ${CGPT_WRAPPER}
939
940${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
941 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
942 ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
943
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800944.PHONY: cgpt
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800945cgpt: ${CGPT} ${CGPT_WRAPPER}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800946
947${CGPT}: LDFLAGS += -static
948${CGPT}: LDLIBS += -luuid
949
Bill Richardson78299022014-06-20 14:33:00 -0700950${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500951 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700952 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800953
954.PHONY: cgpt_install
955cgpt_install: ${CGPT}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500956 @${PRINTF} " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800957 ${Q}mkdir -p ${UB_DIR}
958 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800959
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800960.PHONY: cgpt_wrapper_install
961cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
962 @$(PRINTF) " INSTALL cgpt_wrapper\n"
963 ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
964 ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
965 ${UB_DIR}/$(notdir ${CGPT}).bin
966 ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
967 ${UB_DIR}/$(notdir ${CGPT})
968
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800969# ----------------------------------------------------------------------------
970# Utilities
971
972# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700973${BUILD}/utility/%: INCLUDES += -Iutility/include
974
975${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
976${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800977
978# Utilities for auto-update toolkits must be statically linked.
979${UTIL_BINS_STATIC}: LDFLAGS += -static
980
Bill Richardsona130e0b2013-04-04 18:16:39 -0700981
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800982.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800983utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800984 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
985 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
986
987.PHONY: utils_install
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800988utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500989 @${PRINTF} " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800990 ${Q}mkdir -p ${UB_DIR}
991 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800992 ${Q}mkdir -p ${DF_DIR}
993 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800994
995# And some signing stuff for the target
996.PHONY: signing_install
997signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500998 @${PRINTF} " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700999 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001000 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -07001001 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1002 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001003
1004# ----------------------------------------------------------------------------
1005# new Firmware Utility
1006
1007.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -07001008futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1009
Bill Richardson06eb78c2015-01-27 15:01:51 -08001010${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001011 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001012 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001013
Bill Richardsonb84b81d2014-07-14 14:48:31 -07001014${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson06eb78c2015-01-27 15:01:51 -08001015${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001016 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001017 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001018
1019.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -07001020futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001021 @${PRINTF} " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -07001022 ${Q}mkdir -p ${UB_DIR}
1023 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -07001024 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -07001025 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001026
1027# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001028# Utility to generate TLCL structure definition header file.
1029
1030${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1031
1032STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1033STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1034
1035.PHONY: update_tlcl_structures
1036update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001037 @${PRINTF} " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001038 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1039 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1040 ( echo "%% Updating structures.h %%" && \
1041 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1042
1043# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001044# Tests
1045
1046.PHONY: tests
1047tests: ${TEST_BINS}
1048
Bill Richardson78299022014-06-20 14:33:00 -07001049${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -07001050${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001051${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001052
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001053${TEST2X_BINS}: ${FWLIB2X}
1054${TEST2X_BINS}: LIBS += ${FWLIB2X}
1055
Randall Spangler108d9912014-12-02 15:55:56 -08001056${TEST20_BINS}: ${FWLIB20}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001057${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -08001058${TEST20_BINS}: LIBS += ${FWLIB20}
1059
1060${TEST21_BINS}: ${UTILLIB21}
1061${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1062${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -08001063
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001064${TESTLIB}: ${TESTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001065 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001066 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001067 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001068 ${Q}ar qc $@ $^
1069
1070
1071# ----------------------------------------------------------------------------
1072# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1073# rules for specific targets.
1074
1075${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001076 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001077 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001078
1079${BUILD}/%.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001080 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001081 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1082
Alex Deymoe08ee282014-08-29 01:07:48 -07001083${BUILD}/%.o: ${BUILD}/%.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001084 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001085 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1086
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001087# Rules to recompile a single source file for library and test
1088# TODO: is there a tidier way to do this?
1089${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1090${BUILD}/%_for_lib.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001091 @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001092 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1093
1094${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1095${BUILD}/%_for_test.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001096 @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001097 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1098
1099# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1100${BUILD}/%.o: %.cc
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001101 @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001102 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1103
1104# ----------------------------------------------------------------------------
1105# Here are the special tweaks to the generic rules.
1106
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001107# Always create the defaults file, since it depends on input variables
1108.PHONY: ${UTIL_DEFAULTS}
1109${UTIL_DEFAULTS}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001110 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001111 ${Q}rm -f $@
1112 ${Q}mkdir -p $(dir $@)
1113 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1114 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1115 ${Q}mv -f $@.tmp $@
1116
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001117# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001118CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1119
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001120${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1121${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1122${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001123
1124${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1125${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1126${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001127${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1128${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsona77541f2014-12-04 19:06:35 -08001129${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001130
1131${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001132
Mike Frysinger0b789c52015-01-15 15:37:59 -05001133LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1134YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1135
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136${BUILD}/utility/bmpblk_utility: LD = ${CXX}
Mike Frysinger0b789c52015-01-15 15:37:59 -05001137${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001138
1139BMPBLK_UTILITY_DEPS = \
1140 ${BUILD}/utility/bmpblk_util.o \
1141 ${BUILD}/utility/image_types.o \
1142 ${BUILD}/utility/eficompress_for_lib.o \
1143 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001144
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001145${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1146${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001147ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001148
1149${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1150${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001151ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001152
1153# Allow multiple definitions, so tests can mock functions from other libraries
1154${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001155${BUILD}/tests/%: LDLIBS += -lrt -luuid
1156${BUILD}/tests/%: LIBS += ${TESTLIB}
1157
1158${BUILD}/tests/rollback_index2_tests: OBJS += \
1159 ${BUILD}/firmware/lib/rollback_index_for_test.o
1160${BUILD}/tests/rollback_index2_tests: \
1161 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001162TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001163
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001164${BUILD}/tests/tlcl_tests: OBJS += \
1165 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1166${BUILD}/tests/tlcl_tests: \
1167 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001168TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001169
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001170${BUILD}/tests/vboot_audio_tests: OBJS += \
1171 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1172${BUILD}/tests/vboot_audio_tests: \
1173 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001174TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001175
Bill Richardson339f7e02013-04-05 09:49:24 -07001176TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001177${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1178${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001179TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001180
Alex Deymoe08ee282014-08-29 01:07:48 -07001181# ----------------------------------------------------------------------------
1182# Here are the special rules that don't fit in the generic rules.
1183
1184# Generates the list of commands defined in futility by running grep in the
1185# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1186${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1187${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1188${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001189 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001190 ${Q}rm -f $@ $@_t $@_commands
1191 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001192 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001193 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1194 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001195 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001196 ${Q}echo '#define _CMD(NAME) extern const struct' \
1197 'futil_cmd_t __cmd_##NAME;' >> $@_t
1198 ${Q}cat $@_commands >> $@_t
1199 ${Q}echo '#undef _CMD' >> $@_t
1200 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1201 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1202 ${Q}cat $@_commands >> $@_t
1203 ${Q}echo '0}; /* null-terminated */' >> $@_t
1204 ${Q}echo '#undef _CMD' >> $@_t
1205 ${Q}mv $@_t $@
1206 ${Q}rm -f $@_commands
1207
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001208##############################################################################
1209# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001210
1211# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001212.PHONY: test_targets
Bill Richardson06eb78c2015-01-27 15:01:51 -08001213test_targets:: runcgpttests runmisctests run2tests
Randall Spangler844bce52013-01-15 16:16:43 -08001214
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001215ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001216# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001217test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001218# Scripts don't work under qemu testing
1219# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001220test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001221endif
1222
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001223.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001224test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001225
Randall Spangler844bce52013-01-15 16:16:43 -08001226# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1227# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001228ifneq (${QEMU_ARCH},)
1229test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001230
1231.PHONY: qemu_install
1232qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001233ifeq (${SYSROOT},)
1234 $(error SYSROOT must be set to the top of the target-specific root \
1235when cross-compiling for qemu-based tests to run properly.)
1236endif
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001237 @${PRINTF} " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001238 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1239 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001240endif
1241
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001242.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001243runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001244
1245# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001246.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001247genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001248 tests/gen_test_keys.sh
1249
1250# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001251.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001252genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001253 tests/gen_fuzz_test_cases.sh
1254
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001255.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001256runbmptests: test_setup
1257 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001258 ./TestBmpBlock.py -v
1259
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001260.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001261runcgpttests: test_setup
1262 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001263
Randall Spangler844bce52013-01-15 16:16:43 -08001264.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001265runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001266 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001267 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001268 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001269 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001270 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001271 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001272 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001273 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001274 tests/vb2_firmware_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001275
Randall Spangler844bce52013-01-15 16:16:43 -08001276.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001277runmisctests: test_setup
1278 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001279 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001280 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1281 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1282 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001283 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001284 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1285 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1286 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1287 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001288 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001289 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1290 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001291 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1292 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1293 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001294 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001295 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1296 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1297 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001298 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001299 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001300 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001301 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001302
Randall Spangler786acda2014-05-22 13:27:07 -07001303.PHONY: run2tests
1304run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001305 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001306 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001307 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1308 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001309 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001310 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001311 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001312 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1313 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1314 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1315 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1316 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001317 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1318 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1319 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1320 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1321 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1322 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1323 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1324 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1325 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001326
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001327.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001328runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001329 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001330 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001331
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001332# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001333# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001334# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001335.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001336runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001337 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1338 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001339 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1340 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001341 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001342 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001343 tests/run_vbutil_tests.sh --all
1344
Bill Richardson78d59bf2014-08-27 16:17:04 -07001345# TODO: There were a number of ancient tests that hadn't been run in years.
1346# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1347# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001348
Bill Richardson78299022014-06-20 14:33:00 -07001349.PHONY: runalltests
1350runalltests: runtests runfutiltests runlongtests
1351
Randall Spangler59d75082013-01-23 09:29:54 -08001352# Code coverage
1353.PHONY: coverage_init
1354coverage_init: test_setup
1355 rm -f ${COV_INFO}*
1356 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1357
1358.PHONY: coverage_html
1359coverage_html:
1360 lcov -c -d . -b . -o ${COV_INFO}.tests
1361 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1362 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1363 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001364# Generate addtional coverage stats just for firmware subdir, because the stats
1365# for the whole project don't include subdirectory summaries. This will print
1366# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001367 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1368 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001369 -o ${COV_INFO}.firmware
1370
1371.PHONY: coverage
1372ifeq (${COV},)
1373coverage:
1374 $(error Build coverage like this: make clean && COV=1 make)
1375else
1376coverage: coverage_init runtests coverage_html
1377endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001378
1379# Include generated dependencies
1380ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001381TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
Bill Richardson04d98e32015-01-31 01:14:39 -08001382-include ${ALL_DEPS}
1383-include ${TEST_DEPS}
Bill Richardson80872db2014-10-03 10:26:11 -07001384
1385# We want to use only relative paths in cscope.files, especially since the
1386# paths inside and outside the chroot are different.
1387SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1388
Bill Richardson8db64da2015-01-29 21:46:58 -08001389# Note: vboot 2.0 is deprecated, so don't index those files
Bill Richardson80872db2014-10-03 10:26:11 -07001390${BUILD}/cscope.files: test_setup
1391 ${Q}rm -f $@
1392 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
Bill Richardson8db64da2015-01-29 21:46:58 -08001393 grep -v /lib20/ | \
Bill Richardson80872db2014-10-03 10:26:11 -07001394 sed -e "s/${SRCDIRPAT}//" | \
1395 egrep '\.[chS]$$' | sort | uniq > $@
1396
1397cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1398cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1399run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1400
1401.PHONY: tags TAGS xrefs
1402tags TAGS xrefs: ${BUILD}/cscope.files
1403 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1404 ${Q}$(call run_if_prog,etags,${cmd_etags})
1405 ${Q}$(call run_if_prog,ctags,${cmd_ctags})