blob: 349f275f85577e56f6c762b2b0adf1ae09ab30e1 [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill Richardson64ddad72014-08-29 23:49:23 -070040export SRCDIR
Bill Richardsonfeb25182013-03-07 12:54:29 -080041BUILD = $(SRCDIR)/build
Randall Spangler844bce52013-01-15 16:16:43 -080042export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080043
Bill Richardsonc9bf3482013-02-13 14:38:29 -080044# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080045INSTALL = install
46DESTDIR = /usr/local/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsonfeb25182013-03-07 12:54:29 -080048# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070049# UB_DIR = utility binary directory
50# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080051ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070052# Host install just puts everything where it's told
53UB_DIR=${DESTDIR}
54VB_DIR=${DESTDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080055else
Bill Richardson6f396152014-07-15 12:52:19 -070056# Target install puts things into subdirectories under DESTDIR
57UB_DIR=${DESTDIR}/usr/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080058VB_DIR=${DESTDIR}/usr/share/vboot/bin
59endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080060
Bill Richardsoneecc18f2013-01-17 15:28:17 -080061# Where to install the (exportable) executables for testing?
62TEST_INSTALL_DIR = ${BUILD}/install_for_test
63
64# Verbose? Use V=1
65ifeq (${V},)
66Q := @
67endif
68
Simon Glass661ae9e2013-03-26 11:39:21 -070069# Quiet? Use QUIET=1
70ifeq ($(QUIET),)
71PRINTF := printf
72else
73PRINTF := :
74endif
75
Randall Spangler61a2eb32013-01-23 10:20:16 -080076# Architecture detection
77_machname := $(shell uname -m)
78HOST_ARCH ?= ${_machname}
79
80# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
81# Pick a sane target architecture if none is defined.
82ifeq (${ARCH},)
83 ARCH := ${HOST_ARCH}
84else ifeq (${ARCH},i386)
85 override ARCH := x86
86else ifeq (${ARCH},amd64)
87 override ARCH := x86_64
88endif
89
90# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
91# for a firmware target (such as u-boot or depthcharge). It must map
92# to the same consistent set of architectures as the host.
93ifeq (${FIRMWARE_ARCH},i386)
94 override FIRMWARE_ARCH := x86
95else ifeq (${FIRMWARE_ARCH},amd64)
96 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -070097else ifeq (${FIRMWARE_ARCH},armv7)
98 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -080099endif
100
Simon Glassb265c342011-11-16 15:09:51 -0800101# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
102# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700103#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800104# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
105# temporarily. As we are still investigating which flags are necessary for
106# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700107#
Simon Glassb265c342011-11-16 15:09:51 -0800108# As a first step, this makes the setting of CC and CFLAGS here optional, to
109# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700110#
Simon Glassb265c342011-11-16 15:09:51 -0800111# Flag ordering: arch, then -f, then -m, then -W
112DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
113COMMON_FLAGS := -nostdinc -pipe \
114 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800115 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800116
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800117# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
118ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800119CC ?= armv7a-cros-linux-gnueabi-gcc
120CFLAGS ?= -march=armv5 \
121 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700122 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800123 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800124else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800125CC ?= i686-pc-linux-gnu-gcc
126# Drop -march=i386 to permit use of SSE instructions
127CFLAGS ?= \
128 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
129 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800130 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800131 ${COMMON_FLAGS}
132else ifeq (${FIRMWARE_ARCH}, x86_64)
133CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800134 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800135else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800136# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800137CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700138CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800139endif
140
141ifneq (${DEBUG},)
142CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700143endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800144
vbendebb2b0fcc2010-07-15 15:09:47 -0700145ifeq (${DISABLE_NDEBUG},)
146CFLAGS += -DNDEBUG
147endif
148
Bill Richardsonfeb25182013-03-07 12:54:29 -0800149ifneq (${FORCE_LOGGING_ON},)
150CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
151endif
152
Randall Spangler6014c042014-07-22 14:42:58 -0700153ifneq (${PD_SYNC},)
154CFLAGS += -DPD_SYNC
155endif
156
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800157# Create / use dependency files
158CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800159
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700160ifeq (${FIRMWARE_ARCH},)
161# Creates position independent code for non firmware target.
162CFLAGS += -fPIE
163endif
164
Bill Richardson0c3ba242013-03-29 11:09:30 -0700165# These are required to access large disks and files on 32-bit systems.
166CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167
Randall Spangler59d75082013-01-23 09:29:54 -0800168# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800169ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700170 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800171 CFLAGS += ${COV_FLAGS}
172 LDFLAGS += ${COV_FLAGS}
173 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800174endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# And a few more default utilities
177LD = ${CC}
178CXX ?= g++ # HEY: really?
179PKG_CONFIG ?= pkg-config
180
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181# Determine QEMU architecture needed, if any
182ifeq (${ARCH},${HOST_ARCH})
183 # Same architecture; no need for QEMU
184 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800185else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186 # 64-bit host can run 32-bit targets directly
187 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800188else
189 QEMU_ARCH := ${ARCH}
190endif
191
192# The top of the chroot for qemu must be passed in via the SYSROOT environment
193# variable. In the Chromium OS chroot, this is done automatically by the
194# ebuild.
195
196ifeq (${QEMU_ARCH},)
197 # Path to build output for running tests is same as for building
198 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200else
201 $(info Using qemu for testing.)
202 # Path to build output for running tests is different in the chroot
203 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800204 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205
206 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800207 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
208 export QEMU_RUN
209
210 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800211endif
212
Randall Spanglere061a252013-01-22 15:34:07 -0800213export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800214
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800215##############################################################################
216# Now we need to describe everything we might want or need to build
217
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800218# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800219INCLUDES += \
220 -Ifirmware/include \
221 -Ifirmware/lib/include \
222 -Ifirmware/lib/cgptlib/include \
223 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700224 -Ifirmware/lib/tpm_lite/include \
225 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700226
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227# If we're not building for a specific target, just stub out things like the
228# TPM commands and various external functions that are provided by the BIOS.
229ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700230INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800231else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800232INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800233endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800234
Bill Richardson78299022014-06-20 14:33:00 -0700235# Firmware library, used by the other firmware components (depthcharge,
236# coreboot, etc.). It doesn't need exporting to some other place; they'll build
237# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800238FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800239
Randall Spangler786acda2014-05-22 13:27:07 -0700240# Smaller firmware library. TODO: Do we still need to export this?
241ifneq (${VBOOT2},)
242FWLIB2 = ${BUILD}/vboot_fw2.a
243endif
244
Randall Spangler93943262013-02-26 11:03:57 -0800245# Firmware library sources needed by VbInit() call
246VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800247 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800248 firmware/lib/utility.c \
249 firmware/lib/vboot_api_init.c \
250 firmware/lib/vboot_common_init.c \
251 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700252 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600253 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800254
255# Additional firmware library sources needed by VbSelectFirmware() call
256VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800257 firmware/lib/cryptolib/padding.c \
258 firmware/lib/cryptolib/rsa.c \
259 firmware/lib/cryptolib/rsa_utility.c \
260 firmware/lib/cryptolib/sha1.c \
261 firmware/lib/cryptolib/sha256.c \
262 firmware/lib/cryptolib/sha512.c \
263 firmware/lib/cryptolib/sha_utility.c \
264 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800265 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800266 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600267 firmware/lib/vboot_firmware.c \
268 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800269
270# Additional firmware library sources needed by VbSelectAndLoadKernel() call
271VBSLK_SRCS = \
272 firmware/lib/cgptlib/cgptlib.c \
273 firmware/lib/cgptlib/cgptlib_internal.c \
274 firmware/lib/cgptlib/crc32.c \
Albert Chaulk5c9e4532013-03-20 16:03:49 -0700275 firmware/lib/cgptlib/mtdlib.c \
Randall Spangler93943262013-02-26 11:03:57 -0800276 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800277 firmware/lib/vboot_api_kernel.c \
278 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800279 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600280 firmware/lib/vboot_kernel.c \
281 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800282
Randall Spangler786acda2014-05-22 13:27:07 -0700283# Firmware library source needed for smaller library 2
284FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700285 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700286 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700287 firmware/2lib/2crc8.c \
288 firmware/2lib/2misc.c \
289 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700290 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700291 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700292 firmware/2lib/2sha1.c \
293 firmware/2lib/2sha256.c \
294 firmware/2lib/2sha512.c \
295 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700296
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800297# Support real TPM unless BIOS sets MOCK_TPM
298ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800299VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800300 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800301 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800302
303VBSF_SRCS += \
304 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800305else
Randall Spangler93943262013-02-26 11:03:57 -0800306VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800307 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800308 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800309
310VBSF_SRCS += \
311 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800312endif
313
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800314ifeq (${FIRMWARE_ARCH},)
315# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800316# TODO: split out other stub funcs too
317VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800318 firmware/stub/tpm_lite_stub.c \
319 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600320 firmware/stub/vboot_api_stub_init.c \
321 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800322
323VBSF_SRCS += \
324 firmware/stub/vboot_api_stub_sf.c
325
326VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800327 firmware/stub/vboot_api_stub.c \
328 firmware/stub/vboot_api_stub_disk.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700329
330FWLIB2_SRCS += \
331 firmware/2lib/2stub.c
332
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800333endif
334
Randall Spangler93943262013-02-26 11:03:57 -0800335VBSF_SRCS += ${VBINIT_SRCS}
336FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
337
338VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
339VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
340
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800341FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700342
Randall Spangler786acda2014-05-22 13:27:07 -0700343ifneq (${VBOOT2},)
344FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
345endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800346
Randall Spangler786acda2014-05-22 13:27:07 -0700347ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800348
Bill Richardson78299022014-06-20 14:33:00 -0700349# Intermediate library for the vboot_reference utilities to link against.
350UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800351
Bill Richardson78299022014-06-20 14:33:00 -0700352UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800353 cgpt/cgpt_create.c \
354 cgpt/cgpt_add.c \
355 cgpt/cgpt_boot.c \
356 cgpt/cgpt_show.c \
357 cgpt/cgpt_repair.c \
358 cgpt/cgpt_prioritize.c \
359 cgpt/cgpt_common.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700360 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700361 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700362 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700363 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800364 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800365 host/lib/crossystem.c \
366 host/lib/file_keys.c \
367 host/lib/fmap.c \
368 host/lib/host_common.c \
369 host/lib/host_key.c \
370 host/lib/host_keyblock.c \
371 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700372 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800373 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700374 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800375
Bill Richardson78299022014-06-20 14:33:00 -0700376UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
377ALL_OBJS += ${UTILLIB_OBJS}
378
379# Externally exported library for some target userspace apps to link with
380# (cryptohome, updater, etc.)
381HOSTLIB = ${BUILD}/libvboot_host.a
382
383HOSTLIB_SRCS = \
384 cgpt/cgpt_add.c \
385 cgpt/cgpt_boot.c \
386 cgpt/cgpt_common.c \
387 cgpt/cgpt_create.c \
388 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700389 cgpt/flash_ts.c \
Bill Richardson78299022014-06-20 14:33:00 -0700390 cgpt/flash_ts_drv.c \
391 firmware/lib/cgptlib/cgptlib_internal.c \
392 firmware/lib/cgptlib/crc32.c \
393 firmware/lib/cgptlib/mtdlib.c \
394 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700395 firmware/lib/tpm_lite/tlcl.c \
396 firmware/lib/utility_string.c \
397 firmware/lib/vboot_nvstorage.c \
398 firmware/stub/tpm_lite_stub.c \
399 firmware/stub/utility_stub.c \
400 firmware/stub/vboot_api_stub_init.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700401 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700402 host/arch/${ARCH}/lib/crossystem_arch.c \
403 host/lib/crossystem.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700404 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700405
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800406HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800407ALL_OBJS += ${HOSTLIB_OBJS}
408
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800409# Sigh. For historical reasons, the autoupdate installer must sometimes be a
410# 32-bit executable, even when everything else is 64-bit. But it only needs a
411# few functions, so let's just build those.
412TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
413
414TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800415 cgpt/cgpt_add.c \
416 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800417 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700418 cgpt/cgpt_create.c \
419 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700420 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700421 cgpt/flash_ts_drv.c \
Bill Richardson78299022014-06-20 14:33:00 -0700422 firmware/lib/cgptlib/cgptlib_internal.c \
423 firmware/lib/cgptlib/crc32.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700424 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800425 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700426 firmware/stub/utility_stub.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700427 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800428
429TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800430
431# ----------------------------------------------------------------------------
432# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800433
434CGPT = ${BUILD}/cgpt/cgpt
435
436CGPT_SRCS = \
437 cgpt/cgpt.c \
438 cgpt/cgpt_add.c \
439 cgpt/cgpt_boot.c \
440 cgpt/cgpt_common.c \
441 cgpt/cgpt_create.c \
442 cgpt/cgpt_find.c \
443 cgpt/cgpt_legacy.c \
444 cgpt/cgpt_prioritize.c \
445 cgpt/cgpt_repair.c \
446 cgpt/cgpt_show.c \
447 cgpt/cmd_add.c \
448 cgpt/cmd_boot.c \
449 cgpt/cmd_create.c \
450 cgpt/cmd_find.c \
451 cgpt/cmd_legacy.c \
452 cgpt/cmd_prioritize.c \
453 cgpt/cmd_repair.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700454 cgpt/cmd_show.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700455 cgpt/flash_ts.c \
456 cgpt/flash_ts_drv.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800457
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800458CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459ALL_OBJS += ${CGPT_OBJS}
460
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800461
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800462# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800463UTIL_SCRIPTS = \
464 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800465 utility/enable_dev_usb_boot \
466 utility/vbutil_what_keys
467
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800468ifeq (${MINIMAL},)
469UTIL_SCRIPTS += \
470 utility/dev_make_keypair
471endif
472
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800473# These utilities should be linked statically.
474UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700475 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800476
477UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700478 utility/tpm_init_temp_fix \
Bill Richardson6f396152014-07-15 12:52:19 -0700479 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800480
Bill Richardson6f396152014-07-15 12:52:19 -0700481# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800482ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800483UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700484 utility/bmpblk_font \
485 utility/bmpblk_utility \
Bill Richardson6f396152014-07-15 12:52:19 -0700486 utility/dumpRSAPublicKey \
Bill Richardson339f7e02013-04-05 09:49:24 -0700487 utility/eficompress \
488 utility/efidecompress \
489 utility/load_kernel_test \
490 utility/pad_digest_utility \
491 utility/signature_digest_utility \
492 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700493
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 Richardsoncf6e78d2014-08-27 15:50:25 -0700538 futility/cmd_gbb_utility.c \
539 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800540
Bill Richardson6db8c752013-04-05 13:30:43 -0700541FUTIL_SRCS = \
542 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700543 futility/cmd_dev_sign_file.c \
544 futility/cmd_dump_kernel_config.c \
545 futility/cmd_vbutil_firmware.c \
546 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700547 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700548 futility/cmd_vbutil_keyblock.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700549 futility/cmd_verify_kernel.c \
550 futility/cmd_show.c \
551 futility/traversal.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700552
Randall Spangler028f4682014-08-19 14:42:08 -0700553ifneq (${VBOOT2},)
554FUTIL_SRCS += \
555 futility/cmd_vb2_verify_fw.c
556endif
557
Alex Deymoe08ee282014-08-29 01:07:48 -0700558# List of commands built in futility and futility_s.
559FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
560FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800561
Alex Deymoe08ee282014-08-29 01:07:48 -0700562FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
563 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
564FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800565
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800566ALL_OBJS += ${FUTIL_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# Library of handy test functions.
570TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800571
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800572TESTLIB_SRCS = \
573 tests/test_common.c \
574 tests/timer_utils.c \
575 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800576
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800577TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
578ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800579
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800580
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800581# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800582TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700583 tests/cgptlib_test \
584 tests/rollback_index2_tests \
585 tests/rollback_index3_tests \
586 tests/rsa_padding_test \
587 tests/rsa_utility_tests \
588 tests/rsa_verify_benchmark \
589 tests/sha_benchmark \
590 tests/sha_tests \
591 tests/stateful_util_tests \
592 tests/tlcl_tests \
593 tests/tpm_bootmode_tests \
594 tests/utility_string_tests \
595 tests/utility_tests \
596 tests/vboot_api_init_tests \
597 tests/vboot_api_devmode_tests \
598 tests/vboot_api_firmware_tests \
599 tests/vboot_api_kernel_tests \
600 tests/vboot_api_kernel2_tests \
601 tests/vboot_api_kernel3_tests \
602 tests/vboot_api_kernel4_tests \
603 tests/vboot_audio_tests \
604 tests/vboot_common_tests \
605 tests/vboot_common2_tests \
606 tests/vboot_common3_tests \
607 tests/vboot_display_tests \
608 tests/vboot_firmware_tests \
609 tests/vboot_kernel_tests \
610 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700611 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700612 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800613
Simon Glass527ba812013-07-25 08:48:47 -0600614ifdef REGION_READ
615TEST_NAMES += tests/vboot_region_tests
616endif
617
Randall Spangler786acda2014-05-22 13:27:07 -0700618ifneq (${VBOOT2},)
619TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700620 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700621 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700622 tests/vb2_common2_tests \
623 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700624 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700625 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700626 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700627 tests/vb2_rsa_padding_tests \
628 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700629 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700630 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700631
632endif
633
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800634# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700635TLCL_TEST_NAMES = \
636 tests/tpm_lite/tpmtest_earlyextend \
637 tests/tpm_lite/tpmtest_earlynvram \
638 tests/tpm_lite/tpmtest_earlynvram2 \
639 tests/tpm_lite/tpmtest_enable \
640 tests/tpm_lite/tpmtest_fastenable \
641 tests/tpm_lite/tpmtest_globallock \
642 tests/tpm_lite/tpmtest_redefine_unowned \
643 tests/tpm_lite/tpmtest_spaceperm \
644 tests/tpm_lite/tpmtest_testsetup \
645 tests/tpm_lite/tpmtest_timing \
646 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800647
648TEST_NAMES += ${TLCL_TEST_NAMES}
649
Bill Richardson339f7e02013-04-05 09:49:24 -0700650# Finally
651TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700652ALL_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800653
Randall Spanglere061a252013-01-22 15:34:07 -0800654# Directory containing test keys
655TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800656
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800657
658##############################################################################
659# Finally, some targets. High-level ones first.
660
661# Create output directories if necessary. Do this via explicit shell commands
662# so it happens before trying to generate/include dependencies.
663SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
664_dir_create := $(foreach d, \
665 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
666 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
667
668
669# Default target.
670.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700671all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
672 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800673
674# Host targets
675.PHONY: host_stuff
Bill Richardsonbc2d2b22014-07-09 21:11:12 -0700676host_stuff: utillib hostlib cgpt utils futil tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800677
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800678.PHONY: clean
679clean:
680 ${Q}/bin/rm -rf ${BUILD}
681
682.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800683install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800684
Bill Richardson3e3790d2014-07-14 15:05:54 -0700685.PHONY: install_for_test
686install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
687install_for_test: install
688
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800689# Don't delete intermediate object files
690.SECONDARY:
691
Bill Richardson0e6ae292014-08-26 10:34:40 -0700692.PHONY: tags TAGS
693tags TAGS: ${CGPT_SRCS} ${FUTIL_SRCS} ${UTILLIB_SRCS} ${FWLIB_SRCS} \
694 $(if ${VBOOT2},${FWLIB2_SRCS}) \
695 $(wildcard $(patsubst -I%,%/*.h,${INCLUDES}))
696 ${Q}\rm -f cscope.* TAGS
697 ${Q}echo $^ | tr ' ' '\012' > cscope.files
698 ${Q}$(if $(shell which etags 2>/dev/null),etags $^,echo "no etags")
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800699
700# ----------------------------------------------------------------------------
701# Firmware library
702
703# TPM-specific flags. These depend on the particular TPM we're targeting for.
704# They are needed here only for compiling parts of the firmware code into
705# user-level tests.
706
707# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
708# the self test has completed.
709
Randall Spangler45cc0f22013-01-25 09:34:26 -0800710${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800711
712# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
713# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
714# power on.
715#
716# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
717# are not both defined at the same time. (See comment in code.)
718
719# CFLAGS += -DTPM_MANUAL_SELFTEST
720
721ifeq (${FIRMWARE_ARCH},i386)
722# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800723${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700724${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800725
726# Workaround for coreboot on x86, which will power off asynchronously
727# without giving us a chance to react. This is not an example of the Right
728# Way to do things. See chrome-os-partner:7689, and the commit message
729# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800730${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800731
732# On x86 we don't actually read the GBB data into RAM until it is needed.
733# Therefore it makes sense to cache it rather than reading it each time.
734# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800735${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800736endif
737
Simon Glass527ba812013-07-25 08:48:47 -0600738ifdef REGION_READ
739${FWLIB_OBJS}: CFLAGS += -DREGION_READ
740endif
741
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800742ifeq (${FIRMWARE_ARCH},)
743# Disable rollback TPM when compiling locally, since otherwise
744# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800745${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800746endif
747
Bill Richardsona130e0b2013-04-04 18:16:39 -0700748# Linktest ensures firmware lib doesn't rely on outside libraries
749${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800750${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700751ALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700752${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800753${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700754ALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700755${BUILD}/firmware/linktest/main: ${FWLIB}
756${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700757ALL_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800758
Bill Richardsond2d08b22014-07-08 16:31:40 -0700759.PHONY: fwlinktest
760fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800761 ${BUILD}/firmware/linktest/main_vbinit \
762 ${BUILD}/firmware/linktest/main_vbsf \
763 ${BUILD}/firmware/linktest/main
764
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800765.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700766fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800767
Randall Spangler786acda2014-05-22 13:27:07 -0700768.PHONY: fwlib2
769fwlib2: ${FWLIB2}
770
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800771${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700772 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800773 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700774 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800775 ${Q}ar qc $@ $^
776
Randall Spangler786acda2014-05-22 13:27:07 -0700777${FWLIB2}: ${FWLIB2_OBJS}
778 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
779 ${Q}rm -f $@
780 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
781 ${Q}ar qc $@ $^
782
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800783# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700784# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800785
Bill Richardson78299022014-06-20 14:33:00 -0700786# Link tests for local utilities
787${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700788${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
789ALL_OBJS += ${BUILD}/host/linktest/main.o
790
791.PHONY: utillib
792utillib: ${UTILLIB} \
793 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800794
795# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700796${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
797 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
798 ${Q}rm -f $@
799 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
800 ${Q}ar qc $@ $^
801
802
803# Link tests for external repos
804${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700805${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
806${BUILD}/host/linktest/extern: LDLIBS += -static
807ALL_OBJS += ${BUILD}/host/linktest/extern.o
808
809.PHONY: hostlib
810hostlib: ${HOSTLIB} \
811 ${BUILD}/host/linktest/extern
812
813# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700814${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700815 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800816 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700817 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800818 ${Q}ar qc $@ $^
819
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800820
821# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
822.PHONY: tinyhostlib
823tinyhostlib: ${TINYHOSTLIB}
824 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
825
826${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700827 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800828 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700829 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800830 ${Q}ar qc $@ $^
831
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800832# ----------------------------------------------------------------------------
833# CGPT library and utility
834
835.PHONY: cgpt
836cgpt: ${CGPT}
837
838${CGPT}: LDFLAGS += -static
839${CGPT}: LDLIBS += -luuid
840
Bill Richardson78299022014-06-20 14:33:00 -0700841${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700842 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700843 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800844
845.PHONY: cgpt_install
846cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700847 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800848 ${Q}mkdir -p ${UB_DIR}
849 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800850
851# ----------------------------------------------------------------------------
852# Utilities
853
854# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700855${BUILD}/utility/%: INCLUDES += -Iutility/include
856
857${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
858${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800859
860# Utilities for auto-update toolkits must be statically linked.
861${UTIL_BINS_STATIC}: LDFLAGS += -static
862
Bill Richardsona130e0b2013-04-04 18:16:39 -0700863
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800864.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800865utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800866 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
867 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
868
869.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800870utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700871 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800872 ${Q}mkdir -p ${UB_DIR}
873 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800874
875# And some signing stuff for the target
876.PHONY: signing_install
877signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700878 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700879 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800880 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700881 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
882 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800883
884# ----------------------------------------------------------------------------
885# new Firmware Utility
886
887.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700888futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
889
Alex Deymoe08ee282014-08-29 01:07:48 -0700890${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
Bill Richardson6db8c752013-04-05 13:30:43 -0700891 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
892 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800893
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700894${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Alex Deymoe08ee282014-08-29 01:07:48 -0700895${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700896 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700897 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800898
899.PHONY: futil_install
900futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700901 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700902 ${Q}mkdir -p ${UB_DIR}
903 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
904 ${Q}for prog in ${FUTIL_BUILTIN}; do \
905 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800906
907# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800908# Utility to generate TLCL structure definition header file.
909
910${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
911
912STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
913STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
914
915.PHONY: update_tlcl_structures
916update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700917 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800918 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
919 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
920 ( echo "%% Updating structures.h %%" && \
921 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
922
923# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800924# Tests
925
926.PHONY: tests
927tests: ${TEST_BINS}
928
Bill Richardson78299022014-06-20 14:33:00 -0700929${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700930${TEST_BINS}: INCLUDES += -Itests
Bill Richardson78299022014-06-20 14:33:00 -0700931${TEST_BINS}: LIBS = ${UTILLIB} ${TESTLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800932
933${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700934 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800935 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700936 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800937 ${Q}ar qc $@ $^
938
939
940# ----------------------------------------------------------------------------
941# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
942# rules for specific targets.
943
944${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700945 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700946 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800947
948${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700949 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800950 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
951
Alex Deymoe08ee282014-08-29 01:07:48 -0700952${BUILD}/%.o: ${BUILD}/%.c
953 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
954 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
955
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800956# Rules to recompile a single source file for library and test
957# TODO: is there a tidier way to do this?
958${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
959${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700960 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800961 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
962
963${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
964${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700965 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800966 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
967
968# TODO: C++ files don't belong in vboot reference at all. Convert to C.
969${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700970 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800971 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
972
973# ----------------------------------------------------------------------------
974# Here are the special tweaks to the generic rules.
975
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 Richardson339f7e02013-04-05 09:49:24 -07001033TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001034${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1035${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001036ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001037
Alex Deymoe08ee282014-08-29 01:07:48 -07001038# ----------------------------------------------------------------------------
1039# Here are the special rules that don't fit in the generic rules.
1040
1041# Generates the list of commands defined in futility by running grep in the
1042# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1043${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1044${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1045${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1046 @$(PRINTF) " GEN $(subst ${BUILD}/,,$@)\n"
1047 ${Q}rm -f $@ $@_t $@_commands
1048 ${Q}mkdir -p ${BUILD}/gen
1049 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ -R \
1050 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1051 | sort >>$@_commands
1052 ${Q}echo '#define _CMD(NAME) extern const struct' \
1053 'futil_cmd_t __cmd_##NAME;' >> $@_t
1054 ${Q}cat $@_commands >> $@_t
1055 ${Q}echo '#undef _CMD' >> $@_t
1056 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1057 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1058 ${Q}cat $@_commands >> $@_t
1059 ${Q}echo '0}; /* null-terminated */' >> $@_t
1060 ${Q}echo '#undef _CMD' >> $@_t
1061 ${Q}mv $@_t $@
1062 ${Q}rm -f $@_commands
1063
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001064##############################################################################
1065# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001066
1067# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001068.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001069test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001070
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001071ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001072# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001073test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001074# Scripts don't work under qemu testing
1075# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001076test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001077endif
1078
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001079.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001080test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001081
Randall Spangler844bce52013-01-15 16:16:43 -08001082# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1083# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001084ifneq (${QEMU_ARCH},)
1085test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001086
1087.PHONY: qemu_install
1088qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001089ifeq (${SYSROOT},)
1090 $(error SYSROOT must be set to the top of the target-specific root \
1091when cross-compiling for qemu-based tests to run properly.)
1092endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001093 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001094 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1095 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001096endif
1097
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001098.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001099runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001100
1101# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001102.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001103genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001104 tests/gen_test_keys.sh
1105
1106# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001107.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001108genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001109 tests/gen_fuzz_test_cases.sh
1110
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001111.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001112runbmptests: test_setup
1113 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001114 ./TestBmpBlock.py -v
1115
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001116.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001117runcgpttests: test_setup
1118 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001119
Randall Spangler844bce52013-01-15 16:16:43 -08001120.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001121runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001122 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001123 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Albert Chaulk42c08cb2013-04-02 14:38:07 -07001124 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001125 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001126 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001127 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001128 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001129ifneq (${VBOOT2},)
1130 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001131 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001132endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001133
Randall Spangler844bce52013-01-15 16:16:43 -08001134.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001135runmisctests: test_setup
1136 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001137 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001138 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1139 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1140 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001141 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001142 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1143 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1144 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1145 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001146 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001147 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1148 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001149 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1150 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1151 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001152 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001153 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1154 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1155 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001156 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001157 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001158 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001159 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001160
Randall Spangler786acda2014-05-22 13:27:07 -07001161.PHONY: run2tests
1162run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001163 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001164 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001165 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1166 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001167 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001168 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001169 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001170 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001171 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001172 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001173
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001174.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001175runfutiltests: test_setup
1176 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}
Bill Richardson339f7e02013-04-05 09:49:24 -07001177 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001178
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001179# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001180# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001181# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001182.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001183runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001184 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1185 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001186ifneq (${VBOOT2},)
1187 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1188 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1189endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001190 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001191 tests/run_vbutil_tests.sh --all
1192
Bill Richardson78d59bf2014-08-27 16:17:04 -07001193# TODO: There were a number of ancient tests that hadn't been run in years.
1194# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1195# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001196
Bill Richardson78299022014-06-20 14:33:00 -07001197.PHONY: runalltests
1198runalltests: runtests runfutiltests runlongtests
1199
Randall Spangler59d75082013-01-23 09:29:54 -08001200# Code coverage
1201.PHONY: coverage_init
1202coverage_init: test_setup
1203 rm -f ${COV_INFO}*
1204 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1205
1206.PHONY: coverage_html
1207coverage_html:
1208 lcov -c -d . -b . -o ${COV_INFO}.tests
1209 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1210 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1211 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001212# Generate addtional coverage stats just for firmware subdir, because the stats
1213# for the whole project don't include subdirectory summaries. This will print
1214# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001215 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1216 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001217 -o ${COV_INFO}.firmware
1218
1219.PHONY: coverage
1220ifeq (${COV},)
1221coverage:
1222 $(error Build coverage like this: make clean && COV=1 make)
1223else
1224coverage: coverage_init runtests coverage_html
1225endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001226
1227# Include generated dependencies
1228ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1229-include ${ALL_DEPS}