blob: 94677791493fee1d30f5213bb4bdceaa6d13a6d8 [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)
Bill Richardsonfeb25182013-03-07 12:54:29 -080040BUILD = $(SRCDIR)/build
Randall Spangler844bce52013-01-15 16:16:43 -080041export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080042
Bill Richardsonc9bf3482013-02-13 14:38:29 -080043# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080044INSTALL = install
45DESTDIR = /usr/local/bin
46OLDDIR = old_bins
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsonfeb25182013-03-07 12:54:29 -080048# Where exactly do the pieces go?
49# FT_DIR = futility target directory - where it will be on the target
50# F_DIR = futility install directory - where it gets put right now
51# UB_DIR = userspace binary directory for futility's exec() targets
52# VB_DIR = target vboot directory - for dev-mode-only helpers, keys, etc.
Bill Richardsonc9bf3482013-02-13 14:38:29 -080053ifeq (${MINIMAL},)
54# Host install just puts everything in one place
Bill Richardsonfeb25182013-03-07 12:54:29 -080055FT_DIR=${DESTDIR}
56F_DIR=${DESTDIR}
57UB_DIR=${DESTDIR}/${OLDDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080058else
59# Target install puts things into DESTDIR subdirectories
Bill Richardsonfeb25182013-03-07 12:54:29 -080060FT_DIR=/usr/bin
61F_DIR=${DESTDIR}${FT_DIR}
62UB_DIR=${F_DIR}/${OLDDIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -080063VB_DIR=${DESTDIR}/usr/share/vboot/bin
64endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080065
Bill Richardsoneecc18f2013-01-17 15:28:17 -080066# Where to install the (exportable) executables for testing?
67TEST_INSTALL_DIR = ${BUILD}/install_for_test
68
69# Verbose? Use V=1
70ifeq (${V},)
71Q := @
72endif
73
Simon Glass661ae9e2013-03-26 11:39:21 -070074# Quiet? Use QUIET=1
75ifeq ($(QUIET),)
76PRINTF := printf
77else
78PRINTF := :
79endif
80
Randall Spangler61a2eb32013-01-23 10:20:16 -080081# Architecture detection
82_machname := $(shell uname -m)
83HOST_ARCH ?= ${_machname}
84
85# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
86# Pick a sane target architecture if none is defined.
87ifeq (${ARCH},)
88 ARCH := ${HOST_ARCH}
89else ifeq (${ARCH},i386)
90 override ARCH := x86
91else ifeq (${ARCH},amd64)
92 override ARCH := x86_64
93endif
94
95# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
96# for a firmware target (such as u-boot or depthcharge). It must map
97# to the same consistent set of architectures as the host.
98ifeq (${FIRMWARE_ARCH},i386)
99 override FIRMWARE_ARCH := x86
100else ifeq (${FIRMWARE_ARCH},amd64)
101 override FIRMWARE_ARCH := x86_64
102endif
103
Simon Glassb265c342011-11-16 15:09:51 -0800104# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
105# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700106#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800107# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
108# temporarily. As we are still investigating which flags are necessary for
109# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700110#
Simon Glassb265c342011-11-16 15:09:51 -0800111# As a first step, this makes the setting of CC and CFLAGS here optional, to
112# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700113#
Simon Glassb265c342011-11-16 15:09:51 -0800114# Flag ordering: arch, then -f, then -m, then -W
115DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
116COMMON_FLAGS := -nostdinc -pipe \
117 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800118 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800119
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800120# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
121ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800122CC ?= armv7a-cros-linux-gnueabi-gcc
123CFLAGS ?= -march=armv5 \
124 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700125 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800126 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800127else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800128CC ?= i686-pc-linux-gnu-gcc
129# Drop -march=i386 to permit use of SSE instructions
130CFLAGS ?= \
131 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
132 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
133 -mpreferred-stack-boundary=2 -mregparm=3 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800134 ${COMMON_FLAGS}
135else ifeq (${FIRMWARE_ARCH}, x86_64)
136CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800137 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800138else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800139# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800140CC ?= gcc
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800141CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800142endif
143
Bill Richardsonfeb25182013-03-07 12:54:29 -0800144ifneq (${OLDDIR},)
145CFLAGS += -DOLDDIR=${OLDDIR}
146endif
147
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800148ifneq (${DEBUG},)
149CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700150endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800151
vbendebb2b0fcc2010-07-15 15:09:47 -0700152ifeq (${DISABLE_NDEBUG},)
153CFLAGS += -DNDEBUG
154endif
155
Bill Richardsonfeb25182013-03-07 12:54:29 -0800156ifneq (${FORCE_LOGGING_ON},)
157CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
158endif
159
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800160# Create / use dependency files
161CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800162
Randall Spangler59d75082013-01-23 09:29:54 -0800163# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800164ifneq (${COV},)
Randall Spangler59d75082013-01-23 09:29:54 -0800165 COV_FLAGS = -O0 --coverage
166 CFLAGS += ${COV_FLAGS}
167 LDFLAGS += ${COV_FLAGS}
168 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800169endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800170
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800171# And a few more default utilities
172LD = ${CC}
173CXX ?= g++ # HEY: really?
174PKG_CONFIG ?= pkg-config
175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# Determine QEMU architecture needed, if any
177ifeq (${ARCH},${HOST_ARCH})
178 # Same architecture; no need for QEMU
179 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800180else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181 # 64-bit host can run 32-bit targets directly
182 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800183else
184 QEMU_ARCH := ${ARCH}
185endif
186
187# The top of the chroot for qemu must be passed in via the SYSROOT environment
188# variable. In the Chromium OS chroot, this is done automatically by the
189# ebuild.
190
191ifeq (${QEMU_ARCH},)
192 # Path to build output for running tests is same as for building
193 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800194 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800195else
196 $(info Using qemu for testing.)
197 # Path to build output for running tests is different in the chroot
198 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200
201 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800202 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
203 export QEMU_RUN
204
205 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800206endif
207
Randall Spanglere061a252013-01-22 15:34:07 -0800208export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800209
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800210##############################################################################
211# Now we need to describe everything we might want or need to build
212
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800213# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800214INCLUDES += \
215 -Ifirmware/include \
216 -Ifirmware/lib/include \
217 -Ifirmware/lib/cgptlib/include \
218 -Ifirmware/lib/cryptolib/include \
219 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700220
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800221# If we're not building for a specific target, just stub out things like the
222# TPM commands and various external functions that are provided by the BIOS.
223ifeq (${FIRMWARE_ARCH},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800224INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800225else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800226INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800227endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800228
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800229# Firmware library. TODO: Do we still need to export this?
230FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800231
Randall Spangler93943262013-02-26 11:03:57 -0800232# Firmware library sources needed by VbInit() call
233VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800234 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800235 firmware/lib/utility.c \
236 firmware/lib/vboot_api_init.c \
237 firmware/lib/vboot_common_init.c \
238 firmware/lib/vboot_nvstorage.c \
239
240# Additional firmware library sources needed by VbSelectFirmware() call
241VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800242 firmware/lib/cryptolib/padding.c \
243 firmware/lib/cryptolib/rsa.c \
244 firmware/lib/cryptolib/rsa_utility.c \
245 firmware/lib/cryptolib/sha1.c \
246 firmware/lib/cryptolib/sha256.c \
247 firmware/lib/cryptolib/sha512.c \
248 firmware/lib/cryptolib/sha_utility.c \
249 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800250 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800251 firmware/lib/vboot_common.c \
252 firmware/lib/vboot_firmware.c
253
254# Additional firmware library sources needed by VbSelectAndLoadKernel() call
255VBSLK_SRCS = \
256 firmware/lib/cgptlib/cgptlib.c \
257 firmware/lib/cgptlib/cgptlib_internal.c \
258 firmware/lib/cgptlib/crc32.c \
259 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800260 firmware/lib/vboot_api_kernel.c \
261 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800262 firmware/lib/vboot_display.c \
Randall Spangler93943262013-02-26 11:03:57 -0800263 firmware/lib/vboot_kernel.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800264
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800265# Support real TPM unless BIOS sets MOCK_TPM
266ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800267VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800268 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800269 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800270
271VBSF_SRCS += \
272 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800273else
Randall Spangler93943262013-02-26 11:03:57 -0800274VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800275 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800277
278VBSF_SRCS += \
279 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800280endif
281
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800282ifeq (${FIRMWARE_ARCH},)
283# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800284# TODO: split out other stub funcs too
285VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800286 firmware/stub/tpm_lite_stub.c \
287 firmware/stub/utility_stub.c \
Randall Spangler93943262013-02-26 11:03:57 -0800288 firmware/stub/vboot_api_stub_init.c
289
290VBSF_SRCS += \
291 firmware/stub/vboot_api_stub_sf.c
292
293VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800294 firmware/stub/vboot_api_stub.c \
295 firmware/stub/vboot_api_stub_disk.c
296endif
297
Randall Spangler93943262013-02-26 11:03:57 -0800298VBSF_SRCS += ${VBINIT_SRCS}
299FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
300
301VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
302VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
303
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800304FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800305ALL_OBJS += ${FWLIB_OBJS}
306
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800307
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800308# Library to build the utilities. "HOST" mostly means "userspace".
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800309HOSTLIB = ${BUILD}/libvboot_host.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800310
311HOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800312 cgpt/cgpt_create.c \
313 cgpt/cgpt_add.c \
314 cgpt/cgpt_boot.c \
315 cgpt/cgpt_show.c \
316 cgpt/cgpt_repair.c \
317 cgpt/cgpt_prioritize.c \
318 cgpt/cgpt_common.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800319 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800320 host/lib/crossystem.c \
321 host/lib/file_keys.c \
322 host/lib/fmap.c \
323 host/lib/host_common.c \
324 host/lib/host_key.c \
325 host/lib/host_keyblock.c \
326 host/lib/host_misc.c \
327 host/lib/host_signature.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800328 host/lib/signature_digest.c \
329 utility/dump_kernel_config_lib.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800330
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800331HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800332ALL_OBJS += ${HOSTLIB_OBJS}
333
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800334# Link with hostlib by default
335LIBS = $(HOSTLIB)
336
337# Might need this too.
338CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
339
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800340# Sigh. For historical reasons, the autoupdate installer must sometimes be a
341# 32-bit executable, even when everything else is 64-bit. But it only needs a
342# few functions, so let's just build those.
343TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
344
345TINYHOSTLIB_SRCS = \
346 cgpt/cgpt_create.c \
347 cgpt/cgpt_add.c \
348 cgpt/cgpt_boot.c \
349 cgpt/cgpt_show.c \
350 cgpt/cgpt_repair.c \
351 cgpt/cgpt_prioritize.c \
352 cgpt/cgpt_common.c \
353 utility/dump_kernel_config_lib.c \
354 firmware/lib/cgptlib/crc32.c \
355 firmware/lib/cgptlib/cgptlib_internal.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800356 firmware/lib/utility_string.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800357 firmware/stub/utility_stub.c
358
359TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800360
361# ----------------------------------------------------------------------------
362# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800363
364CGPT = ${BUILD}/cgpt/cgpt
365
366CGPT_SRCS = \
367 cgpt/cgpt.c \
368 cgpt/cgpt_add.c \
369 cgpt/cgpt_boot.c \
370 cgpt/cgpt_common.c \
371 cgpt/cgpt_create.c \
372 cgpt/cgpt_find.c \
373 cgpt/cgpt_legacy.c \
374 cgpt/cgpt_prioritize.c \
375 cgpt/cgpt_repair.c \
376 cgpt/cgpt_show.c \
377 cgpt/cmd_add.c \
378 cgpt/cmd_boot.c \
379 cgpt/cmd_create.c \
380 cgpt/cmd_find.c \
381 cgpt/cmd_legacy.c \
382 cgpt/cmd_prioritize.c \
383 cgpt/cmd_repair.c \
384 cgpt/cmd_show.c
385
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800386CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800387ALL_OBJS += ${CGPT_OBJS}
388
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800389
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800390# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800391UTIL_SCRIPTS = \
392 utility/dev_debug_vboot \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800393 utility/enable_dev_usb_boot \
394 utility/vbutil_what_keys
395
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800396ifeq (${MINIMAL},)
397UTIL_SCRIPTS += \
398 utility/dev_make_keypair
399endif
400
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800401# These utilities should be linked statically.
402UTIL_NAMES_STATIC = \
403 crossystem \
404 dump_fmap \
405 gbb_utility
406
407UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800408 dev_sign_file \
409 dump_kernel_config \
410 dumpRSAPublicKey \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800411 tpm_init_temp_fix \
412 tpmc \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800413 vbutil_firmware \
414 vbutil_kernel \
415 vbutil_key \
416 vbutil_keyblock \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800417
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800418ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800419UTIL_NAMES += \
420 bmpblk_font \
421 bmpblk_utility \
422 eficompress \
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800423 efidecompress \
424 load_kernel_test \
425 pad_digest_utility \
426 signature_digest_utility \
427 verify_data
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800428endif
429
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800430UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC})
431UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800432ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
433
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800434
435# Scripts for signing stuff.
436SIGNING_SCRIPTS = \
437 utility/tpm-nvsize \
438 utility/chromeos-tpm-recovery
439
440# These go in a different place.
441SIGNING_SCRIPTS_DEV = \
442 scripts/image_signing/resign_firmwarefd.sh \
443 scripts/image_signing/make_dev_firmware.sh \
444 scripts/image_signing/make_dev_ssd.sh \
445 scripts/image_signing/set_gbb_flags.sh
446
447# Installed, but not made executable.
448SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800449
Bill Richardson826db092013-01-14 12:37:15 -0800450
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800451# The unified firmware utility will eventually replace all the others
452FUTIL_BIN = ${BUILD}/futility/futility
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800453
Bill Richardsonfeb25182013-03-07 12:54:29 -0800454# These are the others it will replace.
455FUTIL_OLD = $(notdir ${CGPT} ${UTIL_BINS} ${UTIL_SCRIPTS} \
456 ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV})
457
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800458FUTIL_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800459 futility/futility.c \
460 futility/cmd_foo.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800461
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800462FUTIL_LDS = futility/futility.lds
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800463
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800464FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800465
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800466ALL_DEPS += $(addsuffix .d,${FUTIL_BIN})
467ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800468
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800469
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800470# Library of handy test functions.
471TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800472
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800473TESTLIB_SRCS = \
474 tests/test_common.c \
475 tests/timer_utils.c \
476 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800477
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800478TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
479ALL_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800480
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800481
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800482# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800483TEST_NAMES = \
484 cgptlib_test \
485 rollback_index2_tests \
Randall Spanglera3eac792013-01-23 13:04:05 -0800486 rollback_index3_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800487 rsa_padding_test \
488 rsa_utility_tests \
489 rsa_verify_benchmark \
490 sha_benchmark \
491 sha_tests \
492 stateful_util_tests \
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800493 tlcl_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800494 tpm_bootmode_tests \
495 utility_string_tests \
496 utility_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800497 vboot_api_init_tests \
498 vboot_api_devmode_tests \
499 vboot_api_firmware_tests \
500 vboot_api_kernel_tests \
Randall Spangler7f436692013-02-05 12:42:36 -0800501 vboot_api_kernel2_tests \
502 vboot_api_kernel3_tests \
503 vboot_api_kernel4_tests \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800504 vboot_audio_tests \
505 vboot_common_tests \
506 vboot_common2_tests \
507 vboot_common3_tests \
Randall Spangler786a5dc2013-01-24 14:19:56 -0800508 vboot_display_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800509 vboot_firmware_tests \
Randall Spangler49cb0d32013-01-29 14:28:16 -0800510 vboot_kernel_tests \
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800511 vboot_nvstorage_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800512
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800513# TODO: port these tests to new API, if not already eqivalent
514# functionality in other tests. These don't even compile at present.
515#
516# big_firmware_tests
517# big_kernel_tests
518# firmware_image_tests
519# firmware_rollback_tests
520# firmware_splicing_tests
521# firmware_verify_benchmark
522# kernel_image_tests
523# kernel_rollback_tests
524# kernel_splicing_tests
525# kernel_verify_benchmark
526# rollback_index_test
527# verify_firmware_fuzz_driver
528# verify_kernel_fuzz_driver
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800529# utility/load_firmware_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800530
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800531# And a few more...
532TLCL_TESTS = \
533 tpmtest_earlyextend \
534 tpmtest_earlynvram \
535 tpmtest_earlynvram2 \
536 tpmtest_enable \
537 tpmtest_fastenable \
538 tpmtest_globallock \
539 tpmtest_redefine_unowned \
540 tpmtest_spaceperm \
541 tpmtest_testsetup \
542 tpmtest_timing \
543 tpmtest_writelimit
544TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS})
545TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES})
546
547TEST_NAMES += ${TLCL_TEST_NAMES}
548
549TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES})
550ALL_DEPS += $(addsuffix .d,${TEST_BINS})
551
Randall Spanglere061a252013-01-22 15:34:07 -0800552# Directory containing test keys
553TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800554
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800555
556##############################################################################
557# Finally, some targets. High-level ones first.
558
559# Create output directories if necessary. Do this via explicit shell commands
560# so it happens before trying to generate/include dependencies.
561SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
562_dir_create := $(foreach d, \
563 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
564 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
565
566
567# Default target.
568.PHONY: all
Randall Spangler59d75082013-01-23 09:29:54 -0800569all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800570
571# Host targets
572.PHONY: host_stuff
573host_stuff: hostlib cgpt utils futil tests
574
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800575.PHONY: clean
576clean:
577 ${Q}/bin/rm -rf ${BUILD}
578
579.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800580install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800581
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800582# Don't delete intermediate object files
583.SECONDARY:
584
585# TODO: I suspect this is missing some object files. Make a temp
586# target which cleans all known obj/exe's and see what's left; those
587# are the files which need deps.
588ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
589-include ${ALL_DEPS}
590
591# ----------------------------------------------------------------------------
592# Firmware library
593
594# TPM-specific flags. These depend on the particular TPM we're targeting for.
595# They are needed here only for compiling parts of the firmware code into
596# user-level tests.
597
598# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
599# the self test has completed.
600
Randall Spangler45cc0f22013-01-25 09:34:26 -0800601${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800602
603# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
604# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
605# power on.
606#
607# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
608# are not both defined at the same time. (See comment in code.)
609
610# CFLAGS += -DTPM_MANUAL_SELFTEST
611
612ifeq (${FIRMWARE_ARCH},i386)
613# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800614${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800615
616# Workaround for coreboot on x86, which will power off asynchronously
617# without giving us a chance to react. This is not an example of the Right
618# Way to do things. See chrome-os-partner:7689, and the commit message
619# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800620${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800621
622# On x86 we don't actually read the GBB data into RAM until it is needed.
623# Therefore it makes sense to cache it rather than reading it each time.
624# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800625${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800626endif
627
628ifeq (${FIRMWARE_ARCH},)
629# Disable rollback TPM when compiling locally, since otherwise
630# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800631${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800632endif
633
Randall Spangler93943262013-02-26 11:03:57 -0800634# Link tests
635${BUILD}/firmware/linktest/main_vbinit: LIBS =
636${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
637${BUILD}/firmware/linktest/main_vbsf: LIBS =
638${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
639
640.phony: fwlinktest
641fwlinktest: ${FWLIB} \
642 ${BUILD}/firmware/linktest/main_vbinit \
643 ${BUILD}/firmware/linktest/main_vbsf \
644 ${BUILD}/firmware/linktest/main
645
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800646.PHONY: fwlib
Randall Spangler93943262013-02-26 11:03:57 -0800647fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800648
649${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700650 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800651 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700652 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800653 ${Q}ar qc $@ $^
654
655# ----------------------------------------------------------------------------
656# Host library
657
658.PHONY: hostlib
659hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main
660
661${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
662 -Ihost/include\
663 -Ihost/arch/${ARCH}/include
664
665# TODO: better way to make .a than duplicating this recipe each time?
666${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700667 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800668 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700669 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800670 ${Q}ar qc $@ $^
671
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800672
673# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
674.PHONY: tinyhostlib
675tinyhostlib: ${TINYHOSTLIB}
676 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
677
678${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700679 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800680 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700681 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800682 ${Q}ar qc $@ $^
683
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800684# ----------------------------------------------------------------------------
685# CGPT library and utility
686
687.PHONY: cgpt
688cgpt: ${CGPT}
689
690${CGPT}: LDFLAGS += -static
691${CGPT}: LDLIBS += -luuid
692
693${CGPT}: ${CGPT_OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700694 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800695 ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
696
697.PHONY: cgpt_install
698cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700699 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800700 ${Q}mkdir -p ${UB_DIR}
701 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800702
703# ----------------------------------------------------------------------------
704# Utilities
705
706# These have their own headers too.
707${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
708
709# Utilities for auto-update toolkits must be statically linked.
710${UTIL_BINS_STATIC}: LDFLAGS += -static
711
712.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800713utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800714 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
715 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
716
717.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800718utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700719 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800720 ${Q}mkdir -p ${UB_DIR}
721 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800722
723# And some signing stuff for the target
724.PHONY: signing_install
725signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700726 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800727 ${Q}mkdir -p ${UB_DIR}
728 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800729 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS_DEV}
730 ${Q}${INSTALL} -t ${UB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
731ifneq (${VB_DIR},)
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800732 ${Q}mkdir -p ${VB_DIR}
Bill Richardsonfeb25182013-03-07 12:54:29 -0800733 ${Q}for prog in $(notdir ${SIGNING_SCRIPTS_DEV}); do \
734 ln -sf "${FT_DIR}/futility" "${VB_DIR}/$$prog"; done
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800735endif
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800736
737# ----------------------------------------------------------------------------
738# new Firmware Utility
739
740.PHONY: futil
741futil: ${FUTIL_BIN}
742
743${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700744 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800745 ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
746
747.PHONY: futil_install
748futil_install: ${FUTIL_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700749 @$(PRINTF) " INSTALL futility\n"
Bill Richardsonfeb25182013-03-07 12:54:29 -0800750 ${Q}mkdir -p ${F_DIR}
751 ${Q}${INSTALL} -t ${F_DIR} ${FUTIL_BIN}
752 ${Q}for prog in ${FUTIL_OLD}; do \
753 ln -sf futility "${F_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800754
755# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800756# Utility to generate TLCL structure definition header file.
757
758${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
759
760STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
761STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
762
763.PHONY: update_tlcl_structures
764update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700765 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800766 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
767 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
768 ( echo "%% Updating structures.h %%" && \
769 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
770
771# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800772# Tests
773
774.PHONY: tests
775tests: ${TEST_BINS}
776
777${TEST_BINS}: ${TESTLIB}
778
779${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700780 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800781 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700782 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800783 ${Q}ar qc $@ $^
784
785
786# ----------------------------------------------------------------------------
787# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
788# rules for specific targets.
789
790${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700791 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800792 ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS}
793
794${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700795 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800796 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
797
798# Rules to recompile a single source file for library and test
799# TODO: is there a tidier way to do this?
800${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
801${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700802 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800803 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
804
805${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
806${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700807 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800808 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
809
810# TODO: C++ files don't belong in vboot reference at all. Convert to C.
811${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700812 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800813 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
814
815# ----------------------------------------------------------------------------
816# Here are the special tweaks to the generic rules.
817
818# Linktest ensures firmware lib doesn't rely on outside libraries
819${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
820
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800821# GBB utility needs C++ linker. TODO: It shouldn't.
822${BUILD}/utility/gbb_utility: LD = ${CXX}
823
Bill Richardsonfeb25182013-03-07 12:54:29 -0800824# Because we play some clever linker script games to add new commands without
825# changing any header files, futility must be linked with ld.bfd, not gold.
826${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
827
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800828# Some utilities need external crypto functions
829${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
830${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
831${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
832${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800833${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
834${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
835${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
836${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
837
838${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
839${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
840${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800841
842${BUILD}/utility/bmpblk_utility: LD = ${CXX}
843${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
844
845BMPBLK_UTILITY_DEPS = \
846 ${BUILD}/utility/bmpblk_util.o \
847 ${BUILD}/utility/image_types.o \
848 ${BUILD}/utility/eficompress_for_lib.o \
849 ${BUILD}/utility/efidecompress_for_lib.o
850${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
851${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
852
853${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
854${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
855
856# Allow multiple definitions, so tests can mock functions from other libraries
857${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
858${BUILD}/tests/%: INCLUDES += -Ihost/include
859${BUILD}/tests/%: LDLIBS += -lrt -luuid
860${BUILD}/tests/%: LIBS += ${TESTLIB}
861
862${BUILD}/tests/rollback_index2_tests: OBJS += \
863 ${BUILD}/firmware/lib/rollback_index_for_test.o
864${BUILD}/tests/rollback_index2_tests: \
865 ${BUILD}/firmware/lib/rollback_index_for_test.o
866
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800867${BUILD}/tests/tlcl_tests: OBJS += \
868 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
869${BUILD}/tests/tlcl_tests: \
870 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
871
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800872${BUILD}/tests/vboot_audio_tests: OBJS += \
873 ${BUILD}/firmware/lib/vboot_audio_for_test.o
874${BUILD}/tests/vboot_audio_tests: \
875 ${BUILD}/firmware/lib/vboot_audio_for_test.o
876
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800877${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
878${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
879
880${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
881${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
882
883##############################################################################
884# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800885
886# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800887.PHONY: test_targets
888test_targets:: runcgpttests runmisctests
Randall Spangler844bce52013-01-15 16:16:43 -0800889
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800890ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -0800891# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -0800892test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -0800893# Scripts don't work under qemu testing
894# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800895test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -0800896endif
897
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800898.PHONY: test_setup
899test_setup:: cgpt utils futil tests
900
Randall Spangler844bce52013-01-15 16:16:43 -0800901# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
902# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800903ifneq (${QEMU_ARCH},)
904test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -0800905
906.PHONY: qemu_install
907qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800908ifeq (${SYSROOT},)
909 $(error SYSROOT must be set to the top of the target-specific root \
910when cross-compiling for qemu-based tests to run properly.)
911endif
Simon Glass661ae9e2013-03-26 11:39:21 -0700912 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800913 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
914 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -0800915endif
916
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800917.PHONY: runtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800918runtests: test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800919
920# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800921.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -0800922genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800923 tests/gen_test_keys.sh
924
925# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800926.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -0800927genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800928 tests/gen_fuzz_test_cases.sh
929
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800930.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800931runbmptests: test_setup
932 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800933 ./TestBmpBlock.py -v
934
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800935.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800936runcgpttests: test_setup
937 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800938
Randall Spangler844bce52013-01-15 16:16:43 -0800939.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800940runtestscripts: test_setup genfuzztestcases
941 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800942 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800943 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -0800944 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800945 tests/run_vbutil_tests.sh
946
Randall Spangler844bce52013-01-15 16:16:43 -0800947.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800948runmisctests: test_setup
949 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -0800950 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800951 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
952 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
953 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -0800954 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800955 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
956 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
957 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
958 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800959 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -0800960 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
961 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -0800962 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
963 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
964 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800965 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -0800966 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
967 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
968 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -0800969 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800970 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -0800971 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -0800972 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800973
974.PHONY: runfutiltests
Bill Richardsonfeb25182013-03-07 12:54:29 -0800975runfutiltests: override DESTDIR = ${TEST_INSTALL_DIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800976runfutiltests: test_setup install
Bill Richardsonfeb25182013-03-07 12:54:29 -0800977 futility/tests/run_futility_tests.sh ${DESTDIR}
Randall Spangler844bce52013-01-15 16:16:43 -0800978
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800979# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -0800980# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800981# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800982.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800983runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -0800984 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
985 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800986 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800987 tests/run_vbutil_tests.sh --all
988
989# TODO: tests to run when ported to new API
990# ./run_image_verification_tests.sh
991# # Splicing tests
992# ${BUILD}/tests/firmware_splicing_tests
993# ${BUILD}/tests/kernel_splicing_tests
994# # Rollback Tests
995# ${BUILD}/tests/firmware_rollback_tests
996# ${BUILD}/tests/kernel_rollback_tests
997
Randall Spangler59d75082013-01-23 09:29:54 -0800998# Code coverage
999.PHONY: coverage_init
1000coverage_init: test_setup
1001 rm -f ${COV_INFO}*
1002 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1003
1004.PHONY: coverage_html
1005coverage_html:
1006 lcov -c -d . -b . -o ${COV_INFO}.tests
1007 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1008 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1009 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1010
1011# Generate addtional coverage stats just for firmware subdir, because the
1012# per-directory stats for the whole project don't include their own subdirs.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001013 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1014 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001015 -o ${COV_INFO}.firmware
1016
1017.PHONY: coverage
1018ifeq (${COV},)
1019coverage:
1020 $(error Build coverage like this: make clean && COV=1 make)
1021else
1022coverage: coverage_init runtests coverage_html
1023endif