blob: 574e96168ae29b339604c43edd8e2b3e8214ed7e [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill Richardson64ddad72014-08-29 23:49:23 -070040export SRCDIR
Mike Frysingerc8c87b32015-01-15 17:04:40 -050041BUILD = ${SRCDIR}/build
Randall Spangler844bce52013-01-15 16:16:43 -080042export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080043
Bill Richardsonc9bf3482013-02-13 14:38:29 -080044# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080045INSTALL = install
Bill Richardsonefa87562014-09-11 10:41:51 -070046DESTDIR = /usr/local
Nam T. Nguyen07d90432015-02-17 13:26:44 -080047LIBDIR ?= lib
Bill Richardsonc9bf3482013-02-13 14:38:29 -080048
Bill Richardsoncfe83a82014-12-04 11:29:57 -080049# Default values
50DEV_DEBUG_FORCE=
51
Bill Richardsonfeb25182013-03-07 12:54:29 -080052# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070053# UB_DIR = utility binary directory
Nam T. Nguyen07d90432015-02-17 13:26:44 -080054# ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080055# DF_DIR = utility defaults directory
Bill Richardson6f396152014-07-15 12:52:19 -070056# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080057ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070058# Host install just puts everything where it's told
Bill Richardsonefa87562014-09-11 10:41:51 -070059UB_DIR=${DESTDIR}/bin
Nam T. Nguyen07d90432015-02-17 13:26:44 -080060ULP_DIR=${DESTDIR}/${LIBDIR}/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080061DF_DIR=${DESTDIR}/default
Bill Richardsonefa87562014-09-11 10:41:51 -070062VB_DIR=${DESTDIR}/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080063else
Bill Richardsonefa87562014-09-11 10:41:51 -070064# Target install puts things into different places
Bill Richardson6f396152014-07-15 12:52:19 -070065UB_DIR=${DESTDIR}/usr/bin
Nam T. Nguyen07d90432015-02-17 13:26:44 -080066ULP_DIR=${DESTDIR}/usr/${LIBDIR}/pkgconfig
Bill Richardsoncfe83a82014-12-04 11:29:57 -080067DF_DIR=${DESTDIR}/etc/default
Bill Richardsonc9bf3482013-02-13 14:38:29 -080068VB_DIR=${DESTDIR}/usr/share/vboot/bin
69endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080070
Bill Richardsoneecc18f2013-01-17 15:28:17 -080071# Where to install the (exportable) executables for testing?
72TEST_INSTALL_DIR = ${BUILD}/install_for_test
73
74# Verbose? Use V=1
75ifeq (${V},)
76Q := @
77endif
78
Simon Glass661ae9e2013-03-26 11:39:21 -070079# Quiet? Use QUIET=1
Mike Frysingerc8c87b32015-01-15 17:04:40 -050080ifeq (${QUIET},)
Simon Glass661ae9e2013-03-26 11:39:21 -070081PRINTF := printf
82else
83PRINTF := :
84endif
85
Randall Spangler61a2eb32013-01-23 10:20:16 -080086# Architecture detection
87_machname := $(shell uname -m)
88HOST_ARCH ?= ${_machname}
89
90# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
91# Pick a sane target architecture if none is defined.
92ifeq (${ARCH},)
93 ARCH := ${HOST_ARCH}
94else ifeq (${ARCH},i386)
95 override ARCH := x86
96else ifeq (${ARCH},amd64)
97 override ARCH := x86_64
98endif
99
100# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
101# for a firmware target (such as u-boot or depthcharge). It must map
102# to the same consistent set of architectures as the host.
103ifeq (${FIRMWARE_ARCH},i386)
104 override FIRMWARE_ARCH := x86
105else ifeq (${FIRMWARE_ARCH},amd64)
106 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -0700107else ifeq (${FIRMWARE_ARCH},armv7)
108 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -0800109endif
110
Simon Glassb265c342011-11-16 15:09:51 -0800111# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
112# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700113#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800114# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
115# temporarily. As we are still investigating which flags are necessary for
116# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700117#
Simon Glassb265c342011-11-16 15:09:51 -0800118# As a first step, this makes the setting of CC and CFLAGS here optional, to
119# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700120#
Simon Glassb265c342011-11-16 15:09:51 -0800121# Flag ordering: arch, then -f, then -m, then -W
122DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
123COMMON_FLAGS := -nostdinc -pipe \
124 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800125 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800126
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800127# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
128ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800129CC ?= armv7a-cros-linux-gnueabi-gcc
130CFLAGS ?= -march=armv5 \
131 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700132 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800133 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800134else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800135CC ?= i686-pc-linux-gnu-gcc
136# Drop -march=i386 to permit use of SSE instructions
137CFLAGS ?= \
138 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
139 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800140 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800141 ${COMMON_FLAGS}
142else ifeq (${FIRMWARE_ARCH}, x86_64)
143CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800144 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800145else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800146# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800147CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700148CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800149endif
150
151ifneq (${DEBUG},)
152CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700153endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800154
vbendebb2b0fcc2010-07-15 15:09:47 -0700155ifeq (${DISABLE_NDEBUG},)
156CFLAGS += -DNDEBUG
157endif
158
Bill Richardsonfeb25182013-03-07 12:54:29 -0800159ifneq (${FORCE_LOGGING_ON},)
160CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
161endif
162
Randall Spangler6014c042014-07-22 14:42:58 -0700163ifneq (${PD_SYNC},)
164CFLAGS += -DPD_SYNC
165endif
166
Nam T. Nguyen07d90432015-02-17 13:26:44 -0800167# NOTE: We don't use these files but they are useful for other packages to
168# query about required compiling/linking flags.
169PC_IN_FILES = vboot_host.pc.in
170
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800171# Create / use dependency files
172CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800173
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700174ifeq (${FIRMWARE_ARCH},)
175# Creates position independent code for non firmware target.
176CFLAGS += -fPIE
177endif
178
Bill Richardson0c3ba242013-03-29 11:09:30 -0700179# These are required to access large disks and files on 32-bit systems.
180CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
181
Randall Spangler59d75082013-01-23 09:29:54 -0800182# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800183ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700184 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800185 CFLAGS += ${COV_FLAGS}
186 LDFLAGS += ${COV_FLAGS}
187 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800188endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800189
David Riley05987b12015-02-05 19:22:49 -0800190ifdef HAVE_MACOS
191 CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
192endif
193
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800194# And a few more default utilities
195LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700196CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800197PKG_CONFIG ?= pkg-config
198
Mike Frysinger0b789c52015-01-15 15:37:59 -0500199# Static?
200ifneq (${STATIC},)
201LDFLAGS += -static
202PKG_CONFIG += --static
203endif
204
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205# Determine QEMU architecture needed, if any
206ifeq (${ARCH},${HOST_ARCH})
207 # Same architecture; no need for QEMU
208 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800209else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210 # 64-bit host can run 32-bit targets directly
211 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800212else
213 QEMU_ARCH := ${ARCH}
214endif
215
216# The top of the chroot for qemu must be passed in via the SYSROOT environment
217# variable. In the Chromium OS chroot, this is done automatically by the
218# ebuild.
219
220ifeq (${QEMU_ARCH},)
221 # Path to build output for running tests is same as for building
222 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800223 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800224else
225 $(info Using qemu for testing.)
226 # Path to build output for running tests is different in the chroot
227 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800228 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800229
230 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800231 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
232 export QEMU_RUN
233
234 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800235endif
236
Randall Spanglere061a252013-01-22 15:34:07 -0800237export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800238
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800239##############################################################################
240# Now we need to describe everything we might want or need to build
241
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800242# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800243INCLUDES += \
244 -Ifirmware/include \
245 -Ifirmware/lib/include \
246 -Ifirmware/lib/cgptlib/include \
247 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700248 -Ifirmware/lib/tpm_lite/include \
249 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700250
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800251# If we're not building for a specific target, just stub out things like the
252# TPM commands and various external functions that are provided by the BIOS.
253ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700254INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800255endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800256
Bill Richardson78299022014-06-20 14:33:00 -0700257# Firmware library, used by the other firmware components (depthcharge,
258# coreboot, etc.). It doesn't need exporting to some other place; they'll build
259# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800260FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800261
Bill Richardson06eb78c2015-01-27 15:01:51 -0800262# Smaller firmware library common to all vboot 2.x, used only for
263# 1) compile-time tests of the public API or
264# 2) linking with an actual 2.0 or 2.1 implementation
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800265FWLIB2X = ${BUILD}/vboot_fw2x.a
Bill Richardson06eb78c2015-01-27 15:01:51 -0800266
267# Vboot 2.0 (deprecated - see firmware/README)
268FWLIB20 = ${BUILD}/vboot_fw20.a
269# Vboot 2.1 (not yet ready - see firmware/README)
Randall Spanglera5b69b02014-12-02 13:41:29 -0800270FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700271
Randall Spangler93943262013-02-26 11:03:57 -0800272# Firmware library sources needed by VbInit() call
273VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800274 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800275 firmware/lib/utility.c \
276 firmware/lib/vboot_api_init.c \
277 firmware/lib/vboot_common_init.c \
278 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700279 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600280 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800281
282# Additional firmware library sources needed by VbSelectFirmware() call
283VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800284 firmware/lib/cryptolib/padding.c \
285 firmware/lib/cryptolib/rsa.c \
286 firmware/lib/cryptolib/rsa_utility.c \
287 firmware/lib/cryptolib/sha1.c \
288 firmware/lib/cryptolib/sha256.c \
289 firmware/lib/cryptolib/sha512.c \
290 firmware/lib/cryptolib/sha_utility.c \
291 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800292 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800293 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600294 firmware/lib/vboot_firmware.c \
295 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800296
297# Additional firmware library sources needed by VbSelectAndLoadKernel() call
298VBSLK_SRCS = \
299 firmware/lib/cgptlib/cgptlib.c \
300 firmware/lib/cgptlib/cgptlib_internal.c \
301 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700302 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800303 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800304 firmware/lib/vboot_api_kernel.c \
305 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800306 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600307 firmware/lib/vboot_kernel.c \
308 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800309
Bill Richardson06eb78c2015-01-27 15:01:51 -0800310# Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
311FWLIB2X_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700312 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700313 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700314 firmware/2lib/2crc8.c \
315 firmware/2lib/2misc.c \
316 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700317 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700318 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700319 firmware/2lib/2sha1.c \
320 firmware/2lib/2sha256.c \
321 firmware/2lib/2sha512.c \
Daisuke Nojiri62d482e2015-01-29 14:37:25 -0800322 firmware/2lib/2sha_utility.c \
323 firmware/2lib/2tpm_bootmode.c
Randall Spanglera5b69b02014-12-02 13:41:29 -0800324
Randall Spangler108d9912014-12-02 15:55:56 -0800325FWLIB20_SRCS = \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800326 firmware/lib20/api.c \
327 firmware/lib20/common.c \
328 firmware/lib20/misc.c \
329 firmware/lib20/packed_key.c
Randall Spangler108d9912014-12-02 15:55:56 -0800330
Randall Spanglera5b69b02014-12-02 13:41:29 -0800331FWLIB21_SRCS = \
332 firmware/lib21/api.c \
333 firmware/lib21/common.c \
334 firmware/lib21/misc.c \
335 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700336
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800337# Support real TPM unless BIOS sets MOCK_TPM
338ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800339VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800340 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800341 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800342
343VBSF_SRCS += \
344 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800345else
Randall Spangler93943262013-02-26 11:03:57 -0800346VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800347 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800348 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800349
350VBSF_SRCS += \
351 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800352endif
353
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800354ifeq (${FIRMWARE_ARCH},)
355# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800356# TODO: split out other stub funcs too
357VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800358 firmware/stub/tpm_lite_stub.c \
359 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600360 firmware/stub/vboot_api_stub_init.c \
361 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800362
363VBSF_SRCS += \
364 firmware/stub/vboot_api_stub_sf.c
365
366VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800367 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700368 firmware/stub/vboot_api_stub_disk.c \
369 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700370
Bill Richardson06eb78c2015-01-27 15:01:51 -0800371FWLIB2X_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700372 firmware/2lib/2stub.c
373
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800374endif
375
Randall Spangler93943262013-02-26 11:03:57 -0800376VBSF_SRCS += ${VBINIT_SRCS}
377FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
378
379VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
380VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800381ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800382
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800383FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800384FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800385FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800386FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Bill Richardson06eb78c2015-01-27 15:01:51 -0800387ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800388
Bill Richardson78299022014-06-20 14:33:00 -0700389# Intermediate library for the vboot_reference utilities to link against.
390UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800391UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800392
Bill Richardson78299022014-06-20 14:33:00 -0700393UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800394 cgpt/cgpt_create.c \
395 cgpt/cgpt_add.c \
396 cgpt/cgpt_boot.c \
397 cgpt/cgpt_show.c \
398 cgpt/cgpt_repair.c \
399 cgpt/cgpt_prioritize.c \
400 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700401 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800402 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800403 host/lib/crossystem.c \
404 host/lib/file_keys.c \
405 host/lib/fmap.c \
406 host/lib/host_common.c \
407 host/lib/host_key.c \
408 host/lib/host_keyblock.c \
409 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700410 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800411 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700412 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800413
Randall Spangleraaaff862014-12-01 15:40:08 -0800414UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
415ALL_OBJS += ${UTILLIB_OBJS}
416
Randall Spanglera5b69b02014-12-02 13:41:29 -0800417UTILLIB21_SRCS += \
418 host/lib21/host_fw_preamble.c \
419 host/lib21/host_key.c \
420 host/lib21/host_keyblock.c \
421 host/lib21/host_misc.c \
422 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800423
Randall Spanglera5b69b02014-12-02 13:41:29 -0800424UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
425ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700426
427# Externally exported library for some target userspace apps to link with
428# (cryptohome, updater, etc.)
429HOSTLIB = ${BUILD}/libvboot_host.a
430
431HOSTLIB_SRCS = \
432 cgpt/cgpt_add.c \
433 cgpt/cgpt_boot.c \
434 cgpt/cgpt_common.c \
435 cgpt/cgpt_create.c \
436 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700437 firmware/lib/cgptlib/cgptlib_internal.c \
438 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700439 firmware/lib/crc8.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800440 firmware/lib/gpt_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700441 firmware/lib/tpm_lite/tlcl.c \
442 firmware/lib/utility_string.c \
443 firmware/lib/vboot_nvstorage.c \
444 firmware/stub/tpm_lite_stub.c \
445 firmware/stub/utility_stub.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800446 firmware/stub/vboot_api_stub_disk.c \
Bill Richardson78299022014-06-20 14:33:00 -0700447 firmware/stub/vboot_api_stub_init.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800448 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700449 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700450 host/arch/${ARCH}/lib/crossystem_arch.c \
451 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700452 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700453 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700454
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800455HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800456ALL_OBJS += ${HOSTLIB_OBJS}
457
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800458# Sigh. For historical reasons, the autoupdate installer must sometimes be a
459# 32-bit executable, even when everything else is 64-bit. But it only needs a
460# few functions, so let's just build those.
461TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
462
463TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800464 cgpt/cgpt_add.c \
465 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800466 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700467 cgpt/cgpt_create.c \
468 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700469 firmware/lib/cgptlib/cgptlib_internal.c \
470 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800471 firmware/lib/gpt_misc.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800472 firmware/lib/utility_string.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800473 firmware/stub/vboot_api_stub_disk.c \
474 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson78299022014-06-20 14:33:00 -0700475 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800476 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800477
478TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800479
480# ----------------------------------------------------------------------------
481# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800482
483CGPT = ${BUILD}/cgpt/cgpt
484
485CGPT_SRCS = \
486 cgpt/cgpt.c \
487 cgpt/cgpt_add.c \
488 cgpt/cgpt_boot.c \
489 cgpt/cgpt_common.c \
490 cgpt/cgpt_create.c \
491 cgpt/cgpt_find.c \
492 cgpt/cgpt_legacy.c \
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800493 cgpt/cgpt_nor.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800494 cgpt/cgpt_prioritize.c \
495 cgpt/cgpt_repair.c \
496 cgpt/cgpt_show.c \
497 cgpt/cmd_add.c \
498 cgpt/cmd_boot.c \
499 cgpt/cmd_create.c \
500 cgpt/cmd_find.c \
501 cgpt/cmd_legacy.c \
502 cgpt/cmd_prioritize.c \
503 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800504 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800505
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800506CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800507
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800508ALL_OBJS += ${CGPT_OBJS}
509
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800510CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
511
512CGPT_WRAPPER_SRCS = \
513 cgpt/cgpt_nor.c \
514 cgpt/cgpt_wrapper.c
515
516CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
517
518ALL_OBJS += ${CGPT_WRAPPER_OBJS}
519
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800520# Utility defaults
521UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800522
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800523# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800524UTIL_SCRIPTS = \
525 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700526 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800527
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800528ifeq (${MINIMAL},)
529UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700530 utility/dev_make_keypair \
531 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800532endif
533
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800534# These utilities should be linked statically.
535UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700536 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800537
538UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700539 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700540 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700541 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800542
Bill Richardson6f396152014-07-15 12:52:19 -0700543# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800544ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800545UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700546 utility/bmpblk_font \
547 utility/bmpblk_utility \
548 utility/eficompress \
549 utility/efidecompress \
550 utility/load_kernel_test \
551 utility/pad_digest_utility \
552 utility/signature_digest_utility \
553 utility/verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800554endif
555
Bill Richardson339f7e02013-04-05 09:49:24 -0700556UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
557UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700558ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800559
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800560
561# Scripts for signing stuff.
562SIGNING_SCRIPTS = \
563 utility/tpm-nvsize \
564 utility/chromeos-tpm-recovery
565
566# These go in a different place.
567SIGNING_SCRIPTS_DEV = \
568 scripts/image_signing/resign_firmwarefd.sh \
569 scripts/image_signing/make_dev_firmware.sh \
570 scripts/image_signing/make_dev_ssd.sh \
571 scripts/image_signing/set_gbb_flags.sh
572
573# Installed, but not made executable.
574SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800575
Bill Richardson826db092013-01-14 12:37:15 -0800576
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800577# The unified firmware utility will eventually replace all the others
578FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700579# But we still need both static (tiny) and dynamic (with openssl) versions.
580FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800581
Bill Richardson6f396152014-07-15 12:52:19 -0700582# These are the executables that are now built in to futility. We'll create
583# symlinks for these so the old names will still work.
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700584FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700585 dump_fmap \
586 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700587 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700588 vbutil_firmware \
589 vbutil_kernel \
590 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700591 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800592
Bill Richardson6db8c752013-04-05 13:30:43 -0700593FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800594 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700595 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700596 futility/cmd_gbb_utility.c \
597 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800598
Bill Richardson6db8c752013-04-05 13:30:43 -0700599FUTIL_SRCS = \
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500600 ${FUTIL_STATIC_SRCS} \
Bill Richardson6f396152014-07-15 12:52:19 -0700601 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700602 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700603 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700604 futility/cmd_show.c \
605 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700606 futility/cmd_vbutil_firmware.c \
607 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700608 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700609 futility/cmd_vbutil_keyblock.c \
Bill Richardson25593382015-01-30 12:22:28 -0800610 futility/file_type.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700611 futility/traversal.c \
612 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700613
Alex Deymoe08ee282014-08-29 01:07:48 -0700614# List of commands built in futility and futility_s.
615FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
616FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800617
Bill Richardson91852e72014-11-28 12:28:04 -0800618# Workaround for TODO(crbug.com/437107).
619FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
620
Alex Deymoe08ee282014-08-29 01:07:48 -0700621FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800622 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700623 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
624FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800625
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800626ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800627
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800628
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800629# Library of handy test functions.
630TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800631
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800632TESTLIB_SRCS = \
633 tests/test_common.c \
634 tests/timer_utils.c \
635 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800636
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800637TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700638TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800639
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800640
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800641# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800642TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700643 tests/cgptlib_test \
644 tests/rollback_index2_tests \
645 tests/rollback_index3_tests \
646 tests/rsa_padding_test \
647 tests/rsa_utility_tests \
648 tests/rsa_verify_benchmark \
649 tests/sha_benchmark \
650 tests/sha_tests \
651 tests/stateful_util_tests \
652 tests/tlcl_tests \
653 tests/tpm_bootmode_tests \
654 tests/utility_string_tests \
655 tests/utility_tests \
656 tests/vboot_api_init_tests \
657 tests/vboot_api_devmode_tests \
658 tests/vboot_api_firmware_tests \
659 tests/vboot_api_kernel_tests \
660 tests/vboot_api_kernel2_tests \
661 tests/vboot_api_kernel3_tests \
662 tests/vboot_api_kernel4_tests \
663 tests/vboot_audio_tests \
664 tests/vboot_common_tests \
665 tests/vboot_common2_tests \
666 tests/vboot_common3_tests \
667 tests/vboot_display_tests \
668 tests/vboot_firmware_tests \
669 tests/vboot_kernel_tests \
670 tests/vboot_nvstorage_test \
Bill Richardsona77541f2014-12-04 19:06:35 -0800671 tests/verify_kernel \
Bill Richardson6f396152014-07-15 12:52:19 -0700672 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700673 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800674
Simon Glass527ba812013-07-25 08:48:47 -0600675ifdef REGION_READ
676TEST_NAMES += tests/vboot_region_tests
677endif
678
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800679TEST2X_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700680 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700681 tests/vb2_common_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700682 tests/vb2_misc_tests \
683 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700684 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700685 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800686 tests/vb2_sha_tests
687
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800688TEST20_NAMES = \
689 tests/vb20_api_tests \
690 tests/vb20_common_tests \
691 tests/vb20_common2_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800692 tests/vb20_verify_fw.c \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800693 tests/vb20_common3_tests \
694 tests/vb20_misc_tests \
Bill Richardson5fb14632015-01-27 13:59:35 -0800695 tests/vb20_rsa_padding_tests \
696 tests/vb20_verify_fw
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800697
Randall Spangler108d9912014-12-02 15:55:56 -0800698TEST21_NAMES = \
699 tests/vb21_api_tests \
700 tests/vb21_common_tests \
701 tests/vb21_common2_tests \
702 tests/vb21_misc_tests \
703 tests/vb21_host_fw_preamble_tests \
704 tests/vb21_host_key_tests \
705 tests/vb21_host_keyblock_tests \
706 tests/vb21_host_misc_tests \
707 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700708
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800709TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700710
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800711# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700712TLCL_TEST_NAMES = \
713 tests/tpm_lite/tpmtest_earlyextend \
714 tests/tpm_lite/tpmtest_earlynvram \
715 tests/tpm_lite/tpmtest_earlynvram2 \
716 tests/tpm_lite/tpmtest_enable \
717 tests/tpm_lite/tpmtest_fastenable \
718 tests/tpm_lite/tpmtest_globallock \
719 tests/tpm_lite/tpmtest_redefine_unowned \
720 tests/tpm_lite/tpmtest_spaceperm \
721 tests/tpm_lite/tpmtest_testsetup \
722 tests/tpm_lite/tpmtest_timing \
723 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800724
725TEST_NAMES += ${TLCL_TEST_NAMES}
726
Bill Richardson339f7e02013-04-05 09:49:24 -0700727# Finally
728TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700729TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800730
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800731TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800732TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800733TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800734
Randall Spanglere061a252013-01-22 15:34:07 -0800735# Directory containing test keys
736TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800737
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800738
739##############################################################################
740# Finally, some targets. High-level ones first.
741
742# Create output directories if necessary. Do this via explicit shell commands
743# so it happens before trying to generate/include dependencies.
744SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
745_dir_create := $(foreach d, \
746 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
747 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
748
749
750# Default target.
751.PHONY: all
Bill Richardson06eb78c2015-01-27 15:01:51 -0800752all: fwlib fwlib2x fwlib20 fwlib21 \
Randall Spangleraaaff862014-12-01 15:40:08 -0800753 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700754 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800755
756# Host targets
757.PHONY: host_stuff
Bill Richardson06eb78c2015-01-27 15:01:51 -0800758host_stuff: utillib hostlib cgpt utils futil tests utillib21
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800759
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800760.PHONY: clean
761clean:
762 ${Q}/bin/rm -rf ${BUILD}
763
764.PHONY: install
Nam T. Nguyen07d90432015-02-17 13:26:44 -0800765install: cgpt_install utils_install signing_install futil_install \
766 pc_files_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800767
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800768.PHONY: install_mtd
769install_mtd: install cgpt_wrapper_install
770
Bill Richardson3e3790d2014-07-14 15:05:54 -0700771.PHONY: install_for_test
772install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
773install_for_test: install
774
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800775# Don't delete intermediate object files
776.SECONDARY:
777
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800778# ----------------------------------------------------------------------------
779# Firmware library
780
781# TPM-specific flags. These depend on the particular TPM we're targeting for.
782# They are needed here only for compiling parts of the firmware code into
783# user-level tests.
784
785# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
786# the self test has completed.
787
Randall Spangler45cc0f22013-01-25 09:34:26 -0800788${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800789
790# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
791# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
792# power on.
793#
794# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
795# are not both defined at the same time. (See comment in code.)
796
797# CFLAGS += -DTPM_MANUAL_SELFTEST
798
799ifeq (${FIRMWARE_ARCH},i386)
800# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800801${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardson06eb78c2015-01-27 15:01:51 -0800802${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800803${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800804${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800805
806# Workaround for coreboot on x86, which will power off asynchronously
807# without giving us a chance to react. This is not an example of the Right
808# Way to do things. See chrome-os-partner:7689, and the commit message
809# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800810${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800811
812# On x86 we don't actually read the GBB data into RAM until it is needed.
813# Therefore it makes sense to cache it rather than reading it each time.
814# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800815${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800816endif
817
Simon Glass527ba812013-07-25 08:48:47 -0600818ifdef REGION_READ
819${FWLIB_OBJS}: CFLAGS += -DREGION_READ
820endif
821
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800822ifeq (${FIRMWARE_ARCH},)
823# Disable rollback TPM when compiling locally, since otherwise
824# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800825${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800826endif
827
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800828${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -0800829${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
830
Bill Richardsona130e0b2013-04-04 18:16:39 -0700831# Linktest ensures firmware lib doesn't rely on outside libraries
832${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800833${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700834TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700835${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800836${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700837TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700838${BUILD}/firmware/linktest/main: ${FWLIB}
839${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700840TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800841
Bill Richardsond2d08b22014-07-08 16:31:40 -0700842.PHONY: fwlinktest
843fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800844 ${BUILD}/firmware/linktest/main_vbinit \
845 ${BUILD}/firmware/linktest/main_vbsf \
846 ${BUILD}/firmware/linktest/main
847
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800848.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700849fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800850
851${FWLIB}: ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500852 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800853 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500854 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800855 ${Q}ar qc $@ $^
856
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800857.PHONY: fwlib2x
858fwlib2x: ${FWLIB2X}
859
Bill Richardson06eb78c2015-01-27 15:01:51 -0800860${FWLIB2X}: ${FWLIB2X_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500861 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800862 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500863 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800864 ${Q}ar qc $@ $^
865
Bill Richardson06eb78c2015-01-27 15:01:51 -0800866.PHONY: fwlib20
867fwlib20: ${FWLIB20}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800868
Bill Richardson06eb78c2015-01-27 15:01:51 -0800869${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500870 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700871 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500872 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangler786acda2014-05-22 13:27:07 -0700873 ${Q}ar qc $@ $^
874
Randall Spanglera5b69b02014-12-02 13:41:29 -0800875.PHONY: fwlib21
876fwlib21: ${FWLIB21}
877
Bill Richardson06eb78c2015-01-27 15:01:51 -0800878${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500879 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800880 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500881 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spanglera5b69b02014-12-02 13:41:29 -0800882 ${Q}ar qc $@ $^
883
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800884# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700885# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800886
Bill Richardson78299022014-06-20 14:33:00 -0700887# Link tests for local utilities
888${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700889${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700890TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700891
892.PHONY: utillib
893utillib: ${UTILLIB} \
894 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800895
896# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800897${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500898 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800899 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500900 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Randall Spangleraaaff862014-12-01 15:40:08 -0800901 ${Q}ar qc $@ $^
902
Randall Spanglera5b69b02014-12-02 13:41:29 -0800903.PHONY: utillib21
904utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800905
Randall Spangler108d9912014-12-02 15:55:56 -0800906${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Bill Richardson06eb78c2015-01-27 15:01:51 -0800907${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500908 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700909 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500910 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson78299022014-06-20 14:33:00 -0700911 ${Q}ar qc $@ $^
912
913
914# Link tests for external repos
915${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700916${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
917${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700918TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700919
920.PHONY: hostlib
921hostlib: ${HOSTLIB} \
922 ${BUILD}/host/linktest/extern
923
924# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700925${HOSTLIB}: ${HOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500926 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800927 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500928 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800929 ${Q}ar qc $@ $^
930
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800931
932# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
933.PHONY: tinyhostlib
934tinyhostlib: ${TINYHOSTLIB}
935 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
936
937${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500938 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800939 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500940 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800941 ${Q}ar qc $@ $^
942
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800943# ----------------------------------------------------------------------------
944# CGPT library and utility
945
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800946.PHONY: cgpt_wrapper
947cgpt_wrapper: ${CGPT_WRAPPER}
948
949${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
950 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
951 ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
952
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800953.PHONY: cgpt
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800954cgpt: ${CGPT} ${CGPT_WRAPPER}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800955
956${CGPT}: LDFLAGS += -static
957${CGPT}: LDLIBS += -luuid
958
Bill Richardson78299022014-06-20 14:33:00 -0700959${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500960 @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700961 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800962
963.PHONY: cgpt_install
964cgpt_install: ${CGPT}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500965 @${PRINTF} " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800966 ${Q}mkdir -p ${UB_DIR}
967 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800968
Nam T. Nguyend1236e42015-01-08 11:43:27 -0800969.PHONY: cgpt_wrapper_install
970cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
971 @$(PRINTF) " INSTALL cgpt_wrapper\n"
972 ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
973 ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
974 ${UB_DIR}/$(notdir ${CGPT}).bin
975 ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
976 ${UB_DIR}/$(notdir ${CGPT})
977
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800978# ----------------------------------------------------------------------------
979# Utilities
980
981# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700982${BUILD}/utility/%: INCLUDES += -Iutility/include
983
984${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
985${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800986
987# Utilities for auto-update toolkits must be statically linked.
988${UTIL_BINS_STATIC}: LDFLAGS += -static
989
Bill Richardsona130e0b2013-04-04 18:16:39 -0700990
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800991.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800992utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800993 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
994 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
995
996.PHONY: utils_install
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800997utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -0500998 @${PRINTF} " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800999 ${Q}mkdir -p ${UB_DIR}
1000 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001001 ${Q}mkdir -p ${DF_DIR}
1002 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001003
1004# And some signing stuff for the target
1005.PHONY: signing_install
1006signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001007 @${PRINTF} " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -07001008 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -08001009 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -07001010 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1011 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001012
1013# ----------------------------------------------------------------------------
1014# new Firmware Utility
1015
1016.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -07001017futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1018
Bill Richardson06eb78c2015-01-27 15:01:51 -08001019${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001020 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001021 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001022
Bill Richardsonb84b81d2014-07-14 14:48:31 -07001023${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson06eb78c2015-01-27 15:01:51 -08001024${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001025 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001026 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001027
1028.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -07001029futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001030 @${PRINTF} " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -07001031 ${Q}mkdir -p ${UB_DIR}
1032 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -07001033 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -07001034 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001035
1036# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001037# Utility to generate TLCL structure definition header file.
1038
1039${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1040
1041STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1042STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1043
1044.PHONY: update_tlcl_structures
1045update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001046 @${PRINTF} " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001047 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1048 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1049 ( echo "%% Updating structures.h %%" && \
1050 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1051
1052# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001053# Tests
1054
1055.PHONY: tests
1056tests: ${TEST_BINS}
1057
Bill Richardson78299022014-06-20 14:33:00 -07001058${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -07001059${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001060${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001061
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001062${TEST2X_BINS}: ${FWLIB2X}
1063${TEST2X_BINS}: LIBS += ${FWLIB2X}
1064
Randall Spangler108d9912014-12-02 15:55:56 -08001065${TEST20_BINS}: ${FWLIB20}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001066${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -08001067${TEST20_BINS}: LIBS += ${FWLIB20}
1068
1069${TEST21_BINS}: ${UTILLIB21}
1070${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1071${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -08001072
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001073${TESTLIB}: ${TESTLIB_OBJS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001074 @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001075 ${Q}rm -f $@
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001076 @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001077 ${Q}ar qc $@ $^
1078
1079
1080# ----------------------------------------------------------------------------
1081# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1082# rules for specific targets.
1083
1084${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001085 @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001086 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001087
1088${BUILD}/%.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001089 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001090 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1091
Alex Deymoe08ee282014-08-29 01:07:48 -07001092${BUILD}/%.o: ${BUILD}/%.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001093 @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001094 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1095
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001096# Rules to recompile a single source file for library and test
1097# TODO: is there a tidier way to do this?
1098${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1099${BUILD}/%_for_lib.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001100 @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001101 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1102
1103${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1104${BUILD}/%_for_test.o: %.c
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001105 @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001106 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1107
1108# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1109${BUILD}/%.o: %.cc
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001110 @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001111 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1112
1113# ----------------------------------------------------------------------------
1114# Here are the special tweaks to the generic rules.
1115
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001116# Always create the defaults file, since it depends on input variables
1117.PHONY: ${UTIL_DEFAULTS}
1118${UTIL_DEFAULTS}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001119 @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001120 ${Q}rm -f $@
1121 ${Q}mkdir -p $(dir $@)
1122 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1123 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1124 ${Q}mv -f $@.tmp $@
1125
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001126# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001127CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1128
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001129${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1130${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1131${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001132
1133${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1134${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1135${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001136${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1137${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsona77541f2014-12-04 19:06:35 -08001138${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001139
1140${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001141
Mike Frysinger0b789c52015-01-15 15:37:59 -05001142LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
1143YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
1144
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001145${BUILD}/utility/bmpblk_utility: LD = ${CXX}
Mike Frysinger0b789c52015-01-15 15:37:59 -05001146${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001147
1148BMPBLK_UTILITY_DEPS = \
1149 ${BUILD}/utility/bmpblk_util.o \
1150 ${BUILD}/utility/image_types.o \
1151 ${BUILD}/utility/eficompress_for_lib.o \
1152 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001153
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001154${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1155${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001156ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001157
1158${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1159${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001160ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001161
1162# Allow multiple definitions, so tests can mock functions from other libraries
1163${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001164${BUILD}/tests/%: LDLIBS += -lrt -luuid
1165${BUILD}/tests/%: LIBS += ${TESTLIB}
1166
1167${BUILD}/tests/rollback_index2_tests: OBJS += \
1168 ${BUILD}/firmware/lib/rollback_index_for_test.o
1169${BUILD}/tests/rollback_index2_tests: \
1170 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001171TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001172
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001173${BUILD}/tests/tlcl_tests: OBJS += \
1174 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1175${BUILD}/tests/tlcl_tests: \
1176 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001177TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001178
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001179${BUILD}/tests/vboot_audio_tests: OBJS += \
1180 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1181${BUILD}/tests/vboot_audio_tests: \
1182 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001183TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001184
Bill Richardson339f7e02013-04-05 09:49:24 -07001185TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001186${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1187${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001188TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001189
Alex Deymoe08ee282014-08-29 01:07:48 -07001190# ----------------------------------------------------------------------------
1191# Here are the special rules that don't fit in the generic rules.
1192
1193# Generates the list of commands defined in futility by running grep in the
1194# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1195${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1196${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1197${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001198 @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
Alex Deymoe08ee282014-08-29 01:07:48 -07001199 ${Q}rm -f $@ $@_t $@_commands
1200 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001201 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001202 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1203 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001204 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001205 ${Q}echo '#define _CMD(NAME) extern const struct' \
1206 'futil_cmd_t __cmd_##NAME;' >> $@_t
1207 ${Q}cat $@_commands >> $@_t
1208 ${Q}echo '#undef _CMD' >> $@_t
1209 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1210 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1211 ${Q}cat $@_commands >> $@_t
1212 ${Q}echo '0}; /* null-terminated */' >> $@_t
1213 ${Q}echo '#undef _CMD' >> $@_t
1214 ${Q}mv $@_t $@
1215 ${Q}rm -f $@_commands
1216
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001217##############################################################################
1218# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001219
1220# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001221.PHONY: test_targets
Bill Richardson06eb78c2015-01-27 15:01:51 -08001222test_targets:: runcgpttests runmisctests run2tests
Randall Spangler844bce52013-01-15 16:16:43 -08001223
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001224ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001225# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001226test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001227# Scripts don't work under qemu testing
1228# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001229test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001230endif
1231
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001232.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001233test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001234
Randall Spangler844bce52013-01-15 16:16:43 -08001235# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1236# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001237ifneq (${QEMU_ARCH},)
1238test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001239
1240.PHONY: qemu_install
1241qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001242ifeq (${SYSROOT},)
1243 $(error SYSROOT must be set to the top of the target-specific root \
1244when cross-compiling for qemu-based tests to run properly.)
1245endif
Mike Frysingerc8c87b32015-01-15 17:04:40 -05001246 @${PRINTF} " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001247 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1248 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001249endif
1250
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001251.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001252runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001253
1254# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001255.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001256genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001257 tests/gen_test_keys.sh
1258
1259# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001260.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001261genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001262 tests/gen_fuzz_test_cases.sh
1263
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001264.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001265runbmptests: test_setup
1266 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001267 ./TestBmpBlock.py -v
1268
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001269.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001270runcgpttests: test_setup
1271 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001272
Randall Spangler844bce52013-01-15 16:16:43 -08001273.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001274runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001275 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001276 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001277 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001278 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001279 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001280 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001281 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001282 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001283 tests/vb2_firmware_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001284
Randall Spangler844bce52013-01-15 16:16:43 -08001285.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001286runmisctests: test_setup
1287 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001288 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001289 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1290 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1291 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001292 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001293 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1294 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1295 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1296 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001297 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001298 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1299 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001300 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1301 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1302 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001303 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001304 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1305 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1306 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001307 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001308 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001309 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001310 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001311
Randall Spangler786acda2014-05-22 13:27:07 -07001312.PHONY: run2tests
1313run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001314 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001315 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001316 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1317 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001318 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001319 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001320 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001321 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1322 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1323 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1324 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1325 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001326 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1327 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1328 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1329 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1330 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1331 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1332 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1333 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1334 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001335
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001336.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001337runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001338 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001339 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001340
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001341# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001342# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001343# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001344.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001345runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001346 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1347 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001348 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1349 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001350 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001351 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001352 tests/run_vbutil_tests.sh --all
1353
Bill Richardson78d59bf2014-08-27 16:17:04 -07001354# TODO: There were a number of ancient tests that hadn't been run in years.
1355# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1356# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001357
Bill Richardson78299022014-06-20 14:33:00 -07001358.PHONY: runalltests
1359runalltests: runtests runfutiltests runlongtests
1360
Randall Spangler59d75082013-01-23 09:29:54 -08001361# Code coverage
1362.PHONY: coverage_init
1363coverage_init: test_setup
1364 rm -f ${COV_INFO}*
1365 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1366
1367.PHONY: coverage_html
1368coverage_html:
1369 lcov -c -d . -b . -o ${COV_INFO}.tests
1370 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1371 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1372 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001373# Generate addtional coverage stats just for firmware subdir, because the stats
1374# for the whole project don't include subdirectory summaries. This will print
1375# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001376 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1377 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001378 -o ${COV_INFO}.firmware
1379
1380.PHONY: coverage
1381ifeq (${COV},)
1382coverage:
1383 $(error Build coverage like this: make clean && COV=1 make)
1384else
1385coverage: coverage_init runtests coverage_html
1386endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001387
1388# Include generated dependencies
1389ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001390TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
Bill Richardson04d98e32015-01-31 01:14:39 -08001391-include ${ALL_DEPS}
1392-include ${TEST_DEPS}
Bill Richardson80872db2014-10-03 10:26:11 -07001393
1394# We want to use only relative paths in cscope.files, especially since the
1395# paths inside and outside the chroot are different.
1396SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1397
Bill Richardson8db64da2015-01-29 21:46:58 -08001398# Note: vboot 2.0 is deprecated, so don't index those files
Bill Richardson80872db2014-10-03 10:26:11 -07001399${BUILD}/cscope.files: test_setup
1400 ${Q}rm -f $@
1401 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
Bill Richardson8db64da2015-01-29 21:46:58 -08001402 grep -v /lib20/ | \
Bill Richardson80872db2014-10-03 10:26:11 -07001403 sed -e "s/${SRCDIRPAT}//" | \
1404 egrep '\.[chS]$$' | sort | uniq > $@
1405
1406cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1407cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1408run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1409
1410.PHONY: tags TAGS xrefs
1411tags TAGS xrefs: ${BUILD}/cscope.files
1412 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1413 ${Q}$(call run_if_prog,etags,${cmd_etags})
1414 ${Q}$(call run_if_prog,ctags,${cmd_ctags})
Nam T. Nguyen07d90432015-02-17 13:26:44 -08001415
1416PC_FILES = ${PC_IN_FILES:%.pc.in=%.pc}
1417${PC_FILES}: ${PC_IN_FILES}
1418 ${Q}sed \
1419 -e 's:@LDLIBS@:${LDLIBS}:' \
1420 -e 's:@LIBDIR@:${LIBDIR}:' \
1421 $< > $@
1422
1423.PHONY: pc_files_install
1424pc_files_install: ${PC_FILES}
1425 ${Q}mkdir -p ${ULP_DIR}
1426 ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$<