blob: d50cc4ffd8d31f296c2586031d73adcb1597cc7e [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 Spangler6014c042014-07-22 14:42:58 -0700152ifneq (${PD_SYNC},)
153CFLAGS += -DPD_SYNC
154endif
155
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800156# Create / use dependency files
157CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800158
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700159ifeq (${FIRMWARE_ARCH},)
160# Creates position independent code for non firmware target.
161CFLAGS += -fPIE
162endif
163
Bill Richardson0c3ba242013-03-29 11:09:30 -0700164# These are required to access large disks and files on 32-bit systems.
165CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
166
Randall Spangler59d75082013-01-23 09:29:54 -0800167# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800168ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700169 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800170 CFLAGS += ${COV_FLAGS}
171 LDFLAGS += ${COV_FLAGS}
172 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800173endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800174
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800175# And a few more default utilities
176LD = ${CC}
177CXX ?= g++ # HEY: really?
178PKG_CONFIG ?= pkg-config
179
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800180# Determine QEMU architecture needed, if any
181ifeq (${ARCH},${HOST_ARCH})
182 # Same architecture; no need for QEMU
183 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800184else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800185 # 64-bit host can run 32-bit targets directly
186 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800187else
188 QEMU_ARCH := ${ARCH}
189endif
190
191# The top of the chroot for qemu must be passed in via the SYSROOT environment
192# variable. In the Chromium OS chroot, this is done automatically by the
193# ebuild.
194
195ifeq (${QEMU_ARCH},)
196 # Path to build output for running tests is same as for building
197 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800198 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800199else
200 $(info Using qemu for testing.)
201 # Path to build output for running tests is different in the chroot
202 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800203 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800204
205 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800206 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
207 export QEMU_RUN
208
209 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210endif
211
Randall Spanglere061a252013-01-22 15:34:07 -0800212export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800213
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800214##############################################################################
215# Now we need to describe everything we might want or need to build
216
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800217# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800218INCLUDES += \
219 -Ifirmware/include \
220 -Ifirmware/lib/include \
221 -Ifirmware/lib/cgptlib/include \
222 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700223 -Ifirmware/lib/tpm_lite/include \
224 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700225
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800226# If we're not building for a specific target, just stub out things like the
227# TPM commands and various external functions that are provided by the BIOS.
228ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700229INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800230else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800231INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800232endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800233
Bill Richardson78299022014-06-20 14:33:00 -0700234# Firmware library, used by the other firmware components (depthcharge,
235# coreboot, etc.). It doesn't need exporting to some other place; they'll build
236# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800237FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800238
Randall Spangler786acda2014-05-22 13:27:07 -0700239# Smaller firmware library. TODO: Do we still need to export this?
240ifneq (${VBOOT2},)
241FWLIB2 = ${BUILD}/vboot_fw2.a
242endif
243
Randall Spangler93943262013-02-26 11:03:57 -0800244# Firmware library sources needed by VbInit() call
245VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800246 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800247 firmware/lib/utility.c \
248 firmware/lib/vboot_api_init.c \
249 firmware/lib/vboot_common_init.c \
250 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700251 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600252 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800253
254# Additional firmware library sources needed by VbSelectFirmware() call
255VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800256 firmware/lib/cryptolib/padding.c \
257 firmware/lib/cryptolib/rsa.c \
258 firmware/lib/cryptolib/rsa_utility.c \
259 firmware/lib/cryptolib/sha1.c \
260 firmware/lib/cryptolib/sha256.c \
261 firmware/lib/cryptolib/sha512.c \
262 firmware/lib/cryptolib/sha_utility.c \
263 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800264 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800265 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600266 firmware/lib/vboot_firmware.c \
267 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800268
269# Additional firmware library sources needed by VbSelectAndLoadKernel() call
270VBSLK_SRCS = \
271 firmware/lib/cgptlib/cgptlib.c \
272 firmware/lib/cgptlib/cgptlib_internal.c \
273 firmware/lib/cgptlib/crc32.c \
Albert Chaulk5c9e4532013-03-20 16:03:49 -0700274 firmware/lib/cgptlib/mtdlib.c \
Randall Spangler93943262013-02-26 11:03:57 -0800275 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 firmware/lib/vboot_api_kernel.c \
277 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800278 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600279 firmware/lib/vboot_kernel.c \
280 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800281
Randall Spangler786acda2014-05-22 13:27:07 -0700282# Firmware library source needed for smaller library 2
283FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700284 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700285 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700286 firmware/2lib/2crc8.c \
287 firmware/2lib/2misc.c \
288 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700289 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700290 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700291 firmware/2lib/2sha1.c \
292 firmware/2lib/2sha256.c \
293 firmware/2lib/2sha512.c \
294 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700295
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800296# Support real TPM unless BIOS sets MOCK_TPM
297ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800298VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800299 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800300 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800301
302VBSF_SRCS += \
303 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800304else
Randall Spangler93943262013-02-26 11:03:57 -0800305VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800306 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800307 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800308
309VBSF_SRCS += \
310 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800311endif
312
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800313ifeq (${FIRMWARE_ARCH},)
314# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800315# TODO: split out other stub funcs too
316VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800317 firmware/stub/tpm_lite_stub.c \
318 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600319 firmware/stub/vboot_api_stub_init.c \
320 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800321
322VBSF_SRCS += \
323 firmware/stub/vboot_api_stub_sf.c
324
325VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800326 firmware/stub/vboot_api_stub.c \
327 firmware/stub/vboot_api_stub_disk.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700328
329FWLIB2_SRCS += \
330 firmware/2lib/2stub.c
331
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800332endif
333
Randall Spangler93943262013-02-26 11:03:57 -0800334VBSF_SRCS += ${VBINIT_SRCS}
335FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
336
337VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
338VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
339
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800340FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700341
Randall Spangler786acda2014-05-22 13:27:07 -0700342ifneq (${VBOOT2},)
343FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
344endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800345
Randall Spangler786acda2014-05-22 13:27:07 -0700346ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800347
Bill Richardson78299022014-06-20 14:33:00 -0700348# Intermediate library for the vboot_reference utilities to link against.
349UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800350
Bill Richardson78299022014-06-20 14:33:00 -0700351UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800352 cgpt/cgpt_create.c \
353 cgpt/cgpt_add.c \
354 cgpt/cgpt_boot.c \
355 cgpt/cgpt_show.c \
356 cgpt/cgpt_repair.c \
357 cgpt/cgpt_prioritize.c \
358 cgpt/cgpt_common.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700359 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700360 cgpt/flash_ts_drv.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700361 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700362 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800363 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800364 host/lib/crossystem.c \
365 host/lib/file_keys.c \
366 host/lib/fmap.c \
367 host/lib/host_common.c \
368 host/lib/host_key.c \
369 host/lib/host_keyblock.c \
370 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700371 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800372 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700373 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800374
Bill Richardson78299022014-06-20 14:33:00 -0700375UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
376ALL_OBJS += ${UTILLIB_OBJS}
377
378# Externally exported library for some target userspace apps to link with
379# (cryptohome, updater, etc.)
380HOSTLIB = ${BUILD}/libvboot_host.a
381
382HOSTLIB_SRCS = \
383 cgpt/cgpt_add.c \
384 cgpt/cgpt_boot.c \
385 cgpt/cgpt_common.c \
386 cgpt/cgpt_create.c \
387 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700388 cgpt/flash_ts.c \
Bill Richardson78299022014-06-20 14:33:00 -0700389 cgpt/flash_ts_drv.c \
390 firmware/lib/cgptlib/cgptlib_internal.c \
391 firmware/lib/cgptlib/crc32.c \
392 firmware/lib/cgptlib/mtdlib.c \
393 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700394 firmware/lib/tpm_lite/tlcl.c \
395 firmware/lib/utility_string.c \
396 firmware/lib/vboot_nvstorage.c \
397 firmware/stub/tpm_lite_stub.c \
398 firmware/stub/utility_stub.c \
399 firmware/stub/vboot_api_stub_init.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700400 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700401 host/arch/${ARCH}/lib/crossystem_arch.c \
402 host/lib/crossystem.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700403 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700404
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800405HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800406ALL_OBJS += ${HOSTLIB_OBJS}
407
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800408# Sigh. For historical reasons, the autoupdate installer must sometimes be a
409# 32-bit executable, even when everything else is 64-bit. But it only needs a
410# few functions, so let's just build those.
411TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
412
413TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800414 cgpt/cgpt_add.c \
415 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800416 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700417 cgpt/cgpt_create.c \
418 cgpt/cgpt_prioritize.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700419 cgpt/flash_ts.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700420 cgpt/flash_ts_drv.c \
Bill Richardson78299022014-06-20 14:33:00 -0700421 firmware/lib/cgptlib/cgptlib_internal.c \
422 firmware/lib/cgptlib/crc32.c \
Albert Chaulkb334e652013-03-28 15:25:33 -0700423 firmware/lib/cgptlib/mtdlib.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800424 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700425 firmware/stub/utility_stub.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700426 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800427
428TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800429
430# ----------------------------------------------------------------------------
431# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800432
433CGPT = ${BUILD}/cgpt/cgpt
434
435CGPT_SRCS = \
436 cgpt/cgpt.c \
437 cgpt/cgpt_add.c \
438 cgpt/cgpt_boot.c \
439 cgpt/cgpt_common.c \
440 cgpt/cgpt_create.c \
441 cgpt/cgpt_find.c \
442 cgpt/cgpt_legacy.c \
443 cgpt/cgpt_prioritize.c \
444 cgpt/cgpt_repair.c \
445 cgpt/cgpt_show.c \
446 cgpt/cmd_add.c \
447 cgpt/cmd_boot.c \
448 cgpt/cmd_create.c \
449 cgpt/cmd_find.c \
450 cgpt/cmd_legacy.c \
451 cgpt/cmd_prioritize.c \
452 cgpt/cmd_repair.c \
Albert Chaulk534723a2013-03-20 14:46:50 -0700453 cgpt/cmd_show.c \
Bill Richardson18e03702014-06-23 17:48:33 -0700454 cgpt/flash_ts.c \
455 cgpt/flash_ts_drv.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800456
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800457CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800458ALL_OBJS += ${CGPT_OBJS}
459
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800460
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800461# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462UTIL_SCRIPTS = \
463 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800464 utility/enable_dev_usb_boot \
465 utility/vbutil_what_keys
466
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800467ifeq (${MINIMAL},)
468UTIL_SCRIPTS += \
469 utility/dev_make_keypair
470endif
471
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800472# These utilities should be linked statically.
473UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700474 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800475
476UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700477 utility/tpm_init_temp_fix \
Bill Richardson6f396152014-07-15 12:52:19 -0700478 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800479
Bill Richardson6f396152014-07-15 12:52:19 -0700480# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800481ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800482UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700483 utility/bmpblk_font \
484 utility/bmpblk_utility \
Bill Richardson6f396152014-07-15 12:52:19 -0700485 utility/dumpRSAPublicKey \
Bill Richardson339f7e02013-04-05 09:49:24 -0700486 utility/eficompress \
487 utility/efidecompress \
488 utility/load_kernel_test \
489 utility/pad_digest_utility \
490 utility/signature_digest_utility \
491 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700492
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800493endif
494
Bill Richardson339f7e02013-04-05 09:49:24 -0700495UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
496UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700497ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800498
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800499
500# Scripts for signing stuff.
501SIGNING_SCRIPTS = \
502 utility/tpm-nvsize \
503 utility/chromeos-tpm-recovery
504
505# These go in a different place.
506SIGNING_SCRIPTS_DEV = \
507 scripts/image_signing/resign_firmwarefd.sh \
508 scripts/image_signing/make_dev_firmware.sh \
509 scripts/image_signing/make_dev_ssd.sh \
510 scripts/image_signing/set_gbb_flags.sh
511
512# Installed, but not made executable.
513SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800514
Bill Richardson826db092013-01-14 12:37:15 -0800515
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800516# The unified firmware utility will eventually replace all the others
517FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700518# But we still need both static (tiny) and dynamic (with openssl) versions.
519FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800520
Bill Richardson6f396152014-07-15 12:52:19 -0700521# These are the executables that are now built in to futility. We'll create
522# symlinks for these so the old names will still work.
523# TODO: Do we still need dev_sign_file for anything?
524FUTIL_BUILTIN = \
Bill Richardsone1550442014-07-17 11:32:17 -0700525 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700526 dump_fmap \
527 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700528 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700529 vbutil_firmware \
530 vbutil_kernel \
531 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700532 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800533
Bill Richardson6db8c752013-04-05 13:30:43 -0700534FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800535 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700536 futility/cmd_dump_fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700537 futility/cmd_gbb_utility.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800538
Bill Richardson6db8c752013-04-05 13:30:43 -0700539FUTIL_SRCS = \
540 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700541 futility/cmd_dev_sign_file.c \
542 futility/cmd_dump_kernel_config.c \
543 futility/cmd_vbutil_firmware.c \
544 futility/cmd_vbutil_kernel.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700545 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700546 futility/cmd_vbutil_keyblock.c \
547 futility/cmd_verify_kernel.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700548
Randall Spangler028f4682014-08-19 14:42:08 -0700549ifneq (${VBOOT2},)
550FUTIL_SRCS += \
551 futility/cmd_vb2_verify_fw.c
552endif
553
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800554FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800555
Bill Richardson6db8c752013-04-05 13:30:43 -0700556FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800557FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800558
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800559ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800560
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800561
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800562# Library of handy test functions.
563TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800564
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800565TESTLIB_SRCS = \
566 tests/test_common.c \
567 tests/timer_utils.c \
568 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800569
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800570TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
571ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800572
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800573
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800574# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800575TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700576 tests/cgptlib_test \
577 tests/rollback_index2_tests \
578 tests/rollback_index3_tests \
579 tests/rsa_padding_test \
580 tests/rsa_utility_tests \
581 tests/rsa_verify_benchmark \
582 tests/sha_benchmark \
583 tests/sha_tests \
584 tests/stateful_util_tests \
585 tests/tlcl_tests \
586 tests/tpm_bootmode_tests \
587 tests/utility_string_tests \
588 tests/utility_tests \
589 tests/vboot_api_init_tests \
590 tests/vboot_api_devmode_tests \
591 tests/vboot_api_firmware_tests \
592 tests/vboot_api_kernel_tests \
593 tests/vboot_api_kernel2_tests \
594 tests/vboot_api_kernel3_tests \
595 tests/vboot_api_kernel4_tests \
596 tests/vboot_audio_tests \
597 tests/vboot_common_tests \
598 tests/vboot_common2_tests \
599 tests/vboot_common3_tests \
600 tests/vboot_display_tests \
601 tests/vboot_firmware_tests \
602 tests/vboot_kernel_tests \
603 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700604 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700605 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800606
Simon Glass527ba812013-07-25 08:48:47 -0600607ifdef REGION_READ
608TEST_NAMES += tests/vboot_region_tests
609endif
610
Randall Spangler786acda2014-05-22 13:27:07 -0700611ifneq (${VBOOT2},)
612TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700613 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700614 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700615 tests/vb2_common2_tests \
616 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700617 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700618 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700619 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700620 tests/vb2_rsa_padding_tests \
621 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700622 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700623 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700624
625endif
626
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800627# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700628TLCL_TEST_NAMES = \
629 tests/tpm_lite/tpmtest_earlyextend \
630 tests/tpm_lite/tpmtest_earlynvram \
631 tests/tpm_lite/tpmtest_earlynvram2 \
632 tests/tpm_lite/tpmtest_enable \
633 tests/tpm_lite/tpmtest_fastenable \
634 tests/tpm_lite/tpmtest_globallock \
635 tests/tpm_lite/tpmtest_redefine_unowned \
636 tests/tpm_lite/tpmtest_spaceperm \
637 tests/tpm_lite/tpmtest_testsetup \
638 tests/tpm_lite/tpmtest_timing \
639 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800640
641TEST_NAMES += ${TLCL_TEST_NAMES}
642
Bill Richardson339f7e02013-04-05 09:49:24 -0700643# Finally
644TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700645ALL_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800646
Randall Spanglere061a252013-01-22 15:34:07 -0800647# Directory containing test keys
648TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800649
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800650
651##############################################################################
652# Finally, some targets. High-level ones first.
653
654# Create output directories if necessary. Do this via explicit shell commands
655# so it happens before trying to generate/include dependencies.
656SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
657_dir_create := $(foreach d, \
658 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
659 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
660
661
662# Default target.
663.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700664all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
665 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800666
667# Host targets
668.PHONY: host_stuff
Bill Richardsonbc2d2b22014-07-09 21:11:12 -0700669host_stuff: utillib hostlib cgpt utils futil tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800670
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800671.PHONY: clean
672clean:
673 ${Q}/bin/rm -rf ${BUILD}
674
675.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800676install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800677
Bill Richardson3e3790d2014-07-14 15:05:54 -0700678.PHONY: install_for_test
679install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
680install_for_test: install
681
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800682# Don't delete intermediate object files
683.SECONDARY:
684
Bill Richardson0e6ae292014-08-26 10:34:40 -0700685.PHONY: tags TAGS
686tags TAGS: ${CGPT_SRCS} ${FUTIL_SRCS} ${UTILLIB_SRCS} ${FWLIB_SRCS} \
687 $(if ${VBOOT2},${FWLIB2_SRCS}) \
688 $(wildcard $(patsubst -I%,%/*.h,${INCLUDES}))
689 ${Q}\rm -f cscope.* TAGS
690 ${Q}echo $^ | tr ' ' '\012' > cscope.files
691 ${Q}$(if $(shell which etags 2>/dev/null),etags $^,echo "no etags")
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800692
693# ----------------------------------------------------------------------------
694# Firmware library
695
696# TPM-specific flags. These depend on the particular TPM we're targeting for.
697# They are needed here only for compiling parts of the firmware code into
698# user-level tests.
699
700# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
701# the self test has completed.
702
Randall Spangler45cc0f22013-01-25 09:34:26 -0800703${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800704
705# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
706# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
707# power on.
708#
709# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
710# are not both defined at the same time. (See comment in code.)
711
712# CFLAGS += -DTPM_MANUAL_SELFTEST
713
714ifeq (${FIRMWARE_ARCH},i386)
715# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800716${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700717${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800718
719# Workaround for coreboot on x86, which will power off asynchronously
720# without giving us a chance to react. This is not an example of the Right
721# Way to do things. See chrome-os-partner:7689, and the commit message
722# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800723${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800724
725# On x86 we don't actually read the GBB data into RAM until it is needed.
726# Therefore it makes sense to cache it rather than reading it each time.
727# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800728${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800729endif
730
Simon Glass527ba812013-07-25 08:48:47 -0600731ifdef REGION_READ
732${FWLIB_OBJS}: CFLAGS += -DREGION_READ
733endif
734
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800735ifeq (${FIRMWARE_ARCH},)
736# Disable rollback TPM when compiling locally, since otherwise
737# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800738${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800739endif
740
Bill Richardsona130e0b2013-04-04 18:16:39 -0700741# Linktest ensures firmware lib doesn't rely on outside libraries
742${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800743${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700744ALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700745${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800746${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700747ALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700748${BUILD}/firmware/linktest/main: ${FWLIB}
749${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson1912bba2013-04-04 21:08:50 -0700750ALL_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800751
Bill Richardsond2d08b22014-07-08 16:31:40 -0700752.PHONY: fwlinktest
753fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800754 ${BUILD}/firmware/linktest/main_vbinit \
755 ${BUILD}/firmware/linktest/main_vbsf \
756 ${BUILD}/firmware/linktest/main
757
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800758.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700759fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800760
Randall Spangler786acda2014-05-22 13:27:07 -0700761.PHONY: fwlib2
762fwlib2: ${FWLIB2}
763
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800764${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700765 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700767 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800768 ${Q}ar qc $@ $^
769
Randall Spangler786acda2014-05-22 13:27:07 -0700770${FWLIB2}: ${FWLIB2_OBJS}
771 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
772 ${Q}rm -f $@
773 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
774 ${Q}ar qc $@ $^
775
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800776# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700777# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800778
Bill Richardson78299022014-06-20 14:33:00 -0700779# Link tests for local utilities
780${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700781${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
782ALL_OBJS += ${BUILD}/host/linktest/main.o
783
784.PHONY: utillib
785utillib: ${UTILLIB} \
786 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800787
788# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700789${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
790 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
791 ${Q}rm -f $@
792 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
793 ${Q}ar qc $@ $^
794
795
796# Link tests for external repos
797${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700798${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
799${BUILD}/host/linktest/extern: LDLIBS += -static
800ALL_OBJS += ${BUILD}/host/linktest/extern.o
801
802.PHONY: hostlib
803hostlib: ${HOSTLIB} \
804 ${BUILD}/host/linktest/extern
805
806# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700807${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700808 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800809 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700810 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800811 ${Q}ar qc $@ $^
812
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800813
814# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
815.PHONY: tinyhostlib
816tinyhostlib: ${TINYHOSTLIB}
817 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
818
819${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700820 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800821 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700822 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800823 ${Q}ar qc $@ $^
824
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800825# ----------------------------------------------------------------------------
826# CGPT library and utility
827
828.PHONY: cgpt
829cgpt: ${CGPT}
830
831${CGPT}: LDFLAGS += -static
832${CGPT}: LDLIBS += -luuid
833
Bill Richardson78299022014-06-20 14:33:00 -0700834${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700835 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700836 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800837
838.PHONY: cgpt_install
839cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700840 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800841 ${Q}mkdir -p ${UB_DIR}
842 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800843
844# ----------------------------------------------------------------------------
845# Utilities
846
847# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700848${BUILD}/utility/%: INCLUDES += -Iutility/include
849
850${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
851${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800852
853# Utilities for auto-update toolkits must be statically linked.
854${UTIL_BINS_STATIC}: LDFLAGS += -static
855
Bill Richardsona130e0b2013-04-04 18:16:39 -0700856
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800857.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800858utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800859 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
860 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
861
862.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800863utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700864 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800865 ${Q}mkdir -p ${UB_DIR}
866 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800867
868# And some signing stuff for the target
869.PHONY: signing_install
870signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700871 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700872 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800873 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700874 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
875 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800876
877# ----------------------------------------------------------------------------
878# new Firmware Utility
879
880.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700881futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
882
Bill Richardson0f6679e2014-07-10 15:49:52 -0700883${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS} ${UTILLIB}
Bill Richardson6db8c752013-04-05 13:30:43 -0700884 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
885 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800886
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700887${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardson0f6679e2014-07-10 15:49:52 -0700888${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700889 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700890 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800891
892.PHONY: futil_install
893futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700894 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700895 ${Q}mkdir -p ${UB_DIR}
896 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
897 ${Q}for prog in ${FUTIL_BUILTIN}; do \
898 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800899
900# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800901# Utility to generate TLCL structure definition header file.
902
903${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
904
905STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
906STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
907
908.PHONY: update_tlcl_structures
909update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700910 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800911 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
912 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
913 ( echo "%% Updating structures.h %%" && \
914 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
915
916# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800917# Tests
918
919.PHONY: tests
920tests: ${TEST_BINS}
921
Bill Richardson78299022014-06-20 14:33:00 -0700922${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700923${TEST_BINS}: INCLUDES += -Itests
Bill Richardson78299022014-06-20 14:33:00 -0700924${TEST_BINS}: LIBS = ${UTILLIB} ${TESTLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800925
926${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700927 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800928 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700929 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800930 ${Q}ar qc $@ $^
931
932
933# ----------------------------------------------------------------------------
934# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
935# rules for specific targets.
936
937${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700938 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700939 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800940
941${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700942 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800943 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
944
945# Rules to recompile a single source file for library and test
946# TODO: is there a tidier way to do this?
947${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
948${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700949 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800950 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
951
952${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
953${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700954 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800955 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
956
957# TODO: C++ files don't belong in vboot reference at all. Convert to C.
958${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700959 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800960 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
961
962# ----------------------------------------------------------------------------
963# Here are the special tweaks to the generic rules.
964
Bill Richardsonfeb25182013-03-07 12:54:29 -0800965# Because we play some clever linker script games to add new commands without
966# changing any header files, futility must be linked with ld.bfd, not gold.
967${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardson6db8c752013-04-05 13:30:43 -0700968${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
Bill Richardsonfeb25182013-03-07 12:54:29 -0800969
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800970# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -0700971CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
972
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800973${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
974${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
975${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800976
977${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler7141d732014-05-15 15:34:54 -0700978${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
979${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800980${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
981${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800982
Bill Richardson18e03702014-06-23 17:48:33 -0700983${BUILD}/tests/cgptlib_test: OBJS += \
984 ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
985${BUILD}/tests/cgptlib_test: ${BUILD}/firmware/lib/cgptlib/mtdlib_unused.o
986
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800987${BUILD}/utility/bmpblk_utility: LD = ${CXX}
988${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
989
990BMPBLK_UTILITY_DEPS = \
991 ${BUILD}/utility/bmpblk_util.o \
992 ${BUILD}/utility/image_types.o \
993 ${BUILD}/utility/eficompress_for_lib.o \
994 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -0700995
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800996${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
997${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -0700998ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800999
1000${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1001${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001002ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001003
1004# Allow multiple definitions, so tests can mock functions from other libraries
1005${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001006${BUILD}/tests/%: LDLIBS += -lrt -luuid
1007${BUILD}/tests/%: LIBS += ${TESTLIB}
1008
1009${BUILD}/tests/rollback_index2_tests: OBJS += \
1010 ${BUILD}/firmware/lib/rollback_index_for_test.o
1011${BUILD}/tests/rollback_index2_tests: \
1012 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001013ALL_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001014
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001015${BUILD}/tests/tlcl_tests: OBJS += \
1016 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1017${BUILD}/tests/tlcl_tests: \
1018 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001019ALL_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001020
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001021${BUILD}/tests/vboot_audio_tests: OBJS += \
1022 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1023${BUILD}/tests/vboot_audio_tests: \
1024 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001025ALL_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001026
Bill Richardson339f7e02013-04-05 09:49:24 -07001027TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001028${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1029${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001030ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001031
1032##############################################################################
1033# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001034
1035# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001036.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001037test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001038
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001039ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001040# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001041test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001042# Scripts don't work under qemu testing
1043# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001044test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001045endif
1046
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001047.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001048test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001049
Randall Spangler844bce52013-01-15 16:16:43 -08001050# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1051# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001052ifneq (${QEMU_ARCH},)
1053test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001054
1055.PHONY: qemu_install
1056qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001057ifeq (${SYSROOT},)
1058 $(error SYSROOT must be set to the top of the target-specific root \
1059when cross-compiling for qemu-based tests to run properly.)
1060endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001061 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001062 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1063 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001064endif
1065
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001066.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001067runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001068
1069# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001070.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001071genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001072 tests/gen_test_keys.sh
1073
1074# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001075.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001076genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001077 tests/gen_fuzz_test_cases.sh
1078
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001079.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001080runbmptests: test_setup
1081 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001082 ./TestBmpBlock.py -v
1083
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001084.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001085runcgpttests: test_setup
1086 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001087
Randall Spangler844bce52013-01-15 16:16:43 -08001088.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001089runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001090 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001091 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Albert Chaulk42c08cb2013-04-02 14:38:07 -07001092 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001093 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001094 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001095 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001096 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001097ifneq (${VBOOT2},)
1098 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001099 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001100endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001101
Randall Spangler844bce52013-01-15 16:16:43 -08001102.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001103runmisctests: test_setup
1104 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001105 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001106 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1107 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1108 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001109 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001110 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1111 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1112 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1113 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001114 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001115 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1116 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001117 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1118 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1119 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001120 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001121 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1122 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1123 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001124 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001125 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001126 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001127 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001128
Randall Spangler786acda2014-05-22 13:27:07 -07001129.PHONY: run2tests
1130run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001131 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001132 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001133 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1134 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001135 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001136 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001137 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001138 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001139 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001140 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001141
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001142.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001143runfutiltests: test_setup
1144 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}
Bill Richardson339f7e02013-04-05 09:49:24 -07001145 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001146
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001147# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001148# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001149# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001150.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001151runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001152 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1153 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001154ifneq (${VBOOT2},)
1155 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1156 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1157endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001158 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001159 tests/run_vbutil_tests.sh --all
1160
Bill Richardson78d59bf2014-08-27 16:17:04 -07001161# TODO: There were a number of ancient tests that hadn't been run in years.
1162# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1163# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001164
Bill Richardson78299022014-06-20 14:33:00 -07001165.PHONY: runalltests
1166runalltests: runtests runfutiltests runlongtests
1167
Randall Spangler59d75082013-01-23 09:29:54 -08001168# Code coverage
1169.PHONY: coverage_init
1170coverage_init: test_setup
1171 rm -f ${COV_INFO}*
1172 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1173
1174.PHONY: coverage_html
1175coverage_html:
1176 lcov -c -d . -b . -o ${COV_INFO}.tests
1177 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1178 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1179 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001180# Generate addtional coverage stats just for firmware subdir, because the stats
1181# for the whole project don't include subdirectory summaries. This will print
1182# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001183 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1184 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001185 -o ${COV_INFO}.firmware
1186
1187.PHONY: coverage
1188ifeq (${COV},)
1189coverage:
1190 $(error Build coverage like this: make clean && COV=1 make)
1191else
1192coverage: coverage_init runtests coverage_html
1193endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001194
1195# Include generated dependencies
1196ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1197-include ${ALL_DEPS}