blob: 30d04fc65f3dbb5224e337dca262702949766d9b [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
188# Some things only compile inside the Chromium OS chroot.
189# TODO: Those things should be in their own repo, not part of vboot_reference
190# TODO: Is there a better way to detect this?
191ifneq (${CROS_WORKON_SRCROOT},)
192IN_CHROOT := yes
193endif
194
195# TODO: Move to separate repo.
196ifneq (${IN_CHROOT},)
197PC_BASE_VER ?= 125070
198PC_DEPS := libchrome-${PC_BASE_VER}
199PC_CFLAGS := $(shell ${PKG_CONFIG} --cflags ${PC_DEPS})
200PC_LDLIBS := $(shell ${PKG_CONFIG} --libs ${PC_DEPS})
201endif
202
203
204##############################################################################
205# Now we need to describe everything we might want or need to build
206
207# TODO: This should go in its own repo.
208AU_CGPTLIB = ${BUILD}/cgpt/libcgpt-cc.a
209# This is just ... Gah. There's no good place for it.
210DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a
211
212# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800213INCLUDES += \
214 -Ifirmware/include \
215 -Ifirmware/lib/include \
216 -Ifirmware/lib/cgptlib/include \
217 -Ifirmware/lib/cryptolib/include \
218 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700219
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800220# If we're not building for a specific target, just stub out things like the
221# TPM commands and various external functions that are provided by the BIOS.
222ifeq (${FIRMWARE_ARCH},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800223INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800224else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800225INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800226endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800227
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800228# Firmware library. TODO: Do we still need to export this?
229FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800230
231# find lib -iname '*.c' | sort
232FWLIB_SRCS = \
233 firmware/lib/cgptlib/cgptlib.c \
234 firmware/lib/cgptlib/cgptlib_internal.c \
235 firmware/lib/cgptlib/crc32.c \
236 firmware/lib/crc8.c \
237 firmware/lib/cryptolib/padding.c \
238 firmware/lib/cryptolib/rsa.c \
239 firmware/lib/cryptolib/rsa_utility.c \
240 firmware/lib/cryptolib/sha1.c \
241 firmware/lib/cryptolib/sha256.c \
242 firmware/lib/cryptolib/sha512.c \
243 firmware/lib/cryptolib/sha_utility.c \
244 firmware/lib/stateful_util.c \
245 firmware/lib/utility.c \
246 firmware/lib/utility_string.c \
247 firmware/lib/vboot_api_init.c \
248 firmware/lib/vboot_api_firmware.c \
249 firmware/lib/vboot_api_kernel.c \
250 firmware/lib/vboot_audio.c \
251 firmware/lib/vboot_common.c \
252 firmware/lib/vboot_display.c \
253 firmware/lib/vboot_firmware.c \
254 firmware/lib/vboot_kernel.c \
255 firmware/lib/vboot_nvstorage.c
256
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800257# Support real TPM unless BIOS sets MOCK_TPM
258ifeq (${MOCK_TPM},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800259FWLIB_SRCS += \
260 firmware/lib/rollback_index.c \
261 firmware/lib/tpm_bootmode.c \
262 firmware/lib/tpm_lite/tlcl.c
263else
264FWLIB_SRCS += \
265 firmware/lib/mocked_rollback_index.c \
266 firmware/lib/mocked_tpm_bootmode.c \
267 firmware/lib/tpm_lite/mocked_tlcl.c
268endif
269
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800270ifeq (${FIRMWARE_ARCH},)
271# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800272FWLIB_SRCS += \
273 firmware/stub/tpm_lite_stub.c \
274 firmware/stub/utility_stub.c \
275 firmware/stub/vboot_api_stub.c \
276 firmware/stub/vboot_api_stub_disk.c
277endif
278
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800279FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800280ALL_OBJS += ${FWLIB_OBJS}
281
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800282
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800283# Library to build the utilities. "HOST" mostly means "userspace".
284HOSTLIB = ${BUILD}/vboot_host.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800285
286HOSTLIB_SRCS = \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800287 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800288 host/lib/crossystem.c \
289 host/lib/file_keys.c \
290 host/lib/fmap.c \
291 host/lib/host_common.c \
292 host/lib/host_key.c \
293 host/lib/host_keyblock.c \
294 host/lib/host_misc.c \
295 host/lib/host_signature.c \
296 host/lib/signature_digest.c
297
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800298HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800299ALL_OBJS += ${HOSTLIB_OBJS}
300
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800301
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800302# Link with hostlib by default
303LIBS = $(HOSTLIB)
304
305# Might need this too.
306CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
307
308
309# ----------------------------------------------------------------------------
310# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800311
312CGPT = ${BUILD}/cgpt/cgpt
313
314CGPT_SRCS = \
315 cgpt/cgpt.c \
316 cgpt/cgpt_add.c \
317 cgpt/cgpt_boot.c \
318 cgpt/cgpt_common.c \
319 cgpt/cgpt_create.c \
320 cgpt/cgpt_find.c \
321 cgpt/cgpt_legacy.c \
322 cgpt/cgpt_prioritize.c \
323 cgpt/cgpt_repair.c \
324 cgpt/cgpt_show.c \
325 cgpt/cmd_add.c \
326 cgpt/cmd_boot.c \
327 cgpt/cmd_create.c \
328 cgpt/cmd_find.c \
329 cgpt/cmd_legacy.c \
330 cgpt/cmd_prioritize.c \
331 cgpt/cmd_repair.c \
332 cgpt/cmd_show.c
333
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800334CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800335ALL_OBJS += ${CGPT_OBJS}
336
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800337
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800338# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800339UTIL_SCRIPTS = \
340 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800341 utility/enable_dev_usb_boot \
342 utility/vbutil_what_keys
343
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800344ifeq (${MINIMAL},)
345UTIL_SCRIPTS += \
346 utility/dev_make_keypair
347endif
348
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800349# These utilities should be linked statically.
350UTIL_NAMES_STATIC = \
351 crossystem \
352 dump_fmap \
353 gbb_utility
354
355UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800356 dev_sign_file \
357 dump_kernel_config \
358 dumpRSAPublicKey \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800359 tpm_init_temp_fix \
360 tpmc \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800361 vbutil_firmware \
362 vbutil_kernel \
363 vbutil_key \
364 vbutil_keyblock \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800365
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800366ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800367UTIL_NAMES += \
368 bmpblk_font \
369 bmpblk_utility \
370 eficompress \
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800371 efidecompress \
372 load_kernel_test \
373 pad_digest_utility \
374 signature_digest_utility \
375 verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800376endif
377
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800378UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC})
379UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES})
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800380ifneq (${IN_CHROOT},)
381UTIL_SBINS = $(addprefix ${BUILD}/utility/,mount-encrypted)
382endif
383
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800384ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
385
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800386
387# Scripts for signing stuff.
388SIGNING_SCRIPTS = \
389 utility/tpm-nvsize \
390 utility/chromeos-tpm-recovery
391
392# These go in a different place.
393SIGNING_SCRIPTS_DEV = \
394 scripts/image_signing/resign_firmwarefd.sh \
395 scripts/image_signing/make_dev_firmware.sh \
396 scripts/image_signing/make_dev_ssd.sh \
397 scripts/image_signing/set_gbb_flags.sh
398
399# Installed, but not made executable.
400SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800401
Bill Richardson826db092013-01-14 12:37:15 -0800402
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800403# The unified firmware utility will eventually replace all the others
404FUTIL_BIN = ${BUILD}/futility/futility
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800405
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800406FUTIL_SRCS = \
407 futility/IGNOREME.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800408
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800409FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800410
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800411FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800412
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800413ALL_DEPS += $(addsuffix .d,${FUTIL_BIN})
414ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800415
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800416
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800417# Library of handy test functions.
418TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800419
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800420TESTLIB_SRCS = \
421 tests/test_common.c \
422 tests/timer_utils.c \
423 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800424
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800425TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
426ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800427
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800428
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800429# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800430TEST_NAMES = \
431 cgptlib_test \
432 rollback_index2_tests \
Randall Spanglera3eac792013-01-23 13:04:05 -0800433 rollback_index3_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800434 rsa_padding_test \
435 rsa_utility_tests \
436 rsa_verify_benchmark \
437 sha_benchmark \
438 sha_tests \
439 stateful_util_tests \
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800440 tlcl_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800441 tpm_bootmode_tests \
442 utility_string_tests \
443 utility_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800444 vboot_api_init_tests \
445 vboot_api_devmode_tests \
446 vboot_api_firmware_tests \
447 vboot_api_kernel_tests \
Randall Spangler7f436692013-02-05 12:42:36 -0800448 vboot_api_kernel2_tests \
449 vboot_api_kernel3_tests \
450 vboot_api_kernel4_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800451 vboot_audio_tests \
452 vboot_common_tests \
453 vboot_common2_tests \
454 vboot_common3_tests \
Randall Spangler786a5dc2013-01-24 14:19:56 -0800455 vboot_display_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800456 vboot_firmware_tests \
Randall Spangler49cb0d32013-01-29 14:28:16 -0800457 vboot_kernel_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800458 vboot_nvstorage_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800460# Grrr
461ifneq (${IN_CHROOT},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462TEST_NAMES += CgptManagerTests
463endif
464
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800465# TODO: port these tests to new API, if not already eqivalent
466# functionality in other tests. These don't even compile at present.
467#
468# big_firmware_tests
469# big_kernel_tests
470# firmware_image_tests
471# firmware_rollback_tests
472# firmware_splicing_tests
473# firmware_verify_benchmark
474# kernel_image_tests
475# kernel_rollback_tests
476# kernel_splicing_tests
477# kernel_verify_benchmark
478# rollback_index_test
479# verify_firmware_fuzz_driver
480# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800481# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800482
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800483# And a few more...
484TLCL_TESTS = \
485 tpmtest_earlyextend \
486 tpmtest_earlynvram \
487 tpmtest_earlynvram2 \
488 tpmtest_enable \
489 tpmtest_fastenable \
490 tpmtest_globallock \
491 tpmtest_redefine_unowned \
492 tpmtest_spaceperm \
493 tpmtest_testsetup \
494 tpmtest_timing \
495 tpmtest_writelimit
496TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS})
497TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES})
498
499TEST_NAMES += ${TLCL_TEST_NAMES}
500
501TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES})
502ALL_DEPS += $(addsuffix .d,${TEST_BINS})
503
Randall Spanglere061a252013-01-22 15:34:07 -0800504# Directory containing test keys
505TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800506
507# ----------------------------------------------------------------------------
508# TODO: why not make this include *all* the cgpt files, and simply have
509# cgpt link against it?
510# TODO: CgptManager.cc should move to the installer project. Shouldn't be
511# in libcgpt-cc.a.
512AU_CGPTLIB_SRCS = \
513 cgpt/CgptManager.cc \
514 cgpt/cgpt_create.c \
515 cgpt/cgpt_add.c \
516 cgpt/cgpt_boot.c \
517 cgpt/cgpt_show.c \
518 cgpt/cgpt_repair.c \
519 cgpt/cgpt_prioritize.c \
520 cgpt/cgpt_common.c \
521 firmware/lib/cgptlib/crc32.c \
522 firmware/lib/cgptlib/cgptlib_internal.c \
523 firmware/stub/utility_stub.c
524
525AU_CGPTLIB_OBJS = $(filter %.o, \
526 ${AU_CGPTLIB_SRCS:%.c=${BUILD}/%.o} \
527 ${AU_CGPTLIB_SRCS:%.cc=${BUILD}/%.o})
528ALL_OBJS += ${AU_CGPTLIB_OBJS}
529
530
531##############################################################################
532# Finally, some targets. High-level ones first.
533
534# Create output directories if necessary. Do this via explicit shell commands
535# so it happens before trying to generate/include dependencies.
536SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
537_dir_create := $(foreach d, \
538 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
539 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
540
541
542# Default target.
543.PHONY: all
Randall Spangler59d75082013-01-23 09:29:54 -0800544all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800545
546# Host targets
547.PHONY: host_stuff
548host_stuff: hostlib cgpt utils futil tests
549
550# AU targets
551.PHONY: au_stuff
552au_stuff: libcgpt_cc libdump_kernel_config cgptmanager_tests
553
554.PHONY: clean
555clean:
556 ${Q}/bin/rm -rf ${BUILD}
557
558.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800559install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800560
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800561# Don't delete intermediate object files
562.SECONDARY:
563
564# TODO: I suspect this is missing some object files. Make a temp
565# target which cleans all known obj/exe's and see what's left; those
566# are the files which need deps.
567ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
568-include ${ALL_DEPS}
569
570# ----------------------------------------------------------------------------
571# Firmware library
572
573# TPM-specific flags. These depend on the particular TPM we're targeting for.
574# They are needed here only for compiling parts of the firmware code into
575# user-level tests.
576
577# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
578# the self test has completed.
579
Randall Spangler45cc0f22013-01-25 09:34:26 -0800580${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800581
582# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
583# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
584# power on.
585#
586# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
587# are not both defined at the same time. (See comment in code.)
588
589# CFLAGS += -DTPM_MANUAL_SELFTEST
590
591ifeq (${FIRMWARE_ARCH},i386)
592# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800593${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800594
595# Workaround for coreboot on x86, which will power off asynchronously
596# without giving us a chance to react. This is not an example of the Right
597# Way to do things. See chrome-os-partner:7689, and the commit message
598# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800599${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800600
601# On x86 we don't actually read the GBB data into RAM until it is needed.
602# Therefore it makes sense to cache it rather than reading it each time.
603# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800604${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800605endif
606
607ifeq (${FIRMWARE_ARCH},)
608# Disable rollback TPM when compiling locally, since otherwise
609# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800610${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800611endif
612
613.PHONY: fwlib
614fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,${BUILD}/firmware/linktest/main)
615
616${FWLIB}: ${FWLIB_OBJS}
617 @printf " RM $(subst ${BUILD}/,,$@)\n"
618 ${Q}rm -f $@
619 @printf " AR $(subst ${BUILD}/,,$@)\n"
620 ${Q}ar qc $@ $^
621
622# ----------------------------------------------------------------------------
623# Host library
624
625.PHONY: hostlib
626hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main
627
628${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
629 -Ihost/include\
630 -Ihost/arch/${ARCH}/include
631
632# TODO: better way to make .a than duplicating this recipe each time?
633${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS}
634 @printf " RM $(subst ${BUILD}/,,$@)\n"
635 ${Q}rm -f $@
636 @printf " AR $(subst ${BUILD}/,,$@)\n"
637 ${Q}ar qc $@ $^
638
639# ----------------------------------------------------------------------------
640# CGPT library and utility
641
642.PHONY: cgpt
643cgpt: ${CGPT}
644
645${CGPT}: LDFLAGS += -static
646${CGPT}: LDLIBS += -luuid
647
648${CGPT}: ${CGPT_OBJS} ${LIBS}
649 @printf " LDcgpt $(subst ${BUILD}/,,$@)\n"
650 ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
651
652.PHONY: cgpt_install
653cgpt_install: ${CGPT}
654 @printf " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800655 ${Q}mkdir -p ${UB_DIR}
656 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800657
658# ----------------------------------------------------------------------------
659# Utilities
660
661# These have their own headers too.
662${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
663
664# Utilities for auto-update toolkits must be statically linked.
665${UTIL_BINS_STATIC}: LDFLAGS += -static
666
667.PHONY: utils
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800668utils: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_SBINS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800669 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
670 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
671
672.PHONY: utils_install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800673utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_SBINS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800674 @printf " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800675 ${Q}mkdir -p ${UB_DIR}
676 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
677ifneq (${UTIL_SBINS},)
678 ${Q}mkdir -p ${SB_DIR}
679 ${Q}${INSTALL} -t ${SB_DIR} ${UTIL_SBINS}
680endif
681
682
683# And some signing stuff for the target
684.PHONY: signing_install
685signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
686ifneq (${MINIMAL},)
687 @printf " INSTALL SIGNING\n"
688 ${Q}mkdir -p ${UB_DIR}
689 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
690 ${Q}mkdir -p ${VB_DIR}
691 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
692 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
693endif
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800694
695# ----------------------------------------------------------------------------
696# new Firmware Utility
697
698.PHONY: futil
699futil: ${FUTIL_BIN}
700
701${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
702 @printf " LD $(subst ${BUILD}/,,$@)\n"
703 ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
704
705.PHONY: futil_install
706futil_install: ${FUTIL_BIN}
707 @printf " INSTALL futility\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800708 ${Q}mkdir -p ${UB_DIR}
709 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800710
711
712# ----------------------------------------------------------------------------
713# Mount-encrypted utility for cryptohome
714
715# TODO: mount-encrypted should move to cryptohome and just link against
716# vboot-host.a for tlcl and crossystem.
717
718# The embedded libcrypto conflicts with the shipped openssl,
719# so mount-* builds without the common CFLAGS (and those includes).
720
721${BUILD}/utility/mount-helpers.o: \
722 utility/mount-helpers.c \
723 utility/mount-helpers.h \
724 utility/mount-encrypted.h
725 @printf " CCm-e $(subst ${BUILD}/,,$@)\n"
726 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
727 ${COV_FLAGS} \
728 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \
729 -c $< -o $@
730
731${BUILD}/utility/mount-encrypted: \
732 utility/mount-encrypted.c \
733 utility/mount-encrypted.h \
734 ${BUILD}/utility/mount-helpers.o ${LIBS}
735 @printf " CCm-exe $(subst ${BUILD}/,,$@)\n"
736 ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
737 $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \
738 -Ifirmware/include \
739 -Ihost/include \
740 ${COV_FLAGS} \
741 ${LDFLAGS} \
742 $< -o $@ \
743 ${BUILD}/utility/mount-helpers.o ${LIBS} \
744 $(shell ${PKG_CONFIG} --libs glib-2.0 openssl) \
745 -lm
746ifneq (${COV},)
747 ${Q}mv -f mount-encrypted.gcno ${BUILD}/utility
748endif
749
750# ----------------------------------------------------------------------------
751# Utility to generate TLCL structure definition header file.
752
753${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
754
755STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
756STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
757
758.PHONY: update_tlcl_structures
759update_tlcl_structures: ${BUILD}/utility/tlcl_generator
760 @printf " Rebuilding TLCL structures\n"
761 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
762 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
763 ( echo "%% Updating structures.h %%" && \
764 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
765
766# ----------------------------------------------------------------------------
767# Library to dump kernel config
768# Used by platform/installer, as well as standalone utility.
769
770.PHONY: libdump_kernel_config
771libdump_kernel_config: ${DUMPKERNELCONFIGLIB}
772
773${DUMPKERNELCONFIGLIB}: ${BUILD}/utility/dump_kernel_config_lib.o
774 @printf " RM $(subst ${BUILD}/,,$@)\n"
775 ${Q}rm -f $@
776 @printf " AR $(subst ${BUILD}/,,$@)\n"
777 ${Q}ar qc $@ $^
778
779# ----------------------------------------------------------------------------
780# And this thing.
781
782.PHONY: libcgpt_cc
783libcgpt_cc: ${AU_CGPTLIB}
784
785${AU_CGPTLIB}: INCLUDES += -Ifirmware/lib/cgptlib/include
786${AU_CGPTLIB}: ${AU_CGPTLIB_OBJS}
787 @printf " RM $(subst ${BUILD}/,,$@)\n"
788 ${Q}rm -f $@
789 @printf " AR $(subst ${BUILD}/,,$@)\n"
790 ${Q}ar qc $@ $^
791
792# ----------------------------------------------------------------------------
793# Tests
794
795.PHONY: tests
796tests: ${TEST_BINS}
797
798${TEST_BINS}: ${TESTLIB}
799
800${TESTLIB}: ${TESTLIB_OBJS}
801 @printf " RM $(subst ${BUILD}/,,$@)\n"
802 ${Q}rm -f $@
803 @printf " AR $(subst ${BUILD}/,,$@)\n"
804 ${Q}ar qc $@ $^
805
806
807# ----------------------------------------------------------------------------
808# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
809# rules for specific targets.
810
811${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
812 @printf " LD $(subst ${BUILD}/,,$@)\n"
813 ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS}
814
815${BUILD}/%.o: %.c
816 @printf " CC $(subst ${BUILD}/,,$@)\n"
817 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
818
819# Rules to recompile a single source file for library and test
820# TODO: is there a tidier way to do this?
821${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
822${BUILD}/%_for_lib.o: %.c
823 @printf " CC-for-lib $(subst ${BUILD}/,,$@)\n"
824 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
825
826${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
827${BUILD}/%_for_test.o: %.c
828 @printf " CC-for-test $(subst ${BUILD}/,,$@)\n"
829 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
830
831# TODO: C++ files don't belong in vboot reference at all. Convert to C.
832${BUILD}/%.o: %.cc
833 @printf " CXX $(subst ${BUILD}/,,$@)\n"
834 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
835
836# ----------------------------------------------------------------------------
837# Here are the special tweaks to the generic rules.
838
839# Linktest ensures firmware lib doesn't rely on outside libraries
840${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
841
842# Specific dependency here.
843${BUILD}/utility/dump_kernel_config: LIBS += ${DUMPKERNELCONFIGLIB}
844${BUILD}/utility/dump_kernel_config: ${DUMPKERNELCONFIGLIB}
845
846# GBB utility needs C++ linker. TODO: It shouldn't.
847${BUILD}/utility/gbb_utility: LD = ${CXX}
848
849# Some utilities need external crypto functions
850${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
851${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
852${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
853${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800854${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
855${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
856${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
857${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
858
859${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
860${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
861${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800862
863${BUILD}/utility/bmpblk_utility: LD = ${CXX}
864${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
865
866BMPBLK_UTILITY_DEPS = \
867 ${BUILD}/utility/bmpblk_util.o \
868 ${BUILD}/utility/image_types.o \
869 ${BUILD}/utility/eficompress_for_lib.o \
870 ${BUILD}/utility/efidecompress_for_lib.o
871${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
872${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
873
874${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
875${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
876
877# Allow multiple definitions, so tests can mock functions from other libraries
878${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
879${BUILD}/tests/%: INCLUDES += -Ihost/include
880${BUILD}/tests/%: LDLIBS += -lrt -luuid
881${BUILD}/tests/%: LIBS += ${TESTLIB}
882
883${BUILD}/tests/rollback_index2_tests: OBJS += \
884 ${BUILD}/firmware/lib/rollback_index_for_test.o
885${BUILD}/tests/rollback_index2_tests: \
886 ${BUILD}/firmware/lib/rollback_index_for_test.o
887
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800888${BUILD}/tests/tlcl_tests: OBJS += \
889 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
890${BUILD}/tests/tlcl_tests: \
891 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
892
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800893${BUILD}/tests/vboot_audio_tests: OBJS += \
894 ${BUILD}/firmware/lib/vboot_audio_for_test.o
895${BUILD}/tests/vboot_audio_tests: \
896 ${BUILD}/firmware/lib/vboot_audio_for_test.o
897
898.PHONY: cgptmanager_tests
899cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
900
901${BUILD}/tests/CgptManagerTests: CFLAGS += ${PC_CFLAGS}
902${BUILD}/tests/CgptManagerTests: LD = ${CXX}
903${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags ${PC_LDLIBS}
904${BUILD}/tests/CgptManagerTests: LIBS = ${AU_CGPTLIB}
905${BUILD}/tests/CgptManagerTests: ${AU_CGPTLIB}
906
907${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
908${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
909
910${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
911${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
912
913##############################################################################
914# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800915
916# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800917.PHONY: test_targets
918test_targets:: runcgpttests runmisctests
Randall Spangler844bce52013-01-15 16:16:43 -0800919
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800920ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -0800921# Bitmap utility isn't compiled for minimal variant
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800922test_targets:: runbmptests
Randall Spangler844bce52013-01-15 16:16:43 -0800923# Scripts don't work under qemu testing
924# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800925test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -0800926endif
927
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800928.PHONY: test_setup
929test_setup:: cgpt utils futil tests
930
Randall Spangler844bce52013-01-15 16:16:43 -0800931# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
932# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800933ifneq (${QEMU_ARCH},)
934test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -0800935
936.PHONY: qemu_install
937qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800938ifeq (${SYSROOT},)
939 $(error SYSROOT must be set to the top of the target-specific root \
940when cross-compiling for qemu-based tests to run properly.)
941endif
Randall Spangler844bce52013-01-15 16:16:43 -0800942 @printf " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800943 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
944 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -0800945endif
946
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800947.PHONY: runtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800948runtests: test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800949
950# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800951.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -0800952genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800953 tests/gen_test_keys.sh
954
955# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800956.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -0800957genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800958 tests/gen_fuzz_test_cases.sh
959
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800960.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800961runbmptests: test_setup
962 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800963 ./TestBmpBlock.py -v
964
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800965.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800966runcgpttests: test_setup
967 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
968# HEY - elsewhere
969ifneq (${IN_CHROOT},)
970 ${RUNTEST} ${BUILD_RUN}/tests/CgptManagerTests --v=1
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800971endif
972
Randall Spangler844bce52013-01-15 16:16:43 -0800973.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800974runtestscripts: test_setup genfuzztestcases
975 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800976 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800977 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -0800978 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800979 tests/run_vbutil_tests.sh
980
Randall Spangler844bce52013-01-15 16:16:43 -0800981.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800982runmisctests: test_setup
983 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -0800984 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800985 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
986 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
987 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800988 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800989 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
990 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
991 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
992 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800993 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -0800994 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
995 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -0800996 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
997 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
998 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800999 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001000 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1001 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1002 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001003 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001004 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001005 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001006 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001007
1008.PHONY: runfutiltests
1009runfutiltests: DESTDIR := ${TEST_INSTALL_DIR}
1010runfutiltests: test_setup install
1011 @echo "$@ passed"
Randall Spangler844bce52013-01-15 16:16:43 -08001012
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001013# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001014# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001015# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001016.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001017runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001018 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1019 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001020 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001021 tests/run_vbutil_tests.sh --all
1022
1023# TODO: tests to run when ported to new API
1024# ./run_image_verification_tests.sh
1025# # Splicing tests
1026# ${BUILD}/tests/firmware_splicing_tests
1027# ${BUILD}/tests/kernel_splicing_tests
1028# # Rollback Tests
1029# ${BUILD}/tests/firmware_rollback_tests
1030# ${BUILD}/tests/kernel_rollback_tests
1031
Randall Spangler59d75082013-01-23 09:29:54 -08001032# Code coverage
1033.PHONY: coverage_init
1034coverage_init: test_setup
1035 rm -f ${COV_INFO}*
1036 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1037
1038.PHONY: coverage_html
1039coverage_html:
1040 lcov -c -d . -b . -o ${COV_INFO}.tests
1041 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1042 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1043 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1044
1045# Generate addtional coverage stats just for firmware subdir, because the
1046# per-directory stats for the whole project don't include their own subdirs.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001047 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1048 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001049 -o ${COV_INFO}.firmware
1050
1051.PHONY: coverage
1052ifeq (${COV},)
1053coverage:
1054 $(error Build coverage like this: make clean && COV=1 make)
1055else
1056coverage: coverage_init runtests coverage_html
1057endif
1058