blob: d7742f45c2fe4f4731497bb196ad2d1c4ef2efc4 [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 Richardsond4621012014-07-09 23:31:13 -0700143CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
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
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700165ifeq (${FIRMWARE_ARCH},)
166# Creates position independent code for non firmware target.
167CFLAGS += -fPIE
168endif
169
Bill Richardson0c3ba242013-03-29 11:09:30 -0700170# These are required to access large disks and files on 32-bit systems.
171CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
172
Randall Spangler59d75082013-01-23 09:29:54 -0800173# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800174ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700175 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800176 CFLAGS += ${COV_FLAGS}
177 LDFLAGS += ${COV_FLAGS}
178 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800179endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800180
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181# And a few more default utilities
182LD = ${CC}
183CXX ?= g++ # HEY: really?
184PKG_CONFIG ?= pkg-config
185
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186# Determine QEMU architecture needed, if any
187ifeq (${ARCH},${HOST_ARCH})
188 # Same architecture; no need for QEMU
189 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800190else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800191 # 64-bit host can run 32-bit targets directly
192 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800193else
194 QEMU_ARCH := ${ARCH}
195endif
196
197# The top of the chroot for qemu must be passed in via the SYSROOT environment
198# variable. In the Chromium OS chroot, this is done automatically by the
199# ebuild.
200
201ifeq (${QEMU_ARCH},)
202 # Path to build output for running tests is same as for building
203 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800204 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205else
206 $(info Using qemu for testing.)
207 # Path to build output for running tests is different in the chroot
208 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800209 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210
211 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800212 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
213 export QEMU_RUN
214
215 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800216endif
217
Randall Spanglere061a252013-01-22 15:34:07 -0800218export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800219
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800220##############################################################################
221# Now we need to describe everything we might want or need to build
222
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800223# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800224INCLUDES += \
225 -Ifirmware/include \
226 -Ifirmware/lib/include \
227 -Ifirmware/lib/cgptlib/include \
228 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700229 -Ifirmware/lib/tpm_lite/include \
230 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700231
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800232# If we're not building for a specific target, just stub out things like the
233# TPM commands and various external functions that are provided by the BIOS.
234ifeq (${FIRMWARE_ARCH},)
Bill Richardson0f6679e2014-07-10 15:49:52 -0700235INCLUDES += -Ifirmware/stub/include -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800236else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800237INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800238endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800239
Bill Richardson78299022014-06-20 14:33:00 -0700240# Firmware library, used by the other firmware components (depthcharge,
241# coreboot, etc.). It doesn't need exporting to some other place; they'll build
242# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800243FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800244
Randall Spangler786acda2014-05-22 13:27:07 -0700245# Smaller firmware library. TODO: Do we still need to export this?
246ifneq (${VBOOT2},)
247FWLIB2 = ${BUILD}/vboot_fw2.a
248endif
249
Randall Spangler93943262013-02-26 11:03:57 -0800250# Firmware library sources needed by VbInit() call
251VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800252 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800253 firmware/lib/utility.c \
254 firmware/lib/vboot_api_init.c \
255 firmware/lib/vboot_common_init.c \
256 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700257 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600258 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800259
260# Additional firmware library sources needed by VbSelectFirmware() call
261VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800262 firmware/lib/cryptolib/padding.c \
263 firmware/lib/cryptolib/rsa.c \
264 firmware/lib/cryptolib/rsa_utility.c \
265 firmware/lib/cryptolib/sha1.c \
266 firmware/lib/cryptolib/sha256.c \
267 firmware/lib/cryptolib/sha512.c \
268 firmware/lib/cryptolib/sha_utility.c \
269 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800270 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800271 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600272 firmware/lib/vboot_firmware.c \
273 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800274
275# Additional firmware library sources needed by VbSelectAndLoadKernel() call
276VBSLK_SRCS = \
277 firmware/lib/cgptlib/cgptlib.c \
278 firmware/lib/cgptlib/cgptlib_internal.c \
279 firmware/lib/cgptlib/crc32.c \
Albert Chaulk5c9e4532013-03-20 16:03:49 -0700280 firmware/lib/cgptlib/mtdlib.c \
Randall Spangler93943262013-02-26 11:03:57 -0800281 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800282 firmware/lib/vboot_api_kernel.c \
283 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800284 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600285 firmware/lib/vboot_kernel.c \
286 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800287
Randall Spangler786acda2014-05-22 13:27:07 -0700288# Firmware library source needed for smaller library 2
289FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700290 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700291 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700292 firmware/2lib/2crc8.c \
293 firmware/2lib/2misc.c \
294 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700295 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700296 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700297 firmware/2lib/2sha1.c \
298 firmware/2lib/2sha256.c \
299 firmware/2lib/2sha512.c \
300 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700301
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800302# Support real TPM unless BIOS sets MOCK_TPM
303ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800304VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800305 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800306 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800307
308VBSF_SRCS += \
309 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800310else
Randall Spangler93943262013-02-26 11:03:57 -0800311VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800312 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800313 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800314
315VBSF_SRCS += \
316 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800317endif
318
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800319ifeq (${FIRMWARE_ARCH},)
320# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800321# TODO: split out other stub funcs too
322VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800323 firmware/stub/tpm_lite_stub.c \
324 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600325 firmware/stub/vboot_api_stub_init.c \
326 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800327
328VBSF_SRCS += \
329 firmware/stub/vboot_api_stub_sf.c
330
331VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800332 firmware/stub/vboot_api_stub.c \
333 firmware/stub/vboot_api_stub_disk.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700334
335FWLIB2_SRCS += \
336 firmware/2lib/2stub.c
337
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800338endif
339
Randall Spangler93943262013-02-26 11:03:57 -0800340VBSF_SRCS += ${VBINIT_SRCS}
341FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
342
343VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
344VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
345
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800346FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700347
Randall Spangler786acda2014-05-22 13:27:07 -0700348ifneq (${VBOOT2},)
349FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
350endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800351
Randall Spangler786acda2014-05-22 13:27:07 -0700352ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800353
Bill Richardson78299022014-06-20 14:33:00 -0700354# Intermediate library for the vboot_reference utilities to link against.
355UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800356
Bill Richardson78299022014-06-20 14:33:00 -0700357UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800358 cgpt/cgpt_create.c \
359 cgpt/cgpt_add.c \
360 cgpt/cgpt_boot.c \
361 cgpt/cgpt_show.c \
362 cgpt/cgpt_repair.c \
363 cgpt/cgpt_prioritize.c \
364 cgpt/cgpt_common.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700365 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700366 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700367 firmware/lib/cgptlib/mtdlib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800368 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800369 host/lib/crossystem.c \
370 host/lib/file_keys.c \
371 host/lib/fmap.c \
372 host/lib/host_common.c \
373 host/lib/host_key.c \
374 host/lib/host_keyblock.c \
375 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700376 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800377 host/lib/host_signature.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800378 host/lib/signature_digest.c \
379 utility/dump_kernel_config_lib.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800380
Bill Richardson78299022014-06-20 14:33:00 -0700381UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
382ALL_OBJS += ${UTILLIB_OBJS}
383
384# Externally exported library for some target userspace apps to link with
385# (cryptohome, updater, etc.)
386HOSTLIB = ${BUILD}/libvboot_host.a
387
388HOSTLIB_SRCS = \
389 cgpt/cgpt_add.c \
390 cgpt/cgpt_boot.c \
391 cgpt/cgpt_common.c \
392 cgpt/cgpt_create.c \
393 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700394 cgpt/flash_ts.c \
Bill Richardson78299022014-06-20 14:33:00 -0700395 cgpt/flash_ts_drv.c \
396 firmware/lib/cgptlib/cgptlib_internal.c \
397 firmware/lib/cgptlib/crc32.c \
398 firmware/lib/cgptlib/mtdlib.c \
399 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700400 firmware/lib/tpm_lite/tlcl.c \
401 firmware/lib/utility_string.c \
402 firmware/lib/vboot_nvstorage.c \
403 firmware/stub/tpm_lite_stub.c \
404 firmware/stub/utility_stub.c \
405 firmware/stub/vboot_api_stub_init.c \
406 host/arch/${ARCH}/lib/crossystem_arch.c \
407 host/lib/crossystem.c \
408 host/lib/host_misc.c \
409 utility/dump_kernel_config_lib.c
410
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800411HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800412ALL_OBJS += ${HOSTLIB_OBJS}
413
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800414# Sigh. For historical reasons, the autoupdate installer must sometimes be a
415# 32-bit executable, even when everything else is 64-bit. But it only needs a
416# few functions, so let's just build those.
417TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
418
419TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800420 cgpt/cgpt_add.c \
421 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800422 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700423 cgpt/cgpt_create.c \
424 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700425 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700426 cgpt/flash_ts_drv.c \
Bill Richardson78299022014-06-20 14:33:00 -0700427 firmware/lib/cgptlib/cgptlib_internal.c \
428 firmware/lib/cgptlib/crc32.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700429 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800430 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700431 firmware/stub/utility_stub.c \
432 utility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800433
434TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800435
436# ----------------------------------------------------------------------------
437# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800438
439CGPT = ${BUILD}/cgpt/cgpt
440
441CGPT_SRCS = \
442 cgpt/cgpt.c \
443 cgpt/cgpt_add.c \
444 cgpt/cgpt_boot.c \
445 cgpt/cgpt_common.c \
446 cgpt/cgpt_create.c \
447 cgpt/cgpt_find.c \
448 cgpt/cgpt_legacy.c \
449 cgpt/cgpt_prioritize.c \
450 cgpt/cgpt_repair.c \
451 cgpt/cgpt_show.c \
452 cgpt/cmd_add.c \
453 cgpt/cmd_boot.c \
454 cgpt/cmd_create.c \
455 cgpt/cmd_find.c \
456 cgpt/cmd_legacy.c \
457 cgpt/cmd_prioritize.c \
458 cgpt/cmd_repair.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700459 cgpt/cmd_show.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700460 cgpt/flash_ts.c \
461 cgpt/flash_ts_drv.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800463CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800464ALL_OBJS += ${CGPT_OBJS}
465
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800466
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800467# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800468UTIL_SCRIPTS = \
469 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800470 utility/enable_dev_usb_boot \
471 utility/vbutil_what_keys
472
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800473ifeq (${MINIMAL},)
474UTIL_SCRIPTS += \
475 utility/dev_make_keypair
476endif
477
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800478# These utilities should be linked statically.
479UTIL_NAMES_STATIC = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700480 utility/crossystem \
Bill Richardson339f7e02013-04-05 09:49:24 -0700481 utility/gbb_utility
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800482
483UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700484 utility/dev_sign_file \
485 utility/dump_kernel_config \
486 utility/dumpRSAPublicKey \
487 utility/tpm_init_temp_fix \
488 utility/tpmc \
489 utility/vbutil_firmware \
Bill Richardson884a5f12014-07-14 16:19:59 -0700490 utility/vbutil_kernel
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800491
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800492ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800493UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700494 utility/bmpblk_font \
495 utility/bmpblk_utility \
496 utility/eficompress \
497 utility/efidecompress \
498 utility/load_kernel_test \
499 utility/pad_digest_utility \
500 utility/signature_digest_utility \
501 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700502
503ifneq (${VBOOT2},)
504UTIL_NAMES += \
505 utility/vb2_verify_fw
506endif
507
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800508endif
509
Bill Richardson339f7e02013-04-05 09:49:24 -0700510UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
511UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700512ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800513
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800514
515# Scripts for signing stuff.
516SIGNING_SCRIPTS = \
517 utility/tpm-nvsize \
518 utility/chromeos-tpm-recovery
519
520# These go in a different place.
521SIGNING_SCRIPTS_DEV = \
522 scripts/image_signing/resign_firmwarefd.sh \
523 scripts/image_signing/make_dev_firmware.sh \
524 scripts/image_signing/make_dev_ssd.sh \
525 scripts/image_signing/set_gbb_flags.sh
526
527# Installed, but not made executable.
528SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800529
Bill Richardson826db092013-01-14 12:37:15 -0800530
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800531# The unified firmware utility will eventually replace all the others
532FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700533# But we still need both static (tiny) and dynamic (with openssl) versions.
534FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800535
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700536# These are the executables to be replaced with symlinks.
Bill Richardsone1550442014-07-17 11:32:17 -0700537FUTIL_OLD = \
538 bmpblk_font \
539 bmpblk_utility \
540 cgpt \
541 chromeos-tpm-recovery \
542 crossystem \
543 dev_debug_vboot \
544 dev_make_keypair \
545 dev_sign_file \
546 dumpRSAPublicKey \
547 dump_fmap \
548 dump_kernel_config \
549 eficompress \
550 efidecompress \
551 enable_dev_usb_boot \
552 gbb_utility \
553 load_kernel_test \
554 make_dev_firmware.sh \
555 make_dev_ssd.sh \
556 pad_digest_utility \
557 resign_firmwarefd.sh \
558 set_gbb_flags.sh \
559 signature_digest_utility \
560 tpm-nvsize \
561 tpm_init_temp_fix \
562 tpmc \
563 vbutil_firmware \
564 vbutil_kernel \
565 vbutil_key \
566 vbutil_keyblock \
567 vbutil_what_keys \
568 verify_data
Bill Richardsonfeb25182013-03-07 12:54:29 -0800569
Bill Richardson6db8c752013-04-05 13:30:43 -0700570FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800571 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700572 futility/cmd_dump_fmap.c \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800573 futility/cmd_foo.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800574
Bill Richardson6db8c752013-04-05 13:30:43 -0700575FUTIL_SRCS = \
576 $(FUTIL_STATIC_SRCS) \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700577 futility/cmd_vbutil_key.c \
Bill Richardson884a5f12014-07-14 16:19:59 -0700578 futility/cmd_vbutil_keyblock.c \
Bill Richardson6db8c752013-04-05 13:30:43 -0700579 futility/cmd_hey.c
580
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800581FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800582
Bill Richardson6db8c752013-04-05 13:30:43 -0700583FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800584FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800585
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800586ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800587
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800588
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800589# Library of handy test functions.
590TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800591
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800592TESTLIB_SRCS = \
593 tests/test_common.c \
594 tests/timer_utils.c \
595 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800596
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800597TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
598ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800599
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800600
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800601# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800602TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700603 tests/cgptlib_test \
604 tests/rollback_index2_tests \
605 tests/rollback_index3_tests \
606 tests/rsa_padding_test \
607 tests/rsa_utility_tests \
608 tests/rsa_verify_benchmark \
609 tests/sha_benchmark \
610 tests/sha_tests \
611 tests/stateful_util_tests \
612 tests/tlcl_tests \
613 tests/tpm_bootmode_tests \
614 tests/utility_string_tests \
615 tests/utility_tests \
616 tests/vboot_api_init_tests \
617 tests/vboot_api_devmode_tests \
618 tests/vboot_api_firmware_tests \
619 tests/vboot_api_kernel_tests \
620 tests/vboot_api_kernel2_tests \
621 tests/vboot_api_kernel3_tests \
622 tests/vboot_api_kernel4_tests \
623 tests/vboot_audio_tests \
624 tests/vboot_common_tests \
625 tests/vboot_common2_tests \
626 tests/vboot_common3_tests \
627 tests/vboot_display_tests \
628 tests/vboot_firmware_tests \
629 tests/vboot_kernel_tests \
630 tests/vboot_nvstorage_test \
631 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800632
Simon Glass527ba812013-07-25 08:48:47 -0600633ifdef REGION_READ
634TEST_NAMES += tests/vboot_region_tests
635endif
636
Randall Spangler786acda2014-05-22 13:27:07 -0700637ifneq (${VBOOT2},)
638TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700639 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700640 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700641 tests/vb2_common2_tests \
642 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700643 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700644 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700645 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700646 tests/vb2_rsa_padding_tests \
647 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700648 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700649 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700650
651endif
652
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800653# TODO: port these tests to new API, if not already eqivalent
654# functionality in other tests. These don't even compile at present.
655#
656# big_firmware_tests
657# big_kernel_tests
658# firmware_image_tests
659# firmware_rollback_tests
660# firmware_splicing_tests
661# firmware_verify_benchmark
662# kernel_image_tests
663# kernel_rollback_tests
664# kernel_splicing_tests
665# kernel_verify_benchmark
666# rollback_index_test
667# verify_firmware_fuzz_driver
668# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800669# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800670
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800671# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700672TLCL_TEST_NAMES = \
673 tests/tpm_lite/tpmtest_earlyextend \
674 tests/tpm_lite/tpmtest_earlynvram \
675 tests/tpm_lite/tpmtest_earlynvram2 \
676 tests/tpm_lite/tpmtest_enable \
677 tests/tpm_lite/tpmtest_fastenable \
678 tests/tpm_lite/tpmtest_globallock \
679 tests/tpm_lite/tpmtest_redefine_unowned \
680 tests/tpm_lite/tpmtest_spaceperm \
681 tests/tpm_lite/tpmtest_testsetup \
682 tests/tpm_lite/tpmtest_timing \
683 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800684
685TEST_NAMES += ${TLCL_TEST_NAMES}
686
Bill Richardson339f7e02013-04-05 09:49:24 -0700687# Finally
688TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700689ALL_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800690
Randall Spanglere061a252013-01-22 15:34:07 -0800691# Directory containing test keys
692TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800693
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800694
695##############################################################################
696# Finally, some targets. High-level ones first.
697
698# Create output directories if necessary. Do this via explicit shell commands
699# so it happens before trying to generate/include dependencies.
700SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
701_dir_create := $(foreach d, \
702 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
703 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
704
705
706# Default target.
707.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700708all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
709 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800710
711# Host targets
712.PHONY: host_stuff
Bill Richardsonbc2d2b22014-07-09 21:11:12 -0700713host_stuff: utillib hostlib cgpt utils futil tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800714
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800715.PHONY: clean
716clean:
717 ${Q}/bin/rm -rf ${BUILD}
718
719.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800720install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800721
Bill Richardson3e3790d2014-07-14 15:05:54 -0700722.PHONY: install_for_test
723install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
724install_for_test: install
725
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800726# Don't delete intermediate object files
727.SECONDARY:
728
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800729
730# ----------------------------------------------------------------------------
731# Firmware library
732
733# TPM-specific flags. These depend on the particular TPM we're targeting for.
734# They are needed here only for compiling parts of the firmware code into
735# user-level tests.
736
737# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
738# the self test has completed.
739
Randall Spangler45cc0f22013-01-25 09:34:26 -0800740${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800741
742# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
743# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
744# power on.
745#
746# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
747# are not both defined at the same time. (See comment in code.)
748
749# CFLAGS += -DTPM_MANUAL_SELFTEST
750
751ifeq (${FIRMWARE_ARCH},i386)
752# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800753${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700754${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800755
756# Workaround for coreboot on x86, which will power off asynchronously
757# without giving us a chance to react. This is not an example of the Right
758# Way to do things. See chrome-os-partner:7689, and the commit message
759# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800760${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800761
762# On x86 we don't actually read the GBB data into RAM until it is needed.
763# Therefore it makes sense to cache it rather than reading it each time.
764# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800765${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766endif
767
Simon Glass527ba812013-07-25 08:48:47 -0600768ifdef REGION_READ
769${FWLIB_OBJS}: CFLAGS += -DREGION_READ
770endif
771
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800772ifeq (${FIRMWARE_ARCH},)
773# Disable rollback TPM when compiling locally, since otherwise
774# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800775${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800776endif
777
Bill Richardsona130e0b2013-04-04 18:16:39 -0700778# Linktest ensures firmware lib doesn't rely on outside libraries
779${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800780${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700781ALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700782${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800783${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700784ALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700785${BUILD}/firmware/linktest/main: ${FWLIB}
786${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700787ALL_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800788
Bill Richardsond2d08b22014-07-08 16:31:40 -0700789.PHONY: fwlinktest
790fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800791 ${BUILD}/firmware/linktest/main_vbinit \
792 ${BUILD}/firmware/linktest/main_vbsf \
793 ${BUILD}/firmware/linktest/main
794
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800795.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700796fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800797
Randall Spangler786acda2014-05-22 13:27:07 -0700798.PHONY: fwlib2
799fwlib2: ${FWLIB2}
800
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800801${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700802 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800803 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700804 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800805 ${Q}ar qc $@ $^
806
Randall Spangler786acda2014-05-22 13:27:07 -0700807${FWLIB2}: ${FWLIB2_OBJS}
808 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
809 ${Q}rm -f $@
810 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
811 ${Q}ar qc $@ $^
812
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800813# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700814# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800815
Bill Richardson78299022014-06-20 14:33:00 -0700816# Link tests for local utilities
817${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700818${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
819ALL_OBJS += ${BUILD}/host/linktest/main.o
820
821.PHONY: utillib
822utillib: ${UTILLIB} \
823 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800824
825# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700826${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
827 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
828 ${Q}rm -f $@
829 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
830 ${Q}ar qc $@ $^
831
832
833# Link tests for external repos
834${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700835${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
836${BUILD}/host/linktest/extern: LDLIBS += -static
837ALL_OBJS += ${BUILD}/host/linktest/extern.o
838
839.PHONY: hostlib
840hostlib: ${HOSTLIB} \
841 ${BUILD}/host/linktest/extern
842
843# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700844${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700845 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800846 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700847 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800848 ${Q}ar qc $@ $^
849
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800850
851# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
852.PHONY: tinyhostlib
853tinyhostlib: ${TINYHOSTLIB}
854 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
855
856${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700857 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800858 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700859 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800860 ${Q}ar qc $@ $^
861
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800862# ----------------------------------------------------------------------------
863# CGPT library and utility
864
865.PHONY: cgpt
866cgpt: ${CGPT}
867
868${CGPT}: LDFLAGS += -static
869${CGPT}: LDLIBS += -luuid
870
Bill Richardson78299022014-06-20 14:33:00 -0700871${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700872 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700873 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800874
875.PHONY: cgpt_install
876cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700877 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800878 ${Q}mkdir -p ${UB_DIR}
879 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800880
881# ----------------------------------------------------------------------------
882# Utilities
883
884# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700885${BUILD}/utility/%: INCLUDES += -Iutility/include
886
887${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
888${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800889
890# Utilities for auto-update toolkits must be statically linked.
891${UTIL_BINS_STATIC}: LDFLAGS += -static
892
Bill Richardsona130e0b2013-04-04 18:16:39 -0700893
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800894.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800895utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800896 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
897 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
898
899.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800900utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700901 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800902 ${Q}mkdir -p ${UB_DIR}
903 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800904
905# And some signing stuff for the target
906.PHONY: signing_install
907signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700908 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800909 ${Q}mkdir -p ${UB_DIR}
910 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800911 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS_DEV}
912 ${Q}${INSTALL} -t ${UB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
913ifneq (${VB_DIR},)
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800914 ${Q}mkdir -p ${VB_DIR}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800915 ${Q}for prog in $(notdir ${SIGNING_SCRIPTS_DEV}); do \
916 ln -sf "${FT_DIR}/futility" "${VB_DIR}/$$prog"; done
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800917endif
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800918
919# ----------------------------------------------------------------------------
920# new Firmware Utility
921
922.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700923futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
924
Bill Richardson0f6679e2014-07-10 15:49:52 -0700925${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS} ${UTILLIB}
Bill Richardson6db8c752013-04-05 13:30:43 -0700926 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
927 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800928
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700929${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson0f6679e2014-07-10 15:49:52 -0700930${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700931 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700932 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800933
934.PHONY: futil_install
935futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700936 @$(PRINTF) " INSTALL futility\n"
Bill Richardsonfeb25182013-03-07 12:54:29 -0800937 ${Q}mkdir -p ${F_DIR}
Bill Richardson6db8c752013-04-05 13:30:43 -0700938 ${Q}${INSTALL} -t ${F_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800939 ${Q}for prog in ${FUTIL_OLD}; do \
940 ln -sf futility "${F_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800941
942# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800943# Utility to generate TLCL structure definition header file.
944
945${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
946
947STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
948STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
949
950.PHONY: update_tlcl_structures
951update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700952 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800953 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
954 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
955 ( echo "%% Updating structures.h %%" && \
956 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
957
958# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800959# Tests
960
961.PHONY: tests
962tests: ${TEST_BINS}
963
Bill Richardson78299022014-06-20 14:33:00 -0700964${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700965${TEST_BINS}: INCLUDES += -Itests
Bill Richardson78299022014-06-20 14:33:00 -0700966${TEST_BINS}: LIBS = ${UTILLIB} ${TESTLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800967
968${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700969 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800970 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700971 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800972 ${Q}ar qc $@ $^
973
974
975# ----------------------------------------------------------------------------
976# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
977# rules for specific targets.
978
979${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700980 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700981 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800982
983${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700984 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800985 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
986
987# Rules to recompile a single source file for library and test
988# TODO: is there a tidier way to do this?
989${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
990${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700991 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800992 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
993
994${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
995${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700996 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800997 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
998
999# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1000${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -07001001 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001002 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1003
1004# ----------------------------------------------------------------------------
1005# Here are the special tweaks to the generic rules.
1006
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001007# GBB utility needs C++ linker. TODO: It shouldn't.
1008${BUILD}/utility/gbb_utility: LD = ${CXX}
1009
Bill Richardsonfeb25182013-03-07 12:54:29 -08001010# Because we play some clever linker script games to add new commands without
1011# changing any header files, futility must be linked with ld.bfd, not gold.
1012${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardson6db8c752013-04-05 13:30:43 -07001013${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardsonfeb25182013-03-07 12:54:29 -08001014
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001015# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001016CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1017
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001018${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1019${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1020${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1021${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001022${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
1023${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001024
1025${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler7141d732014-05-15 15:34:54 -07001026${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1027${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001028${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1029${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001030
Bill Richardson18e03702014-06-23 17:48:33 -07001031${BUILD}/tests/cgptlib_test: OBJS += \
1032 ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
1033${BUILD}/tests/cgptlib_test: ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
1034
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001035${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1036${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
1037
1038BMPBLK_UTILITY_DEPS = \
1039 ${BUILD}/utility/bmpblk_util.o \
1040 ${BUILD}/utility/image_types.o \
1041 ${BUILD}/utility/eficompress_for_lib.o \
1042 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001043
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001044${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1045${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001046ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001047
1048${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1049${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001050ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001051
1052# Allow multiple definitions, so tests can mock functions from other libraries
1053${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001054${BUILD}/tests/%: LDLIBS += -lrt -luuid
1055${BUILD}/tests/%: LIBS += ${TESTLIB}
1056
1057${BUILD}/tests/rollback_index2_tests: OBJS += \
1058 ${BUILD}/firmware/lib/rollback_index_for_test.o
1059${BUILD}/tests/rollback_index2_tests: \
1060 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001061ALL_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001062
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001063${BUILD}/tests/tlcl_tests: OBJS += \
1064 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1065${BUILD}/tests/tlcl_tests: \
1066 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001067ALL_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001068
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001069${BUILD}/tests/vboot_audio_tests: OBJS += \
1070 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1071${BUILD}/tests/vboot_audio_tests: \
1072 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001073ALL_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001074
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001075${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
1076${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
1077
Bill Richardson339f7e02013-04-05 09:49:24 -07001078TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001079${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1080${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001081ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001082
1083##############################################################################
1084# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001085
1086# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001087.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001088test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001089
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001090ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001091# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001092test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001093# Scripts don't work under qemu testing
1094# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001095test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001096endif
1097
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001098.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001099test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001100
Randall Spangler844bce52013-01-15 16:16:43 -08001101# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1102# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001103ifneq (${QEMU_ARCH},)
1104test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001105
1106.PHONY: qemu_install
1107qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001108ifeq (${SYSROOT},)
1109 $(error SYSROOT must be set to the top of the target-specific root \
1110when cross-compiling for qemu-based tests to run properly.)
1111endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001112 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001113 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1114 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001115endif
1116
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001117.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001118runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001119
1120# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001121.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001122genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001123 tests/gen_test_keys.sh
1124
1125# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001126.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001127genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001128 tests/gen_fuzz_test_cases.sh
1129
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001130.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001131runbmptests: test_setup
1132 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001133 ./TestBmpBlock.py -v
1134
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001135.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136runcgpttests: test_setup
1137 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001138
Randall Spangler844bce52013-01-15 16:16:43 -08001139.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001140runtestscripts: test_setup genfuzztestcases
1141 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Albert Chaulk42c08cb2013-04-02 14:38:07 -07001142 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001143 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001144 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001145 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001146 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001147ifneq (${VBOOT2},)
1148 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001149 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001150endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001151
Randall Spangler844bce52013-01-15 16:16:43 -08001152.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001153runmisctests: test_setup
1154 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001155 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001156 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1157 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1158 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001159 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001160 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1161 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1162 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1163 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001164 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001165 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1166 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001167 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1168 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1169 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001170 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001171 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1172 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1173 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001174 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001175 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001176 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001177 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001178
Randall Spangler786acda2014-05-22 13:27:07 -07001179.PHONY: run2tests
1180run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001181 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001182 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001183 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1184 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001185 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001186 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001187 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001188 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001189 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001190 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001191
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001192.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001193runfutiltests: test_setup
1194 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}
Bill Richardson339f7e02013-04-05 09:49:24 -07001195 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001196
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001197# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001198# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001199# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001200.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001201runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001202 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1203 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001204ifneq (${VBOOT2},)
1205 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1206 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1207endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001208 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001209 tests/run_vbutil_tests.sh --all
1210
1211# TODO: tests to run when ported to new API
1212# ./run_image_verification_tests.sh
1213# # Splicing tests
1214# ${BUILD}/tests/firmware_splicing_tests
1215# ${BUILD}/tests/kernel_splicing_tests
1216# # Rollback Tests
1217# ${BUILD}/tests/firmware_rollback_tests
1218# ${BUILD}/tests/kernel_rollback_tests
1219
Bill Richardson78299022014-06-20 14:33:00 -07001220.PHONY: runalltests
1221runalltests: runtests runfutiltests runlongtests
1222
Randall Spangler59d75082013-01-23 09:29:54 -08001223# Code coverage
1224.PHONY: coverage_init
1225coverage_init: test_setup
1226 rm -f ${COV_INFO}*
1227 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1228
1229.PHONY: coverage_html
1230coverage_html:
1231 lcov -c -d . -b . -o ${COV_INFO}.tests
1232 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1233 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1234 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001235# Generate addtional coverage stats just for firmware subdir, because the stats
1236# for the whole project don't include subdirectory summaries. This will print
1237# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001238 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1239 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001240 -o ${COV_INFO}.firmware
1241
1242.PHONY: coverage
1243ifeq (${COV},)
1244coverage:
1245 $(error Build coverage like this: make clean && COV=1 make)
1246else
1247coverage: coverage_init runtests coverage_html
1248endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001249
1250# Include generated dependencies
1251ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1252-include ${ALL_DEPS}