blob: 4a481036bd2c21b4ee985b1478b6dc226ce214ee [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill 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
Bill Richardsonc9bf3482013-02-13 14:38:29 -080046
Bill Richardsonfeb25182013-03-07 12:54:29 -080047# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070048# UB_DIR = utility binary directory
49# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080050ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070051# Host install just puts everything where it's told
52UB_DIR=${DESTDIR}
53VB_DIR=${DESTDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080054else
Bill Richardson6f396152014-07-15 12:52:19 -070055# Target install puts things into subdirectories under DESTDIR
56UB_DIR=${DESTDIR}/usr/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080057VB_DIR=${DESTDIR}/usr/share/vboot/bin
58endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080059
Bill Richardsoneecc18f2013-01-17 15:28:17 -080060# Where to install the (exportable) executables for testing?
61TEST_INSTALL_DIR = ${BUILD}/install_for_test
62
63# Verbose? Use V=1
64ifeq (${V},)
65Q := @
66endif
67
Simon Glass661ae9e2013-03-26 11:39:21 -070068# Quiet? Use QUIET=1
69ifeq ($(QUIET),)
70PRINTF := printf
71else
72PRINTF := :
73endif
74
Randall Spangler61a2eb32013-01-23 10:20:16 -080075# Architecture detection
76_machname := $(shell uname -m)
77HOST_ARCH ?= ${_machname}
78
79# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
80# Pick a sane target architecture if none is defined.
81ifeq (${ARCH},)
82 ARCH := ${HOST_ARCH}
83else ifeq (${ARCH},i386)
84 override ARCH := x86
85else ifeq (${ARCH},amd64)
86 override ARCH := x86_64
87endif
88
89# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
90# for a firmware target (such as u-boot or depthcharge). It must map
91# to the same consistent set of architectures as the host.
92ifeq (${FIRMWARE_ARCH},i386)
93 override FIRMWARE_ARCH := x86
94else ifeq (${FIRMWARE_ARCH},amd64)
95 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -070096else ifeq (${FIRMWARE_ARCH},armv7)
97 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -080098endif
99
Simon Glassb265c342011-11-16 15:09:51 -0800100# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
101# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700102#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800103# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
104# temporarily. As we are still investigating which flags are necessary for
105# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700106#
Simon Glassb265c342011-11-16 15:09:51 -0800107# As a first step, this makes the setting of CC and CFLAGS here optional, to
108# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700109#
Simon Glassb265c342011-11-16 15:09:51 -0800110# Flag ordering: arch, then -f, then -m, then -W
111DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
112COMMON_FLAGS := -nostdinc -pipe \
113 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800114 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800115
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800116# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
117ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800118CC ?= armv7a-cros-linux-gnueabi-gcc
119CFLAGS ?= -march=armv5 \
120 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700121 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800122 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800123else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800124CC ?= i686-pc-linux-gnu-gcc
125# Drop -march=i386 to permit use of SSE instructions
126CFLAGS ?= \
127 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
128 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800129 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800130 ${COMMON_FLAGS}
131else ifeq (${FIRMWARE_ARCH}, x86_64)
132CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800133 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800134else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800135# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800136CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700137CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800138endif
139
140ifneq (${DEBUG},)
141CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700142endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800143
vbendebb2b0fcc2010-07-15 15:09:47 -0700144ifeq (${DISABLE_NDEBUG},)
145CFLAGS += -DNDEBUG
146endif
147
Bill Richardsonfeb25182013-03-07 12:54:29 -0800148ifneq (${FORCE_LOGGING_ON},)
149CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
150endif
151
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800152# Create / use dependency files
153CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800154
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700155ifeq (${FIRMWARE_ARCH},)
156# Creates position independent code for non firmware target.
157CFLAGS += -fPIE
158endif
159
Bill Richardson0c3ba242013-03-29 11:09:30 -0700160# These are required to access large disks and files on 32-bit systems.
161CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
162
Randall Spangler59d75082013-01-23 09:29:54 -0800163# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800164ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700165 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800166 CFLAGS += ${COV_FLAGS}
167 LDFLAGS += ${COV_FLAGS}
168 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800169endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800170
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800171# And a few more default utilities
172LD = ${CC}
173CXX ?= g++ # HEY: really?
174PKG_CONFIG ?= pkg-config
175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# Determine QEMU architecture needed, if any
177ifeq (${ARCH},${HOST_ARCH})
178 # Same architecture; no need for QEMU
179 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800180else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181 # 64-bit host can run 32-bit targets directly
182 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800183else
184 QEMU_ARCH := ${ARCH}
185endif
186
187# The top of the chroot for qemu must be passed in via the SYSROOT environment
188# variable. In the Chromium OS chroot, this is done automatically by the
189# ebuild.
190
191ifeq (${QEMU_ARCH},)
192 # Path to build output for running tests is same as for building
193 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800194 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800195else
196 $(info Using qemu for testing.)
197 # Path to build output for running tests is different in the chroot
198 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200
201 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800202 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
203 export QEMU_RUN
204
205 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800206endif
207
Randall Spanglere061a252013-01-22 15:34:07 -0800208export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800209
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210##############################################################################
211# Now we need to describe everything we might want or need to build
212
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800213# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800214INCLUDES += \
215 -Ifirmware/include \
216 -Ifirmware/lib/include \
217 -Ifirmware/lib/cgptlib/include \
218 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700219 -Ifirmware/lib/tpm_lite/include \
220 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700221
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800222# If we're not building for a specific target, just stub out things like the
223# TPM commands and various external functions that are provided by the BIOS.
224ifeq (${FIRMWARE_ARCH},)
Bill Richardson0f6679e2014-07-10 15:49:52 -0700225INCLUDES += -Ifirmware/stub/include -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800226else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800228endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800229
Bill Richardson78299022014-06-20 14:33:00 -0700230# Firmware library, used by the other firmware components (depthcharge,
231# coreboot, etc.). It doesn't need exporting to some other place; they'll build
232# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800233FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800234
Randall Spangler786acda2014-05-22 13:27:07 -0700235# Smaller firmware library. TODO: Do we still need to export this?
236ifneq (${VBOOT2},)
237FWLIB2 = ${BUILD}/vboot_fw2.a
238endif
239
Randall Spangler93943262013-02-26 11:03:57 -0800240# Firmware library sources needed by VbInit() call
241VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800242 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800243 firmware/lib/utility.c \
244 firmware/lib/vboot_api_init.c \
245 firmware/lib/vboot_common_init.c \
246 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700247 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600248 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800249
250# Additional firmware library sources needed by VbSelectFirmware() call
251VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800252 firmware/lib/cryptolib/padding.c \
253 firmware/lib/cryptolib/rsa.c \
254 firmware/lib/cryptolib/rsa_utility.c \
255 firmware/lib/cryptolib/sha1.c \
256 firmware/lib/cryptolib/sha256.c \
257 firmware/lib/cryptolib/sha512.c \
258 firmware/lib/cryptolib/sha_utility.c \
259 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800260 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800261 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600262 firmware/lib/vboot_firmware.c \
263 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800264
265# Additional firmware library sources needed by VbSelectAndLoadKernel() call
266VBSLK_SRCS = \
267 firmware/lib/cgptlib/cgptlib.c \
268 firmware/lib/cgptlib/cgptlib_internal.c \
269 firmware/lib/cgptlib/crc32.c \
Albert Chaulk5c9e4532013-03-20 16:03:49 -0700270 firmware/lib/cgptlib/mtdlib.c \
Randall Spangler93943262013-02-26 11:03:57 -0800271 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800272 firmware/lib/vboot_api_kernel.c \
273 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800274 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600275 firmware/lib/vboot_kernel.c \
276 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800277
Randall Spangler786acda2014-05-22 13:27:07 -0700278# Firmware library source needed for smaller library 2
279FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700280 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700281 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700282 firmware/2lib/2crc8.c \
283 firmware/2lib/2misc.c \
284 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700285 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700286 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700287 firmware/2lib/2sha1.c \
288 firmware/2lib/2sha256.c \
289 firmware/2lib/2sha512.c \
290 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700291
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800292# Support real TPM unless BIOS sets MOCK_TPM
293ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800294VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800295 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800296 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800297
298VBSF_SRCS += \
299 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800300else
Randall Spangler93943262013-02-26 11:03:57 -0800301VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800302 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800303 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800304
305VBSF_SRCS += \
306 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800307endif
308
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800309ifeq (${FIRMWARE_ARCH},)
310# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800311# TODO: split out other stub funcs too
312VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800313 firmware/stub/tpm_lite_stub.c \
314 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600315 firmware/stub/vboot_api_stub_init.c \
316 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800317
318VBSF_SRCS += \
319 firmware/stub/vboot_api_stub_sf.c
320
321VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800322 firmware/stub/vboot_api_stub.c \
323 firmware/stub/vboot_api_stub_disk.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700324
325FWLIB2_SRCS += \
326 firmware/2lib/2stub.c
327
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800328endif
329
Randall Spangler93943262013-02-26 11:03:57 -0800330VBSF_SRCS += ${VBINIT_SRCS}
331FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
332
333VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
334VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
335
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800336FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700337
Randall Spangler786acda2014-05-22 13:27:07 -0700338ifneq (${VBOOT2},)
339FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
340endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800341
Randall Spangler786acda2014-05-22 13:27:07 -0700342ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800343
Bill Richardson78299022014-06-20 14:33:00 -0700344# Intermediate library for the vboot_reference utilities to link against.
345UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800346
Bill Richardson78299022014-06-20 14:33:00 -0700347UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800348 cgpt/cgpt_create.c \
349 cgpt/cgpt_add.c \
350 cgpt/cgpt_boot.c \
351 cgpt/cgpt_show.c \
352 cgpt/cgpt_repair.c \
353 cgpt/cgpt_prioritize.c \
354 cgpt/cgpt_common.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700355 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700356 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700357 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700358 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800359 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800360 host/lib/crossystem.c \
361 host/lib/file_keys.c \
362 host/lib/fmap.c \
363 host/lib/host_common.c \
364 host/lib/host_key.c \
365 host/lib/host_keyblock.c \
366 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700367 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800368 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700369 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800370
Bill Richardson78299022014-06-20 14:33:00 -0700371UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
372ALL_OBJS += ${UTILLIB_OBJS}
373
374# Externally exported library for some target userspace apps to link with
375# (cryptohome, updater, etc.)
376HOSTLIB = ${BUILD}/libvboot_host.a
377
378HOSTLIB_SRCS = \
379 cgpt/cgpt_add.c \
380 cgpt/cgpt_boot.c \
381 cgpt/cgpt_common.c \
382 cgpt/cgpt_create.c \
383 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700384 cgpt/flash_ts.c \
Bill Richardson78299022014-06-20 14:33:00 -0700385 cgpt/flash_ts_drv.c \
386 firmware/lib/cgptlib/cgptlib_internal.c \
387 firmware/lib/cgptlib/crc32.c \
388 firmware/lib/cgptlib/mtdlib.c \
389 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700390 firmware/lib/tpm_lite/tlcl.c \
391 firmware/lib/utility_string.c \
392 firmware/lib/vboot_nvstorage.c \
393 firmware/stub/tpm_lite_stub.c \
394 firmware/stub/utility_stub.c \
395 firmware/stub/vboot_api_stub_init.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700396 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700397 host/arch/${ARCH}/lib/crossystem_arch.c \
398 host/lib/crossystem.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700399 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700400
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800401HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800402ALL_OBJS += ${HOSTLIB_OBJS}
403
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800404# Sigh. For historical reasons, the autoupdate installer must sometimes be a
405# 32-bit executable, even when everything else is 64-bit. But it only needs a
406# few functions, so let's just build those.
407TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
408
409TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800410 cgpt/cgpt_add.c \
411 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800412 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700413 cgpt/cgpt_create.c \
414 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700415 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700416 cgpt/flash_ts_drv.c \
Bill Richardson78299022014-06-20 14:33:00 -0700417 firmware/lib/cgptlib/cgptlib_internal.c \
418 firmware/lib/cgptlib/crc32.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700419 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800420 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700421 firmware/stub/utility_stub.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700422 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800423
424TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800425
426# ----------------------------------------------------------------------------
427# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800428
429CGPT = ${BUILD}/cgpt/cgpt
430
431CGPT_SRCS = \
432 cgpt/cgpt.c \
433 cgpt/cgpt_add.c \
434 cgpt/cgpt_boot.c \
435 cgpt/cgpt_common.c \
436 cgpt/cgpt_create.c \
437 cgpt/cgpt_find.c \
438 cgpt/cgpt_legacy.c \
439 cgpt/cgpt_prioritize.c \
440 cgpt/cgpt_repair.c \
441 cgpt/cgpt_show.c \
442 cgpt/cmd_add.c \
443 cgpt/cmd_boot.c \
444 cgpt/cmd_create.c \
445 cgpt/cmd_find.c \
446 cgpt/cmd_legacy.c \
447 cgpt/cmd_prioritize.c \
448 cgpt/cmd_repair.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700449 cgpt/cmd_show.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700450 cgpt/flash_ts.c \
451 cgpt/flash_ts_drv.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800452
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800453CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800454ALL_OBJS += ${CGPT_OBJS}
455
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800456
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800457# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800458UTIL_SCRIPTS = \
459 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800460 utility/enable_dev_usb_boot \
461 utility/vbutil_what_keys
462
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800463ifeq (${MINIMAL},)
464UTIL_SCRIPTS += \
465 utility/dev_make_keypair
466endif
467
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800468# These utilities should be linked statically.
469UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700470 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800471
472UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700473 utility/tpm_init_temp_fix \
Bill Richardson6f396152014-07-15 12:52:19 -0700474 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800475
Bill Richardson6f396152014-07-15 12:52:19 -0700476# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800477ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800478UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700479 utility/bmpblk_font \
480 utility/bmpblk_utility \
Bill Richardson6f396152014-07-15 12:52:19 -0700481 utility/dumpRSAPublicKey \
Bill Richardson339f7e02013-04-05 09:49:24 -0700482 utility/eficompress \
483 utility/efidecompress \
484 utility/load_kernel_test \
485 utility/pad_digest_utility \
486 utility/signature_digest_utility \
487 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700488
489ifneq (${VBOOT2},)
490UTIL_NAMES += \
491 utility/vb2_verify_fw
492endif
493
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800494endif
495
Bill Richardson339f7e02013-04-05 09:49:24 -0700496UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
497UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700498ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800499
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800500
501# Scripts for signing stuff.
502SIGNING_SCRIPTS = \
503 utility/tpm-nvsize \
504 utility/chromeos-tpm-recovery
505
506# These go in a different place.
507SIGNING_SCRIPTS_DEV = \
508 scripts/image_signing/resign_firmwarefd.sh \
509 scripts/image_signing/make_dev_firmware.sh \
510 scripts/image_signing/make_dev_ssd.sh \
511 scripts/image_signing/set_gbb_flags.sh
512
513# Installed, but not made executable.
514SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800515
Bill Richardson826db092013-01-14 12:37:15 -0800516
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800517# The unified firmware utility will eventually replace all the others
518FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700519# But we still need both static (tiny) and dynamic (with openssl) versions.
520FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800521
Bill Richardson6f396152014-07-15 12:52:19 -0700522# These are the executables that are now built in to futility. We'll create
523# symlinks for these so the old names will still work.
524# TODO: Do we still need dev_sign_file for anything?
525FUTIL_BUILTIN = \
Bill Richardsone1550442014-07-17 11:32:17 -0700526 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700527 dump_fmap \
528 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700529 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700530 vbutil_firmware \
531 vbutil_kernel \
532 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700533 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800534
Bill Richardson6db8c752013-04-05 13:30:43 -0700535FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800536 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700537 futility/cmd_dump_fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700538 futility/cmd_gbb_utility.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800539
Bill Richardson6db8c752013-04-05 13:30:43 -0700540FUTIL_SRCS = \
541 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700542 futility/cmd_dev_sign_file.c \
543 futility/cmd_dump_kernel_config.c \
544 futility/cmd_vbutil_firmware.c \
545 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700546 futility/cmd_vbutil_key.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700547 futility/cmd_vbutil_keyblock.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700548
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800549FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800550
Bill Richardson6db8c752013-04-05 13:30:43 -0700551FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800552FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800553
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800554ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800555
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800556
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800557# Library of handy test functions.
558TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800559
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800560TESTLIB_SRCS = \
561 tests/test_common.c \
562 tests/timer_utils.c \
563 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800564
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800565TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
566ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800567
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800568
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800569# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800570TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700571 tests/cgptlib_test \
572 tests/rollback_index2_tests \
573 tests/rollback_index3_tests \
574 tests/rsa_padding_test \
575 tests/rsa_utility_tests \
576 tests/rsa_verify_benchmark \
577 tests/sha_benchmark \
578 tests/sha_tests \
579 tests/stateful_util_tests \
580 tests/tlcl_tests \
581 tests/tpm_bootmode_tests \
582 tests/utility_string_tests \
583 tests/utility_tests \
584 tests/vboot_api_init_tests \
585 tests/vboot_api_devmode_tests \
586 tests/vboot_api_firmware_tests \
587 tests/vboot_api_kernel_tests \
588 tests/vboot_api_kernel2_tests \
589 tests/vboot_api_kernel3_tests \
590 tests/vboot_api_kernel4_tests \
591 tests/vboot_audio_tests \
592 tests/vboot_common_tests \
593 tests/vboot_common2_tests \
594 tests/vboot_common3_tests \
595 tests/vboot_display_tests \
596 tests/vboot_firmware_tests \
597 tests/vboot_kernel_tests \
598 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700599 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700600 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800601
Simon Glass527ba812013-07-25 08:48:47 -0600602ifdef REGION_READ
603TEST_NAMES += tests/vboot_region_tests
604endif
605
Randall Spangler786acda2014-05-22 13:27:07 -0700606ifneq (${VBOOT2},)
607TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700608 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700609 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700610 tests/vb2_common2_tests \
611 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700612 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700613 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700614 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700615 tests/vb2_rsa_padding_tests \
616 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700617 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700618 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700619
620endif
621
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800622# TODO: port these tests to new API, if not already eqivalent
623# functionality in other tests. These don't even compile at present.
624#
625# big_firmware_tests
626# big_kernel_tests
627# firmware_image_tests
628# firmware_rollback_tests
629# firmware_splicing_tests
630# firmware_verify_benchmark
631# kernel_image_tests
632# kernel_rollback_tests
633# kernel_splicing_tests
634# kernel_verify_benchmark
635# rollback_index_test
636# verify_firmware_fuzz_driver
637# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800638# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800639
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800640# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700641TLCL_TEST_NAMES = \
642 tests/tpm_lite/tpmtest_earlyextend \
643 tests/tpm_lite/tpmtest_earlynvram \
644 tests/tpm_lite/tpmtest_earlynvram2 \
645 tests/tpm_lite/tpmtest_enable \
646 tests/tpm_lite/tpmtest_fastenable \
647 tests/tpm_lite/tpmtest_globallock \
648 tests/tpm_lite/tpmtest_redefine_unowned \
649 tests/tpm_lite/tpmtest_spaceperm \
650 tests/tpm_lite/tpmtest_testsetup \
651 tests/tpm_lite/tpmtest_timing \
652 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800653
654TEST_NAMES += ${TLCL_TEST_NAMES}
655
Bill Richardson339f7e02013-04-05 09:49:24 -0700656# Finally
657TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700658ALL_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800659
Randall Spanglere061a252013-01-22 15:34:07 -0800660# Directory containing test keys
661TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800662
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800663
664##############################################################################
665# Finally, some targets. High-level ones first.
666
667# Create output directories if necessary. Do this via explicit shell commands
668# so it happens before trying to generate/include dependencies.
669SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
670_dir_create := $(foreach d, \
671 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
672 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
673
674
675# Default target.
676.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700677all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
678 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800679
680# Host targets
681.PHONY: host_stuff
Bill Richardsonbc2d2b22014-07-09 21:11:12 -0700682host_stuff: utillib hostlib cgpt utils futil tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800683
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800684.PHONY: clean
685clean:
686 ${Q}/bin/rm -rf ${BUILD}
687
688.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800689install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800690
Bill Richardson3e3790d2014-07-14 15:05:54 -0700691.PHONY: install_for_test
692install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
693install_for_test: install
694
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800695# Don't delete intermediate object files
696.SECONDARY:
697
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800698
699# ----------------------------------------------------------------------------
700# Firmware library
701
702# TPM-specific flags. These depend on the particular TPM we're targeting for.
703# They are needed here only for compiling parts of the firmware code into
704# user-level tests.
705
706# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
707# the self test has completed.
708
Randall Spangler45cc0f22013-01-25 09:34:26 -0800709${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800710
711# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
712# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
713# power on.
714#
715# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
716# are not both defined at the same time. (See comment in code.)
717
718# CFLAGS += -DTPM_MANUAL_SELFTEST
719
720ifeq (${FIRMWARE_ARCH},i386)
721# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800722${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700723${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800724
725# Workaround for coreboot on x86, which will power off asynchronously
726# without giving us a chance to react. This is not an example of the Right
727# Way to do things. See chrome-os-partner:7689, and the commit message
728# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800729${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800730
731# On x86 we don't actually read the GBB data into RAM until it is needed.
732# Therefore it makes sense to cache it rather than reading it each time.
733# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800734${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800735endif
736
Simon Glass527ba812013-07-25 08:48:47 -0600737ifdef REGION_READ
738${FWLIB_OBJS}: CFLAGS += -DREGION_READ
739endif
740
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800741ifeq (${FIRMWARE_ARCH},)
742# Disable rollback TPM when compiling locally, since otherwise
743# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800744${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800745endif
746
Bill Richardsona130e0b2013-04-04 18:16:39 -0700747# Linktest ensures firmware lib doesn't rely on outside libraries
748${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800749${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700750ALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700751${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800752${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700753ALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700754${BUILD}/firmware/linktest/main: ${FWLIB}
755${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700756ALL_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800757
Bill Richardsond2d08b22014-07-08 16:31:40 -0700758.PHONY: fwlinktest
759fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800760 ${BUILD}/firmware/linktest/main_vbinit \
761 ${BUILD}/firmware/linktest/main_vbsf \
762 ${BUILD}/firmware/linktest/main
763
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800764.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700765fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766
Randall Spangler786acda2014-05-22 13:27:07 -0700767.PHONY: fwlib2
768fwlib2: ${FWLIB2}
769
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800770${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700771 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800772 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700773 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800774 ${Q}ar qc $@ $^
775
Randall Spangler786acda2014-05-22 13:27:07 -0700776${FWLIB2}: ${FWLIB2_OBJS}
777 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
778 ${Q}rm -f $@
779 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
780 ${Q}ar qc $@ $^
781
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800782# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700783# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800784
Bill Richardson78299022014-06-20 14:33:00 -0700785# Link tests for local utilities
786${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700787${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
788ALL_OBJS += ${BUILD}/host/linktest/main.o
789
790.PHONY: utillib
791utillib: ${UTILLIB} \
792 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800793
794# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700795${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
796 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
797 ${Q}rm -f $@
798 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
799 ${Q}ar qc $@ $^
800
801
802# Link tests for external repos
803${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700804${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
805${BUILD}/host/linktest/extern: LDLIBS += -static
806ALL_OBJS += ${BUILD}/host/linktest/extern.o
807
808.PHONY: hostlib
809hostlib: ${HOSTLIB} \
810 ${BUILD}/host/linktest/extern
811
812# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700813${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700814 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800815 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700816 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800817 ${Q}ar qc $@ $^
818
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800819
820# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
821.PHONY: tinyhostlib
822tinyhostlib: ${TINYHOSTLIB}
823 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
824
825${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700826 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800827 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700828 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800829 ${Q}ar qc $@ $^
830
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800831# ----------------------------------------------------------------------------
832# CGPT library and utility
833
834.PHONY: cgpt
835cgpt: ${CGPT}
836
837${CGPT}: LDFLAGS += -static
838${CGPT}: LDLIBS += -luuid
839
Bill Richardson78299022014-06-20 14:33:00 -0700840${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700841 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700842 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800843
844.PHONY: cgpt_install
845cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700846 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800847 ${Q}mkdir -p ${UB_DIR}
848 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800849
850# ----------------------------------------------------------------------------
851# Utilities
852
853# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700854${BUILD}/utility/%: INCLUDES += -Iutility/include
855
856${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
857${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800858
859# Utilities for auto-update toolkits must be statically linked.
860${UTIL_BINS_STATIC}: LDFLAGS += -static
861
Bill Richardsona130e0b2013-04-04 18:16:39 -0700862
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800863.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800864utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800865 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
866 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
867
868.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800869utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700870 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800871 ${Q}mkdir -p ${UB_DIR}
872 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800873
874# And some signing stuff for the target
875.PHONY: signing_install
876signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700877 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700878 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800879 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700880 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
881 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800882
883# ----------------------------------------------------------------------------
884# new Firmware Utility
885
886.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700887futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
888
Bill Richardson0f6679e2014-07-10 15:49:52 -0700889${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS} ${UTILLIB}
Bill Richardson6db8c752013-04-05 13:30:43 -0700890 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
891 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800892
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700893${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson0f6679e2014-07-10 15:49:52 -0700894${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700895 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700896 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800897
898.PHONY: futil_install
899futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700900 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700901 ${Q}mkdir -p ${UB_DIR}
902 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
903 ${Q}for prog in ${FUTIL_BUILTIN}; do \
904 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800905
906# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800907# Utility to generate TLCL structure definition header file.
908
909${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
910
911STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
912STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
913
914.PHONY: update_tlcl_structures
915update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700916 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800917 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
918 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
919 ( echo "%% Updating structures.h %%" && \
920 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
921
922# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800923# Tests
924
925.PHONY: tests
926tests: ${TEST_BINS}
927
Bill Richardson78299022014-06-20 14:33:00 -0700928${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700929${TEST_BINS}: INCLUDES += -Itests
Bill Richardson78299022014-06-20 14:33:00 -0700930${TEST_BINS}: LIBS = ${UTILLIB} ${TESTLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800931
932${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700933 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800934 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700935 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800936 ${Q}ar qc $@ $^
937
938
939# ----------------------------------------------------------------------------
940# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
941# rules for specific targets.
942
943${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700944 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700945 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800946
947${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700948 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800949 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
950
951# Rules to recompile a single source file for library and test
952# TODO: is there a tidier way to do this?
953${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
954${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700955 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800956 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
957
958${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
959${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700960 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800961 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
962
963# TODO: C++ files don't belong in vboot reference at all. Convert to C.
964${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700965 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800966 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
967
968# ----------------------------------------------------------------------------
969# Here are the special tweaks to the generic rules.
970
Bill Richardsonfeb25182013-03-07 12:54:29 -0800971# Because we play some clever linker script games to add new commands without
972# changing any header files, futility must be linked with ld.bfd, not gold.
973${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardson6db8c752013-04-05 13:30:43 -0700974${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardsonfeb25182013-03-07 12:54:29 -0800975
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800976# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -0700977CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
978
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800979${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
980${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
981${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800982
983${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler7141d732014-05-15 15:34:54 -0700984${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
985${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800986${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
987${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800988
Bill Richardson18e03702014-06-23 17:48:33 -0700989${BUILD}/tests/cgptlib_test: OBJS += \
990 ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
991${BUILD}/tests/cgptlib_test: ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
992
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800993${BUILD}/utility/bmpblk_utility: LD = ${CXX}
994${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
995
996BMPBLK_UTILITY_DEPS = \
997 ${BUILD}/utility/bmpblk_util.o \
998 ${BUILD}/utility/image_types.o \
999 ${BUILD}/utility/eficompress_for_lib.o \
1000 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001001
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001002${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1003${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001004ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001005
1006${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1007${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001008ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001009
1010# Allow multiple definitions, so tests can mock functions from other libraries
1011${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001012${BUILD}/tests/%: LDLIBS += -lrt -luuid
1013${BUILD}/tests/%: LIBS += ${TESTLIB}
1014
1015${BUILD}/tests/rollback_index2_tests: OBJS += \
1016 ${BUILD}/firmware/lib/rollback_index_for_test.o
1017${BUILD}/tests/rollback_index2_tests: \
1018 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001019ALL_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001020
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001021${BUILD}/tests/tlcl_tests: OBJS += \
1022 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1023${BUILD}/tests/tlcl_tests: \
1024 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001025ALL_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001026
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001027${BUILD}/tests/vboot_audio_tests: OBJS += \
1028 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1029${BUILD}/tests/vboot_audio_tests: \
1030 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001031ALL_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001032
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001033${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
1034${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
1035
Bill Richardson339f7e02013-04-05 09:49:24 -07001036TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001037${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1038${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001039ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001040
1041##############################################################################
1042# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001043
1044# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001045.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001046test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001047
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001048ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001049# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001050test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001051# Scripts don't work under qemu testing
1052# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001053test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001054endif
1055
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001056.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001057test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001058
Randall Spangler844bce52013-01-15 16:16:43 -08001059# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1060# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001061ifneq (${QEMU_ARCH},)
1062test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001063
1064.PHONY: qemu_install
1065qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001066ifeq (${SYSROOT},)
1067 $(error SYSROOT must be set to the top of the target-specific root \
1068when cross-compiling for qemu-based tests to run properly.)
1069endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001070 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001071 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1072 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001073endif
1074
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001075.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001076runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001077
1078# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001079.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001080genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001081 tests/gen_test_keys.sh
1082
1083# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001084.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001085genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001086 tests/gen_fuzz_test_cases.sh
1087
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001088.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001089runbmptests: test_setup
1090 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001091 ./TestBmpBlock.py -v
1092
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001093.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001094runcgpttests: test_setup
1095 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001096
Randall Spangler844bce52013-01-15 16:16:43 -08001097.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001098runtestscripts: test_setup genfuzztestcases
1099 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Albert Chaulk42c08cb2013-04-02 14:38:07 -07001100 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001101 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001102 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001103 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001104 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001105ifneq (${VBOOT2},)
1106 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001107 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001108endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001109
Randall Spangler844bce52013-01-15 16:16:43 -08001110.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001111runmisctests: test_setup
1112 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001113 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001114 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1115 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1116 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001117 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001118 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1119 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1120 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1121 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001122 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001123 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1124 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001125 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1126 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1127 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001128 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001129 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1130 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1131 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001132 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001133 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001134 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001135 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136
Randall Spangler786acda2014-05-22 13:27:07 -07001137.PHONY: run2tests
1138run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001139 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001140 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001141 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1142 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001143 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001144 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001145 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001146 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001147 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001148 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001149
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001150.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001151runfutiltests: test_setup
1152 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}
Bill Richardson339f7e02013-04-05 09:49:24 -07001153 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001154
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001155# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001156# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001157# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001158.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001159runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001160 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1161 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001162ifneq (${VBOOT2},)
1163 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1164 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1165endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001166 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001167 tests/run_vbutil_tests.sh --all
1168
1169# TODO: tests to run when ported to new API
1170# ./run_image_verification_tests.sh
1171# # Splicing tests
1172# ${BUILD}/tests/firmware_splicing_tests
1173# ${BUILD}/tests/kernel_splicing_tests
1174# # Rollback Tests
1175# ${BUILD}/tests/firmware_rollback_tests
1176# ${BUILD}/tests/kernel_rollback_tests
1177
Bill Richardson78299022014-06-20 14:33:00 -07001178.PHONY: runalltests
1179runalltests: runtests runfutiltests runlongtests
1180
Randall Spangler59d75082013-01-23 09:29:54 -08001181# Code coverage
1182.PHONY: coverage_init
1183coverage_init: test_setup
1184 rm -f ${COV_INFO}*
1185 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1186
1187.PHONY: coverage_html
1188coverage_html:
1189 lcov -c -d . -b . -o ${COV_INFO}.tests
1190 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1191 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1192 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001193# Generate addtional coverage stats just for firmware subdir, because the stats
1194# for the whole project don't include subdirectory summaries. This will print
1195# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001196 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1197 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001198 -o ${COV_INFO}.firmware
1199
1200.PHONY: coverage
1201ifeq (${COV},)
1202coverage:
1203 $(error Build coverage like this: make clean && COV=1 make)
1204else
1205coverage: coverage_init runtests coverage_html
1206endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001207
1208# Include generated dependencies
1209ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1210-include ${ALL_DEPS}