blob: b37a21f2614b5fc7f93ab5d948d165266b2dd85b [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
38# 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
Randall Spangler5d9bbf22013-01-08 10:44:23 -080043# Target for 'make install'
44DESTDIR ?= /usr/bin
Bill Richardson826db092013-01-14 12:37:15 -080045INSTALL ?= install
Randall Spangler5d9bbf22013-01-08 10:44:23 -080046
Bill Richardsoneecc18f2013-01-17 15:28:17 -080047# Where to install the (exportable) executables for testing?
48TEST_INSTALL_DIR = ${BUILD}/install_for_test
49
50# Verbose? Use V=1
51ifeq (${V},)
52Q := @
53endif
54
Randall Spangler61a2eb32013-01-23 10:20:16 -080055# Architecture detection
56_machname := $(shell uname -m)
57HOST_ARCH ?= ${_machname}
58
59# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
60# Pick a sane target architecture if none is defined.
61ifeq (${ARCH},)
62 ARCH := ${HOST_ARCH}
63else ifeq (${ARCH},i386)
64 override ARCH := x86
65else ifeq (${ARCH},amd64)
66 override ARCH := x86_64
67endif
68
69# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
70# for a firmware target (such as u-boot or depthcharge). It must map
71# to the same consistent set of architectures as the host.
72ifeq (${FIRMWARE_ARCH},i386)
73 override FIRMWARE_ARCH := x86
74else ifeq (${FIRMWARE_ARCH},amd64)
75 override FIRMWARE_ARCH := x86_64
76endif
77
Simon Glassb265c342011-11-16 15:09:51 -080078# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
79# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070080#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080081# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
82# temporarily. As we are still investigating which flags are necessary for
83# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070084#
Simon Glassb265c342011-11-16 15:09:51 -080085# As a first step, this makes the setting of CC and CFLAGS here optional, to
86# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070087#
Simon Glassb265c342011-11-16 15:09:51 -080088# Flag ordering: arch, then -f, then -m, then -W
89DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
90COMMON_FLAGS := -nostdinc -pipe \
91 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -080092 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -080093
Bill Richardsoneecc18f2013-01-17 15:28:17 -080094# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
95ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -080096CC ?= armv7a-cros-linux-gnueabi-gcc
97CFLAGS ?= -march=armv5 \
98 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -070099 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800100 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800101else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800102CC ?= i686-pc-linux-gnu-gcc
103# Drop -march=i386 to permit use of SSE instructions
104CFLAGS ?= \
105 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
106 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
107 -mpreferred-stack-boundary=2 -mregparm=3 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800108 ${COMMON_FLAGS}
109else ifeq (${FIRMWARE_ARCH}, x86_64)
110CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800111 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800112else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800113# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800114CC ?= gcc
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800115CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800116endif
117
118ifneq (${DEBUG},)
119CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700120endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800121
vbendebb2b0fcc2010-07-15 15:09:47 -0700122ifeq (${DISABLE_NDEBUG},)
123CFLAGS += -DNDEBUG
124endif
125
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800126# Create / use dependency files
127CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800128
Randall Spangler59d75082013-01-23 09:29:54 -0800129# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800130ifneq (${COV},)
Randall Spangler59d75082013-01-23 09:29:54 -0800131 COV_FLAGS = -O0 --coverage
132 CFLAGS += ${COV_FLAGS}
133 LDFLAGS += ${COV_FLAGS}
134 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800135endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800136
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800137# And a few more default utilities
138LD = ${CC}
139CXX ?= g++ # HEY: really?
140PKG_CONFIG ?= pkg-config
141
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800142# Determine QEMU architecture needed, if any
143ifeq (${ARCH},${HOST_ARCH})
144 # Same architecture; no need for QEMU
145 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800146else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800147 # 64-bit host can run 32-bit targets directly
148 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800149else
150 QEMU_ARCH := ${ARCH}
151endif
152
153# The top of the chroot for qemu must be passed in via the SYSROOT environment
154# variable. In the Chromium OS chroot, this is done automatically by the
155# ebuild.
156
157ifeq (${QEMU_ARCH},)
158 # Path to build output for running tests is same as for building
159 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800160 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800161else
162 $(info Using qemu for testing.)
163 # Path to build output for running tests is different in the chroot
164 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800165 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800166
167 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800168 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
169 export QEMU_RUN
170
171 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800172endif
173
Randall Spanglere061a252013-01-22 15:34:07 -0800174export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800175
176# Some things only compile inside the Chromium OS chroot.
177# TODO: Those things should be in their own repo, not part of vboot_reference
178# TODO: Is there a better way to detect this?
179ifneq (${CROS_WORKON_SRCROOT},)
180IN_CHROOT := yes
181endif
182
183# TODO: Move to separate repo.
184ifneq (${IN_CHROOT},)
185PC_BASE_VER ?= 125070
186PC_DEPS := libchrome-${PC_BASE_VER}
187PC_CFLAGS := $(shell ${PKG_CONFIG} --cflags ${PC_DEPS})
188PC_LDLIBS := $(shell ${PKG_CONFIG} --libs ${PC_DEPS})
189endif
190
191
192##############################################################################
193# Now we need to describe everything we might want or need to build
194
195# TODO: This should go in its own repo.
196AU_CGPTLIB = ${BUILD}/cgpt/libcgpt-cc.a
197# This is just ... Gah. There's no good place for it.
198DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a
199
200# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800201INCLUDES += \
202 -Ifirmware/include \
203 -Ifirmware/lib/include \
204 -Ifirmware/lib/cgptlib/include \
205 -Ifirmware/lib/cryptolib/include \
206 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700207
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800208# If we're not building for a specific target, just stub out things like the
209# TPM commands and various external functions that are provided by the BIOS.
210ifeq (${FIRMWARE_ARCH},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800211INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800212else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800213INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800214endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800215
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800216# Firmware library. TODO: Do we still need to export this?
217FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800218
219# find lib -iname '*.c' | sort
220FWLIB_SRCS = \
221 firmware/lib/cgptlib/cgptlib.c \
222 firmware/lib/cgptlib/cgptlib_internal.c \
223 firmware/lib/cgptlib/crc32.c \
224 firmware/lib/crc8.c \
225 firmware/lib/cryptolib/padding.c \
226 firmware/lib/cryptolib/rsa.c \
227 firmware/lib/cryptolib/rsa_utility.c \
228 firmware/lib/cryptolib/sha1.c \
229 firmware/lib/cryptolib/sha256.c \
230 firmware/lib/cryptolib/sha512.c \
231 firmware/lib/cryptolib/sha_utility.c \
232 firmware/lib/stateful_util.c \
233 firmware/lib/utility.c \
234 firmware/lib/utility_string.c \
235 firmware/lib/vboot_api_init.c \
236 firmware/lib/vboot_api_firmware.c \
237 firmware/lib/vboot_api_kernel.c \
238 firmware/lib/vboot_audio.c \
239 firmware/lib/vboot_common.c \
240 firmware/lib/vboot_display.c \
241 firmware/lib/vboot_firmware.c \
242 firmware/lib/vboot_kernel.c \
243 firmware/lib/vboot_nvstorage.c
244
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800245# Support real TPM unless BIOS sets MOCK_TPM
246ifeq (${MOCK_TPM},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800247FWLIB_SRCS += \
248 firmware/lib/rollback_index.c \
249 firmware/lib/tpm_bootmode.c \
250 firmware/lib/tpm_lite/tlcl.c
251else
252FWLIB_SRCS += \
253 firmware/lib/mocked_rollback_index.c \
254 firmware/lib/mocked_tpm_bootmode.c \
255 firmware/lib/tpm_lite/mocked_tlcl.c
256endif
257
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800258ifeq (${FIRMWARE_ARCH},)
259# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800260FWLIB_SRCS += \
261 firmware/stub/tpm_lite_stub.c \
262 firmware/stub/utility_stub.c \
263 firmware/stub/vboot_api_stub.c \
264 firmware/stub/vboot_api_stub_disk.c
265endif
266
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800267FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800268ALL_OBJS += ${FWLIB_OBJS}
269
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800270
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800271# Library to build the utilities. "HOST" mostly means "userspace".
272HOSTLIB = ${BUILD}/vboot_host.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800273
274HOSTLIB_SRCS = \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800275 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 host/lib/crossystem.c \
277 host/lib/file_keys.c \
278 host/lib/fmap.c \
279 host/lib/host_common.c \
280 host/lib/host_key.c \
281 host/lib/host_keyblock.c \
282 host/lib/host_misc.c \
283 host/lib/host_signature.c \
284 host/lib/signature_digest.c
285
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800286HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800287ALL_OBJS += ${HOSTLIB_OBJS}
288
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800289
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800290# Link with hostlib by default
291LIBS = $(HOSTLIB)
292
293# Might need this too.
294CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
295
296
297# ----------------------------------------------------------------------------
298# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800299
300CGPT = ${BUILD}/cgpt/cgpt
301
302CGPT_SRCS = \
303 cgpt/cgpt.c \
304 cgpt/cgpt_add.c \
305 cgpt/cgpt_boot.c \
306 cgpt/cgpt_common.c \
307 cgpt/cgpt_create.c \
308 cgpt/cgpt_find.c \
309 cgpt/cgpt_legacy.c \
310 cgpt/cgpt_prioritize.c \
311 cgpt/cgpt_repair.c \
312 cgpt/cgpt_show.c \
313 cgpt/cmd_add.c \
314 cgpt/cmd_boot.c \
315 cgpt/cmd_create.c \
316 cgpt/cmd_find.c \
317 cgpt/cmd_legacy.c \
318 cgpt/cmd_prioritize.c \
319 cgpt/cmd_repair.c \
320 cgpt/cmd_show.c
321
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800322CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800323ALL_OBJS += ${CGPT_OBJS}
324
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800325C_DESTDIR = ${DESTDIR}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800326
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800327
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800328# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800329UTIL_SCRIPTS = \
330 utility/dev_debug_vboot \
331 utility/dev_make_keypair \
332 utility/enable_dev_usb_boot \
333 utility/vbutil_what_keys
334
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800335# These utilities should be linked statically.
336UTIL_NAMES_STATIC = \
337 crossystem \
338 dump_fmap \
339 gbb_utility
340
341UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800342 dev_sign_file \
343 dump_kernel_config \
344 dumpRSAPublicKey \
345 load_kernel_test \
346 pad_digest_utility \
347 signature_digest_utility \
348 tpm_init_temp_fix \
349 tpmc \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800350 vbutil_firmware \
351 vbutil_kernel \
352 vbutil_key \
353 vbutil_keyblock \
354 verify_data
355
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800356ifneq (${IN_CHROOT},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800357UTIL_NAMES += mount-encrypted
358endif
359
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800360ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800361UTIL_NAMES += \
362 bmpblk_font \
363 bmpblk_utility \
364 eficompress \
365 efidecompress
366endif
367
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800368UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC})
369UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800370ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
371
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800372U_DESTDIR = ${DESTDIR}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800373
Bill Richardson826db092013-01-14 12:37:15 -0800374
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800375# The unified firmware utility will eventually replace all the others
376FUTIL_BIN = ${BUILD}/futility/futility
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800377
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800378FUTIL_SRCS = \
379 futility/IGNOREME.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800380
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800381FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800382
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800383FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800384
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800385ALL_DEPS += $(addsuffix .d,${FUTIL_BIN})
386ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800387
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800388F_DESTDIR = ${DESTDIR}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800389
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800390
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800391# Library of handy test functions.
392TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800393
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800394TESTLIB_SRCS = \
395 tests/test_common.c \
396 tests/timer_utils.c \
397 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800398
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800399TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
400ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800401
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800402
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800403# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800404TEST_NAMES = \
405 cgptlib_test \
406 rollback_index2_tests \
Randall Spanglera3eac792013-01-23 13:04:05 -0800407 rollback_index3_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800408 rsa_padding_test \
409 rsa_utility_tests \
410 rsa_verify_benchmark \
411 sha_benchmark \
412 sha_tests \
413 stateful_util_tests \
414 tpm_bootmode_tests \
415 utility_string_tests \
416 utility_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800417 vboot_api_init_tests \
418 vboot_api_devmode_tests \
419 vboot_api_firmware_tests \
420 vboot_api_kernel_tests \
421 vboot_audio_tests \
422 vboot_common_tests \
423 vboot_common2_tests \
424 vboot_common3_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800425 vboot_firmware_tests \
426 vboot_nvstorage_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800427
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800428# Grrr
429ifneq (${IN_CHROOT},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800430TEST_NAMES += CgptManagerTests
431endif
432
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800433# TODO: port these tests to new API, if not already eqivalent
434# functionality in other tests. These don't even compile at present.
435#
436# big_firmware_tests
437# big_kernel_tests
438# firmware_image_tests
439# firmware_rollback_tests
440# firmware_splicing_tests
441# firmware_verify_benchmark
442# kernel_image_tests
443# kernel_rollback_tests
444# kernel_splicing_tests
445# kernel_verify_benchmark
446# rollback_index_test
447# verify_firmware_fuzz_driver
448# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800449# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800450
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800451# And a few more...
452TLCL_TESTS = \
453 tpmtest_earlyextend \
454 tpmtest_earlynvram \
455 tpmtest_earlynvram2 \
456 tpmtest_enable \
457 tpmtest_fastenable \
458 tpmtest_globallock \
459 tpmtest_redefine_unowned \
460 tpmtest_spaceperm \
461 tpmtest_testsetup \
462 tpmtest_timing \
463 tpmtest_writelimit
464TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS})
465TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES})
466
467TEST_NAMES += ${TLCL_TEST_NAMES}
468
469TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES})
470ALL_DEPS += $(addsuffix .d,${TEST_BINS})
471
Randall Spanglere061a252013-01-22 15:34:07 -0800472# Directory containing test keys
473TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800474
475# ----------------------------------------------------------------------------
476# TODO: why not make this include *all* the cgpt files, and simply have
477# cgpt link against it?
478# TODO: CgptManager.cc should move to the installer project. Shouldn't be
479# in libcgpt-cc.a.
480AU_CGPTLIB_SRCS = \
481 cgpt/CgptManager.cc \
482 cgpt/cgpt_create.c \
483 cgpt/cgpt_add.c \
484 cgpt/cgpt_boot.c \
485 cgpt/cgpt_show.c \
486 cgpt/cgpt_repair.c \
487 cgpt/cgpt_prioritize.c \
488 cgpt/cgpt_common.c \
489 firmware/lib/cgptlib/crc32.c \
490 firmware/lib/cgptlib/cgptlib_internal.c \
491 firmware/stub/utility_stub.c
492
493AU_CGPTLIB_OBJS = $(filter %.o, \
494 ${AU_CGPTLIB_SRCS:%.c=${BUILD}/%.o} \
495 ${AU_CGPTLIB_SRCS:%.cc=${BUILD}/%.o})
496ALL_OBJS += ${AU_CGPTLIB_OBJS}
497
498
499##############################################################################
500# Finally, some targets. High-level ones first.
501
502# Create output directories if necessary. Do this via explicit shell commands
503# so it happens before trying to generate/include dependencies.
504SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
505_dir_create := $(foreach d, \
506 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
507 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
508
509
510# Default target.
511.PHONY: all
Randall Spangler59d75082013-01-23 09:29:54 -0800512all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800513
514# Host targets
515.PHONY: host_stuff
516host_stuff: hostlib cgpt utils futil tests
517
518# AU targets
519.PHONY: au_stuff
520au_stuff: libcgpt_cc libdump_kernel_config cgptmanager_tests
521
522.PHONY: clean
523clean:
524 ${Q}/bin/rm -rf ${BUILD}
525
526.PHONY: install
527install: cgpt_install utils_install futil_install
528
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800529# Don't delete intermediate object files
530.SECONDARY:
531
532# TODO: I suspect this is missing some object files. Make a temp
533# target which cleans all known obj/exe's and see what's left; those
534# are the files which need deps.
535ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
536-include ${ALL_DEPS}
537
538# ----------------------------------------------------------------------------
539# Firmware library
540
541# TPM-specific flags. These depend on the particular TPM we're targeting for.
542# They are needed here only for compiling parts of the firmware code into
543# user-level tests.
544
545# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
546# the self test has completed.
547
Randall Spangler45cc0f22013-01-25 09:34:26 -0800548${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800549
550# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
551# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
552# power on.
553#
554# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
555# are not both defined at the same time. (See comment in code.)
556
557# CFLAGS += -DTPM_MANUAL_SELFTEST
558
559ifeq (${FIRMWARE_ARCH},i386)
560# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800561${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800562
563# Workaround for coreboot on x86, which will power off asynchronously
564# without giving us a chance to react. This is not an example of the Right
565# Way to do things. See chrome-os-partner:7689, and the commit message
566# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800567${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800568
569# On x86 we don't actually read the GBB data into RAM until it is needed.
570# Therefore it makes sense to cache it rather than reading it each time.
571# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800572${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800573endif
574
575ifeq (${FIRMWARE_ARCH},)
576# Disable rollback TPM when compiling locally, since otherwise
577# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800578${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800579endif
580
581.PHONY: fwlib
582fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,${BUILD}/firmware/linktest/main)
583
584${FWLIB}: ${FWLIB_OBJS}
585 @printf " RM $(subst ${BUILD}/,,$@)\n"
586 ${Q}rm -f $@
587 @printf " AR $(subst ${BUILD}/,,$@)\n"
588 ${Q}ar qc $@ $^
589
590# ----------------------------------------------------------------------------
591# Host library
592
593.PHONY: hostlib
594hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main
595
596${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
597 -Ihost/include\
598 -Ihost/arch/${ARCH}/include
599
600# TODO: better way to make .a than duplicating this recipe each time?
601${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS}
602 @printf " RM $(subst ${BUILD}/,,$@)\n"
603 ${Q}rm -f $@
604 @printf " AR $(subst ${BUILD}/,,$@)\n"
605 ${Q}ar qc $@ $^
606
607# ----------------------------------------------------------------------------
608# CGPT library and utility
609
610.PHONY: cgpt
611cgpt: ${CGPT}
612
613${CGPT}: LDFLAGS += -static
614${CGPT}: LDLIBS += -luuid
615
616${CGPT}: ${CGPT_OBJS} ${LIBS}
617 @printf " LDcgpt $(subst ${BUILD}/,,$@)\n"
618 ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
619
620.PHONY: cgpt_install
621cgpt_install: ${CGPT}
622 @printf " INSTALL CGPT\n"
623 ${Q}mkdir -p ${C_DESTDIR}
624 ${Q}${INSTALL} -t ${C_DESTDIR} $^
625
626# ----------------------------------------------------------------------------
627# Utilities
628
629# These have their own headers too.
630${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
631
632# Utilities for auto-update toolkits must be statically linked.
633${UTIL_BINS_STATIC}: LDFLAGS += -static
634
635.PHONY: utils
636utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
637# TODO: change ebuild to pull scripts directly out of utility dir
638 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
639 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
640
641.PHONY: utils_install
642utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
643 @printf " INSTALL UTILS\n"
644 ${Q}mkdir -p ${U_DESTDIR}
645 ${Q}${INSTALL} -t ${U_DESTDIR} $^
646
647# ----------------------------------------------------------------------------
648# new Firmware Utility
649
650.PHONY: futil
651futil: ${FUTIL_BIN}
652
653${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
654 @printf " LD $(subst ${BUILD}/,,$@)\n"
655 ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
656
657.PHONY: futil_install
658futil_install: ${FUTIL_BIN}
659 @printf " INSTALL futility\n"
660 ${Q}mkdir -p ${F_DESTDIR}
661 ${Q}${INSTALL} -t ${F_DESTDIR} $^
662
663
664# ----------------------------------------------------------------------------
665# Mount-encrypted utility for cryptohome
666
667# TODO: mount-encrypted should move to cryptohome and just link against
668# vboot-host.a for tlcl and crossystem.
669
670# The embedded libcrypto conflicts with the shipped openssl,
671# so mount-* builds without the common CFLAGS (and those includes).
672
673${BUILD}/utility/mount-helpers.o: \
674 utility/mount-helpers.c \
675 utility/mount-helpers.h \
676 utility/mount-encrypted.h
677 @printf " CCm-e $(subst ${BUILD}/,,$@)\n"
678 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
679 ${COV_FLAGS} \
680 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \
681 -c $< -o $@
682
683${BUILD}/utility/mount-encrypted: \
684 utility/mount-encrypted.c \
685 utility/mount-encrypted.h \
686 ${BUILD}/utility/mount-helpers.o ${LIBS}
687 @printf " CCm-exe $(subst ${BUILD}/,,$@)\n"
688 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
689 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \
690 -Ifirmware/include \
691 -Ihost/include \
692 ${COV_FLAGS} \
693 ${LDFLAGS} \
694 $< -o $@ \
695 ${BUILD}/utility/mount-helpers.o ${LIBS} \
696 $(shell ${PKG_CONFIG} --libs glib-2.0 openssl) \
697 -lm
698ifneq (${COV},)
699 ${Q}mv -f mount-encrypted.gcno ${BUILD}/utility
700endif
701
702# ----------------------------------------------------------------------------
703# Utility to generate TLCL structure definition header file.
704
705${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
706
707STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
708STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
709
710.PHONY: update_tlcl_structures
711update_tlcl_structures: ${BUILD}/utility/tlcl_generator
712 @printf " Rebuilding TLCL structures\n"
713 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
714 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
715 ( echo "%% Updating structures.h %%" && \
716 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
717
718# ----------------------------------------------------------------------------
719# Library to dump kernel config
720# Used by platform/installer, as well as standalone utility.
721
722.PHONY: libdump_kernel_config
723libdump_kernel_config: ${DUMPKERNELCONFIGLIB}
724
725${DUMPKERNELCONFIGLIB}: ${BUILD}/utility/dump_kernel_config_lib.o
726 @printf " RM $(subst ${BUILD}/,,$@)\n"
727 ${Q}rm -f $@
728 @printf " AR $(subst ${BUILD}/,,$@)\n"
729 ${Q}ar qc $@ $^
730
731# ----------------------------------------------------------------------------
732# And this thing.
733
734.PHONY: libcgpt_cc
735libcgpt_cc: ${AU_CGPTLIB}
736
737${AU_CGPTLIB}: INCLUDES += -Ifirmware/lib/cgptlib/include
738${AU_CGPTLIB}: ${AU_CGPTLIB_OBJS}
739 @printf " RM $(subst ${BUILD}/,,$@)\n"
740 ${Q}rm -f $@
741 @printf " AR $(subst ${BUILD}/,,$@)\n"
742 ${Q}ar qc $@ $^
743
744# ----------------------------------------------------------------------------
745# Tests
746
747.PHONY: tests
748tests: ${TEST_BINS}
749
750${TEST_BINS}: ${TESTLIB}
751
752${TESTLIB}: ${TESTLIB_OBJS}
753 @printf " RM $(subst ${BUILD}/,,$@)\n"
754 ${Q}rm -f $@
755 @printf " AR $(subst ${BUILD}/,,$@)\n"
756 ${Q}ar qc $@ $^
757
758
759# ----------------------------------------------------------------------------
760# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
761# rules for specific targets.
762
763${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
764 @printf " LD $(subst ${BUILD}/,,$@)\n"
765 ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS}
766
767${BUILD}/%.o: %.c
768 @printf " CC $(subst ${BUILD}/,,$@)\n"
769 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
770
771# Rules to recompile a single source file for library and test
772# TODO: is there a tidier way to do this?
773${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
774${BUILD}/%_for_lib.o: %.c
775 @printf " CC-for-lib $(subst ${BUILD}/,,$@)\n"
776 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
777
778${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
779${BUILD}/%_for_test.o: %.c
780 @printf " CC-for-test $(subst ${BUILD}/,,$@)\n"
781 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
782
783# TODO: C++ files don't belong in vboot reference at all. Convert to C.
784${BUILD}/%.o: %.cc
785 @printf " CXX $(subst ${BUILD}/,,$@)\n"
786 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
787
788# ----------------------------------------------------------------------------
789# Here are the special tweaks to the generic rules.
790
791# Linktest ensures firmware lib doesn't rely on outside libraries
792${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
793
794# Specific dependency here.
795${BUILD}/utility/dump_kernel_config: LIBS += ${DUMPKERNELCONFIGLIB}
796${BUILD}/utility/dump_kernel_config: ${DUMPKERNELCONFIGLIB}
797
798# GBB utility needs C++ linker. TODO: It shouldn't.
799${BUILD}/utility/gbb_utility: LD = ${CXX}
800
801# Some utilities need external crypto functions
802${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
803${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
804${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
805${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800806${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
807${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
808${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
809${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
810
811${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
812${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
813${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800814
815${BUILD}/utility/bmpblk_utility: LD = ${CXX}
816${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
817
818BMPBLK_UTILITY_DEPS = \
819 ${BUILD}/utility/bmpblk_util.o \
820 ${BUILD}/utility/image_types.o \
821 ${BUILD}/utility/eficompress_for_lib.o \
822 ${BUILD}/utility/efidecompress_for_lib.o
823${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
824${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
825
826${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
827${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
828
829# Allow multiple definitions, so tests can mock functions from other libraries
830${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
831${BUILD}/tests/%: INCLUDES += -Ihost/include
832${BUILD}/tests/%: LDLIBS += -lrt -luuid
833${BUILD}/tests/%: LIBS += ${TESTLIB}
834
835${BUILD}/tests/rollback_index2_tests: OBJS += \
836 ${BUILD}/firmware/lib/rollback_index_for_test.o
837${BUILD}/tests/rollback_index2_tests: \
838 ${BUILD}/firmware/lib/rollback_index_for_test.o
839
840${BUILD}/tests/vboot_audio_tests: OBJS += \
841 ${BUILD}/firmware/lib/vboot_audio_for_test.o
842${BUILD}/tests/vboot_audio_tests: \
843 ${BUILD}/firmware/lib/vboot_audio_for_test.o
844
845.PHONY: cgptmanager_tests
846cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
847
848${BUILD}/tests/CgptManagerTests: CFLAGS += ${PC_CFLAGS}
849${BUILD}/tests/CgptManagerTests: LD = ${CXX}
850${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags ${PC_LDLIBS}
851${BUILD}/tests/CgptManagerTests: LIBS = ${AU_CGPTLIB}
852${BUILD}/tests/CgptManagerTests: ${AU_CGPTLIB}
853
854${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
855${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
856
857${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
858${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
859
860##############################################################################
861# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800862
863# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800864.PHONY: test_targets
865test_targets:: runcgpttests runmisctests
Randall Spangler844bce52013-01-15 16:16:43 -0800866
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800867ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -0800868# Bitmap utility isn't compiled for minimal variant
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800869test_targets:: runbmptests
Randall Spangler844bce52013-01-15 16:16:43 -0800870# Scripts don't work under qemu testing
871# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800872test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -0800873endif
874
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800875.PHONY: test_setup
876test_setup:: cgpt utils futil tests
877
Randall Spangler844bce52013-01-15 16:16:43 -0800878# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
879# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800880ifneq (${QEMU_ARCH},)
881test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -0800882
883.PHONY: qemu_install
884qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800885ifeq (${SYSROOT},)
886 $(error SYSROOT must be set to the top of the target-specific root \
887when cross-compiling for qemu-based tests to run properly.)
888endif
Randall Spangler844bce52013-01-15 16:16:43 -0800889 @printf " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800890 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
891 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -0800892endif
893
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800894.PHONY: runtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800895runtests: test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800896
897# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800898.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -0800899genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800900 tests/gen_test_keys.sh
901
902# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800903.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -0800904genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800905 tests/gen_fuzz_test_cases.sh
906
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800907.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800908runbmptests: test_setup
909 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800910 ./TestBmpBlock.py -v
911
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800912.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800913runcgpttests: test_setup
914 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
915# HEY - elsewhere
916ifneq (${IN_CHROOT},)
917 ${RUNTEST} ${BUILD_RUN}/tests/CgptManagerTests --v=1
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800918endif
919
Randall Spangler844bce52013-01-15 16:16:43 -0800920.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800921runtestscripts: test_setup genfuzztestcases
922 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800923 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800924 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -0800925 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800926 tests/run_vbutil_tests.sh
927
Randall Spangler844bce52013-01-15 16:16:43 -0800928.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800929runmisctests: test_setup
930 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -0800931 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800932 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
933 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
934 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
935 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
936 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
937 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
938 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
939 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
940 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
941 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -0800942 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
943 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
944 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800945 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800946 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800947
948.PHONY: runfutiltests
949runfutiltests: DESTDIR := ${TEST_INSTALL_DIR}
950runfutiltests: test_setup install
951 @echo "$@ passed"
Randall Spangler844bce52013-01-15 16:16:43 -0800952
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800953# Run long tests, including all permutations of encryption keys (instead of
954# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
955# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800956.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800957runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -0800958 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
959 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800960 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800961 tests/run_vbutil_tests.sh --all
962
963# TODO: tests to run when ported to new API
964# ./run_image_verification_tests.sh
965# # Splicing tests
966# ${BUILD}/tests/firmware_splicing_tests
967# ${BUILD}/tests/kernel_splicing_tests
968# # Rollback Tests
969# ${BUILD}/tests/firmware_rollback_tests
970# ${BUILD}/tests/kernel_rollback_tests
971
Randall Spangler59d75082013-01-23 09:29:54 -0800972# Code coverage
973.PHONY: coverage_init
974coverage_init: test_setup
975 rm -f ${COV_INFO}*
976 lcov -c -i -d . -b . -o ${COV_INFO}.initial
977
978.PHONY: coverage_html
979coverage_html:
980 lcov -c -d . -b . -o ${COV_INFO}.tests
981 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
982 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
983 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
984
985# Generate addtional coverage stats just for firmware subdir, because the
986# per-directory stats for the whole project don't include their own subdirs.
987 lcov -e ${COV_INFO}.local '${SRCDIR}/firmware/*' \
988 -o ${COV_INFO}.firmware
989
990.PHONY: coverage
991ifeq (${COV},)
992coverage:
993 $(error Build coverage like this: make clean && COV=1 make)
994else
995coverage: coverage_init runtests coverage_html
996endif
997