blob: e18679f526a5122abd1e1f66be6df1a320809279 [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill Richardson64ddad72014-08-29 23:49:23 -070040export SRCDIR
Bill Richardsonfeb25182013-03-07 12:54:29 -080041BUILD = $(SRCDIR)/build
Randall Spangler844bce52013-01-15 16:16:43 -080042export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080043
Bill Richardsonc9bf3482013-02-13 14:38:29 -080044# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080045INSTALL = install
Bill Richardsonefa87562014-09-11 10:41:51 -070046DESTDIR = /usr/local
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsonfeb25182013-03-07 12:54:29 -080048# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070049# UB_DIR = utility binary directory
50# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080051ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070052# Host install just puts everything where it's told
Bill Richardsonefa87562014-09-11 10:41:51 -070053UB_DIR=${DESTDIR}/bin
54VB_DIR=${DESTDIR}/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080055else
Bill Richardsonefa87562014-09-11 10:41:51 -070056# Target install puts things into different places
Bill Richardson6f396152014-07-15 12:52:19 -070057UB_DIR=${DESTDIR}/usr/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080058VB_DIR=${DESTDIR}/usr/share/vboot/bin
59endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080060
Bill Richardsoneecc18f2013-01-17 15:28:17 -080061# Where to install the (exportable) executables for testing?
62TEST_INSTALL_DIR = ${BUILD}/install_for_test
63
64# Verbose? Use V=1
65ifeq (${V},)
66Q := @
67endif
68
Simon Glass661ae9e2013-03-26 11:39:21 -070069# Quiet? Use QUIET=1
70ifeq ($(QUIET),)
71PRINTF := printf
72else
73PRINTF := :
74endif
75
Randall Spangler61a2eb32013-01-23 10:20:16 -080076# Architecture detection
77_machname := $(shell uname -m)
78HOST_ARCH ?= ${_machname}
79
80# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
81# Pick a sane target architecture if none is defined.
82ifeq (${ARCH},)
83 ARCH := ${HOST_ARCH}
84else ifeq (${ARCH},i386)
85 override ARCH := x86
86else ifeq (${ARCH},amd64)
87 override ARCH := x86_64
88endif
89
90# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
91# for a firmware target (such as u-boot or depthcharge). It must map
92# to the same consistent set of architectures as the host.
93ifeq (${FIRMWARE_ARCH},i386)
94 override FIRMWARE_ARCH := x86
95else ifeq (${FIRMWARE_ARCH},amd64)
96 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -070097else ifeq (${FIRMWARE_ARCH},armv7)
98 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -080099endif
100
Simon Glassb265c342011-11-16 15:09:51 -0800101# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
102# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700103#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800104# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
105# temporarily. As we are still investigating which flags are necessary for
106# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700107#
Simon Glassb265c342011-11-16 15:09:51 -0800108# As a first step, this makes the setting of CC and CFLAGS here optional, to
109# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700110#
Simon Glassb265c342011-11-16 15:09:51 -0800111# Flag ordering: arch, then -f, then -m, then -W
112DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
113COMMON_FLAGS := -nostdinc -pipe \
114 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800115 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800116
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800117# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
118ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800119CC ?= armv7a-cros-linux-gnueabi-gcc
120CFLAGS ?= -march=armv5 \
121 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700122 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800123 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800124else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800125CC ?= i686-pc-linux-gnu-gcc
126# Drop -march=i386 to permit use of SSE instructions
127CFLAGS ?= \
128 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
129 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800130 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800131 ${COMMON_FLAGS}
132else ifeq (${FIRMWARE_ARCH}, x86_64)
133CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800134 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800135else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800136# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800137CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700138CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800139endif
140
141ifneq (${DEBUG},)
142CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700143endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800144
vbendebb2b0fcc2010-07-15 15:09:47 -0700145ifeq (${DISABLE_NDEBUG},)
146CFLAGS += -DNDEBUG
147endif
148
Bill Richardsonfeb25182013-03-07 12:54:29 -0800149ifneq (${FORCE_LOGGING_ON},)
150CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
151endif
152
Randall Spangler6014c042014-07-22 14:42:58 -0700153ifneq (${PD_SYNC},)
154CFLAGS += -DPD_SYNC
155endif
156
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800157# Create / use dependency files
158CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800159
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700160ifeq (${FIRMWARE_ARCH},)
161# Creates position independent code for non firmware target.
162CFLAGS += -fPIE
163endif
164
Bill Richardson0c3ba242013-03-29 11:09:30 -0700165# These are required to access large disks and files on 32-bit systems.
166CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167
Randall Spangler59d75082013-01-23 09:29:54 -0800168# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800169ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700170 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800171 CFLAGS += ${COV_FLAGS}
172 LDFLAGS += ${COV_FLAGS}
173 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800174endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# And a few more default utilities
177LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700178CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800179PKG_CONFIG ?= pkg-config
180
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181# Determine QEMU architecture needed, if any
182ifeq (${ARCH},${HOST_ARCH})
183 # Same architecture; no need for QEMU
184 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800185else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186 # 64-bit host can run 32-bit targets directly
187 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800188else
189 QEMU_ARCH := ${ARCH}
190endif
191
192# The top of the chroot for qemu must be passed in via the SYSROOT environment
193# variable. In the Chromium OS chroot, this is done automatically by the
194# ebuild.
195
196ifeq (${QEMU_ARCH},)
197 # Path to build output for running tests is same as for building
198 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200else
201 $(info Using qemu for testing.)
202 # Path to build output for running tests is different in the chroot
203 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800204 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205
206 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800207 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
208 export QEMU_RUN
209
210 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800211endif
212
Randall Spanglere061a252013-01-22 15:34:07 -0800213export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800214
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800215##############################################################################
216# Now we need to describe everything we might want or need to build
217
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800218# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800219INCLUDES += \
220 -Ifirmware/include \
221 -Ifirmware/lib/include \
222 -Ifirmware/lib/cgptlib/include \
223 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700224 -Ifirmware/lib/tpm_lite/include \
225 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700226
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227# If we're not building for a specific target, just stub out things like the
228# TPM commands and various external functions that are provided by the BIOS.
229ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700230INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800231endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800232
Bill Richardson78299022014-06-20 14:33:00 -0700233# Firmware library, used by the other firmware components (depthcharge,
234# coreboot, etc.). It doesn't need exporting to some other place; they'll build
235# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800236FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800237
Randall Spangler786acda2014-05-22 13:27:07 -0700238# Smaller firmware library. TODO: Do we still need to export this?
239ifneq (${VBOOT2},)
240FWLIB2 = ${BUILD}/vboot_fw2.a
241endif
242
Randall Spangler93943262013-02-26 11:03:57 -0800243# Firmware library sources needed by VbInit() call
244VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800245 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800246 firmware/lib/utility.c \
247 firmware/lib/vboot_api_init.c \
248 firmware/lib/vboot_common_init.c \
249 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700250 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600251 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800252
253# Additional firmware library sources needed by VbSelectFirmware() call
254VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800255 firmware/lib/cryptolib/padding.c \
256 firmware/lib/cryptolib/rsa.c \
257 firmware/lib/cryptolib/rsa_utility.c \
258 firmware/lib/cryptolib/sha1.c \
259 firmware/lib/cryptolib/sha256.c \
260 firmware/lib/cryptolib/sha512.c \
261 firmware/lib/cryptolib/sha_utility.c \
262 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800263 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800264 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600265 firmware/lib/vboot_firmware.c \
266 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800267
268# Additional firmware library sources needed by VbSelectAndLoadKernel() call
269VBSLK_SRCS = \
270 firmware/lib/cgptlib/cgptlib.c \
271 firmware/lib/cgptlib/cgptlib_internal.c \
272 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700273 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800274 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800275 firmware/lib/vboot_api_kernel.c \
276 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800277 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600278 firmware/lib/vboot_kernel.c \
279 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800280
Randall Spangler786acda2014-05-22 13:27:07 -0700281# Firmware library source needed for smaller library 2
282FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700283 firmware/2lib/2api.c \
Randall Spanglerefa37b82014-11-12 16:20:50 -0800284 firmware/2lib/2api2.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700285 firmware/2lib/2common.c \
Randall Spangler6b5b8f62014-10-31 15:18:48 -0700286 firmware/2lib/2common2.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700287 firmware/2lib/2crc8.c \
288 firmware/2lib/2misc.c \
Randall Spangler837b4082014-11-10 13:40:52 -0800289 firmware/2lib/2misc2.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700290 firmware/2lib/2nvstorage.c \
Randall Spanglerf18038b2014-10-23 15:55:21 -0700291 firmware/2lib/2packed_key.c \
Randall Spanglerd274a2e2014-10-23 17:38:18 -0700292 firmware/2lib/2packed_key2.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700293 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700294 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700295 firmware/2lib/2sha1.c \
296 firmware/2lib/2sha256.c \
297 firmware/2lib/2sha512.c \
298 firmware/2lib/2sha_utility.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700299
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800300# Support real TPM unless BIOS sets MOCK_TPM
301ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800302VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800303 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800304 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800305
306VBSF_SRCS += \
307 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800308else
Randall Spangler93943262013-02-26 11:03:57 -0800309VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800310 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800311 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800312
313VBSF_SRCS += \
314 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800315endif
316
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800317ifeq (${FIRMWARE_ARCH},)
318# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800319# TODO: split out other stub funcs too
320VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800321 firmware/stub/tpm_lite_stub.c \
322 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600323 firmware/stub/vboot_api_stub_init.c \
324 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800325
326VBSF_SRCS += \
327 firmware/stub/vboot_api_stub_sf.c
328
329VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800330 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700331 firmware/stub/vboot_api_stub_disk.c \
332 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700333
334FWLIB2_SRCS += \
335 firmware/2lib/2stub.c
336
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800337endif
338
Randall Spangler93943262013-02-26 11:03:57 -0800339VBSF_SRCS += ${VBINIT_SRCS}
340FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
341
342VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
343VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
344
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800345FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson1912bba2013-04-04 21:08:50 -0700346
Randall Spangler786acda2014-05-22 13:27:07 -0700347ifneq (${VBOOT2},)
348FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
349endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800350
Randall Spangler786acda2014-05-22 13:27:07 -0700351ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800352
Bill Richardson78299022014-06-20 14:33:00 -0700353# Intermediate library for the vboot_reference utilities to link against.
354UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800355
Bill Richardson78299022014-06-20 14:33:00 -0700356UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800357 cgpt/cgpt_create.c \
358 cgpt/cgpt_add.c \
359 cgpt/cgpt_boot.c \
360 cgpt/cgpt_show.c \
361 cgpt/cgpt_repair.c \
362 cgpt/cgpt_prioritize.c \
363 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700364 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800365 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800366 host/lib/crossystem.c \
367 host/lib/file_keys.c \
368 host/lib/fmap.c \
369 host/lib/host_common.c \
370 host/lib/host_key.c \
371 host/lib/host_keyblock.c \
372 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700373 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800374 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700375 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800376
Randall Spangler02e11b32014-11-19 12:48:36 -0800377ifneq (${VBOOT2},)
378UTILLIB_SRCS += \
Randall Spangler59c29202014-11-17 14:24:59 -0800379 host/lib/host_key2.c \
Randall Spangler02e11b32014-11-19 12:48:36 -0800380 host/lib/host_misc2.c \
Randall Spanglerc644a8c2014-11-21 11:04:36 -0800381 host/lib/host_signature2.c \
Randall Spangler02e11b32014-11-19 12:48:36 -0800382
383endif
384
Bill Richardson78299022014-06-20 14:33:00 -0700385UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
386ALL_OBJS += ${UTILLIB_OBJS}
387
388# Externally exported library for some target userspace apps to link with
389# (cryptohome, updater, etc.)
390HOSTLIB = ${BUILD}/libvboot_host.a
391
392HOSTLIB_SRCS = \
393 cgpt/cgpt_add.c \
394 cgpt/cgpt_boot.c \
395 cgpt/cgpt_common.c \
396 cgpt/cgpt_create.c \
397 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700398 firmware/lib/cgptlib/cgptlib_internal.c \
399 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700400 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700401 firmware/lib/tpm_lite/tlcl.c \
402 firmware/lib/utility_string.c \
403 firmware/lib/vboot_nvstorage.c \
404 firmware/stub/tpm_lite_stub.c \
405 firmware/stub/utility_stub.c \
406 firmware/stub/vboot_api_stub_init.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700407 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700408 host/arch/${ARCH}/lib/crossystem_arch.c \
409 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700410 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700411 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700412
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800413HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800414ALL_OBJS += ${HOSTLIB_OBJS}
415
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800416# Sigh. For historical reasons, the autoupdate installer must sometimes be a
417# 32-bit executable, even when everything else is 64-bit. But it only needs a
418# few functions, so let's just build those.
419TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
420
421TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800422 cgpt/cgpt_add.c \
423 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800424 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700425 cgpt/cgpt_create.c \
426 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700427 firmware/lib/cgptlib/cgptlib_internal.c \
428 firmware/lib/cgptlib/crc32.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800429 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700430 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800431 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800432
433TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800434
435# ----------------------------------------------------------------------------
436# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800437
438CGPT = ${BUILD}/cgpt/cgpt
439
440CGPT_SRCS = \
441 cgpt/cgpt.c \
442 cgpt/cgpt_add.c \
443 cgpt/cgpt_boot.c \
444 cgpt/cgpt_common.c \
445 cgpt/cgpt_create.c \
446 cgpt/cgpt_find.c \
447 cgpt/cgpt_legacy.c \
448 cgpt/cgpt_prioritize.c \
449 cgpt/cgpt_repair.c \
450 cgpt/cgpt_show.c \
451 cgpt/cmd_add.c \
452 cgpt/cmd_boot.c \
453 cgpt/cmd_create.c \
454 cgpt/cmd_find.c \
455 cgpt/cmd_legacy.c \
456 cgpt/cmd_prioritize.c \
457 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800458 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800460CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800461ALL_OBJS += ${CGPT_OBJS}
462
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800463
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800464# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800465UTIL_SCRIPTS = \
466 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700467 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800468
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800469ifeq (${MINIMAL},)
470UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700471 utility/dev_make_keypair \
472 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800473endif
474
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800475# These utilities should be linked statically.
476UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700477 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800478
479UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700480 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700481 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700482 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800483
Bill Richardson6f396152014-07-15 12:52:19 -0700484# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800485ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800486UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700487 utility/bmpblk_font \
488 utility/bmpblk_utility \
489 utility/eficompress \
490 utility/efidecompress \
491 utility/load_kernel_test \
492 utility/pad_digest_utility \
493 utility/signature_digest_utility \
494 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700495
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800496endif
497
Bill Richardson339f7e02013-04-05 09:49:24 -0700498UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
499UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700500ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800501
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800502
503# Scripts for signing stuff.
504SIGNING_SCRIPTS = \
505 utility/tpm-nvsize \
506 utility/chromeos-tpm-recovery
507
508# These go in a different place.
509SIGNING_SCRIPTS_DEV = \
510 scripts/image_signing/resign_firmwarefd.sh \
511 scripts/image_signing/make_dev_firmware.sh \
512 scripts/image_signing/make_dev_ssd.sh \
513 scripts/image_signing/set_gbb_flags.sh
514
515# Installed, but not made executable.
516SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800517
Bill Richardson826db092013-01-14 12:37:15 -0800518
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800519# The unified firmware utility will eventually replace all the others
520FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700521# But we still need both static (tiny) and dynamic (with openssl) versions.
522FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800523
Bill Richardson6f396152014-07-15 12:52:19 -0700524# These are the executables that are now built in to futility. We'll create
525# symlinks for these so the old names will still work.
526# TODO: Do we still need dev_sign_file for anything?
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700527FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700528 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700529 dump_fmap \
530 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700531 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700532 vbutil_firmware \
533 vbutil_kernel \
534 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700535 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800536
Bill Richardson6db8c752013-04-05 13:30:43 -0700537FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800538 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700539 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700540 futility/cmd_gbb_utility.c \
541 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800542
Bill Richardson6db8c752013-04-05 13:30:43 -0700543FUTIL_SRCS = \
544 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700545 futility/cmd_dev_sign_file.c \
546 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700547 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700548 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700549 futility/cmd_show.c \
550 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700551 futility/cmd_vbutil_firmware.c \
552 futility/cmd_vbutil_kernel.c \
Bill Richardsonf1dba022014-10-01 14:10:45 -0700553 futility/cmd_vbutil_kernel0.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700554 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700555 futility/cmd_vbutil_keyblock.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700556 futility/cmd_verify_kernel.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700557 futility/traversal.c \
558 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700559
Randall Spangler028f4682014-08-19 14:42:08 -0700560ifneq (${VBOOT2},)
561FUTIL_SRCS += \
562 futility/cmd_vb2_verify_fw.c
563endif
564
Alex Deymoe08ee282014-08-29 01:07:48 -0700565# List of commands built in futility and futility_s.
566FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
567FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800568
Alex Deymoe08ee282014-08-29 01:07:48 -0700569FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
570 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
571FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800572
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800573ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800574
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800575
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800576# Library of handy test functions.
577TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800578
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800579TESTLIB_SRCS = \
580 tests/test_common.c \
581 tests/timer_utils.c \
582 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800583
Randall Spanglerd274a2e2014-10-23 17:38:18 -0700584ifneq (${VBOOT2},)
585TESTLIB_SRCS += \
586 tests/vb2_convert_structs.c
587endif
588
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800589TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700590TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800591
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800592
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800593# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800594TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700595 tests/cgptlib_test \
596 tests/rollback_index2_tests \
597 tests/rollback_index3_tests \
598 tests/rsa_padding_test \
599 tests/rsa_utility_tests \
600 tests/rsa_verify_benchmark \
601 tests/sha_benchmark \
602 tests/sha_tests \
603 tests/stateful_util_tests \
604 tests/tlcl_tests \
605 tests/tpm_bootmode_tests \
606 tests/utility_string_tests \
607 tests/utility_tests \
608 tests/vboot_api_init_tests \
609 tests/vboot_api_devmode_tests \
610 tests/vboot_api_firmware_tests \
611 tests/vboot_api_kernel_tests \
612 tests/vboot_api_kernel2_tests \
613 tests/vboot_api_kernel3_tests \
614 tests/vboot_api_kernel4_tests \
615 tests/vboot_audio_tests \
616 tests/vboot_common_tests \
617 tests/vboot_common2_tests \
618 tests/vboot_common3_tests \
619 tests/vboot_display_tests \
620 tests/vboot_firmware_tests \
621 tests/vboot_kernel_tests \
622 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700623 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700624 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800625
Simon Glass527ba812013-07-25 08:48:47 -0600626ifdef REGION_READ
627TEST_NAMES += tests/vboot_region_tests
628endif
629
Randall Spangler786acda2014-05-22 13:27:07 -0700630ifneq (${VBOOT2},)
631TEST_NAMES += \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700632 tests/vb2_api_tests \
Randall Spanglerefa37b82014-11-12 16:20:50 -0800633 tests/vb2_api2_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700634 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700635 tests/vb2_common2_tests \
636 tests/vb2_common3_tests \
Randall Spangler59c29202014-11-17 14:24:59 -0800637 tests/vb2_host_key_tests \
Randall Spangler02e11b32014-11-19 12:48:36 -0800638 tests/vb2_host_misc_tests \
Randall Spanglerc644a8c2014-11-21 11:04:36 -0800639 tests/vb2_host_sig_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700640 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700641 tests/vb2_misc2_tests \
Randall Spangler837b4082014-11-10 13:40:52 -0800642 tests/vb2_misc3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700643 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700644 tests/vb2_rsa_padding_tests \
645 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700646 tests/vb2_secdata_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700647 tests/vb2_sha_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700648
649endif
650
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800651# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700652TLCL_TEST_NAMES = \
653 tests/tpm_lite/tpmtest_earlyextend \
654 tests/tpm_lite/tpmtest_earlynvram \
655 tests/tpm_lite/tpmtest_earlynvram2 \
656 tests/tpm_lite/tpmtest_enable \
657 tests/tpm_lite/tpmtest_fastenable \
658 tests/tpm_lite/tpmtest_globallock \
659 tests/tpm_lite/tpmtest_redefine_unowned \
660 tests/tpm_lite/tpmtest_spaceperm \
661 tests/tpm_lite/tpmtest_testsetup \
662 tests/tpm_lite/tpmtest_timing \
663 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800664
665TEST_NAMES += ${TLCL_TEST_NAMES}
666
Bill Richardson339f7e02013-04-05 09:49:24 -0700667# Finally
668TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700669TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800670
Randall Spanglere061a252013-01-22 15:34:07 -0800671# Directory containing test keys
672TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800673
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800674
675##############################################################################
676# Finally, some targets. High-level ones first.
677
678# Create output directories if necessary. Do this via explicit shell commands
679# so it happens before trying to generate/include dependencies.
680SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
681_dir_create := $(foreach d, \
682 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
683 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
684
685
686# Default target.
687.PHONY: all
Randall Spangler786acda2014-05-22 13:27:07 -0700688all: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
689 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800690
691# Host targets
692.PHONY: host_stuff
Bill Richardsonbc2d2b22014-07-09 21:11:12 -0700693host_stuff: utillib hostlib cgpt utils futil tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800694
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800695.PHONY: clean
696clean:
697 ${Q}/bin/rm -rf ${BUILD}
698
699.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800700install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800701
Bill Richardson3e3790d2014-07-14 15:05:54 -0700702.PHONY: install_for_test
703install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
704install_for_test: install
705
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800706# Don't delete intermediate object files
707.SECONDARY:
708
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800709# ----------------------------------------------------------------------------
710# Firmware library
711
712# TPM-specific flags. These depend on the particular TPM we're targeting for.
713# They are needed here only for compiling parts of the firmware code into
714# user-level tests.
715
716# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
717# the self test has completed.
718
Randall Spangler45cc0f22013-01-25 09:34:26 -0800719${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800720
721# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
722# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
723# power on.
724#
725# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
726# are not both defined at the same time. (See comment in code.)
727
728# CFLAGS += -DTPM_MANUAL_SELFTEST
729
730ifeq (${FIRMWARE_ARCH},i386)
731# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800732${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler786acda2014-05-22 13:27:07 -0700733${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800734
735# Workaround for coreboot on x86, which will power off asynchronously
736# without giving us a chance to react. This is not an example of the Right
737# Way to do things. See chrome-os-partner:7689, and the commit message
738# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800739${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800740
741# On x86 we don't actually read the GBB data into RAM until it is needed.
742# Therefore it makes sense to cache it rather than reading it each time.
743# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800744${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800745endif
746
Simon Glass527ba812013-07-25 08:48:47 -0600747ifdef REGION_READ
748${FWLIB_OBJS}: CFLAGS += -DREGION_READ
749endif
750
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800751ifeq (${FIRMWARE_ARCH},)
752# Disable rollback TPM when compiling locally, since otherwise
753# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800754${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800755endif
756
Bill Richardsona130e0b2013-04-04 18:16:39 -0700757# Linktest ensures firmware lib doesn't rely on outside libraries
758${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800759${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700760TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700761${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800762${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700763TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700764${BUILD}/firmware/linktest/main: ${FWLIB}
765${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700766TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800767
Bill Richardsond2d08b22014-07-08 16:31:40 -0700768.PHONY: fwlinktest
769fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800770 ${BUILD}/firmware/linktest/main_vbinit \
771 ${BUILD}/firmware/linktest/main_vbsf \
772 ${BUILD}/firmware/linktest/main
773
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800774.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700775fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800776
Randall Spangler786acda2014-05-22 13:27:07 -0700777.PHONY: fwlib2
778fwlib2: ${FWLIB2}
779
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800780${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700781 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800782 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700783 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800784 ${Q}ar qc $@ $^
785
Randall Spangler786acda2014-05-22 13:27:07 -0700786${FWLIB2}: ${FWLIB2_OBJS}
787 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
788 ${Q}rm -f $@
789 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
790 ${Q}ar qc $@ $^
791
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800792# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700793# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800794
Bill Richardson78299022014-06-20 14:33:00 -0700795# Link tests for local utilities
796${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700797${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700798TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700799
800.PHONY: utillib
801utillib: ${UTILLIB} \
802 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800803
804# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700805${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
806 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
807 ${Q}rm -f $@
808 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
809 ${Q}ar qc $@ $^
810
811
812# Link tests for external repos
813${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700814${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
815${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700816TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700817
818.PHONY: hostlib
819hostlib: ${HOSTLIB} \
820 ${BUILD}/host/linktest/extern
821
822# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700823${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700824 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800825 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700826 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800827 ${Q}ar qc $@ $^
828
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800829
830# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
831.PHONY: tinyhostlib
832tinyhostlib: ${TINYHOSTLIB}
833 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
834
835${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700836 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800837 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700838 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800839 ${Q}ar qc $@ $^
840
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800841# ----------------------------------------------------------------------------
842# CGPT library and utility
843
844.PHONY: cgpt
845cgpt: ${CGPT}
846
847${CGPT}: LDFLAGS += -static
848${CGPT}: LDLIBS += -luuid
849
Bill Richardson78299022014-06-20 14:33:00 -0700850${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700851 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700852 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800853
854.PHONY: cgpt_install
855cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700856 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800857 ${Q}mkdir -p ${UB_DIR}
858 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800859
860# ----------------------------------------------------------------------------
861# Utilities
862
863# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700864${BUILD}/utility/%: INCLUDES += -Iutility/include
865
866${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
867${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800868
869# Utilities for auto-update toolkits must be statically linked.
870${UTIL_BINS_STATIC}: LDFLAGS += -static
871
Bill Richardsona130e0b2013-04-04 18:16:39 -0700872
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800873.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800874utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800875 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
876 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
877
878.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800879utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700880 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800881 ${Q}mkdir -p ${UB_DIR}
882 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800883
884# And some signing stuff for the target
885.PHONY: signing_install
886signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700887 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700888 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800889 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700890 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
891 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800892
893# ----------------------------------------------------------------------------
894# new Firmware Utility
895
896.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700897futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
898
Alex Deymoe08ee282014-08-29 01:07:48 -0700899${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
Bill Richardson6db8c752013-04-05 13:30:43 -0700900 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
901 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800902
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700903${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Alex Deymoe08ee282014-08-29 01:07:48 -0700904${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700905 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700906 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800907
908.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -0700909futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700910 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700911 ${Q}mkdir -p ${UB_DIR}
912 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700913 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -0700914 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800915
916# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800917# Utility to generate TLCL structure definition header file.
918
919${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
920
921STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
922STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
923
924.PHONY: update_tlcl_structures
925update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700926 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800927 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
928 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
929 ( echo "%% Updating structures.h %%" && \
930 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
931
932# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800933# Tests
934
935.PHONY: tests
936tests: ${TEST_BINS}
937
Bill Richardson78299022014-06-20 14:33:00 -0700938${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700939${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -0800940${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800941
942${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700943 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800944 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700945 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800946 ${Q}ar qc $@ $^
947
948
949# ----------------------------------------------------------------------------
950# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
951# rules for specific targets.
952
953${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700954 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700955 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800956
957${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700958 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800959 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
960
Alex Deymoe08ee282014-08-29 01:07:48 -0700961${BUILD}/%.o: ${BUILD}/%.c
962 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
963 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
964
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800965# Rules to recompile a single source file for library and test
966# TODO: is there a tidier way to do this?
967${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
968${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700969 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800970 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
971
972${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
973${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -0700974 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800975 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
976
977# TODO: C++ files don't belong in vboot reference at all. Convert to C.
978${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -0700979 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800980 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
981
982# ----------------------------------------------------------------------------
983# Here are the special tweaks to the generic rules.
984
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800985# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -0700986CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
987
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800988${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
989${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
990${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800991
992${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
Randall Spanglerc644a8c2014-11-21 11:04:36 -0800993${BUILD}/tests/vb2_api2_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spanglerfb9a2162014-11-20 11:27:38 -0800994${BUILD}/tests/vb2_common_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler7141d732014-05-15 15:34:54 -0700995${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
996${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler59c29202014-11-17 14:24:59 -0800997${BUILD}/tests/vb2_host_key_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spanglerc644a8c2014-11-21 11:04:36 -0800998${BUILD}/tests/vb2_host_sig_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800999${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1000${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001001
1002${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1003${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
1004
1005BMPBLK_UTILITY_DEPS = \
1006 ${BUILD}/utility/bmpblk_util.o \
1007 ${BUILD}/utility/image_types.o \
1008 ${BUILD}/utility/eficompress_for_lib.o \
1009 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001010
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001011${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1012${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001013ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001014
1015${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1016${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001017ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001018
1019# Allow multiple definitions, so tests can mock functions from other libraries
1020${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001021${BUILD}/tests/%: LDLIBS += -lrt -luuid
1022${BUILD}/tests/%: LIBS += ${TESTLIB}
1023
1024${BUILD}/tests/rollback_index2_tests: OBJS += \
1025 ${BUILD}/firmware/lib/rollback_index_for_test.o
1026${BUILD}/tests/rollback_index2_tests: \
1027 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001028TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001029
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001030${BUILD}/tests/tlcl_tests: OBJS += \
1031 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1032${BUILD}/tests/tlcl_tests: \
1033 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001034TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001035
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001036${BUILD}/tests/vboot_audio_tests: OBJS += \
1037 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1038${BUILD}/tests/vboot_audio_tests: \
1039 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001040TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001041
Bill Richardson339f7e02013-04-05 09:49:24 -07001042TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001043${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1044${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001045TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001046
Alex Deymoe08ee282014-08-29 01:07:48 -07001047# ----------------------------------------------------------------------------
1048# Here are the special rules that don't fit in the generic rules.
1049
1050# Generates the list of commands defined in futility by running grep in the
1051# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1052${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1053${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1054${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1055 @$(PRINTF) " GEN $(subst ${BUILD}/,,$@)\n"
1056 ${Q}rm -f $@ $@_t $@_commands
1057 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001058 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001059 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1060 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001061 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001062 ${Q}echo '#define _CMD(NAME) extern const struct' \
1063 'futil_cmd_t __cmd_##NAME;' >> $@_t
1064 ${Q}cat $@_commands >> $@_t
1065 ${Q}echo '#undef _CMD' >> $@_t
1066 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1067 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1068 ${Q}cat $@_commands >> $@_t
1069 ${Q}echo '0}; /* null-terminated */' >> $@_t
1070 ${Q}echo '#undef _CMD' >> $@_t
1071 ${Q}mv $@_t $@
1072 ${Q}rm -f $@_commands
1073
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001074##############################################################################
1075# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001076
1077# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001078.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001079test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001080
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001081ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001082# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001083test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001084# Scripts don't work under qemu testing
1085# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001086test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001087endif
1088
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001089.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001090test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001091
Randall Spangler844bce52013-01-15 16:16:43 -08001092# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1093# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001094ifneq (${QEMU_ARCH},)
1095test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001096
1097.PHONY: qemu_install
1098qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001099ifeq (${SYSROOT},)
1100 $(error SYSROOT must be set to the top of the target-specific root \
1101when cross-compiling for qemu-based tests to run properly.)
1102endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001103 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001104 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1105 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001106endif
1107
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001108.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001109runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001110
1111# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001112.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001113genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001114 tests/gen_test_keys.sh
1115
1116# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001117.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001118genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001119 tests/gen_fuzz_test_cases.sh
1120
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001121.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001122runbmptests: test_setup
1123 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001124 ./TestBmpBlock.py -v
1125
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001126.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001127runcgpttests: test_setup
1128 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001129
Randall Spangler844bce52013-01-15 16:16:43 -08001130.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001131runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001132 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001133 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001134 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001135 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001136 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001137 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001138 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001139ifneq (${VBOOT2},)
1140 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001141 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001142endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001143
Randall Spangler844bce52013-01-15 16:16:43 -08001144.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001145runmisctests: test_setup
1146 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001147 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001148 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1149 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1150 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001151 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001152 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1153 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1154 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1155 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001156 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001157 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1158 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001159 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1160 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1161 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001162 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001163 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1164 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1165 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001166 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001167 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001168 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001169 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001170
Randall Spangler786acda2014-05-22 13:27:07 -07001171.PHONY: run2tests
1172run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001173 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spanglerefa37b82014-11-12 16:20:50 -08001174 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api2_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001175 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001176 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1177 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler59c29202014-11-17 14:24:59 -08001178 ${RUNTEST} ${BUILD_RUN}/tests/vb2_host_key_tests ${TEST_KEYS}
Randall Spangler02e11b32014-11-19 12:48:36 -08001179 ${RUNTEST} ${BUILD_RUN}/tests/vb2_host_misc_tests
Randall Spanglerc644a8c2014-11-21 11:04:36 -08001180 ${RUNTEST} ${BUILD_RUN}/tests/vb2_host_sig_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001181 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001182 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler837b4082014-11-10 13:40:52 -08001183 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc3_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001184 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001185 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001186 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001187 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001188
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001189.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001190runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001191 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001192 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001193
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001194# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001195# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001196# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001197.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001198runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001199 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1200 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001201ifneq (${VBOOT2},)
1202 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1203 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
1204endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001205 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001206 tests/run_vbutil_tests.sh --all
1207
Bill Richardson78d59bf2014-08-27 16:17:04 -07001208# TODO: There were a number of ancient tests that hadn't been run in years.
1209# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1210# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001211
Bill Richardson78299022014-06-20 14:33:00 -07001212.PHONY: runalltests
1213runalltests: runtests runfutiltests runlongtests
1214
Randall Spangler59d75082013-01-23 09:29:54 -08001215# Code coverage
1216.PHONY: coverage_init
1217coverage_init: test_setup
1218 rm -f ${COV_INFO}*
1219 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1220
1221.PHONY: coverage_html
1222coverage_html:
1223 lcov -c -d . -b . -o ${COV_INFO}.tests
1224 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1225 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1226 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001227# Generate addtional coverage stats just for firmware subdir, because the stats
1228# for the whole project don't include subdirectory summaries. This will print
1229# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001230 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1231 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001232 -o ${COV_INFO}.firmware
1233
1234.PHONY: coverage
1235ifeq (${COV},)
1236coverage:
1237 $(error Build coverage like this: make clean && COV=1 make)
1238else
1239coverage: coverage_init runtests coverage_html
1240endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001241
1242# Include generated dependencies
1243ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001244TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1245
1246# We want to use only relative paths in cscope.files, especially since the
1247# paths inside and outside the chroot are different.
1248SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1249
1250${BUILD}/cscope.files: test_setup
1251 ${Q}rm -f $@
1252 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1253 sed -e "s/${SRCDIRPAT}//" | \
1254 egrep '\.[chS]$$' | sort | uniq > $@
1255
1256cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1257cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1258run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1259
1260.PHONY: tags TAGS xrefs
1261tags TAGS xrefs: ${BUILD}/cscope.files
1262 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1263 ${Q}$(call run_if_prog,etags,${cmd_etags})
1264 ${Q}$(call run_if_prog,ctags,${cmd_ctags})