blob: e595d2c74c809967d72035cee7296b9013fac43a [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
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800182# And a few more default utilities
183LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700184CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800185PKG_CONFIG ?= pkg-config
186
Mike Frysinger0b789c52015-01-15 15:37:59 -0500187# Static?
188ifneq (${STATIC},)
189LDFLAGS += -static
190PKG_CONFIG += --static
191endif
192
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800193# Determine QEMU architecture needed, if any
194ifeq (${ARCH},${HOST_ARCH})
195 # Same architecture; no need for QEMU
196 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800197else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800198 # 64-bit host can run 32-bit targets directly
199 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200else
201 QEMU_ARCH := ${ARCH}
202endif
203
204# The top of the chroot for qemu must be passed in via the SYSROOT environment
205# variable. In the Chromium OS chroot, this is done automatically by the
206# ebuild.
207
208ifeq (${QEMU_ARCH},)
209 # Path to build output for running tests is same as for building
210 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800211 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800212else
213 $(info Using qemu for testing.)
214 # Path to build output for running tests is different in the chroot
215 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800216 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800217
218 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800219 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
220 export QEMU_RUN
221
222 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800223endif
224
Randall Spanglere061a252013-01-22 15:34:07 -0800225export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800226
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227##############################################################################
228# Now we need to describe everything we might want or need to build
229
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800230# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800231INCLUDES += \
232 -Ifirmware/include \
233 -Ifirmware/lib/include \
234 -Ifirmware/lib/cgptlib/include \
235 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700236 -Ifirmware/lib/tpm_lite/include \
237 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700238
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800239# If we're not building for a specific target, just stub out things like the
240# TPM commands and various external functions that are provided by the BIOS.
241ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700242INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800243endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800244
Bill Richardson78299022014-06-20 14:33:00 -0700245# Firmware library, used by the other firmware components (depthcharge,
246# coreboot, etc.). It doesn't need exporting to some other place; they'll build
247# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800248FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800249
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800250# Smaller firmware library
251# Stuff common to all vboot 2.x
252FWLIB2X = ${BUILD}/vboot_fw2x.a
253# Vboot 2.0 (stuck with this filename due to dependencies in coreboot)
Randall Spangleraaaff862014-12-01 15:40:08 -0800254FWLIB20 = ${BUILD}/vboot_fw2.a
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800255# Vboot 2.1
Randall Spanglera5b69b02014-12-02 13:41:29 -0800256FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700257
Randall Spangler93943262013-02-26 11:03:57 -0800258# Firmware library sources needed by VbInit() call
259VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800260 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800261 firmware/lib/utility.c \
262 firmware/lib/vboot_api_init.c \
263 firmware/lib/vboot_common_init.c \
264 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700265 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600266 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800267
268# Additional firmware library sources needed by VbSelectFirmware() call
269VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800270 firmware/lib/cryptolib/padding.c \
271 firmware/lib/cryptolib/rsa.c \
272 firmware/lib/cryptolib/rsa_utility.c \
273 firmware/lib/cryptolib/sha1.c \
274 firmware/lib/cryptolib/sha256.c \
275 firmware/lib/cryptolib/sha512.c \
276 firmware/lib/cryptolib/sha_utility.c \
277 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800278 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800279 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600280 firmware/lib/vboot_firmware.c \
281 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800282
283# Additional firmware library sources needed by VbSelectAndLoadKernel() call
284VBSLK_SRCS = \
285 firmware/lib/cgptlib/cgptlib.c \
286 firmware/lib/cgptlib/cgptlib_internal.c \
287 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700288 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800289 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800290 firmware/lib/vboot_api_kernel.c \
291 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800292 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600293 firmware/lib/vboot_kernel.c \
294 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800295
Randall Spangler786acda2014-05-22 13:27:07 -0700296# Firmware library source needed for smaller library 2
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800297# Code common to vboot 2.0 (old structs) and 2.1 (new structs)
Randall Spangler108d9912014-12-02 15:55:56 -0800298FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700299 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700300 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700301 firmware/2lib/2crc8.c \
302 firmware/2lib/2misc.c \
303 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700304 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700305 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700306 firmware/2lib/2sha1.c \
307 firmware/2lib/2sha256.c \
308 firmware/2lib/2sha512.c \
Randall Spanglera5b69b02014-12-02 13:41:29 -0800309 firmware/2lib/2sha_utility.c
310
Randall Spangler108d9912014-12-02 15:55:56 -0800311FWLIB20_SRCS = \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800312 firmware/lib20/api.c \
313 firmware/lib20/common.c \
314 firmware/lib20/misc.c \
315 firmware/lib20/packed_key.c
Randall Spangler108d9912014-12-02 15:55:56 -0800316
Randall Spanglera5b69b02014-12-02 13:41:29 -0800317FWLIB21_SRCS = \
318 firmware/lib21/api.c \
319 firmware/lib21/common.c \
320 firmware/lib21/misc.c \
321 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700322
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800323# Support real TPM unless BIOS sets MOCK_TPM
324ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800325VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800326 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800327 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800328
329VBSF_SRCS += \
330 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800331else
Randall Spangler93943262013-02-26 11:03:57 -0800332VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800333 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800334 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800335
336VBSF_SRCS += \
337 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800338endif
339
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800340ifeq (${FIRMWARE_ARCH},)
341# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800342# TODO: split out other stub funcs too
343VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800344 firmware/stub/tpm_lite_stub.c \
345 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600346 firmware/stub/vboot_api_stub_init.c \
347 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800348
349VBSF_SRCS += \
350 firmware/stub/vboot_api_stub_sf.c
351
352VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800353 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700354 firmware/stub/vboot_api_stub_disk.c \
355 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700356
Randall Spangler108d9912014-12-02 15:55:56 -0800357FWLIB2_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700358 firmware/2lib/2stub.c
359
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800360endif
361
Randall Spangler93943262013-02-26 11:03:57 -0800362VBSF_SRCS += ${VBINIT_SRCS}
363FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
364
365VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
366VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800367ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800368
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800369FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800370FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800371FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800372FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800373ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800374
Bill Richardson78299022014-06-20 14:33:00 -0700375# Intermediate library for the vboot_reference utilities to link against.
376UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800377UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800378
Bill Richardson78299022014-06-20 14:33:00 -0700379UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800380 cgpt/cgpt_create.c \
381 cgpt/cgpt_add.c \
382 cgpt/cgpt_boot.c \
383 cgpt/cgpt_show.c \
384 cgpt/cgpt_repair.c \
385 cgpt/cgpt_prioritize.c \
386 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700387 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800388 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800389 host/lib/crossystem.c \
390 host/lib/file_keys.c \
391 host/lib/fmap.c \
392 host/lib/host_common.c \
393 host/lib/host_key.c \
394 host/lib/host_keyblock.c \
395 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700396 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800397 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700398 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800399
Randall Spangleraaaff862014-12-01 15:40:08 -0800400UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
401ALL_OBJS += ${UTILLIB_OBJS}
402
Randall Spanglera5b69b02014-12-02 13:41:29 -0800403UTILLIB21_SRCS += \
404 host/lib21/host_fw_preamble.c \
405 host/lib21/host_key.c \
406 host/lib21/host_keyblock.c \
407 host/lib21/host_misc.c \
408 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800409
Randall Spanglera5b69b02014-12-02 13:41:29 -0800410UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
411ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700412
413# Externally exported library for some target userspace apps to link with
414# (cryptohome, updater, etc.)
415HOSTLIB = ${BUILD}/libvboot_host.a
416
417HOSTLIB_SRCS = \
418 cgpt/cgpt_add.c \
419 cgpt/cgpt_boot.c \
420 cgpt/cgpt_common.c \
421 cgpt/cgpt_create.c \
422 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700423 firmware/lib/cgptlib/cgptlib_internal.c \
424 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700425 firmware/lib/crc8.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800426 firmware/lib/gpt_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700427 firmware/lib/tpm_lite/tlcl.c \
428 firmware/lib/utility_string.c \
429 firmware/lib/vboot_nvstorage.c \
430 firmware/stub/tpm_lite_stub.c \
431 firmware/stub/utility_stub.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800432 firmware/stub/vboot_api_stub_disk.c \
Bill Richardson78299022014-06-20 14:33:00 -0700433 firmware/stub/vboot_api_stub_init.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800434 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700435 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700436 host/arch/${ARCH}/lib/crossystem_arch.c \
437 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700438 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700439 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700440
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800441HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800442ALL_OBJS += ${HOSTLIB_OBJS}
443
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800444# Sigh. For historical reasons, the autoupdate installer must sometimes be a
445# 32-bit executable, even when everything else is 64-bit. But it only needs a
446# few functions, so let's just build those.
447TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
448
449TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800450 cgpt/cgpt_add.c \
451 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800452 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700453 cgpt/cgpt_create.c \
454 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700455 firmware/lib/cgptlib/cgptlib_internal.c \
456 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800457 firmware/lib/gpt_misc.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800458 firmware/lib/utility_string.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800459 firmware/stub/vboot_api_stub_disk.c \
460 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson78299022014-06-20 14:33:00 -0700461 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800462 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800463
464TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800465
466# ----------------------------------------------------------------------------
467# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800468
469CGPT = ${BUILD}/cgpt/cgpt
470
471CGPT_SRCS = \
472 cgpt/cgpt.c \
473 cgpt/cgpt_add.c \
474 cgpt/cgpt_boot.c \
475 cgpt/cgpt_common.c \
476 cgpt/cgpt_create.c \
477 cgpt/cgpt_find.c \
478 cgpt/cgpt_legacy.c \
479 cgpt/cgpt_prioritize.c \
480 cgpt/cgpt_repair.c \
481 cgpt/cgpt_show.c \
482 cgpt/cmd_add.c \
483 cgpt/cmd_boot.c \
484 cgpt/cmd_create.c \
485 cgpt/cmd_find.c \
486 cgpt/cmd_legacy.c \
487 cgpt/cmd_prioritize.c \
488 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800489 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800490
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800491CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800492ALL_OBJS += ${CGPT_OBJS}
493
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800494# Utility defaults
495UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800496
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800497# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800498UTIL_SCRIPTS = \
499 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700500 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800501
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800502ifeq (${MINIMAL},)
503UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700504 utility/dev_make_keypair \
505 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800506endif
507
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800508# These utilities should be linked statically.
509UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700510 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800511
512UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700513 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700514 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700515 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800516
Bill Richardson6f396152014-07-15 12:52:19 -0700517# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800518ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800519UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700520 utility/bmpblk_font \
521 utility/bmpblk_utility \
522 utility/eficompress \
523 utility/efidecompress \
524 utility/load_kernel_test \
525 utility/pad_digest_utility \
526 utility/signature_digest_utility \
527 utility/verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800528endif
529
Bill Richardson339f7e02013-04-05 09:49:24 -0700530UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
531UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700532ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800533
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800534
535# Scripts for signing stuff.
536SIGNING_SCRIPTS = \
537 utility/tpm-nvsize \
538 utility/chromeos-tpm-recovery
539
540# These go in a different place.
541SIGNING_SCRIPTS_DEV = \
542 scripts/image_signing/resign_firmwarefd.sh \
543 scripts/image_signing/make_dev_firmware.sh \
544 scripts/image_signing/make_dev_ssd.sh \
545 scripts/image_signing/set_gbb_flags.sh
546
547# Installed, but not made executable.
548SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800549
Bill Richardson826db092013-01-14 12:37:15 -0800550
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800551# The unified firmware utility will eventually replace all the others
552FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700553# But we still need both static (tiny) and dynamic (with openssl) versions.
554FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800555
Bill Richardson6f396152014-07-15 12:52:19 -0700556# These are the executables that are now built in to futility. We'll create
557# symlinks for these so the old names will still work.
558# TODO: Do we still need dev_sign_file for anything?
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700559FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700560 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700561 dump_fmap \
562 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700563 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700564 vbutil_firmware \
565 vbutil_kernel \
566 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700567 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800568
Bill Richardson6db8c752013-04-05 13:30:43 -0700569FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800570 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700571 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700572 futility/cmd_gbb_utility.c \
573 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800574
Bill Richardson6db8c752013-04-05 13:30:43 -0700575FUTIL_SRCS = \
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500576 ${FUTIL_STATIC_SRCS} \
Bill Richardson6f396152014-07-15 12:52:19 -0700577 futility/cmd_dev_sign_file.c \
578 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700579 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700580 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700581 futility/cmd_show.c \
582 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700583 futility/cmd_vbutil_firmware.c \
584 futility/cmd_vbutil_kernel.c \
Bill Richardsonf1dba022014-10-01 14:10:45 -0700585 futility/cmd_vbutil_kernel0.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700586 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700587 futility/cmd_vbutil_keyblock.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700588 futility/cmd_verify_kernel.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700589 futility/traversal.c \
590 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700591
Randall Spangler028f4682014-08-19 14:42:08 -0700592ifneq (${VBOOT2},)
593FUTIL_SRCS += \
594 futility/cmd_vb2_verify_fw.c
595endif
596
Alex Deymoe08ee282014-08-29 01:07:48 -0700597# List of commands built in futility and futility_s.
598FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
599FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800600
Bill Richardson91852e72014-11-28 12:28:04 -0800601# Workaround for TODO(crbug.com/437107).
602FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
603
Alex Deymoe08ee282014-08-29 01:07:48 -0700604FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800605 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700606 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
607FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800608
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800609ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800610
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800611
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800612# Library of handy test functions.
613TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800614
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800615TESTLIB_SRCS = \
616 tests/test_common.c \
617 tests/timer_utils.c \
618 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800619
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800620TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700621TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800622
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800623
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800624# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800625TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700626 tests/cgptlib_test \
627 tests/rollback_index2_tests \
628 tests/rollback_index3_tests \
629 tests/rsa_padding_test \
630 tests/rsa_utility_tests \
631 tests/rsa_verify_benchmark \
632 tests/sha_benchmark \
633 tests/sha_tests \
634 tests/stateful_util_tests \
635 tests/tlcl_tests \
636 tests/tpm_bootmode_tests \
637 tests/utility_string_tests \
638 tests/utility_tests \
639 tests/vboot_api_init_tests \
640 tests/vboot_api_devmode_tests \
641 tests/vboot_api_firmware_tests \
642 tests/vboot_api_kernel_tests \
643 tests/vboot_api_kernel2_tests \
644 tests/vboot_api_kernel3_tests \
645 tests/vboot_api_kernel4_tests \
646 tests/vboot_audio_tests \
647 tests/vboot_common_tests \
648 tests/vboot_common2_tests \
649 tests/vboot_common3_tests \
650 tests/vboot_display_tests \
651 tests/vboot_firmware_tests \
652 tests/vboot_kernel_tests \
653 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700654 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700655 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800656
Simon Glass527ba812013-07-25 08:48:47 -0600657ifdef REGION_READ
658TEST_NAMES += tests/vboot_region_tests
659endif
660
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800661TEST2X_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700662 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700663 tests/vb2_common_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700664 tests/vb2_misc_tests \
665 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700666 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700667 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800668 tests/vb2_sha_tests
669
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800670TEST20_NAMES = \
671 tests/vb20_api_tests \
672 tests/vb20_common_tests \
673 tests/vb20_common2_tests \
674 tests/vb20_common3_tests \
675 tests/vb20_misc_tests \
676 tests/vb20_rsa_padding_tests
677
Randall Spangler108d9912014-12-02 15:55:56 -0800678TEST21_NAMES = \
679 tests/vb21_api_tests \
680 tests/vb21_common_tests \
681 tests/vb21_common2_tests \
682 tests/vb21_misc_tests \
683 tests/vb21_host_fw_preamble_tests \
684 tests/vb21_host_key_tests \
685 tests/vb21_host_keyblock_tests \
686 tests/vb21_host_misc_tests \
687 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700688
Randall Spangleraaaff862014-12-01 15:40:08 -0800689ifneq (${VBOOT2},)
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800690TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700691endif
692
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800693# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700694TLCL_TEST_NAMES = \
695 tests/tpm_lite/tpmtest_earlyextend \
696 tests/tpm_lite/tpmtest_earlynvram \
697 tests/tpm_lite/tpmtest_earlynvram2 \
698 tests/tpm_lite/tpmtest_enable \
699 tests/tpm_lite/tpmtest_fastenable \
700 tests/tpm_lite/tpmtest_globallock \
701 tests/tpm_lite/tpmtest_redefine_unowned \
702 tests/tpm_lite/tpmtest_spaceperm \
703 tests/tpm_lite/tpmtest_testsetup \
704 tests/tpm_lite/tpmtest_timing \
705 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800706
707TEST_NAMES += ${TLCL_TEST_NAMES}
708
Bill Richardson339f7e02013-04-05 09:49:24 -0700709# Finally
710TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700711TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800712
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800713TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800714TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800715TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800716
Randall Spanglere061a252013-01-22 15:34:07 -0800717# Directory containing test keys
718TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800719
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800720
721##############################################################################
722# Finally, some targets. High-level ones first.
723
724# Create output directories if necessary. Do this via explicit shell commands
725# so it happens before trying to generate/include dependencies.
726SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
727_dir_create := $(foreach d, \
728 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
729 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
730
731
732# Default target.
733.PHONY: all
Randall Spangleraaaff862014-12-01 15:40:08 -0800734all: fwlib \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800735 $(if ${VBOOT2},fwlib2x fwlib2 fwlib21) \
Randall Spangleraaaff862014-12-01 15:40:08 -0800736 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700737 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800738
739# Host targets
740.PHONY: host_stuff
Randall Spanglera5b69b02014-12-02 13:41:29 -0800741host_stuff: utillib hostlib cgpt utils futil tests $(if ${VBOOT2},utillib21)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800742
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800743.PHONY: clean
744clean:
745 ${Q}/bin/rm -rf ${BUILD}
746
747.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800748install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800749
Bill Richardson3e3790d2014-07-14 15:05:54 -0700750.PHONY: install_for_test
751install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
752install_for_test: install
753
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800754# Don't delete intermediate object files
755.SECONDARY:
756
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800757# ----------------------------------------------------------------------------
758# Firmware library
759
760# TPM-specific flags. These depend on the particular TPM we're targeting for.
761# They are needed here only for compiling parts of the firmware code into
762# user-level tests.
763
764# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
765# the self test has completed.
766
Randall Spangler45cc0f22013-01-25 09:34:26 -0800767${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800768
769# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
770# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
771# power on.
772#
773# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
774# are not both defined at the same time. (See comment in code.)
775
776# CFLAGS += -DTPM_MANUAL_SELFTEST
777
778ifeq (${FIRMWARE_ARCH},i386)
779# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800780${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler108d9912014-12-02 15:55:56 -0800781${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800782${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800783${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800784
785# Workaround for coreboot on x86, which will power off asynchronously
786# without giving us a chance to react. This is not an example of the Right
787# Way to do things. See chrome-os-partner:7689, and the commit message
788# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800789${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800790
791# On x86 we don't actually read the GBB data into RAM until it is needed.
792# Therefore it makes sense to cache it rather than reading it each time.
793# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800794${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800795endif
796
Simon Glass527ba812013-07-25 08:48:47 -0600797ifdef REGION_READ
798${FWLIB_OBJS}: CFLAGS += -DREGION_READ
799endif
800
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800801ifeq (${FIRMWARE_ARCH},)
802# Disable rollback TPM when compiling locally, since otherwise
803# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800804${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800805endif
806
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800807${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -0800808${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
809
Bill Richardsona130e0b2013-04-04 18:16:39 -0700810# Linktest ensures firmware lib doesn't rely on outside libraries
811${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800812${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700813TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700814${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800815${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700816TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700817${BUILD}/firmware/linktest/main: ${FWLIB}
818${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700819TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800820
Bill Richardsond2d08b22014-07-08 16:31:40 -0700821.PHONY: fwlinktest
822fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800823 ${BUILD}/firmware/linktest/main_vbinit \
824 ${BUILD}/firmware/linktest/main_vbsf \
825 ${BUILD}/firmware/linktest/main
826
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800827.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700828fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800829
830${FWLIB}: ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500831 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800832 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500833 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800834 ${Q}ar qc $@ $^
835
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800836.PHONY: fwlib2x
837fwlib2x: ${FWLIB2X}
838
839${FWLIB2X}: ${FWLIB2_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500840 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800841 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500842 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800843 ${Q}ar qc $@ $^
844
845# TODO: it'd be nice to call this fwlib20, but coreboot expects fwlib2
Randall Spanglera5b69b02014-12-02 13:41:29 -0800846.PHONY: fwlib2
847fwlib2: ${FWLIB20}
848
Randall Spangler108d9912014-12-02 15:55:56 -0800849${FWLIB20}: ${FWLIB2_OBJS} ${FWLIB20_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500850 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700851 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500852 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700853 ${Q}ar qc $@ $^
854
Randall Spanglera5b69b02014-12-02 13:41:29 -0800855.PHONY: fwlib21
856fwlib21: ${FWLIB21}
857
Randall Spangler108d9912014-12-02 15:55:56 -0800858${FWLIB21}: ${FWLIB2_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500859 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800860 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500861 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800862 ${Q}ar qc $@ $^
863
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800864# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700865# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800866
Bill Richardson78299022014-06-20 14:33:00 -0700867# Link tests for local utilities
868${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700869${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700870TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700871
872.PHONY: utillib
873utillib: ${UTILLIB} \
874 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800875
876# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800877${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500878 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800879 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500880 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800881 ${Q}ar qc $@ $^
882
Randall Spanglera5b69b02014-12-02 13:41:29 -0800883.PHONY: utillib21
884utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800885
Randall Spangler108d9912014-12-02 15:55:56 -0800886${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800887${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500888 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700889 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500890 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700891 ${Q}ar qc $@ $^
892
893
894# Link tests for external repos
895${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700896${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
897${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700898TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700899
900.PHONY: hostlib
901hostlib: ${HOSTLIB} \
902 ${BUILD}/host/linktest/extern
903
904# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700905${HOSTLIB}: ${HOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500906 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800907 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500908 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800909 ${Q}ar qc $@ $^
910
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800911
912# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
913.PHONY: tinyhostlib
914tinyhostlib: ${TINYHOSTLIB}
915 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
916
917${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500918 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800919 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500920 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800921 ${Q}ar qc $@ $^
922
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800923# ----------------------------------------------------------------------------
924# CGPT library and utility
925
926.PHONY: cgpt
927cgpt: ${CGPT}
928
929${CGPT}: LDFLAGS += -static
930${CGPT}: LDLIBS += -luuid
931
Bill Richardson78299022014-06-20 14:33:00 -0700932${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500933 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700934 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800935
936.PHONY: cgpt_install
937cgpt_install: ${CGPT}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500938 @${PRINTF} " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800939 ${Q}mkdir -p ${UB_DIR}
940 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800941
942# ----------------------------------------------------------------------------
943# Utilities
944
945# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700946${BUILD}/utility/%: INCLUDES += -Iutility/include
947
948${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
949${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800950
951# Utilities for auto-update toolkits must be statically linked.
952${UTIL_BINS_STATIC}: LDFLAGS += -static
953
Bill Richardsona130e0b2013-04-04 18:16:39 -0700954
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800955.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800956utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800957 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
958 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
959
960.PHONY: utils_install
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800961utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500962 @${PRINTF} " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800963 ${Q}mkdir -p ${UB_DIR}
964 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800965 ${Q}mkdir -p ${DF_DIR}
966 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800967
968# And some signing stuff for the target
969.PHONY: signing_install
970signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500971 @${PRINTF} " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700972 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800973 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700974 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
975 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800976
977# ----------------------------------------------------------------------------
978# new Firmware Utility
979
980.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700981futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
982
Randall Spangleraaaff862014-12-01 15:40:08 -0800983${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB} \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800984 $(if ${VBOOT2},${FWLIB20})
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500985 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700986 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800987
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700988${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800989${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} $(if ${VBOOT2},${FWLIB20})
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500990 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700991 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800992
993.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -0700994futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500995 @${PRINTF} " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700996 ${Q}mkdir -p ${UB_DIR}
997 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700998 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -0700999 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001000
1001# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001002# Utility to generate TLCL structure definition header file.
1003
1004${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1005
1006STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1007STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1008
1009.PHONY: update_tlcl_structures
1010update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001011 @${PRINTF} " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001012 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1013 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1014 ( echo "%% Updating structures.h %%" && \
1015 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1016
1017# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001018# Tests
1019
1020.PHONY: tests
1021tests: ${TEST_BINS}
1022
Bill Richardson78299022014-06-20 14:33:00 -07001023${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -07001024${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001025${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001026
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001027${TEST2X_BINS}: ${FWLIB2X}
1028${TEST2X_BINS}: LIBS += ${FWLIB2X}
1029
Randall Spangler108d9912014-12-02 15:55:56 -08001030${TEST20_BINS}: ${FWLIB20}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001031${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -08001032${TEST20_BINS}: LIBS += ${FWLIB20}
1033
1034${TEST21_BINS}: ${UTILLIB21}
1035${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1036${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -08001037
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001038${TESTLIB}: ${TESTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001039 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001040 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001041 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001042 ${Q}ar qc $@ $^
1043
1044
1045# ----------------------------------------------------------------------------
1046# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1047# rules for specific targets.
1048
1049${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001050 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001051 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001052
1053${BUILD}/%.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001054 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001055 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1056
Alex Deymoe08ee282014-08-29 01:07:48 -07001057${BUILD}/%.o: ${BUILD}/%.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001058 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001059 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1060
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001061# Rules to recompile a single source file for library and test
1062# TODO: is there a tidier way to do this?
1063${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1064${BUILD}/%_for_lib.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001065 @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001066 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1067
1068${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1069${BUILD}/%_for_test.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001070 @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001071 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1072
1073# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1074${BUILD}/%.o: %.cc
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001075 @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001076 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1077
1078# ----------------------------------------------------------------------------
1079# Here are the special tweaks to the generic rules.
1080
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001081# Always create the defaults file, since it depends on input variables
1082.PHONY: ${UTIL_DEFAULTS}
1083${UTIL_DEFAULTS}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001084 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001085 ${Q}rm -f $@
1086 ${Q}mkdir -p $(dir $@)
1087 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1088 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1089 ${Q}mv -f $@.tmp $@
1090
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001091# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001092CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1093
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001094${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1095${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1096${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001097
1098${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1099${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1100${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001101${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1102${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001103
1104${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001105
Mike Frysinger0b789c52015-01-15 15:37:59 -05001106LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1107YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1108
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001109${BUILD}/utility/bmpblk_utility: LD = ${CXX}
Mike Frysinger0b789c52015-01-15 15:37:59 -05001110${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001111
1112BMPBLK_UTILITY_DEPS = \
1113 ${BUILD}/utility/bmpblk_util.o \
1114 ${BUILD}/utility/image_types.o \
1115 ${BUILD}/utility/eficompress_for_lib.o \
1116 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001117
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001118${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1119${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001120ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001121
1122${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1123${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001124ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001125
1126# Allow multiple definitions, so tests can mock functions from other libraries
1127${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001128${BUILD}/tests/%: LDLIBS += -lrt -luuid
1129${BUILD}/tests/%: LIBS += ${TESTLIB}
1130
1131${BUILD}/tests/rollback_index2_tests: OBJS += \
1132 ${BUILD}/firmware/lib/rollback_index_for_test.o
1133${BUILD}/tests/rollback_index2_tests: \
1134 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001135TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001137${BUILD}/tests/tlcl_tests: OBJS += \
1138 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1139${BUILD}/tests/tlcl_tests: \
1140 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001141TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001142
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001143${BUILD}/tests/vboot_audio_tests: OBJS += \
1144 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1145${BUILD}/tests/vboot_audio_tests: \
1146 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001147TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001148
Bill Richardson339f7e02013-04-05 09:49:24 -07001149TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001150${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1151${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001152TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001153
Alex Deymoe08ee282014-08-29 01:07:48 -07001154# ----------------------------------------------------------------------------
1155# Here are the special rules that don't fit in the generic rules.
1156
1157# Generates the list of commands defined in futility by running grep in the
1158# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1159${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1160${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1161${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001162 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001163 ${Q}rm -f $@ $@_t $@_commands
1164 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001165 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001166 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1167 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001168 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001169 ${Q}echo '#define _CMD(NAME) extern const struct' \
1170 'futil_cmd_t __cmd_##NAME;' >> $@_t
1171 ${Q}cat $@_commands >> $@_t
1172 ${Q}echo '#undef _CMD' >> $@_t
1173 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1174 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1175 ${Q}cat $@_commands >> $@_t
1176 ${Q}echo '0}; /* null-terminated */' >> $@_t
1177 ${Q}echo '#undef _CMD' >> $@_t
1178 ${Q}mv $@_t $@
1179 ${Q}rm -f $@_commands
1180
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001181##############################################################################
1182# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001183
1184# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001185.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001186test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001187
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001188ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001189# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001190test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001191# Scripts don't work under qemu testing
1192# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001193test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001194endif
1195
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001196.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001197test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001198
Randall Spangler844bce52013-01-15 16:16:43 -08001199# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1200# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001201ifneq (${QEMU_ARCH},)
1202test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001203
1204.PHONY: qemu_install
1205qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001206ifeq (${SYSROOT},)
1207 $(error SYSROOT must be set to the top of the target-specific root \
1208when cross-compiling for qemu-based tests to run properly.)
1209endif
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001210 @${PRINTF} " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001211 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1212 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001213endif
1214
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001215.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001216runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001217
1218# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001219.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001220genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001221 tests/gen_test_keys.sh
1222
1223# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001224.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001225genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001226 tests/gen_fuzz_test_cases.sh
1227
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001228.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001229runbmptests: test_setup
1230 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001231 ./TestBmpBlock.py -v
1232
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001233.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001234runcgpttests: test_setup
1235 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001236
Randall Spangler844bce52013-01-15 16:16:43 -08001237.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001238runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001239 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001240 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001241 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001242 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001243 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001244 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001245 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001246ifneq (${VBOOT2},)
1247 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001248 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001249endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001250
Randall Spangler844bce52013-01-15 16:16:43 -08001251.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001252runmisctests: test_setup
1253 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001254 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001255 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1256 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1257 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001258 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001259 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1260 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1261 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1262 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001263 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001264 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1265 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001266 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1267 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1268 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001269 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001270 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1271 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1272 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001273 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001274 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001275 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001276 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001277
Randall Spangler786acda2014-05-22 13:27:07 -07001278.PHONY: run2tests
1279run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001280 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001281 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001282 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1283 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001284 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001285 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001286 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001287 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1288 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1289 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1290 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1291 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001292 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1293 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1294 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1295 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1296 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1297 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1298 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1299 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1300 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001301
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001302.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001303runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001304 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001305 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001306
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001307# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001308# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001309# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001310.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001311runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001312 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1313 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001314ifneq (${VBOOT2},)
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001315 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1316 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001317 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001318endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001319 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001320 tests/run_vbutil_tests.sh --all
1321
Bill Richardson78d59bf2014-08-27 16:17:04 -07001322# TODO: There were a number of ancient tests that hadn't been run in years.
1323# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1324# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001325
Bill Richardson78299022014-06-20 14:33:00 -07001326.PHONY: runalltests
1327runalltests: runtests runfutiltests runlongtests
1328
Randall Spangler59d75082013-01-23 09:29:54 -08001329# Code coverage
1330.PHONY: coverage_init
1331coverage_init: test_setup
1332 rm -f ${COV_INFO}*
1333 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1334
1335.PHONY: coverage_html
1336coverage_html:
1337 lcov -c -d . -b . -o ${COV_INFO}.tests
1338 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1339 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1340 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001341# Generate addtional coverage stats just for firmware subdir, because the stats
1342# for the whole project don't include subdirectory summaries. This will print
1343# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001344 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1345 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001346 -o ${COV_INFO}.firmware
1347
1348.PHONY: coverage
1349ifeq (${COV},)
1350coverage:
1351 $(error Build coverage like this: make clean && COV=1 make)
1352else
1353coverage: coverage_init runtests coverage_html
1354endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001355
1356# Include generated dependencies
1357ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001358TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1359
1360# We want to use only relative paths in cscope.files, especially since the
1361# paths inside and outside the chroot are different.
1362SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1363
1364${BUILD}/cscope.files: test_setup
1365 ${Q}rm -f $@
1366 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1367 sed -e "s/${SRCDIRPAT}//" | \
1368 egrep '\.[chS]$$' | sort | uniq > $@
1369
1370cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1371cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1372run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1373
1374.PHONY: tags TAGS xrefs
1375tags TAGS xrefs: ${BUILD}/cscope.files
1376 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1377 ${Q}$(call run_if_prog,etags,${cmd_etags})
1378 ${Q}$(call run_if_prog,ctags,${cmd_ctags})