blob: 60509f671fca512705f4207912ab8281ef1d7f30 [file] [log] [blame]
Randall Spanglere8cfa312013-01-02 16:49:38 -08001# Copyright (c) 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 Richardsonfeb25182013-03-07 12:54:29 -080040BUILD = $(SRCDIR)/build
Randall Spangler844bce52013-01-15 16:16:43 -080041export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080042
Bill Richardsonc9bf3482013-02-13 14:38:29 -080043# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080044INSTALL = install
45DESTDIR = /usr/local/bin
46OLDDIR = old_bins
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsonfeb25182013-03-07 12:54:29 -080048# Where exactly do the pieces go?
49# FT_DIR = futility target directory - where it will be on the target
50# F_DIR = futility install directory - where it gets put right now
51# UB_DIR = userspace binary directory for futility's exec() targets
52# VB_DIR = target vboot directory - for dev-mode-only helpers, keys, etc.
Bill Richardsonc9bf3482013-02-13 14:38:29 -080053ifeq (${MINIMAL},)
54# Host install just puts everything in one place
Bill Richardsonfeb25182013-03-07 12:54:29 -080055FT_DIR=${DESTDIR}
56F_DIR=${DESTDIR}
57UB_DIR=${DESTDIR}/${OLDDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080058else
59# Target install puts things into DESTDIR subdirectories
Bill Richardsonfeb25182013-03-07 12:54:29 -080060FT_DIR=/usr/bin
61F_DIR=${DESTDIR}${FT_DIR}
62UB_DIR=${F_DIR}/${OLDDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080063VB_DIR=${DESTDIR}/usr/share/vboot/bin
64endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080065
Bill Richardsoneecc18f2013-01-17 15:28:17 -080066# Where to install the (exportable) executables for testing?
67TEST_INSTALL_DIR = ${BUILD}/install_for_test
68
69# Verbose? Use V=1
70ifeq (${V},)
71Q := @
72endif
73
Simon Glass661ae9e2013-03-26 11:39:21 -070074# Quiet? Use QUIET=1
75ifeq ($(QUIET),)
76PRINTF := printf
77else
78PRINTF := :
79endif
80
Randall Spangler61a2eb32013-01-23 10:20:16 -080081# Architecture detection
82_machname := $(shell uname -m)
83HOST_ARCH ?= ${_machname}
84
85# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
86# Pick a sane target architecture if none is defined.
87ifeq (${ARCH},)
88 ARCH := ${HOST_ARCH}
89else ifeq (${ARCH},i386)
90 override ARCH := x86
91else ifeq (${ARCH},amd64)
92 override ARCH := x86_64
93endif
94
95# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
96# for a firmware target (such as u-boot or depthcharge). It must map
97# to the same consistent set of architectures as the host.
98ifeq (${FIRMWARE_ARCH},i386)
99 override FIRMWARE_ARCH := x86
100else ifeq (${FIRMWARE_ARCH},amd64)
101 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -0700102else ifeq (${FIRMWARE_ARCH},armv7)
103 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -0800104endif
105
Simon Glassb265c342011-11-16 15:09:51 -0800106# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
107# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700108#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800109# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
110# temporarily. As we are still investigating which flags are necessary for
111# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700112#
Simon Glassb265c342011-11-16 15:09:51 -0800113# As a first step, this makes the setting of CC and CFLAGS here optional, to
114# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700115#
Simon Glassb265c342011-11-16 15:09:51 -0800116# Flag ordering: arch, then -f, then -m, then -W
117DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
118COMMON_FLAGS := -nostdinc -pipe \
119 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800120 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800121
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800122# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
123ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800124CC ?= armv7a-cros-linux-gnueabi-gcc
125CFLAGS ?= -march=armv5 \
126 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700127 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800128 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800129else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800130CC ?= i686-pc-linux-gnu-gcc
131# Drop -march=i386 to permit use of SSE instructions
132CFLAGS ?= \
133 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
134 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800135 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800136 ${COMMON_FLAGS}
137else ifeq (${FIRMWARE_ARCH}, x86_64)
138CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800139 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800140else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800141# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800142CC ?= gcc
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800143CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800144endif
145
Bill Richardsonfeb25182013-03-07 12:54:29 -0800146ifneq (${OLDDIR},)
147CFLAGS += -DOLDDIR=${OLDDIR}
148endif
149
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800150ifneq (${DEBUG},)
151CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700152endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800153
vbendebb2b0fcc2010-07-15 15:09:47 -0700154ifeq (${DISABLE_NDEBUG},)
155CFLAGS += -DNDEBUG
156endif
157
Bill Richardsonfeb25182013-03-07 12:54:29 -0800158ifneq (${FORCE_LOGGING_ON},)
159CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
160endif
161
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800162# Create / use dependency files
163CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800164
Bill Richardson0c3ba242013-03-29 11:09:30 -0700165# These are required to access large disks and files on 32-bit systems.
166CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167
Randall Spangler59d75082013-01-23 09:29:54 -0800168# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800169ifneq (${COV},)
Randall Spangler59d75082013-01-23 09:29:54 -0800170 COV_FLAGS = -O0 --coverage
171 CFLAGS += ${COV_FLAGS}
172 LDFLAGS += ${COV_FLAGS}
173 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800174endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# And a few more default utilities
177LD = ${CC}
178CXX ?= g++ # HEY: really?
179PKG_CONFIG ?= pkg-config
180
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181# Determine QEMU architecture needed, if any
182ifeq (${ARCH},${HOST_ARCH})
183 # Same architecture; no need for QEMU
184 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800185else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186 # 64-bit host can run 32-bit targets directly
187 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800188else
189 QEMU_ARCH := ${ARCH}
190endif
191
192# The top of the chroot for qemu must be passed in via the SYSROOT environment
193# variable. In the Chromium OS chroot, this is done automatically by the
194# ebuild.
195
196ifeq (${QEMU_ARCH},)
197 # Path to build output for running tests is same as for building
198 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200else
201 $(info Using qemu for testing.)
202 # Path to build output for running tests is different in the chroot
203 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800204 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205
206 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800207 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
208 export QEMU_RUN
209
210 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800211endif
212
Randall Spanglere061a252013-01-22 15:34:07 -0800213export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800214
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800215##############################################################################
216# Now we need to describe everything we might want or need to build
217
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800218# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800219INCLUDES += \
220 -Ifirmware/include \
221 -Ifirmware/lib/include \
222 -Ifirmware/lib/cgptlib/include \
223 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700224 -Ifirmware/lib/tpm_lite/include \
225 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700226
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227# If we're not building for a specific target, just stub out things like the
228# TPM commands and various external functions that are provided by the BIOS.
229ifeq (${FIRMWARE_ARCH},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800230INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800231else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800232INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800233endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800234
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800235# Firmware library. TODO: Do we still need to export this?
236FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800237
Randall Spangler786acda2014-05-22 13:27:07 -0700238# Smaller firmware library. TODO: Do we still need to export this?
239ifneq (${VBOOT2},)
240FWLIB2 = ${BUILD}/vboot_fw2.a
241endif
242
Randall Spangler93943262013-02-26 11:03:57 -0800243# Firmware library sources needed by VbInit() call
244VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800245 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800246 firmware/lib/utility.c \
247 firmware/lib/vboot_api_init.c \
248 firmware/lib/vboot_common_init.c \
249 firmware/lib/vboot_nvstorage.c \
Simon Glass527ba812013-07-25 08:48:47 -0600250 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800251
252# Additional firmware library sources needed by VbSelectFirmware() call
253VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800254 firmware/lib/cryptolib/padding.c \
255 firmware/lib/cryptolib/rsa.c \
256 firmware/lib/cryptolib/rsa_utility.c \
257 firmware/lib/cryptolib/sha1.c \
258 firmware/lib/cryptolib/sha256.c \
259 firmware/lib/cryptolib/sha512.c \
260 firmware/lib/cryptolib/sha_utility.c \
261 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800262 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800263 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600264 firmware/lib/vboot_firmware.c \
265 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800266
267# Additional firmware library sources needed by VbSelectAndLoadKernel() call
268VBSLK_SRCS = \
269 firmware/lib/cgptlib/cgptlib.c \
270 firmware/lib/cgptlib/cgptlib_internal.c \
271 firmware/lib/cgptlib/crc32.c \
Albert Chaulk5c9e4532013-03-20 16:03:49 -0700272 firmware/lib/cgptlib/mtdlib.c \
Randall Spangler93943262013-02-26 11:03:57 -0800273 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800274 firmware/lib/vboot_api_kernel.c \
275 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600277 firmware/lib/vboot_kernel.c \
278 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800279
Randall Spangler786acda2014-05-22 13:27:07 -0700280# Firmware library source needed for smaller library 2
281FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700282 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700283 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700284 firmware/2lib/2crc8.c \
285 firmware/2lib/2misc.c \
286 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700287 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700288 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700289 firmware/2lib/2sha1.c \
290 firmware/2lib/2sha256.c \
291 firmware/2lib/2sha512.c \
292 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700293
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800294# Support real TPM unless BIOS sets MOCK_TPM
295ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800296VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800297 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800298 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800299
300VBSF_SRCS += \
301 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800302else
Randall Spangler93943262013-02-26 11:03:57 -0800303VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800304 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800305 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800306
307VBSF_SRCS += \
308 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800309endif
310
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800311ifeq (${FIRMWARE_ARCH},)
312# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800313# TODO: split out other stub funcs too
314VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800315 firmware/stub/tpm_lite_stub.c \
316 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600317 firmware/stub/vboot_api_stub_init.c \
318 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800319
320VBSF_SRCS += \
321 firmware/stub/vboot_api_stub_sf.c
322
323VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800324 firmware/stub/vboot_api_stub.c \
325 firmware/stub/vboot_api_stub_disk.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700326
327FWLIB2_SRCS += \
328 firmware/2lib/2stub.c
329
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800330endif
331
Randall Spangler93943262013-02-26 11:03:57 -0800332VBSF_SRCS += ${VBINIT_SRCS}
333FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
334
335VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
336VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
337
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800338FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700339
Randall Spangler786acda2014-05-22 13:27:07 -0700340ifneq (${VBOOT2},)
341FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
342endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800343
Randall Spangler786acda2014-05-22 13:27:07 -0700344ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800345
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800346# Library to build the utilities. "HOST" mostly means "userspace".
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800347HOSTLIB = ${BUILD}/libvboot_host.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800348
349HOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800350 cgpt/cgpt_create.c \
351 cgpt/cgpt_add.c \
352 cgpt/cgpt_boot.c \
353 cgpt/cgpt_show.c \
354 cgpt/cgpt_repair.c \
355 cgpt/cgpt_prioritize.c \
356 cgpt/cgpt_common.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700357 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700358 firmware/lib/cgptlib/mtdlib.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700359 firmware/lib/flash_ts.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800360 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800361 host/lib/crossystem.c \
362 host/lib/file_keys.c \
363 host/lib/fmap.c \
364 host/lib/host_common.c \
365 host/lib/host_key.c \
366 host/lib/host_keyblock.c \
367 host/lib/host_misc.c \
368 host/lib/host_signature.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800369 host/lib/signature_digest.c \
370 utility/dump_kernel_config_lib.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800371
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800372HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800373ALL_OBJS += ${HOSTLIB_OBJS}
374
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800375# Might need this too.
376CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
377
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800378# Sigh. For historical reasons, the autoupdate installer must sometimes be a
379# 32-bit executable, even when everything else is 64-bit. But it only needs a
380# few functions, so let's just build those.
381TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
382
383TINYHOSTLIB_SRCS = \
384 cgpt/cgpt_create.c \
385 cgpt/cgpt_add.c \
386 cgpt/cgpt_boot.c \
387 cgpt/cgpt_show.c \
388 cgpt/cgpt_repair.c \
389 cgpt/cgpt_prioritize.c \
390 cgpt/cgpt_common.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700391 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700392 firmware/lib/cgptlib/mtdlib.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700393 firmware/lib/flash_ts.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800394 utility/dump_kernel_config_lib.c \
395 firmware/lib/cgptlib/crc32.c \
396 firmware/lib/cgptlib/cgptlib_internal.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800397 firmware/lib/utility_string.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800398 firmware/stub/utility_stub.c
399
400TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800401
402# ----------------------------------------------------------------------------
403# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800404
405CGPT = ${BUILD}/cgpt/cgpt
406
407CGPT_SRCS = \
408 cgpt/cgpt.c \
409 cgpt/cgpt_add.c \
410 cgpt/cgpt_boot.c \
411 cgpt/cgpt_common.c \
412 cgpt/cgpt_create.c \
413 cgpt/cgpt_find.c \
414 cgpt/cgpt_legacy.c \
415 cgpt/cgpt_prioritize.c \
416 cgpt/cgpt_repair.c \
417 cgpt/cgpt_show.c \
418 cgpt/cmd_add.c \
419 cgpt/cmd_boot.c \
420 cgpt/cmd_create.c \
421 cgpt/cmd_find.c \
422 cgpt/cmd_legacy.c \
423 cgpt/cmd_prioritize.c \
424 cgpt/cmd_repair.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700425 cgpt/cmd_show.c \
426 cgpt/flash_ts_drv.c \
427 firmware/lib/flash_ts.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800428
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800429CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800430ALL_OBJS += ${CGPT_OBJS}
431
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800432
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800433# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800434UTIL_SCRIPTS = \
435 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800436 utility/enable_dev_usb_boot \
437 utility/vbutil_what_keys
438
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800439ifeq (${MINIMAL},)
440UTIL_SCRIPTS += \
441 utility/dev_make_keypair
442endif
443
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800444# These utilities should be linked statically.
445UTIL_NAMES_STATIC = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700446 utility/crossystem \
Bill Richardson339f7e02013-04-05 09:49:24 -0700447 utility/gbb_utility
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800448
449UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700450 utility/dev_sign_file \
451 utility/dump_kernel_config \
452 utility/dumpRSAPublicKey \
453 utility/tpm_init_temp_fix \
454 utility/tpmc \
455 utility/vbutil_firmware \
456 utility/vbutil_kernel \
457 utility/vbutil_key \
458 utility/vbutil_keyblock \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800460ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800461UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700462 utility/bmpblk_font \
463 utility/bmpblk_utility \
464 utility/eficompress \
465 utility/efidecompress \
466 utility/load_kernel_test \
467 utility/pad_digest_utility \
468 utility/signature_digest_utility \
469 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700470
471ifneq (${VBOOT2},)
472UTIL_NAMES += \
473 utility/vb2_verify_fw
474endif
475
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800476endif
477
Bill Richardson339f7e02013-04-05 09:49:24 -0700478UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
479UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700480ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800481
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800482
483# Scripts for signing stuff.
484SIGNING_SCRIPTS = \
485 utility/tpm-nvsize \
486 utility/chromeos-tpm-recovery
487
488# These go in a different place.
489SIGNING_SCRIPTS_DEV = \
490 scripts/image_signing/resign_firmwarefd.sh \
491 scripts/image_signing/make_dev_firmware.sh \
492 scripts/image_signing/make_dev_ssd.sh \
493 scripts/image_signing/set_gbb_flags.sh
494
495# Installed, but not made executable.
496SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800497
Bill Richardson826db092013-01-14 12:37:15 -0800498
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800499# The unified firmware utility will eventually replace all the others
500FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700501# But we still need both static (tiny) and dynamic (with openssl) versions.
502FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800503
Bill Richardsonfeb25182013-03-07 12:54:29 -0800504# These are the others it will replace.
Bill Richardson20807b62013-04-09 10:15:26 -0700505FUTIL_OLD = bmpblk_font bmpblk_utility cgpt chromeos-tpm-recovery crossystem \
506 dev_debug_vboot dev_make_keypair dev_sign_file dumpRSAPublicKey \
507 dump_fmap dump_kernel_config eficompress efidecompress \
508 enable_dev_usb_boot gbb_utility load_kernel_test \
509 make_dev_firmware.sh make_dev_ssd.sh pad_digest_utility \
510 resign_firmwarefd.sh set_gbb_flags.sh signature_digest_utility \
511 tpm-nvsize tpm_init_temp_fix tpmc vbutil_firmware vbutil_kernel \
512 vbutil_key vbutil_keyblock vbutil_what_keys verify_data
Bill Richardsonfeb25182013-03-07 12:54:29 -0800513
Bill Richardson6db8c752013-04-05 13:30:43 -0700514FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800515 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700516 futility/cmd_dump_fmap.c \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800517 futility/cmd_foo.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800518
Bill Richardson6db8c752013-04-05 13:30:43 -0700519FUTIL_SRCS = \
520 $(FUTIL_STATIC_SRCS) \
521 futility/cmd_hey.c
522
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800523FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800524
Bill Richardson6db8c752013-04-05 13:30:43 -0700525FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800526FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800527
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800528ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800529
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800530
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800531# Library of handy test functions.
532TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800533
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800534TESTLIB_SRCS = \
535 tests/test_common.c \
536 tests/timer_utils.c \
537 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800538
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800539TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
540ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800541
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800542
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800543# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800544TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700545 tests/cgptlib_test \
546 tests/rollback_index2_tests \
547 tests/rollback_index3_tests \
548 tests/rsa_padding_test \
549 tests/rsa_utility_tests \
550 tests/rsa_verify_benchmark \
551 tests/sha_benchmark \
552 tests/sha_tests \
553 tests/stateful_util_tests \
554 tests/tlcl_tests \
555 tests/tpm_bootmode_tests \
556 tests/utility_string_tests \
557 tests/utility_tests \
558 tests/vboot_api_init_tests \
559 tests/vboot_api_devmode_tests \
560 tests/vboot_api_firmware_tests \
561 tests/vboot_api_kernel_tests \
562 tests/vboot_api_kernel2_tests \
563 tests/vboot_api_kernel3_tests \
564 tests/vboot_api_kernel4_tests \
565 tests/vboot_audio_tests \
566 tests/vboot_common_tests \
567 tests/vboot_common2_tests \
568 tests/vboot_common3_tests \
569 tests/vboot_display_tests \
570 tests/vboot_firmware_tests \
571 tests/vboot_kernel_tests \
572 tests/vboot_nvstorage_test \
573 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800574
Simon Glass527ba812013-07-25 08:48:47 -0600575ifdef REGION_READ
576TEST_NAMES += tests/vboot_region_tests
577endif
578
Randall Spangler786acda2014-05-22 13:27:07 -0700579ifneq (${VBOOT2},)
580TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700581 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700582 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700583 tests/vb2_common2_tests \
584 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700585 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700586 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700587 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700588 tests/vb2_rsa_padding_tests \
589 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700590 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700591 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700592
593endif
594
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800595# TODO: port these tests to new API, if not already eqivalent
596# functionality in other tests. These don't even compile at present.
597#
598# big_firmware_tests
599# big_kernel_tests
600# firmware_image_tests
601# firmware_rollback_tests
602# firmware_splicing_tests
603# firmware_verify_benchmark
604# kernel_image_tests
605# kernel_rollback_tests
606# kernel_splicing_tests
607# kernel_verify_benchmark
608# rollback_index_test
609# verify_firmware_fuzz_driver
610# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800611# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800612
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800613# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700614TLCL_TEST_NAMES = \
615 tests/tpm_lite/tpmtest_earlyextend \
616 tests/tpm_lite/tpmtest_earlynvram \
617 tests/tpm_lite/tpmtest_earlynvram2 \
618 tests/tpm_lite/tpmtest_enable \
619 tests/tpm_lite/tpmtest_fastenable \
620 tests/tpm_lite/tpmtest_globallock \
621 tests/tpm_lite/tpmtest_redefine_unowned \
622 tests/tpm_lite/tpmtest_spaceperm \
623 tests/tpm_lite/tpmtest_testsetup \
624 tests/tpm_lite/tpmtest_timing \
625 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800626
627TEST_NAMES += ${TLCL_TEST_NAMES}
628
Bill Richardson339f7e02013-04-05 09:49:24 -0700629# Finally
630TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700631ALL_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800632
Randall Spanglere061a252013-01-22 15:34:07 -0800633# Directory containing test keys
634TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800635
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800636
637##############################################################################
638# Finally, some targets. High-level ones first.
639
640# Create output directories if necessary. Do this via explicit shell commands
641# so it happens before trying to generate/include dependencies.
642SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
643_dir_create := $(foreach d, \
644 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
645 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
646
647
648# Default target.
649.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700650all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
651 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800652
653# Host targets
654.PHONY: host_stuff
655host_stuff: hostlib cgpt utils futil tests
656
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800657.PHONY: clean
658clean:
659 ${Q}/bin/rm -rf ${BUILD}
660
661.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800662install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800663
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800664# Don't delete intermediate object files
665.SECONDARY:
666
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800667
668# ----------------------------------------------------------------------------
669# Firmware library
670
671# TPM-specific flags. These depend on the particular TPM we're targeting for.
672# They are needed here only for compiling parts of the firmware code into
673# user-level tests.
674
675# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
676# the self test has completed.
677
Randall Spangler45cc0f22013-01-25 09:34:26 -0800678${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800679
680# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
681# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
682# power on.
683#
684# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
685# are not both defined at the same time. (See comment in code.)
686
687# CFLAGS += -DTPM_MANUAL_SELFTEST
688
689ifeq (${FIRMWARE_ARCH},i386)
690# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800691${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700692${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800693
694# Workaround for coreboot on x86, which will power off asynchronously
695# without giving us a chance to react. This is not an example of the Right
696# Way to do things. See chrome-os-partner:7689, and the commit message
697# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800698${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800699
700# On x86 we don't actually read the GBB data into RAM until it is needed.
701# Therefore it makes sense to cache it rather than reading it each time.
702# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800703${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800704endif
705
Simon Glass527ba812013-07-25 08:48:47 -0600706ifdef REGION_READ
707${FWLIB_OBJS}: CFLAGS += -DREGION_READ
708endif
709
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800710ifeq (${FIRMWARE_ARCH},)
711# Disable rollback TPM when compiling locally, since otherwise
712# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800713${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800714endif
715
Bill Richardsona130e0b2013-04-04 18:16:39 -0700716# Linktest ensures firmware lib doesn't rely on outside libraries
717${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800718${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700719ALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700720${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800721${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700722ALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700723${BUILD}/firmware/linktest/main: ${FWLIB}
724${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700725ALL_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800726
727.phony: fwlinktest
728fwlinktest: ${FWLIB} \
729 ${BUILD}/firmware/linktest/main_vbinit \
730 ${BUILD}/firmware/linktest/main_vbsf \
731 ${BUILD}/firmware/linktest/main
732
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800733.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700734fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800735
Randall Spangler786acda2014-05-22 13:27:07 -0700736.PHONY: fwlib2
737fwlib2: ${FWLIB2}
738
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800739${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700740 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800741 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700742 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800743 ${Q}ar qc $@ $^
744
Randall Spangler786acda2014-05-22 13:27:07 -0700745${FWLIB2}: ${FWLIB2_OBJS}
746 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
747 ${Q}rm -f $@
748 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
749 ${Q}ar qc $@ $^
750
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800751# ----------------------------------------------------------------------------
752# Host library
753
Bill Richardsona130e0b2013-04-04 18:16:39 -0700754
755# Link tests
756${BUILD}/host/linktest/main: ${HOSTLIB}
757${BUILD}/host/linktest/main: LIBS = ${HOSTLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700758ALL_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700759
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800760.PHONY: hostlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700761hostlib: ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800762
763${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
Bill Richardson0c3ba242013-03-29 11:09:30 -0700764 -Ihost/include \
765 -Ihost/arch/${ARCH}/include \
766 -Ihost/lib/include
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800767
768# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangler786acda2014-05-22 13:27:07 -0700769${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
Simon Glass661ae9e2013-03-26 11:39:21 -0700770 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800771 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700772 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800773 ${Q}ar qc $@ $^
774
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800775
776# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
777.PHONY: tinyhostlib
778tinyhostlib: ${TINYHOSTLIB}
779 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
780
781${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700782 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800783 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700784 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800785 ${Q}ar qc $@ $^
786
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800787# ----------------------------------------------------------------------------
788# CGPT library and utility
789
790.PHONY: cgpt
791cgpt: ${CGPT}
792
Bill Richardson0c3ba242013-03-29 11:09:30 -0700793${CGPT_OBJS}: INCLUDES += -Ihost/include
794
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800795${CGPT}: LDFLAGS += -static
796${CGPT}: LDLIBS += -luuid
797
Bill Richardsona130e0b2013-04-04 18:16:39 -0700798${CGPT}: ${CGPT_OBJS} ${HOSTLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700799 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700800 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800801
802.PHONY: cgpt_install
803cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700804 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800805 ${Q}mkdir -p ${UB_DIR}
806 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800807
808# ----------------------------------------------------------------------------
809# Utilities
810
811# These have their own headers too.
Bill Richardson0c3ba242013-03-29 11:09:30 -0700812${BUILD}/utility/%: INCLUDES += \
813 -Ihost/include \
814 -Ihost/lib/include \
815 -Iutility/include
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800816
817# Utilities for auto-update toolkits must be statically linked.
818${UTIL_BINS_STATIC}: LDFLAGS += -static
819
Bill Richardsona130e0b2013-04-04 18:16:39 -0700820
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800821.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800822utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800823 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
824 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
825
Bill Richardsona130e0b2013-04-04 18:16:39 -0700826${UTIL_BINS} ${UTIL_BINS_STATIC}: ${HOSTLIB}
827${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${HOSTLIB}
828
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800829.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800830utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700831 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800832 ${Q}mkdir -p ${UB_DIR}
833 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800834
835# And some signing stuff for the target
836.PHONY: signing_install
837signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700838 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800839 ${Q}mkdir -p ${UB_DIR}
840 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800841 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS_DEV}
842 ${Q}${INSTALL} -t ${UB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
843ifneq (${VB_DIR},)
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800844 ${Q}mkdir -p ${VB_DIR}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800845 ${Q}for prog in $(notdir ${SIGNING_SCRIPTS_DEV}); do \
846 ln -sf "${FT_DIR}/futility" "${VB_DIR}/$$prog"; done
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800847endif
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800848
849# ----------------------------------------------------------------------------
850# new Firmware Utility
851
852.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700853futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
854
855${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS}
856 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
857 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800858
859${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700860 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700861 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800862
863.PHONY: futil_install
864futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700865 @$(PRINTF) " INSTALL futility\n"
Bill Richardsonfeb25182013-03-07 12:54:29 -0800866 ${Q}mkdir -p ${F_DIR}
Bill Richardson6db8c752013-04-05 13:30:43 -0700867 ${Q}${INSTALL} -t ${F_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800868 ${Q}for prog in ${FUTIL_OLD}; do \
869 ln -sf futility "${F_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800870
Bill Richardson20807b62013-04-09 10:15:26 -0700871# TODO(wfrichar): This will need some refactoring (crbug.com/228932)
872${BUILD}/futility/% ${HOSTLIB}: INCLUDES += \
873 -Ihost/include \
874 -Ihost/arch/${ARCH}/include \
875 -Ihost/lib/include
876${FUTIL_STATIC_BIN} ${FUTIL_BIN}: ${HOSTLIB}
877${FUTIL_STATIC_BIN} ${FUTIL_BIN}: LIBS = ${HOSTLIB}
878
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800879# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800880# Utility to generate TLCL structure definition header file.
881
882${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
883
884STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
885STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
886
887.PHONY: update_tlcl_structures
888update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700889 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800890 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
891 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
892 ( echo "%% Updating structures.h %%" && \
893 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
894
895# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800896# Tests
897
898.PHONY: tests
899tests: ${TEST_BINS}
900
Bill Richardsona130e0b2013-04-04 18:16:39 -0700901${TEST_BINS}: ${HOSTLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700902${TEST_BINS}: INCLUDES += -Itests
Bill Richardsona130e0b2013-04-04 18:16:39 -0700903${TEST_BINS}: LIBS = ${HOSTLIB} ${TESTLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800904
905${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700906 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800907 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700908 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800909 ${Q}ar qc $@ $^
910
911
912# ----------------------------------------------------------------------------
913# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
914# rules for specific targets.
915
916${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700917 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700918 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800919
920${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700921 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800922 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
923
924# Rules to recompile a single source file for library and test
925# TODO: is there a tidier way to do this?
926${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
927${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700928 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800929 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
930
931${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
932${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700933 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800934 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
935
936# TODO: C++ files don't belong in vboot reference at all. Convert to C.
937${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700938 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800939 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
940
941# ----------------------------------------------------------------------------
942# Here are the special tweaks to the generic rules.
943
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800944# GBB utility needs C++ linker. TODO: It shouldn't.
945${BUILD}/utility/gbb_utility: LD = ${CXX}
946
Bill Richardsonfeb25182013-03-07 12:54:29 -0800947# Because we play some clever linker script games to add new commands without
948# changing any header files, futility must be linked with ld.bfd, not gold.
949${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardson6db8c752013-04-05 13:30:43 -0700950${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardsonfeb25182013-03-07 12:54:29 -0800951
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800952# Some utilities need external crypto functions
953${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
954${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
955${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
956${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800957${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
958${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
959${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
960${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
961
962${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler7141d732014-05-15 15:34:54 -0700963${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
964${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800965${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
966${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800967
968${BUILD}/utility/bmpblk_utility: LD = ${CXX}
969${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
970
971BMPBLK_UTILITY_DEPS = \
972 ${BUILD}/utility/bmpblk_util.o \
973 ${BUILD}/utility/image_types.o \
974 ${BUILD}/utility/eficompress_for_lib.o \
975 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -0700976
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800977${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
978${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700979ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800980
981${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
982${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -0700983ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800984
985# Allow multiple definitions, so tests can mock functions from other libraries
986${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardson0c3ba242013-03-29 11:09:30 -0700987${BUILD}/tests/%: INCLUDES += -Ihost/include -Ihost/lib/include
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800988${BUILD}/tests/%: LDLIBS += -lrt -luuid
989${BUILD}/tests/%: LIBS += ${TESTLIB}
990
991${BUILD}/tests/rollback_index2_tests: OBJS += \
992 ${BUILD}/firmware/lib/rollback_index_for_test.o
993${BUILD}/tests/rollback_index2_tests: \
994 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -0700995ALL_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800996
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800997${BUILD}/tests/tlcl_tests: OBJS += \
998 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
999${BUILD}/tests/tlcl_tests: \
1000 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001001ALL_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001002
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001003${BUILD}/tests/vboot_audio_tests: OBJS += \
1004 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1005${BUILD}/tests/vboot_audio_tests: \
1006 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001007ALL_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001008
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001009${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
1010${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
1011
Bill Richardson339f7e02013-04-05 09:49:24 -07001012TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001013${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1014${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001015ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001016
1017##############################################################################
1018# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001019
1020# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001021.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001022test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001023
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001024ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001025# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001026test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001027# Scripts don't work under qemu testing
1028# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001029test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001030endif
1031
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001032.PHONY: test_setup
1033test_setup:: cgpt utils futil tests
1034
Randall Spangler844bce52013-01-15 16:16:43 -08001035# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1036# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001037ifneq (${QEMU_ARCH},)
1038test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001039
1040.PHONY: qemu_install
1041qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001042ifeq (${SYSROOT},)
1043 $(error SYSROOT must be set to the top of the target-specific root \
1044when cross-compiling for qemu-based tests to run properly.)
1045endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001046 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001047 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1048 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001049endif
1050
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001051.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001052runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001053
1054# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001055.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001056genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001057 tests/gen_test_keys.sh
1058
1059# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001060.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001061genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001062 tests/gen_fuzz_test_cases.sh
1063
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001064.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001065runbmptests: test_setup
1066 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001067 ./TestBmpBlock.py -v
1068
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001069.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001070runcgpttests: test_setup
1071 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001072
Randall Spangler844bce52013-01-15 16:16:43 -08001073.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001074runtestscripts: test_setup genfuzztestcases
1075 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Albert Chaulk42c08cb2013-04-02 14:38:07 -07001076 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001077 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001078 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001079 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001080 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001081ifneq (${VBOOT2},)
1082 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001083 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001084endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001085
Randall Spangler844bce52013-01-15 16:16:43 -08001086.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001087runmisctests: test_setup
1088 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001089 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001090 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1091 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1092 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001093 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001094 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1095 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1096 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1097 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001098 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001099 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1100 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001101 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1102 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1103 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001104 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001105 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1106 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1107 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001108 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001109 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001110 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001111 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001112
Randall Spangler786acda2014-05-22 13:27:07 -07001113.PHONY: run2tests
1114run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001115 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001116 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001117 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1118 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001119 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001120 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001121 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001122 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001123 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001124 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001125
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001126.PHONY: runfutiltests
Bill Richardsonfeb25182013-03-07 12:54:29 -08001127runfutiltests: override DESTDIR = ${TEST_INSTALL_DIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001128runfutiltests: test_setup install
Bill Richardson339f7e02013-04-05 09:49:24 -07001129 tests/futility/run_test_scripts.sh ${DESTDIR}
1130 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001131
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001132# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001133# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001134# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001135.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001137 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1138 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001139ifneq (${VBOOT2},)
1140 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1141 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1142endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001143 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001144 tests/run_vbutil_tests.sh --all
1145
1146# TODO: tests to run when ported to new API
1147# ./run_image_verification_tests.sh
1148# # Splicing tests
1149# ${BUILD}/tests/firmware_splicing_tests
1150# ${BUILD}/tests/kernel_splicing_tests
1151# # Rollback Tests
1152# ${BUILD}/tests/firmware_rollback_tests
1153# ${BUILD}/tests/kernel_rollback_tests
1154
Randall Spangler59d75082013-01-23 09:29:54 -08001155# Code coverage
1156.PHONY: coverage_init
1157coverage_init: test_setup
1158 rm -f ${COV_INFO}*
1159 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1160
1161.PHONY: coverage_html
1162coverage_html:
1163 lcov -c -d . -b . -o ${COV_INFO}.tests
1164 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1165 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1166 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1167
1168# Generate addtional coverage stats just for firmware subdir, because the
1169# per-directory stats for the whole project don't include their own subdirs.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001170 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1171 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001172 -o ${COV_INFO}.firmware
1173
1174.PHONY: coverage
1175ifeq (${COV},)
1176coverage:
1177 $(error Build coverage like this: make clean && COV=1 make)
1178else
1179coverage: coverage_init runtests coverage_html
1180endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001181
1182# Include generated dependencies
1183ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1184-include ${ALL_DEPS}