blob: 77127ded9d40d7a0ec8a5a500e77a90c9498d5e4 [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
Bill Richardsonfeb25182013-03-07 12:54:29 -080041BUILD = $(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
76ifeq ($(QUIET),)
77PRINTF := 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
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800187# Determine QEMU architecture needed, if any
188ifeq (${ARCH},${HOST_ARCH})
189 # Same architecture; no need for QEMU
190 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800191else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800192 # 64-bit host can run 32-bit targets directly
193 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800194else
195 QEMU_ARCH := ${ARCH}
196endif
197
198# The top of the chroot for qemu must be passed in via the SYSROOT environment
199# variable. In the Chromium OS chroot, this is done automatically by the
200# ebuild.
201
202ifeq (${QEMU_ARCH},)
203 # Path to build output for running tests is same as for building
204 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800205 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800206else
207 $(info Using qemu for testing.)
208 # Path to build output for running tests is different in the chroot
209 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800210 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800211
212 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800213 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
214 export QEMU_RUN
215
216 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800217endif
218
Randall Spanglere061a252013-01-22 15:34:07 -0800219export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800220
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800221##############################################################################
222# Now we need to describe everything we might want or need to build
223
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800224# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800225INCLUDES += \
226 -Ifirmware/include \
227 -Ifirmware/lib/include \
228 -Ifirmware/lib/cgptlib/include \
229 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700230 -Ifirmware/lib/tpm_lite/include \
231 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700232
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800233# If we're not building for a specific target, just stub out things like the
234# TPM commands and various external functions that are provided by the BIOS.
235ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700236INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800237endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800238
Bill Richardson78299022014-06-20 14:33:00 -0700239# Firmware library, used by the other firmware components (depthcharge,
240# coreboot, etc.). It doesn't need exporting to some other place; they'll build
241# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800242FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800243
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800244# Smaller firmware library
245# Stuff common to all vboot 2.x
246FWLIB2X = ${BUILD}/vboot_fw2x.a
247# Vboot 2.0 (stuck with this filename due to dependencies in coreboot)
Randall Spangleraaaff862014-12-01 15:40:08 -0800248FWLIB20 = ${BUILD}/vboot_fw2.a
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800249# Vboot 2.1
Randall Spanglera5b69b02014-12-02 13:41:29 -0800250FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700251
Randall Spangler93943262013-02-26 11:03:57 -0800252# Firmware library sources needed by VbInit() call
253VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800254 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800255 firmware/lib/utility.c \
256 firmware/lib/vboot_api_init.c \
257 firmware/lib/vboot_common_init.c \
258 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700259 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600260 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800261
262# Additional firmware library sources needed by VbSelectFirmware() call
263VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800264 firmware/lib/cryptolib/padding.c \
265 firmware/lib/cryptolib/rsa.c \
266 firmware/lib/cryptolib/rsa_utility.c \
267 firmware/lib/cryptolib/sha1.c \
268 firmware/lib/cryptolib/sha256.c \
269 firmware/lib/cryptolib/sha512.c \
270 firmware/lib/cryptolib/sha_utility.c \
271 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800272 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800273 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600274 firmware/lib/vboot_firmware.c \
275 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800276
277# Additional firmware library sources needed by VbSelectAndLoadKernel() call
278VBSLK_SRCS = \
279 firmware/lib/cgptlib/cgptlib.c \
280 firmware/lib/cgptlib/cgptlib_internal.c \
281 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700282 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800283 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800284 firmware/lib/vboot_api_kernel.c \
285 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800286 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600287 firmware/lib/vboot_kernel.c \
288 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800289
Randall Spangler786acda2014-05-22 13:27:07 -0700290# Firmware library source needed for smaller library 2
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800291# Code common to vboot 2.0 (old structs) and 2.1 (new structs)
Randall Spangler108d9912014-12-02 15:55:56 -0800292FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700293 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700294 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700295 firmware/2lib/2crc8.c \
296 firmware/2lib/2misc.c \
297 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700298 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700299 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700300 firmware/2lib/2sha1.c \
301 firmware/2lib/2sha256.c \
302 firmware/2lib/2sha512.c \
Randall Spanglera5b69b02014-12-02 13:41:29 -0800303 firmware/2lib/2sha_utility.c
304
Randall Spangler108d9912014-12-02 15:55:56 -0800305FWLIB20_SRCS = \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800306 firmware/lib20/api.c \
307 firmware/lib20/common.c \
308 firmware/lib20/misc.c \
309 firmware/lib20/packed_key.c
Randall Spangler108d9912014-12-02 15:55:56 -0800310
Randall Spanglera5b69b02014-12-02 13:41:29 -0800311FWLIB21_SRCS = \
312 firmware/lib21/api.c \
313 firmware/lib21/common.c \
314 firmware/lib21/misc.c \
315 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700316
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800317# Support real TPM unless BIOS sets MOCK_TPM
318ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800319VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800320 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800321 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800322
323VBSF_SRCS += \
324 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800325else
Randall Spangler93943262013-02-26 11:03:57 -0800326VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800327 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800328 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800329
330VBSF_SRCS += \
331 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800332endif
333
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800334ifeq (${FIRMWARE_ARCH},)
335# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800336# TODO: split out other stub funcs too
337VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800338 firmware/stub/tpm_lite_stub.c \
339 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600340 firmware/stub/vboot_api_stub_init.c \
341 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800342
343VBSF_SRCS += \
344 firmware/stub/vboot_api_stub_sf.c
345
346VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800347 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700348 firmware/stub/vboot_api_stub_disk.c \
349 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700350
Randall Spangler108d9912014-12-02 15:55:56 -0800351FWLIB2_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700352 firmware/2lib/2stub.c
353
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800354endif
355
Randall Spangler93943262013-02-26 11:03:57 -0800356VBSF_SRCS += ${VBINIT_SRCS}
357FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
358
359VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
360VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800361ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800362
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800363FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800364FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800365FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800366FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800367ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800368
Bill Richardson78299022014-06-20 14:33:00 -0700369# Intermediate library for the vboot_reference utilities to link against.
370UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800371UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800372
Bill Richardson78299022014-06-20 14:33:00 -0700373UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800374 cgpt/cgpt_create.c \
375 cgpt/cgpt_add.c \
376 cgpt/cgpt_boot.c \
377 cgpt/cgpt_show.c \
378 cgpt/cgpt_repair.c \
379 cgpt/cgpt_prioritize.c \
380 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700381 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800382 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800383 host/lib/crossystem.c \
384 host/lib/file_keys.c \
385 host/lib/fmap.c \
386 host/lib/host_common.c \
387 host/lib/host_key.c \
388 host/lib/host_keyblock.c \
389 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700390 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800391 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700392 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800393
Randall Spangleraaaff862014-12-01 15:40:08 -0800394UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
395ALL_OBJS += ${UTILLIB_OBJS}
396
Randall Spanglera5b69b02014-12-02 13:41:29 -0800397UTILLIB21_SRCS += \
398 host/lib21/host_fw_preamble.c \
399 host/lib21/host_key.c \
400 host/lib21/host_keyblock.c \
401 host/lib21/host_misc.c \
402 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800403
Randall Spanglera5b69b02014-12-02 13:41:29 -0800404UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
405ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700406
407# Externally exported library for some target userspace apps to link with
408# (cryptohome, updater, etc.)
409HOSTLIB = ${BUILD}/libvboot_host.a
410
411HOSTLIB_SRCS = \
412 cgpt/cgpt_add.c \
413 cgpt/cgpt_boot.c \
414 cgpt/cgpt_common.c \
415 cgpt/cgpt_create.c \
416 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700417 firmware/lib/cgptlib/cgptlib_internal.c \
418 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700419 firmware/lib/crc8.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800420 firmware/lib/gpt_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700421 firmware/lib/tpm_lite/tlcl.c \
422 firmware/lib/utility_string.c \
423 firmware/lib/vboot_nvstorage.c \
424 firmware/stub/tpm_lite_stub.c \
425 firmware/stub/utility_stub.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800426 firmware/stub/vboot_api_stub_disk.c \
Bill Richardson78299022014-06-20 14:33:00 -0700427 firmware/stub/vboot_api_stub_init.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800428 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700429 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700430 host/arch/${ARCH}/lib/crossystem_arch.c \
431 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700432 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700433 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700434
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800435HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800436ALL_OBJS += ${HOSTLIB_OBJS}
437
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800438# Sigh. For historical reasons, the autoupdate installer must sometimes be a
439# 32-bit executable, even when everything else is 64-bit. But it only needs a
440# few functions, so let's just build those.
441TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
442
443TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800444 cgpt/cgpt_add.c \
445 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800446 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700447 cgpt/cgpt_create.c \
448 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700449 firmware/lib/cgptlib/cgptlib_internal.c \
450 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800451 firmware/lib/gpt_misc.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800452 firmware/lib/utility_string.c \
Dan Ehrenberg32a999d2014-11-21 15:44:05 -0800453 firmware/stub/vboot_api_stub_disk.c \
454 firmware/stub/vboot_api_stub_sf.c \
Bill Richardson78299022014-06-20 14:33:00 -0700455 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800456 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800457
458TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800459
460# ----------------------------------------------------------------------------
461# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462
463CGPT = ${BUILD}/cgpt/cgpt
464
465CGPT_SRCS = \
466 cgpt/cgpt.c \
467 cgpt/cgpt_add.c \
468 cgpt/cgpt_boot.c \
469 cgpt/cgpt_common.c \
470 cgpt/cgpt_create.c \
471 cgpt/cgpt_find.c \
472 cgpt/cgpt_legacy.c \
473 cgpt/cgpt_prioritize.c \
474 cgpt/cgpt_repair.c \
475 cgpt/cgpt_show.c \
476 cgpt/cmd_add.c \
477 cgpt/cmd_boot.c \
478 cgpt/cmd_create.c \
479 cgpt/cmd_find.c \
480 cgpt/cmd_legacy.c \
481 cgpt/cmd_prioritize.c \
482 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800483 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800484
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800485CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800486ALL_OBJS += ${CGPT_OBJS}
487
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800488# Utility defaults
489UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800490
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800491# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800492UTIL_SCRIPTS = \
493 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700494 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800495
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800496ifeq (${MINIMAL},)
497UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700498 utility/dev_make_keypair \
499 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800500endif
501
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800502# These utilities should be linked statically.
503UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700504 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800505
506UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700507 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700508 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700509 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800510
Bill Richardson6f396152014-07-15 12:52:19 -0700511# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800512ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800513UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700514 utility/bmpblk_font \
515 utility/bmpblk_utility \
516 utility/eficompress \
517 utility/efidecompress \
518 utility/load_kernel_test \
519 utility/pad_digest_utility \
520 utility/signature_digest_utility \
521 utility/verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800522endif
523
Bill Richardson339f7e02013-04-05 09:49:24 -0700524UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
525UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700526ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800527
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800528
529# Scripts for signing stuff.
530SIGNING_SCRIPTS = \
531 utility/tpm-nvsize \
532 utility/chromeos-tpm-recovery
533
534# These go in a different place.
535SIGNING_SCRIPTS_DEV = \
536 scripts/image_signing/resign_firmwarefd.sh \
537 scripts/image_signing/make_dev_firmware.sh \
538 scripts/image_signing/make_dev_ssd.sh \
539 scripts/image_signing/set_gbb_flags.sh
540
541# Installed, but not made executable.
542SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800543
Bill Richardson826db092013-01-14 12:37:15 -0800544
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800545# The unified firmware utility will eventually replace all the others
546FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700547# But we still need both static (tiny) and dynamic (with openssl) versions.
548FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800549
Bill Richardson6f396152014-07-15 12:52:19 -0700550# These are the executables that are now built in to futility. We'll create
551# symlinks for these so the old names will still work.
552# TODO: Do we still need dev_sign_file for anything?
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700553FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700554 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700555 dump_fmap \
556 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700557 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700558 vbutil_firmware \
559 vbutil_kernel \
560 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700561 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800562
Bill Richardson6db8c752013-04-05 13:30:43 -0700563FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800564 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700565 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700566 futility/cmd_gbb_utility.c \
567 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800568
Bill Richardson6db8c752013-04-05 13:30:43 -0700569FUTIL_SRCS = \
570 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700571 futility/cmd_dev_sign_file.c \
572 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700573 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700574 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700575 futility/cmd_show.c \
576 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700577 futility/cmd_vbutil_firmware.c \
578 futility/cmd_vbutil_kernel.c \
Bill Richardsonf1dba022014-10-01 14:10:45 -0700579 futility/cmd_vbutil_kernel0.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700580 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700581 futility/cmd_vbutil_keyblock.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700582 futility/cmd_verify_kernel.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700583 futility/traversal.c \
584 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700585
Randall Spangler028f4682014-08-19 14:42:08 -0700586ifneq (${VBOOT2},)
587FUTIL_SRCS += \
588 futility/cmd_vb2_verify_fw.c
589endif
590
Alex Deymoe08ee282014-08-29 01:07:48 -0700591# List of commands built in futility and futility_s.
592FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
593FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800594
Bill Richardson91852e72014-11-28 12:28:04 -0800595# Workaround for TODO(crbug.com/437107).
596FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
597
Alex Deymoe08ee282014-08-29 01:07:48 -0700598FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800599 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700600 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
601FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800602
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800603ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800604
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800605
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800606# Library of handy test functions.
607TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800608
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800609TESTLIB_SRCS = \
610 tests/test_common.c \
611 tests/timer_utils.c \
612 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800613
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800614TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700615TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800616
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800617
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800618# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800619TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700620 tests/cgptlib_test \
621 tests/rollback_index2_tests \
622 tests/rollback_index3_tests \
623 tests/rsa_padding_test \
624 tests/rsa_utility_tests \
625 tests/rsa_verify_benchmark \
626 tests/sha_benchmark \
627 tests/sha_tests \
628 tests/stateful_util_tests \
629 tests/tlcl_tests \
630 tests/tpm_bootmode_tests \
631 tests/utility_string_tests \
632 tests/utility_tests \
633 tests/vboot_api_init_tests \
634 tests/vboot_api_devmode_tests \
635 tests/vboot_api_firmware_tests \
636 tests/vboot_api_kernel_tests \
637 tests/vboot_api_kernel2_tests \
638 tests/vboot_api_kernel3_tests \
639 tests/vboot_api_kernel4_tests \
640 tests/vboot_audio_tests \
641 tests/vboot_common_tests \
642 tests/vboot_common2_tests \
643 tests/vboot_common3_tests \
644 tests/vboot_display_tests \
645 tests/vboot_firmware_tests \
646 tests/vboot_kernel_tests \
647 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700648 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700649 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800650
Simon Glass527ba812013-07-25 08:48:47 -0600651ifdef REGION_READ
652TEST_NAMES += tests/vboot_region_tests
653endif
654
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800655TEST2X_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700656 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700657 tests/vb2_common_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700658 tests/vb2_misc_tests \
659 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700660 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700661 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800662 tests/vb2_sha_tests
663
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800664TEST20_NAMES = \
665 tests/vb20_api_tests \
666 tests/vb20_common_tests \
667 tests/vb20_common2_tests \
668 tests/vb20_common3_tests \
669 tests/vb20_misc_tests \
670 tests/vb20_rsa_padding_tests
671
Randall Spangler108d9912014-12-02 15:55:56 -0800672TEST21_NAMES = \
673 tests/vb21_api_tests \
674 tests/vb21_common_tests \
675 tests/vb21_common2_tests \
676 tests/vb21_misc_tests \
677 tests/vb21_host_fw_preamble_tests \
678 tests/vb21_host_key_tests \
679 tests/vb21_host_keyblock_tests \
680 tests/vb21_host_misc_tests \
681 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700682
Randall Spangleraaaff862014-12-01 15:40:08 -0800683ifneq (${VBOOT2},)
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800684TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700685endif
686
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800687# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700688TLCL_TEST_NAMES = \
689 tests/tpm_lite/tpmtest_earlyextend \
690 tests/tpm_lite/tpmtest_earlynvram \
691 tests/tpm_lite/tpmtest_earlynvram2 \
692 tests/tpm_lite/tpmtest_enable \
693 tests/tpm_lite/tpmtest_fastenable \
694 tests/tpm_lite/tpmtest_globallock \
695 tests/tpm_lite/tpmtest_redefine_unowned \
696 tests/tpm_lite/tpmtest_spaceperm \
697 tests/tpm_lite/tpmtest_testsetup \
698 tests/tpm_lite/tpmtest_timing \
699 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800700
701TEST_NAMES += ${TLCL_TEST_NAMES}
702
Bill Richardson339f7e02013-04-05 09:49:24 -0700703# Finally
704TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700705TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800706
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800707TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800708TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800709TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800710
Randall Spanglere061a252013-01-22 15:34:07 -0800711# Directory containing test keys
712TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800713
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800714
715##############################################################################
716# Finally, some targets. High-level ones first.
717
718# Create output directories if necessary. Do this via explicit shell commands
719# so it happens before trying to generate/include dependencies.
720SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
721_dir_create := $(foreach d, \
722 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
723 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
724
725
726# Default target.
727.PHONY: all
Randall Spangleraaaff862014-12-01 15:40:08 -0800728all: fwlib \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800729 $(if ${VBOOT2},fwlib2x fwlib2 fwlib21) \
Randall Spangleraaaff862014-12-01 15:40:08 -0800730 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700731 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800732
733# Host targets
734.PHONY: host_stuff
Randall Spanglera5b69b02014-12-02 13:41:29 -0800735host_stuff: utillib hostlib cgpt utils futil tests $(if ${VBOOT2},utillib21)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800736
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800737.PHONY: clean
738clean:
739 ${Q}/bin/rm -rf ${BUILD}
740
741.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800742install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800743
Bill Richardson3e3790d2014-07-14 15:05:54 -0700744.PHONY: install_for_test
745install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
746install_for_test: install
747
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800748# Don't delete intermediate object files
749.SECONDARY:
750
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800751# ----------------------------------------------------------------------------
752# Firmware library
753
754# TPM-specific flags. These depend on the particular TPM we're targeting for.
755# They are needed here only for compiling parts of the firmware code into
756# user-level tests.
757
758# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
759# the self test has completed.
760
Randall Spangler45cc0f22013-01-25 09:34:26 -0800761${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800762
763# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
764# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
765# power on.
766#
767# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
768# are not both defined at the same time. (See comment in code.)
769
770# CFLAGS += -DTPM_MANUAL_SELFTEST
771
772ifeq (${FIRMWARE_ARCH},i386)
773# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800774${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler108d9912014-12-02 15:55:56 -0800775${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800776${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800777${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800778
779# Workaround for coreboot on x86, which will power off asynchronously
780# without giving us a chance to react. This is not an example of the Right
781# Way to do things. See chrome-os-partner:7689, and the commit message
782# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800783${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800784
785# On x86 we don't actually read the GBB data into RAM until it is needed.
786# Therefore it makes sense to cache it rather than reading it each time.
787# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800788${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800789endif
790
Simon Glass527ba812013-07-25 08:48:47 -0600791ifdef REGION_READ
792${FWLIB_OBJS}: CFLAGS += -DREGION_READ
793endif
794
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800795ifeq (${FIRMWARE_ARCH},)
796# Disable rollback TPM when compiling locally, since otherwise
797# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800798${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800799endif
800
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800801${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -0800802${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
803
Bill Richardsona130e0b2013-04-04 18:16:39 -0700804# Linktest ensures firmware lib doesn't rely on outside libraries
805${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800806${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700807TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700808${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800809${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700810TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700811${BUILD}/firmware/linktest/main: ${FWLIB}
812${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700813TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800814
Bill Richardsond2d08b22014-07-08 16:31:40 -0700815.PHONY: fwlinktest
816fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800817 ${BUILD}/firmware/linktest/main_vbinit \
818 ${BUILD}/firmware/linktest/main_vbsf \
819 ${BUILD}/firmware/linktest/main
820
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800821.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700822fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800823
824${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700825 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800826 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700827 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800828 ${Q}ar qc $@ $^
829
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800830.PHONY: fwlib2x
831fwlib2x: ${FWLIB2X}
832
833${FWLIB2X}: ${FWLIB2_OBJS}
834 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
835 ${Q}rm -f $@
836 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
837 ${Q}ar qc $@ $^
838
839# TODO: it'd be nice to call this fwlib20, but coreboot expects fwlib2
Randall Spanglera5b69b02014-12-02 13:41:29 -0800840.PHONY: fwlib2
841fwlib2: ${FWLIB20}
842
Randall Spangler108d9912014-12-02 15:55:56 -0800843${FWLIB20}: ${FWLIB2_OBJS} ${FWLIB20_OBJS}
Randall Spangler786acda2014-05-22 13:27:07 -0700844 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
845 ${Q}rm -f $@
846 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
847 ${Q}ar qc $@ $^
848
Randall Spanglera5b69b02014-12-02 13:41:29 -0800849.PHONY: fwlib21
850fwlib21: ${FWLIB21}
851
Randall Spangler108d9912014-12-02 15:55:56 -0800852${FWLIB21}: ${FWLIB2_OBJS} ${FWLIB21_OBJS}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800853 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
854 ${Q}rm -f $@
855 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
856 ${Q}ar qc $@ $^
857
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800858# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700859# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800860
Bill Richardson78299022014-06-20 14:33:00 -0700861# Link tests for local utilities
862${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700863${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700864TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700865
866.PHONY: utillib
867utillib: ${UTILLIB} \
868 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800869
870# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800871${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
872 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
873 ${Q}rm -f $@
874 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
875 ${Q}ar qc $@ $^
876
Randall Spanglera5b69b02014-12-02 13:41:29 -0800877.PHONY: utillib21
878utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800879
Randall Spangler108d9912014-12-02 15:55:56 -0800880${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800881${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2_OBJS} ${FWLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700882 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
883 ${Q}rm -f $@
884 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
885 ${Q}ar qc $@ $^
886
887
888# Link tests for external repos
889${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700890${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
891${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700892TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700893
894.PHONY: hostlib
895hostlib: ${HOSTLIB} \
896 ${BUILD}/host/linktest/extern
897
898# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700899${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700900 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800901 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700902 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800903 ${Q}ar qc $@ $^
904
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800905
906# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
907.PHONY: tinyhostlib
908tinyhostlib: ${TINYHOSTLIB}
909 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
910
911${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700912 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800913 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700914 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800915 ${Q}ar qc $@ $^
916
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800917# ----------------------------------------------------------------------------
918# CGPT library and utility
919
920.PHONY: cgpt
921cgpt: ${CGPT}
922
923${CGPT}: LDFLAGS += -static
924${CGPT}: LDLIBS += -luuid
925
Bill Richardson78299022014-06-20 14:33:00 -0700926${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700927 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700928 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800929
930.PHONY: cgpt_install
931cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700932 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800933 ${Q}mkdir -p ${UB_DIR}
934 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800935
936# ----------------------------------------------------------------------------
937# Utilities
938
939# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700940${BUILD}/utility/%: INCLUDES += -Iutility/include
941
942${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
943${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800944
945# Utilities for auto-update toolkits must be statically linked.
946${UTIL_BINS_STATIC}: LDFLAGS += -static
947
Bill Richardsona130e0b2013-04-04 18:16:39 -0700948
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800949.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800950utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800951 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
952 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
953
954.PHONY: utils_install
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800955utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700956 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800957 ${Q}mkdir -p ${UB_DIR}
958 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoncfe83a82014-12-04 11:29:57 -0800959 ${Q}mkdir -p ${DF_DIR}
960 ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800961
962# And some signing stuff for the target
963.PHONY: signing_install
964signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700965 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700966 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800967 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700968 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
969 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800970
971# ----------------------------------------------------------------------------
972# new Firmware Utility
973
974.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700975futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
976
Randall Spangleraaaff862014-12-01 15:40:08 -0800977${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB} \
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800978 $(if ${VBOOT2},${FWLIB20})
Bill Richardson6db8c752013-04-05 13:30:43 -0700979 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
980 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800981
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700982${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -0800983${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} $(if ${VBOOT2},${FWLIB20})
Simon Glass661ae9e2013-03-26 11:39:21 -0700984 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700985 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800986
987.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -0700988futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700989 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700990 ${Q}mkdir -p ${UB_DIR}
991 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700992 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -0700993 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800994
995# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800996# Utility to generate TLCL structure definition header file.
997
998${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
999
1000STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1001STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1002
1003.PHONY: update_tlcl_structures
1004update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -07001005 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001006 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1007 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1008 ( echo "%% Updating structures.h %%" && \
1009 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1010
1011# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001012# Tests
1013
1014.PHONY: tests
1015tests: ${TEST_BINS}
1016
Bill Richardson78299022014-06-20 14:33:00 -07001017${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -07001018${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001019${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001020
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001021${TEST2X_BINS}: ${FWLIB2X}
1022${TEST2X_BINS}: LIBS += ${FWLIB2X}
1023
Randall Spangler108d9912014-12-02 15:55:56 -08001024${TEST20_BINS}: ${FWLIB20}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001025${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
Randall Spangler108d9912014-12-02 15:55:56 -08001026${TEST20_BINS}: LIBS += ${FWLIB20}
1027
1028${TEST21_BINS}: ${UTILLIB21}
1029${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1030${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -08001031
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001032${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -07001033 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001034 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -07001035 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001036 ${Q}ar qc $@ $^
1037
1038
1039# ----------------------------------------------------------------------------
1040# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1041# rules for specific targets.
1042
1043${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -07001044 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001045 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001046
1047${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001048 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001049 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1050
Alex Deymoe08ee282014-08-29 01:07:48 -07001051${BUILD}/%.o: ${BUILD}/%.c
1052 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
1053 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1054
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001055# Rules to recompile a single source file for library and test
1056# TODO: is there a tidier way to do this?
1057${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1058${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001059 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001060 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1061
1062${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1063${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001064 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001065 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1066
1067# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1068${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -07001069 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001070 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1071
1072# ----------------------------------------------------------------------------
1073# Here are the special tweaks to the generic rules.
1074
Bill Richardsoncfe83a82014-12-04 11:29:57 -08001075# Always create the defaults file, since it depends on input variables
1076.PHONY: ${UTIL_DEFAULTS}
1077${UTIL_DEFAULTS}:
1078 @$(PRINTF) " CREATE $(subst ${BUILD}/,,$@)\n"
1079 ${Q}rm -f $@
1080 ${Q}mkdir -p $(dir $@)
1081 ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1082 ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1083 ${Q}mv -f $@.tmp $@
1084
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001085# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001086CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1087
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001088${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1089${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1090${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001091
1092${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1093${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1094${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001095${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1096${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001097
1098${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001099
1100${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1101${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
1102
1103BMPBLK_UTILITY_DEPS = \
1104 ${BUILD}/utility/bmpblk_util.o \
1105 ${BUILD}/utility/image_types.o \
1106 ${BUILD}/utility/eficompress_for_lib.o \
1107 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001108
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001109${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1110${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001111ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001112
1113${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1114${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001115ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001116
1117# Allow multiple definitions, so tests can mock functions from other libraries
1118${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001119${BUILD}/tests/%: LDLIBS += -lrt -luuid
1120${BUILD}/tests/%: LIBS += ${TESTLIB}
1121
1122${BUILD}/tests/rollback_index2_tests: OBJS += \
1123 ${BUILD}/firmware/lib/rollback_index_for_test.o
1124${BUILD}/tests/rollback_index2_tests: \
1125 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001126TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001127
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001128${BUILD}/tests/tlcl_tests: OBJS += \
1129 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1130${BUILD}/tests/tlcl_tests: \
1131 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001132TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001133
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001134${BUILD}/tests/vboot_audio_tests: OBJS += \
1135 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1136${BUILD}/tests/vboot_audio_tests: \
1137 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001138TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001139
Bill Richardson339f7e02013-04-05 09:49:24 -07001140TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001141${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1142${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001143TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001144
Alex Deymoe08ee282014-08-29 01:07:48 -07001145# ----------------------------------------------------------------------------
1146# Here are the special rules that don't fit in the generic rules.
1147
1148# Generates the list of commands defined in futility by running grep in the
1149# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1150${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1151${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1152${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1153 @$(PRINTF) " GEN $(subst ${BUILD}/,,$@)\n"
1154 ${Q}rm -f $@ $@_t $@_commands
1155 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001156 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001157 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1158 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001159 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001160 ${Q}echo '#define _CMD(NAME) extern const struct' \
1161 'futil_cmd_t __cmd_##NAME;' >> $@_t
1162 ${Q}cat $@_commands >> $@_t
1163 ${Q}echo '#undef _CMD' >> $@_t
1164 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1165 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1166 ${Q}cat $@_commands >> $@_t
1167 ${Q}echo '0}; /* null-terminated */' >> $@_t
1168 ${Q}echo '#undef _CMD' >> $@_t
1169 ${Q}mv $@_t $@
1170 ${Q}rm -f $@_commands
1171
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001172##############################################################################
1173# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001174
1175# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001176.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001177test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001178
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001179ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001180# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001181test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001182# Scripts don't work under qemu testing
1183# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001184test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001185endif
1186
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001187.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001188test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001189
Randall Spangler844bce52013-01-15 16:16:43 -08001190# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1191# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001192ifneq (${QEMU_ARCH},)
1193test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001194
1195.PHONY: qemu_install
1196qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001197ifeq (${SYSROOT},)
1198 $(error SYSROOT must be set to the top of the target-specific root \
1199when cross-compiling for qemu-based tests to run properly.)
1200endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001201 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001202 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1203 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001204endif
1205
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001206.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001207runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001208
1209# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001210.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001211genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001212 tests/gen_test_keys.sh
1213
1214# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001215.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001216genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001217 tests/gen_fuzz_test_cases.sh
1218
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001219.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001220runbmptests: test_setup
1221 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001222 ./TestBmpBlock.py -v
1223
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001224.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001225runcgpttests: test_setup
1226 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001227
Randall Spangler844bce52013-01-15 16:16:43 -08001228.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001229runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001230 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001231 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001232 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001233 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001234 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001235 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001236 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001237ifneq (${VBOOT2},)
1238 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001239 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001240endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001241
Randall Spangler844bce52013-01-15 16:16:43 -08001242.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001243runmisctests: test_setup
1244 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001245 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001246 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1247 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1248 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001249 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001250 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1251 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1252 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1253 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001254 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001255 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1256 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001257 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1258 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1259 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001260 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001261 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1262 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1263 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001264 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001265 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001266 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001267 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001268
Randall Spangler786acda2014-05-22 13:27:07 -07001269.PHONY: run2tests
1270run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001271 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001272 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001273 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1274 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001275 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001276 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001277 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001278 ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1279 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1280 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1281 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1282 ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001283 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1284 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1285 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1286 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1287 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1288 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1289 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1290 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1291 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001292
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001293.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001294runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001295 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001296 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001297
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001298# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001299# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001300# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001301.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001302runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001303 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1304 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001305ifneq (${VBOOT2},)
Randall Spangler6f1b82a2014-12-03 12:29:37 -08001306 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1307 ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001308 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001309endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001310 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001311 tests/run_vbutil_tests.sh --all
1312
Bill Richardson78d59bf2014-08-27 16:17:04 -07001313# TODO: There were a number of ancient tests that hadn't been run in years.
1314# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1315# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001316
Bill Richardson78299022014-06-20 14:33:00 -07001317.PHONY: runalltests
1318runalltests: runtests runfutiltests runlongtests
1319
Randall Spangler59d75082013-01-23 09:29:54 -08001320# Code coverage
1321.PHONY: coverage_init
1322coverage_init: test_setup
1323 rm -f ${COV_INFO}*
1324 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1325
1326.PHONY: coverage_html
1327coverage_html:
1328 lcov -c -d . -b . -o ${COV_INFO}.tests
1329 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1330 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1331 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001332# Generate addtional coverage stats just for firmware subdir, because the stats
1333# for the whole project don't include subdirectory summaries. This will print
1334# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001335 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1336 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001337 -o ${COV_INFO}.firmware
1338
1339.PHONY: coverage
1340ifeq (${COV},)
1341coverage:
1342 $(error Build coverage like this: make clean && COV=1 make)
1343else
1344coverage: coverage_init runtests coverage_html
1345endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001346
1347# Include generated dependencies
1348ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001349TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1350
1351# We want to use only relative paths in cscope.files, especially since the
1352# paths inside and outside the chroot are different.
1353SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1354
1355${BUILD}/cscope.files: test_setup
1356 ${Q}rm -f $@
1357 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1358 sed -e "s/${SRCDIRPAT}//" | \
1359 egrep '\.[chS]$$' | sort | uniq > $@
1360
1361cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1362cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1363run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1364
1365.PHONY: tags TAGS xrefs
1366tags TAGS xrefs: ${BUILD}/cscope.files
1367 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1368 ${Q}$(call run_if_prog,etags,${cmd_etags})
1369 ${Q}$(call run_if_prog,ctags,${cmd_ctags})