blob: 49cdab59433298d57fe16b2ca8f8f9c7196ff58b [file] [log] [blame]
Randall Spanglere8cfa312013-01-02 16:49:38 -08001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
40BUILD ?= $(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 Richardson826db092013-01-14 12:37:15 -080044INSTALL ?= install
Bill Richardsonc9bf3482013-02-13 14:38:29 -080045DESTDIR ?= /usr/local/bin
46
47ifeq (${MINIMAL},)
48# Host install just puts everything in one place
49UB_DIR=${DESTDIR}
50SB_DIR=${DESTDIR}
51VB_DIR=${DESTDIR}
52else
53# Target install puts things into DESTDIR subdirectories
54UB_DIR=${DESTDIR}/usr/bin
55SB_DIR=${DESTDIR}/sbin
56VB_DIR=${DESTDIR}/usr/share/vboot/bin
57endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080058
Bill Richardsoneecc18f2013-01-17 15:28:17 -080059# Where to install the (exportable) executables for testing?
60TEST_INSTALL_DIR = ${BUILD}/install_for_test
61
62# Verbose? Use V=1
63ifeq (${V},)
64Q := @
65endif
66
Randall Spangler61a2eb32013-01-23 10:20:16 -080067# Architecture detection
68_machname := $(shell uname -m)
69HOST_ARCH ?= ${_machname}
70
71# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
72# Pick a sane target architecture if none is defined.
73ifeq (${ARCH},)
74 ARCH := ${HOST_ARCH}
75else ifeq (${ARCH},i386)
76 override ARCH := x86
77else ifeq (${ARCH},amd64)
78 override ARCH := x86_64
79endif
80
81# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
82# for a firmware target (such as u-boot or depthcharge). It must map
83# to the same consistent set of architectures as the host.
84ifeq (${FIRMWARE_ARCH},i386)
85 override FIRMWARE_ARCH := x86
86else ifeq (${FIRMWARE_ARCH},amd64)
87 override FIRMWARE_ARCH := x86_64
88endif
89
Simon Glassb265c342011-11-16 15:09:51 -080090# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
91# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070092#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080093# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
94# temporarily. As we are still investigating which flags are necessary for
95# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070096#
Simon Glassb265c342011-11-16 15:09:51 -080097# As a first step, this makes the setting of CC and CFLAGS here optional, to
98# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070099#
Simon Glassb265c342011-11-16 15:09:51 -0800100# Flag ordering: arch, then -f, then -m, then -W
101DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
102COMMON_FLAGS := -nostdinc -pipe \
103 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800104 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800105
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800106# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
107ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800108CC ?= armv7a-cros-linux-gnueabi-gcc
109CFLAGS ?= -march=armv5 \
110 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700111 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800112 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800113else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800114CC ?= i686-pc-linux-gnu-gcc
115# Drop -march=i386 to permit use of SSE instructions
116CFLAGS ?= \
117 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
118 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
119 -mpreferred-stack-boundary=2 -mregparm=3 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800120 ${COMMON_FLAGS}
121else ifeq (${FIRMWARE_ARCH}, x86_64)
122CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800123 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800124else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800125# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800126CC ?= gcc
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800127CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800128endif
129
130ifneq (${DEBUG},)
131CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700132endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800133
vbendebb2b0fcc2010-07-15 15:09:47 -0700134ifeq (${DISABLE_NDEBUG},)
135CFLAGS += -DNDEBUG
136endif
137
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800138# Create / use dependency files
139CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800140
Randall Spangler59d75082013-01-23 09:29:54 -0800141# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800142ifneq (${COV},)
Randall Spangler59d75082013-01-23 09:29:54 -0800143 COV_FLAGS = -O0 --coverage
144 CFLAGS += ${COV_FLAGS}
145 LDFLAGS += ${COV_FLAGS}
146 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800147endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800148
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800149# And a few more default utilities
150LD = ${CC}
151CXX ?= g++ # HEY: really?
152PKG_CONFIG ?= pkg-config
153
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800154# Determine QEMU architecture needed, if any
155ifeq (${ARCH},${HOST_ARCH})
156 # Same architecture; no need for QEMU
157 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800158else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800159 # 64-bit host can run 32-bit targets directly
160 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800161else
162 QEMU_ARCH := ${ARCH}
163endif
164
165# The top of the chroot for qemu must be passed in via the SYSROOT environment
166# variable. In the Chromium OS chroot, this is done automatically by the
167# ebuild.
168
169ifeq (${QEMU_ARCH},)
170 # Path to build output for running tests is same as for building
171 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800172 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800173else
174 $(info Using qemu for testing.)
175 # Path to build output for running tests is different in the chroot
176 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800177 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800178
179 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800180 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
181 export QEMU_RUN
182
183 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800184endif
185
Randall Spanglere061a252013-01-22 15:34:07 -0800186export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800187
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800188##############################################################################
189# Now we need to describe everything we might want or need to build
190
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800191# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800192INCLUDES += \
193 -Ifirmware/include \
194 -Ifirmware/lib/include \
195 -Ifirmware/lib/cgptlib/include \
196 -Ifirmware/lib/cryptolib/include \
197 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700198
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800199# If we're not building for a specific target, just stub out things like the
200# TPM commands and various external functions that are provided by the BIOS.
201ifeq (${FIRMWARE_ARCH},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800202INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800203else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800204INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800205endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800206
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800207# Firmware library. TODO: Do we still need to export this?
208FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800209
Randall Spangler93943262013-02-26 11:03:57 -0800210# Firmware library sources needed by VbInit() call
211VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800212 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800213 firmware/lib/utility.c \
214 firmware/lib/vboot_api_init.c \
215 firmware/lib/vboot_common_init.c \
216 firmware/lib/vboot_nvstorage.c \
217
218# Additional firmware library sources needed by VbSelectFirmware() call
219VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800220 firmware/lib/cryptolib/padding.c \
221 firmware/lib/cryptolib/rsa.c \
222 firmware/lib/cryptolib/rsa_utility.c \
223 firmware/lib/cryptolib/sha1.c \
224 firmware/lib/cryptolib/sha256.c \
225 firmware/lib/cryptolib/sha512.c \
226 firmware/lib/cryptolib/sha_utility.c \
227 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800228 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800229 firmware/lib/vboot_common.c \
230 firmware/lib/vboot_firmware.c
231
232# Additional firmware library sources needed by VbSelectAndLoadKernel() call
233VBSLK_SRCS = \
234 firmware/lib/cgptlib/cgptlib.c \
235 firmware/lib/cgptlib/cgptlib_internal.c \
236 firmware/lib/cgptlib/crc32.c \
237 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800238 firmware/lib/vboot_api_kernel.c \
239 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800240 firmware/lib/vboot_display.c \
Randall Spangler93943262013-02-26 11:03:57 -0800241 firmware/lib/vboot_kernel.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800242
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800243# Support real TPM unless BIOS sets MOCK_TPM
244ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800245VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800246 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800247 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800248
249VBSF_SRCS += \
250 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800251else
Randall Spangler93943262013-02-26 11:03:57 -0800252VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800253 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800254 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800255
256VBSF_SRCS += \
257 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800258endif
259
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800260ifeq (${FIRMWARE_ARCH},)
261# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800262# TODO: split out other stub funcs too
263VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800264 firmware/stub/tpm_lite_stub.c \
265 firmware/stub/utility_stub.c \
Randall Spangler93943262013-02-26 11:03:57 -0800266 firmware/stub/vboot_api_stub_init.c
267
268VBSF_SRCS += \
269 firmware/stub/vboot_api_stub_sf.c
270
271VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800272 firmware/stub/vboot_api_stub.c \
273 firmware/stub/vboot_api_stub_disk.c
274endif
275
Randall Spangler93943262013-02-26 11:03:57 -0800276VBSF_SRCS += ${VBINIT_SRCS}
277FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
278
279VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
280VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
281
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800282FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800283ALL_OBJS += ${FWLIB_OBJS}
284
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800285
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800286# Library to build the utilities. "HOST" mostly means "userspace".
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800287HOSTLIB = ${BUILD}/libvboot_host.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800288
289HOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800290 cgpt/cgpt_create.c \
291 cgpt/cgpt_add.c \
292 cgpt/cgpt_boot.c \
293 cgpt/cgpt_show.c \
294 cgpt/cgpt_repair.c \
295 cgpt/cgpt_prioritize.c \
296 cgpt/cgpt_common.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800297 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800298 host/lib/crossystem.c \
299 host/lib/file_keys.c \
300 host/lib/fmap.c \
301 host/lib/host_common.c \
302 host/lib/host_key.c \
303 host/lib/host_keyblock.c \
304 host/lib/host_misc.c \
305 host/lib/host_signature.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800306 host/lib/signature_digest.c \
307 utility/dump_kernel_config_lib.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800308
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800309HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800310ALL_OBJS += ${HOSTLIB_OBJS}
311
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800312# Link with hostlib by default
313LIBS = $(HOSTLIB)
314
315# Might need this too.
316CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
317
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800318# Sigh. For historical reasons, the autoupdate installer must sometimes be a
319# 32-bit executable, even when everything else is 64-bit. But it only needs a
320# few functions, so let's just build those.
321TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
322
323TINYHOSTLIB_SRCS = \
324 cgpt/cgpt_create.c \
325 cgpt/cgpt_add.c \
326 cgpt/cgpt_boot.c \
327 cgpt/cgpt_show.c \
328 cgpt/cgpt_repair.c \
329 cgpt/cgpt_prioritize.c \
330 cgpt/cgpt_common.c \
331 utility/dump_kernel_config_lib.c \
332 firmware/lib/cgptlib/crc32.c \
333 firmware/lib/cgptlib/cgptlib_internal.c \
334 firmware/stub/utility_stub.c
335
336TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800337
338# ----------------------------------------------------------------------------
339# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800340
341CGPT = ${BUILD}/cgpt/cgpt
342
343CGPT_SRCS = \
344 cgpt/cgpt.c \
345 cgpt/cgpt_add.c \
346 cgpt/cgpt_boot.c \
347 cgpt/cgpt_common.c \
348 cgpt/cgpt_create.c \
349 cgpt/cgpt_find.c \
350 cgpt/cgpt_legacy.c \
351 cgpt/cgpt_prioritize.c \
352 cgpt/cgpt_repair.c \
353 cgpt/cgpt_show.c \
354 cgpt/cmd_add.c \
355 cgpt/cmd_boot.c \
356 cgpt/cmd_create.c \
357 cgpt/cmd_find.c \
358 cgpt/cmd_legacy.c \
359 cgpt/cmd_prioritize.c \
360 cgpt/cmd_repair.c \
361 cgpt/cmd_show.c
362
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800363CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800364ALL_OBJS += ${CGPT_OBJS}
365
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800366
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800367# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800368UTIL_SCRIPTS = \
369 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800370 utility/enable_dev_usb_boot \
371 utility/vbutil_what_keys
372
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800373ifeq (${MINIMAL},)
374UTIL_SCRIPTS += \
375 utility/dev_make_keypair
376endif
377
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800378# These utilities should be linked statically.
379UTIL_NAMES_STATIC = \
380 crossystem \
381 dump_fmap \
382 gbb_utility
383
384UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800385 dev_sign_file \
386 dump_kernel_config \
387 dumpRSAPublicKey \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800388 tpm_init_temp_fix \
389 tpmc \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800390 vbutil_firmware \
391 vbutil_kernel \
392 vbutil_key \
393 vbutil_keyblock \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800394
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800395ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800396UTIL_NAMES += \
397 bmpblk_font \
398 bmpblk_utility \
399 eficompress \
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800400 efidecompress \
401 load_kernel_test \
402 pad_digest_utility \
403 signature_digest_utility \
404 verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800405endif
406
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800407UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC})
408UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800409ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
410
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800411
412# Scripts for signing stuff.
413SIGNING_SCRIPTS = \
414 utility/tpm-nvsize \
415 utility/chromeos-tpm-recovery
416
417# These go in a different place.
418SIGNING_SCRIPTS_DEV = \
419 scripts/image_signing/resign_firmwarefd.sh \
420 scripts/image_signing/make_dev_firmware.sh \
421 scripts/image_signing/make_dev_ssd.sh \
422 scripts/image_signing/set_gbb_flags.sh
423
424# Installed, but not made executable.
425SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800426
Bill Richardson826db092013-01-14 12:37:15 -0800427
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800428# The unified firmware utility will eventually replace all the others
429FUTIL_BIN = ${BUILD}/futility/futility
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800430
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800431FUTIL_SRCS = \
432 futility/IGNOREME.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800433
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800434FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800435
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800436FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800437
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800438ALL_DEPS += $(addsuffix .d,${FUTIL_BIN})
439ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800440
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800441
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800442# Library of handy test functions.
443TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800444
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800445TESTLIB_SRCS = \
446 tests/test_common.c \
447 tests/timer_utils.c \
448 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800449
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800450TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
451ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800452
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800453
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800454# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800455TEST_NAMES = \
456 cgptlib_test \
457 rollback_index2_tests \
Randall Spanglera3eac792013-01-23 13:04:05 -0800458 rollback_index3_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459 rsa_padding_test \
460 rsa_utility_tests \
461 rsa_verify_benchmark \
462 sha_benchmark \
463 sha_tests \
464 stateful_util_tests \
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800465 tlcl_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800466 tpm_bootmode_tests \
467 utility_string_tests \
468 utility_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800469 vboot_api_init_tests \
470 vboot_api_devmode_tests \
471 vboot_api_firmware_tests \
472 vboot_api_kernel_tests \
Randall Spangler7f436692013-02-05 12:42:36 -0800473 vboot_api_kernel2_tests \
474 vboot_api_kernel3_tests \
475 vboot_api_kernel4_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800476 vboot_audio_tests \
477 vboot_common_tests \
478 vboot_common2_tests \
479 vboot_common3_tests \
Randall Spangler786a5dc2013-01-24 14:19:56 -0800480 vboot_display_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800481 vboot_firmware_tests \
Randall Spangler49cb0d32013-01-29 14:28:16 -0800482 vboot_kernel_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800483 vboot_nvstorage_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800484
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800485# TODO: port these tests to new API, if not already eqivalent
486# functionality in other tests. These don't even compile at present.
487#
488# big_firmware_tests
489# big_kernel_tests
490# firmware_image_tests
491# firmware_rollback_tests
492# firmware_splicing_tests
493# firmware_verify_benchmark
494# kernel_image_tests
495# kernel_rollback_tests
496# kernel_splicing_tests
497# kernel_verify_benchmark
498# rollback_index_test
499# verify_firmware_fuzz_driver
500# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800501# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800502
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800503# And a few more...
504TLCL_TESTS = \
505 tpmtest_earlyextend \
506 tpmtest_earlynvram \
507 tpmtest_earlynvram2 \
508 tpmtest_enable \
509 tpmtest_fastenable \
510 tpmtest_globallock \
511 tpmtest_redefine_unowned \
512 tpmtest_spaceperm \
513 tpmtest_testsetup \
514 tpmtest_timing \
515 tpmtest_writelimit
516TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS})
517TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES})
518
519TEST_NAMES += ${TLCL_TEST_NAMES}
520
521TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES})
522ALL_DEPS += $(addsuffix .d,${TEST_BINS})
523
Randall Spanglere061a252013-01-22 15:34:07 -0800524# Directory containing test keys
525TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800526
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800527
528##############################################################################
529# Finally, some targets. High-level ones first.
530
531# Create output directories if necessary. Do this via explicit shell commands
532# so it happens before trying to generate/include dependencies.
533SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
534_dir_create := $(foreach d, \
535 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
536 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
537
538
539# Default target.
540.PHONY: all
Randall Spangler59d75082013-01-23 09:29:54 -0800541all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800542
543# Host targets
544.PHONY: host_stuff
545host_stuff: hostlib cgpt utils futil tests
546
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800547.PHONY: clean
548clean:
549 ${Q}/bin/rm -rf ${BUILD}
550
551.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800552install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800553
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800554# Don't delete intermediate object files
555.SECONDARY:
556
557# TODO: I suspect this is missing some object files. Make a temp
558# target which cleans all known obj/exe's and see what's left; those
559# are the files which need deps.
560ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
561-include ${ALL_DEPS}
562
563# ----------------------------------------------------------------------------
564# Firmware library
565
566# TPM-specific flags. These depend on the particular TPM we're targeting for.
567# They are needed here only for compiling parts of the firmware code into
568# user-level tests.
569
570# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
571# the self test has completed.
572
Randall Spangler45cc0f22013-01-25 09:34:26 -0800573${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800574
575# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
576# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
577# power on.
578#
579# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
580# are not both defined at the same time. (See comment in code.)
581
582# CFLAGS += -DTPM_MANUAL_SELFTEST
583
584ifeq (${FIRMWARE_ARCH},i386)
585# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800586${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800587
588# Workaround for coreboot on x86, which will power off asynchronously
589# without giving us a chance to react. This is not an example of the Right
590# Way to do things. See chrome-os-partner:7689, and the commit message
591# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800592${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800593
594# On x86 we don't actually read the GBB data into RAM until it is needed.
595# Therefore it makes sense to cache it rather than reading it each time.
596# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800597${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800598endif
599
600ifeq (${FIRMWARE_ARCH},)
601# Disable rollback TPM when compiling locally, since otherwise
602# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800603${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800604endif
605
Randall Spangler93943262013-02-26 11:03:57 -0800606# Link tests
607${BUILD}/firmware/linktest/main_vbinit: LIBS =
608${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
609${BUILD}/firmware/linktest/main_vbsf: LIBS =
610${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
611
612.phony: fwlinktest
613fwlinktest: ${FWLIB} \
614 ${BUILD}/firmware/linktest/main_vbinit \
615 ${BUILD}/firmware/linktest/main_vbsf \
616 ${BUILD}/firmware/linktest/main
617
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800618.PHONY: fwlib
Randall Spangler93943262013-02-26 11:03:57 -0800619fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800620
621${FWLIB}: ${FWLIB_OBJS}
622 @printf " RM $(subst ${BUILD}/,,$@)\n"
623 ${Q}rm -f $@
624 @printf " AR $(subst ${BUILD}/,,$@)\n"
625 ${Q}ar qc $@ $^
626
627# ----------------------------------------------------------------------------
628# Host library
629
630.PHONY: hostlib
631hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main
632
633${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
634 -Ihost/include\
635 -Ihost/arch/${ARCH}/include
636
637# TODO: better way to make .a than duplicating this recipe each time?
638${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS}
639 @printf " RM $(subst ${BUILD}/,,$@)\n"
640 ${Q}rm -f $@
641 @printf " AR $(subst ${BUILD}/,,$@)\n"
642 ${Q}ar qc $@ $^
643
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800644
645# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
646.PHONY: tinyhostlib
647tinyhostlib: ${TINYHOSTLIB}
648 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
649
650${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
651 @printf " RM $(subst ${BUILD}/,,$@)\n"
652 ${Q}rm -f $@
653 @printf " AR $(subst ${BUILD}/,,$@)\n"
654 ${Q}ar qc $@ $^
655
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800656# ----------------------------------------------------------------------------
657# CGPT library and utility
658
659.PHONY: cgpt
660cgpt: ${CGPT}
661
662${CGPT}: LDFLAGS += -static
663${CGPT}: LDLIBS += -luuid
664
665${CGPT}: ${CGPT_OBJS} ${LIBS}
666 @printf " LDcgpt $(subst ${BUILD}/,,$@)\n"
667 ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
668
669.PHONY: cgpt_install
670cgpt_install: ${CGPT}
671 @printf " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800672 ${Q}mkdir -p ${UB_DIR}
673 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800674
675# ----------------------------------------------------------------------------
676# Utilities
677
678# These have their own headers too.
679${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
680
681# Utilities for auto-update toolkits must be statically linked.
682${UTIL_BINS_STATIC}: LDFLAGS += -static
683
684.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800685utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800686 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
687 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
688
689.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800690utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800691 @printf " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800692 ${Q}mkdir -p ${UB_DIR}
693 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800694
695# And some signing stuff for the target
696.PHONY: signing_install
697signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
698ifneq (${MINIMAL},)
699 @printf " INSTALL SIGNING\n"
700 ${Q}mkdir -p ${UB_DIR}
701 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
702 ${Q}mkdir -p ${VB_DIR}
703 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
704 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
705endif
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800706
707# ----------------------------------------------------------------------------
708# new Firmware Utility
709
710.PHONY: futil
711futil: ${FUTIL_BIN}
712
713${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
714 @printf " LD $(subst ${BUILD}/,,$@)\n"
715 ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
716
717.PHONY: futil_install
718futil_install: ${FUTIL_BIN}
719 @printf " INSTALL futility\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800720 ${Q}mkdir -p ${UB_DIR}
721 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800722
723
724# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800725# Utility to generate TLCL structure definition header file.
726
727${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
728
729STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
730STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
731
732.PHONY: update_tlcl_structures
733update_tlcl_structures: ${BUILD}/utility/tlcl_generator
734 @printf " Rebuilding TLCL structures\n"
735 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
736 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
737 ( echo "%% Updating structures.h %%" && \
738 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
739
740# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800741# Tests
742
743.PHONY: tests
744tests: ${TEST_BINS}
745
746${TEST_BINS}: ${TESTLIB}
747
748${TESTLIB}: ${TESTLIB_OBJS}
749 @printf " RM $(subst ${BUILD}/,,$@)\n"
750 ${Q}rm -f $@
751 @printf " AR $(subst ${BUILD}/,,$@)\n"
752 ${Q}ar qc $@ $^
753
754
755# ----------------------------------------------------------------------------
756# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
757# rules for specific targets.
758
759${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
760 @printf " LD $(subst ${BUILD}/,,$@)\n"
761 ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS}
762
763${BUILD}/%.o: %.c
764 @printf " CC $(subst ${BUILD}/,,$@)\n"
765 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
766
767# Rules to recompile a single source file for library and test
768# TODO: is there a tidier way to do this?
769${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
770${BUILD}/%_for_lib.o: %.c
771 @printf " CC-for-lib $(subst ${BUILD}/,,$@)\n"
772 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
773
774${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
775${BUILD}/%_for_test.o: %.c
776 @printf " CC-for-test $(subst ${BUILD}/,,$@)\n"
777 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
778
779# TODO: C++ files don't belong in vboot reference at all. Convert to C.
780${BUILD}/%.o: %.cc
781 @printf " CXX $(subst ${BUILD}/,,$@)\n"
782 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
783
784# ----------------------------------------------------------------------------
785# Here are the special tweaks to the generic rules.
786
787# Linktest ensures firmware lib doesn't rely on outside libraries
788${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
789
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800790# GBB utility needs C++ linker. TODO: It shouldn't.
791${BUILD}/utility/gbb_utility: LD = ${CXX}
792
793# Some utilities need external crypto functions
794${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
795${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
796${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
797${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800798${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
799${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
800${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
801${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
802
803${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
804${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
805${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800806
807${BUILD}/utility/bmpblk_utility: LD = ${CXX}
808${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
809
810BMPBLK_UTILITY_DEPS = \
811 ${BUILD}/utility/bmpblk_util.o \
812 ${BUILD}/utility/image_types.o \
813 ${BUILD}/utility/eficompress_for_lib.o \
814 ${BUILD}/utility/efidecompress_for_lib.o
815${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
816${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
817
818${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
819${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
820
821# Allow multiple definitions, so tests can mock functions from other libraries
822${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
823${BUILD}/tests/%: INCLUDES += -Ihost/include
824${BUILD}/tests/%: LDLIBS += -lrt -luuid
825${BUILD}/tests/%: LIBS += ${TESTLIB}
826
827${BUILD}/tests/rollback_index2_tests: OBJS += \
828 ${BUILD}/firmware/lib/rollback_index_for_test.o
829${BUILD}/tests/rollback_index2_tests: \
830 ${BUILD}/firmware/lib/rollback_index_for_test.o
831
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800832${BUILD}/tests/tlcl_tests: OBJS += \
833 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
834${BUILD}/tests/tlcl_tests: \
835 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
836
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800837${BUILD}/tests/vboot_audio_tests: OBJS += \
838 ${BUILD}/firmware/lib/vboot_audio_for_test.o
839${BUILD}/tests/vboot_audio_tests: \
840 ${BUILD}/firmware/lib/vboot_audio_for_test.o
841
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800842${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
843${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
844
845${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
846${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
847
848##############################################################################
849# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800850
851# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800852.PHONY: test_targets
853test_targets:: runcgpttests runmisctests
Randall Spangler844bce52013-01-15 16:16:43 -0800854
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800855ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -0800856# Bitmap utility isn't compiled for minimal variant
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800857test_targets:: runbmptests
Randall Spangler844bce52013-01-15 16:16:43 -0800858# Scripts don't work under qemu testing
859# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800860test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -0800861endif
862
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800863.PHONY: test_setup
864test_setup:: cgpt utils futil tests
865
Randall Spangler844bce52013-01-15 16:16:43 -0800866# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
867# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800868ifneq (${QEMU_ARCH},)
869test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -0800870
871.PHONY: qemu_install
872qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800873ifeq (${SYSROOT},)
874 $(error SYSROOT must be set to the top of the target-specific root \
875when cross-compiling for qemu-based tests to run properly.)
876endif
Randall Spangler844bce52013-01-15 16:16:43 -0800877 @printf " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800878 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
879 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -0800880endif
881
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800882.PHONY: runtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800883runtests: test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800884
885# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800886.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -0800887genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800888 tests/gen_test_keys.sh
889
890# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800891.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -0800892genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800893 tests/gen_fuzz_test_cases.sh
894
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800895.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800896runbmptests: test_setup
897 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800898 ./TestBmpBlock.py -v
899
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800900.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800901runcgpttests: test_setup
902 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800903
Randall Spangler844bce52013-01-15 16:16:43 -0800904.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800905runtestscripts: test_setup genfuzztestcases
906 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800907 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800908 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -0800909 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800910 tests/run_vbutil_tests.sh
911
Randall Spangler844bce52013-01-15 16:16:43 -0800912.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800913runmisctests: test_setup
914 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -0800915 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800916 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
917 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
918 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800919 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800920 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
921 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
922 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
923 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800924 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -0800925 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
926 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -0800927 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
928 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
929 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800930 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -0800931 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
932 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
933 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -0800934 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800935 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -0800936 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800937 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800938
939.PHONY: runfutiltests
940runfutiltests: DESTDIR := ${TEST_INSTALL_DIR}
941runfutiltests: test_setup install
942 @echo "$@ passed"
Randall Spangler844bce52013-01-15 16:16:43 -0800943
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800944# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -0800945# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800946# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800947.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800948runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -0800949 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
950 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800951 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800952 tests/run_vbutil_tests.sh --all
953
954# TODO: tests to run when ported to new API
955# ./run_image_verification_tests.sh
956# # Splicing tests
957# ${BUILD}/tests/firmware_splicing_tests
958# ${BUILD}/tests/kernel_splicing_tests
959# # Rollback Tests
960# ${BUILD}/tests/firmware_rollback_tests
961# ${BUILD}/tests/kernel_rollback_tests
962
Randall Spangler59d75082013-01-23 09:29:54 -0800963# Code coverage
964.PHONY: coverage_init
965coverage_init: test_setup
966 rm -f ${COV_INFO}*
967 lcov -c -i -d . -b . -o ${COV_INFO}.initial
968
969.PHONY: coverage_html
970coverage_html:
971 lcov -c -d . -b . -o ${COV_INFO}.tests
972 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
973 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
974 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
975
976# Generate addtional coverage stats just for firmware subdir, because the
977# per-directory stats for the whole project don't include their own subdirs.
Randall Spangler49cb0d32013-01-29 14:28:16 -0800978 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
979 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -0800980 -o ${COV_INFO}.firmware
981
982.PHONY: coverage
983ifeq (${COV},)
984coverage:
985 $(error Build coverage like this: make clean && COV=1 make)
986else
987coverage: coverage_init runtests coverage_html
988endif
989