blob: 04d11b20955887b7f1ceaf4f4e340685822ced89 [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
Gabe Black0aedbe12012-12-20 00:26:59 -08005ifneq ($(V),1)
6Q := @
7endif
8
Simon Glass6d696e52011-11-14 13:46:33 -08009# This Makefile normally builds in a 'build' subdir, but use
10#
11# make BUILD=<dir>
12#
13# to put the output somewhere else
Randall Spangler5d9bbf22013-01-08 10:44:23 -080014BUILD ?= $(shell pwd)/build
Simon Glass6d696e52011-11-14 13:46:33 -080015
Randall Spangler5d9bbf22013-01-08 10:44:23 -080016# Target for 'make install'
17DESTDIR ?= /usr/bin
Bill Richardson826db092013-01-14 12:37:15 -080018INSTALL ?= install
Randall Spangler5d9bbf22013-01-08 10:44:23 -080019
Simon Glassb265c342011-11-16 15:09:51 -080020# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
21# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070022#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080023# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
24# temporarily. As we are still investigating which flags are necessary for
25# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070026#
Simon Glassb265c342011-11-16 15:09:51 -080027# As a first step, this makes the setting of CC and CFLAGS here optional, to
28# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070029#
Simon Glassb265c342011-11-16 15:09:51 -080030# Flag ordering: arch, then -f, then -m, then -W
31DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
32COMMON_FLAGS := -nostdinc -pipe \
33 -ffreestanding -fno-builtin -fno-stack-protector \
34 -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS)
35
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070036ifeq ($(FIRMWARE_ARCH), arm)
Simon Glassb265c342011-11-16 15:09:51 -080037CC ?= armv7a-cros-linux-gnueabi-gcc
38CFLAGS ?= -march=armv5 \
39 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -070040 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Simon Glassb265c342011-11-16 15:09:51 -080041 $(COMMON_FLAGS)
Che-Liang Chiou74359b72011-06-21 15:25:51 -070042endif
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070043ifeq ($(FIRMWARE_ARCH), i386)
Simon Glassb265c342011-11-16 15:09:51 -080044CC ?= i686-pc-linux-gnu-gcc
45# Drop -march=i386 to permit use of SSE instructions
46CFLAGS ?= \
47 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
48 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
49 -mpreferred-stack-boundary=2 -mregparm=3 \
50 $(COMMON_FLAGS)
Che-Liang Chiou34be8272011-01-27 16:44:36 +080051endif
Simon Glass8e85e982011-11-22 13:54:50 -080052ifeq ($(FIRMWARE_ARCH), x86_64)
53CFLAGS ?= $(COMMON_FLAGS) \
54 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
55endif
Che-Liang Chiou34be8272011-01-27 16:44:36 +080056
Randall Spangler287beae2011-04-11 12:46:40 -070057# Fix compiling directly on host (outside of emake)
58ifeq ($(ARCH),)
Randall Spangler5d9bbf22013-01-08 10:44:23 -080059ARCH = amd64
Randall Spangler287beae2011-04-11 12:46:40 -070060endif
61
Randall Spangler5d9bbf22013-01-08 10:44:23 -080062# Some things only compile inside the Chromium OS chroot
63# TODO: is there a better way to detect this?
64ifneq ($(CROS_WORKON_SRCROOT),)
65IN_CHROOT = 1
66endif
67
68CC ?= gcc
69CXX ?= g++
70LD = $(CC)
71PKG_CONFIG ?= pkg-config
72
Che-Liang Chiou34be8272011-01-27 16:44:36 +080073ifeq ($(FIRMWARE_ARCH),)
Bill Richardsonf4729192012-05-02 23:30:16 -070074CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror
Che-Liang Chiou34be8272011-01-27 16:44:36 +080075endif
76
77ifneq (${DEBUG},)
78CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -070079endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080080
vbendebb2b0fcc2010-07-15 15:09:47 -070081ifeq (${DISABLE_NDEBUG},)
82CFLAGS += -DNDEBUG
83endif
84
Randall Spangler5d9bbf22013-01-08 10:44:23 -080085# Create / use dependency files
86CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -080087
Randall Spangler5d9bbf22013-01-08 10:44:23 -080088# Code coverage
89ifneq (${COV},)
90#COV_FLAGS = -O0 -fprofile-arcs -ftest-coverage
91COV_FLAGS = -O0 --coverage
92CFLAGS += $(COV_FLAGS)
93LDFLAGS += $(COV_FLAGS)
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080094endif
Gaurav Shah322536d2010-01-28 15:01:23 -080095
Randall Spangler5d9bbf22013-01-08 10:44:23 -080096INCLUDES += \
97 -Ifirmware/include \
98 -Ifirmware/lib/include \
99 -Ifirmware/lib/cgptlib/include \
100 -Ifirmware/lib/cryptolib/include \
101 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700102
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800103ifeq ($(FIRMWARE_ARCH),)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800104INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800105else
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800106INCLUDES += -Ifirmware/arch/$(FIRMWARE_ARCH)/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800107endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800108
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800109# Output libraries
110CGPTLIB := ${BUILD}/cgpt/libcgpt-cc.a
111DUMPKERNELCONFIGLIB := ${BUILD}/libdump_kernel_config.a
112FWLIB := ${BUILD}/vboot_fw.a
113HOSTLIB := ${BUILD}/vboot_host.a
114TEST_LIB := ${BUILD}/tests/test.a
Gaurav Shah322536d2010-01-28 15:01:23 -0800115
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800116CRYPTO_LIBS := $(shell $(PKG_CONFIG) --libs libcrypto)
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800117
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800118ifneq ($(IN_CHROOT),)
119PC_BASE_VER ?= 125070
120PC_DEPS = libchrome-$(PC_BASE_VER)
121PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
122PC_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
123endif
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800124
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800125# Link with hostlib and crypto libs by default
126LIBS = $(HOSTLIB)
127LDLIBS = $(CRYPTO_LIBS)
128
129# Create output directories if necessary. Do this via explicit shell commands
130# so it happens before trying to generate/include dependencies.
131SUBDIRS := firmware host utility cgpt tests tests/tpm_lite
132_dir_create := $(foreach d, \
133 $(shell find $(SUBDIRS) -name '*.c' -exec dirname {} \; | sort -u), \
134 $(shell [ -d $(BUILD)/$(d) ] || mkdir -p $(BUILD)/$(d)))
135
136# First target
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800137.PHONY: all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800138all: fwlib $(if $(FIRMWARE_ARCH),,host_stuff)
139
140# Host targets
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800141.PHONY: host_stuff
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800142host_stuff: fwlib hostlib cgpt utils tests
Jay Srinivasan250549d2012-02-16 17:40:45 -0800143
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800144.PHONY: clean
Gaurav Shah322536d2010-01-28 15:01:23 -0800145clean:
Gabe Black0aedbe12012-12-20 00:26:59 -0800146 $(Q)/bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -0700147
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800148.PHONY: install
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800149install: cgpt_install utils_install
Gaurav Shahe6421982010-06-03 07:49:32 -0700150
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800151# Coverage
152COV_INFO = $(BUILD)/coverage.info
153#coverage: runtests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800154.PHONY: coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800155coverage:
156 rm -f $(COV_INFO)*
157 lcov --capture --directory . --base-directory . -o $(COV_INFO).1
158 lcov --remove $(COV_INFO).1 '/usr/*' -o $(COV_INFO)
159 genhtml $(COV_INFO) --output-directory $(BUILD)/coverage
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700160
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800161# Don't delete intermediate object files
162.SECONDARY:
Randall Spanglere8cfa312013-01-02 16:49:38 -0800163
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800164# Use second expansion phase for $$(LIBS) so dependencies on libraries are
165# properly evaluated for implicit rules.
166.SECONDEXPANSION:
Jay Srinivasan250549d2012-02-16 17:40:45 -0800167
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800168# -----------------------------------------------------------------------------
169# Firmware library
Bill Richardson856e0722011-02-07 15:39:45 -0800170
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800171# TPM-specific flags. These depend on the particular TPM we're targeting for.
172# They are needed here only for compiling parts of the firmware code into
173# user-level tests.
174
175# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
176# the self test has completed.
177
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800178$(FWLIB): CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800179
180# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
181# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
182# power on.
183#
184# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
185# are not both defined at the same time. (See comment in code.)
186
187# CFLAGS += -DTPM_MANUAL_SELFTEST
188
189ifeq ($(FIRMWARE_ARCH),i386)
190# Unrolling loops in cryptolib makes it faster
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800191$(FWLIB): CFLAGS += -DUNROLL_LOOPS
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800192
193# Workaround for coreboot on x86, which will power off asynchronously
194# without giving us a chance to react. This is not an example of the Right
195# Way to do things. See chrome-os-partner:7689, and the commit message
196# that made this change.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800197$(FWLIB): CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800198
199# On x86 we don't actually read the GBB data into RAM until it is needed.
200# Therefore it makes sense to cache it rather than reading it each time.
201# Enable this feature.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800202$(FWLIB): CFLAGS += -DCOPY_BMP_DATA
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800203endif
204
205ifeq ($(FIRMWARE_ARCH),)
206$(warning FIRMWARE_ARCH not defined; assuming local compile)
207
208# Disable rollback TPM when compiling locally, since otherwise
209# load_kernel_test attempts to talk to the TPM.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800210$(FWLIB): CFLAGS += -DDISABLE_ROLLBACK_TPM
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800211endif
212
213# find lib -iname '*.c' | sort
214FWLIB_SRCS = \
215 firmware/lib/cgptlib/cgptlib.c \
216 firmware/lib/cgptlib/cgptlib_internal.c \
217 firmware/lib/cgptlib/crc32.c \
218 firmware/lib/crc8.c \
219 firmware/lib/cryptolib/padding.c \
220 firmware/lib/cryptolib/rsa.c \
221 firmware/lib/cryptolib/rsa_utility.c \
222 firmware/lib/cryptolib/sha1.c \
223 firmware/lib/cryptolib/sha256.c \
224 firmware/lib/cryptolib/sha512.c \
225 firmware/lib/cryptolib/sha_utility.c \
226 firmware/lib/stateful_util.c \
227 firmware/lib/utility.c \
228 firmware/lib/utility_string.c \
229 firmware/lib/vboot_api_init.c \
230 firmware/lib/vboot_api_firmware.c \
231 firmware/lib/vboot_api_kernel.c \
232 firmware/lib/vboot_audio.c \
233 firmware/lib/vboot_common.c \
234 firmware/lib/vboot_display.c \
235 firmware/lib/vboot_firmware.c \
236 firmware/lib/vboot_kernel.c \
237 firmware/lib/vboot_nvstorage.c
238
239ifeq ($(MOCK_TPM),)
240FWLIB_SRCS += \
241 firmware/lib/rollback_index.c \
242 firmware/lib/tpm_bootmode.c \
243 firmware/lib/tpm_lite/tlcl.c
244else
245FWLIB_SRCS += \
246 firmware/lib/mocked_rollback_index.c \
247 firmware/lib/mocked_tpm_bootmode.c \
248 firmware/lib/tpm_lite/mocked_tlcl.c
249endif
250
251ifeq ($(FIRMWARE_ARCH),)
252# Include stub into firmware lib if compiling for host
253FWLIB_SRCS += \
254 firmware/stub/tpm_lite_stub.c \
255 firmware/stub/utility_stub.c \
256 firmware/stub/vboot_api_stub.c \
257 firmware/stub/vboot_api_stub_disk.c
258endif
259
260FWLIB_OBJS = $(FWLIB_SRCS:%.c=${BUILD}/%.o)
261ALL_OBJS += ${FWLIB_OBJS}
262
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800263.PHONY: fwlib
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800264ifeq ($(FIRMWARE_ARCH),)
265# Link test ensures firmware lib doesn't rely on outside libraries
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800266${BUILD}/firmware/linktest/main: LIBS = $(FWLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800267
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800268fwlib: ${BUILD}/firmware/linktest/main
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800269else
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800270fwlib: $(FWLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800271endif
272
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800273$(FWLIB): $(FWLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800274 @printf " RM $(subst $(BUILD)/,,$(@))\n"
275 $(Q)rm -f $@
276 @printf " AR $(subst $(BUILD)/,,$(@))\n"
277 $(Q)ar qc $@ $^
278
279# -----------------------------------------------------------------------------
280# Host library
281
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800282.PHONY: hostlib
283hostlib: $(HOSTLIB) ${BUILD}/host/linktest/main
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800284
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800285${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800286 -Ihost/include\
287 -Ihost/arch/$(ARCH)/include
288
289HOSTLIB_SRCS = \
290 host/arch/$(ARCH)/lib/crossystem_arch.c \
291 host/lib/crossystem.c \
292 host/lib/file_keys.c \
293 host/lib/fmap.c \
294 host/lib/host_common.c \
295 host/lib/host_key.c \
296 host/lib/host_keyblock.c \
297 host/lib/host_misc.c \
298 host/lib/host_signature.c \
299 host/lib/signature_digest.c
300
301HOSTLIB_OBJS = $(HOSTLIB_SRCS:%.c=${BUILD}/%.o)
302ALL_OBJS += ${HOSTLIB_OBJS}
303
304# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800305$(HOSTLIB): $(HOSTLIB_OBJS) $(FWLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800306 @printf " RM $(subst $(BUILD)/,,$(@))\n"
307 $(Q)rm -f $@
308 @printf " AR $(subst $(BUILD)/,,$(@))\n"
309 $(Q)ar qc $@ $^
310
311# -----------------------------------------------------------------------------
312# CGPT library and utility
313
314CGPT = ${BUILD}/cgpt/cgpt
315
316CGPT_SRCS = \
317 cgpt/cgpt.c \
318 cgpt/cgpt_add.c \
319 cgpt/cgpt_boot.c \
320 cgpt/cgpt_common.c \
321 cgpt/cgpt_create.c \
322 cgpt/cgpt_find.c \
323 cgpt/cgpt_legacy.c \
324 cgpt/cgpt_prioritize.c \
325 cgpt/cgpt_repair.c \
326 cgpt/cgpt_show.c \
327 cgpt/cmd_add.c \
328 cgpt/cmd_boot.c \
329 cgpt/cmd_create.c \
330 cgpt/cmd_find.c \
331 cgpt/cmd_legacy.c \
332 cgpt/cmd_prioritize.c \
333 cgpt/cmd_repair.c \
334 cgpt/cmd_show.c
335
336CGPT_OBJS = $(CGPT_SRCS:%.c=${BUILD}/%.o)
337ALL_OBJS += ${CGPT_OBJS}
338
339# TODO: why not make this include *all* the cgpt files, and simply have
340# cgpt link against it?
341# TODO: CgptManager.cc should move to the installer project. Shouldn't be
342# in libcgpt-cc.a.
343CGPTLIB_SRCS = \
344 cgpt/CgptManager.cc \
345 cgpt/cgpt_create.c \
346 cgpt/cgpt_add.c \
347 cgpt/cgpt_boot.c \
348 cgpt/cgpt_show.c \
349 cgpt/cgpt_repair.c \
350 cgpt/cgpt_prioritize.c \
351 cgpt/cgpt_common.c \
352 firmware/lib/cgptlib/crc32.c \
353 firmware/lib/cgptlib/cgptlib_internal.c \
354 firmware/stub/utility_stub.c
355
356CGPTLIB_OBJS = $(filter %.o, \
357 $(CGPTLIB_SRCS:%.c=${BUILD}/%.o) \
358 $(CGPTLIB_SRCS:%.cc=${BUILD}/%.o))
359ALL_OBJS += $(CGPTLIB_OBJS)
360
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800361.PHONY: cgpt
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800362cgpt: $(CGPT)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800363
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800364.PHONY: libcgpt_cc
365libcgpt_cc: $(CGPTLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800366
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800367$(CGPTLIB): INCLUDES += -Ifirmware/lib/cgptlib/include
368$(CGPTLIB): $(CGPTLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800369 @printf " RM $(subst $(BUILD)/,,$(@))\n"
370 $(Q)rm -f $@
371 @printf " AR $(subst $(BUILD)/,,$(@))\n"
372 $(Q)ar qc $@ $^
373
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800374$(CGPT): INCLUDES += -Ifirmware/lib/cgptlib/include
375$(CGPT): LDLIBS = -luuid
376$(CGPT): LDFLAGS += -static
377$(CGPT): $(CGPT_OBJS) $$(LIBS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800378 @printf " LDcgpt $(subst $(BUILD)/,,$(@))\n"
379 $(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS)
380
Bill Richardson826db092013-01-14 12:37:15 -0800381C_DESTDIR = $(DESTDIR)
382
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800383.PHONY: cgpt_install
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800384cgpt_install: $(CGPT)
Bill Richardson826db092013-01-14 12:37:15 -0800385 @printf " INSTALL CGPT\n"
386 ${Q}mkdir -p $(C_DESTDIR)
387 ${Q}$(INSTALL) -t $(C_DESTDIR) $^
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800388
389# -----------------------------------------------------------------------------
390# Utilities
391
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800392${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
393${BUILD}/utility/%: CFLAGS += $(PC_CFLAGS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800394
395AU_NAMES = \
396 crossystem \
397 dump_fmap \
398 gbb_utility
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800399AU_BINS:= $(addprefix ${BUILD}/utility/,$(AU_NAMES))
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800400
401# Utilities for auto-update toolkits must be statically linked, and don't
402# use the crypto libs.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800403${AU_BINS}: LDFLAGS += -static
404${AU_BINS}: CRYPTO_LIBS =
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800405
406# Scripts to install
407UTIL_SCRIPTS = \
408 utility/dev_debug_vboot \
409 utility/dev_make_keypair \
410 utility/enable_dev_usb_boot \
411 utility/vbutil_what_keys
412
413UTIL_NAMES = $(AU_NAMES) \
414 dev_sign_file \
415 dump_kernel_config \
416 dumpRSAPublicKey \
417 load_kernel_test \
418 pad_digest_utility \
419 signature_digest_utility \
420 tpm_init_temp_fix \
421 tpmc \
422 vbutil_ec \
423 vbutil_firmware \
424 vbutil_kernel \
425 vbutil_key \
426 vbutil_keyblock \
427 verify_data
428
429ifneq ($(IN_CHROOT),)
430UTIL_NAMES += mount-encrypted
431endif
432
433ifeq ($(MINIMAL),)
434UTIL_NAMES += \
435 bmpblk_font \
436 bmpblk_utility \
437 eficompress \
438 efidecompress
439endif
440
441UTIL_BINS = $(addprefix ${BUILD}/utility/,$(UTIL_NAMES))
442ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
443
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800444.PHONY: utils
445utils: $(UTIL_BINS) $(UTIL_SCRIPTS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800446# TODO: change ebuild to pull scripts directly out of utility dir
447 $(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility
448 $(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS))
449
Bill Richardson826db092013-01-14 12:37:15 -0800450U_DESTDIR = $(DESTDIR)
451
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800452.PHONY: utils_install
453utils_install: $(UTIL_BINS) $(UTIL_SCRIPTS)
Bill Richardson826db092013-01-14 12:37:15 -0800454 @printf " INSTALL UTILS\n"
455 ${Q}mkdir -p $(U_DESTDIR)
456 ${Q}$(INSTALL) -t $(U_DESTDIR) $^
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800457
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800458${BUILD}/utility/dump_kernel_config: LIBS += $(DUMPKERNELCONFIGLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459
460# GBB utility needs C++ linker
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800461${BUILD}/utility/gbb_utility: LD = $(CXX)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800462
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800463${BUILD}/utility/bmpblk_utility: LD = $(CXX)
464${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
465${BUILD}/utility/bmpblk_utility: OBJS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800466 ${BUILD}/utility/bmpblk_util.o \
467 ${BUILD}/utility/image_types.o \
Randall Spangler17f8d342013-01-11 10:55:11 -0800468 ${BUILD}/utility/eficompress_for_lib.o \
469 ${BUILD}/utility/efidecompress_for_lib.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800470
471${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
472
473# TODO: fix load_firmware_test util; it never got refactored for the new APIs
474
475# -----------------------------------------------------------------------------
476# Mount-encrypted utility for cryptohome
477
478# TODO: mount-encrypted should move to cryptohome and just link against
479# vboot-host.a for tlcl and crossystem.
480
481# The embedded libcrypto conflicts with the shipped openssl,
482# so mount-* builds without the common CFLAGS (and those includes).
483
484${BUILD}/utility/mount-helpers.o: \
485 utility/mount-helpers.c \
486 utility/mount-helpers.h \
487 utility/mount-encrypted.h
488 @printf " CCm-e $(subst $(BUILD)/,,$(@))\n"
489 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
490 $(COV_FLAGS) \
491 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
492 -c $< -o $@
493
494${BUILD}/utility/mount-encrypted: \
495 utility/mount-encrypted.c \
496 utility/mount-encrypted.h \
497 ${BUILD}/utility/mount-helpers.o $$(LIBS)
498 @printf " CCm-exe $(subst $(BUILD)/,,$(@))\n"
499 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
500 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
501 -Ifirmware/include \
502 -Ihost/include \
503 $(COV_FLAGS) \
504 $(LDFLAGS) \
505 $< -o $@ \
506 ${BUILD}/utility/mount-helpers.o $(LIBS) \
507 $(shell $(PKG_CONFIG) --libs glib-2.0 openssl) \
508 -lm
509ifneq (${COV},)
510 $(Q)mv -f mount-encrypted.gcno ${BUILD}/utility
511endif
512
513# -----------------------------------------------------------------------------
514# Utility to generate TLCL structure definition header file.
515
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800516${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
517${BUILD}/utility/tlcl_generator: LIBS =
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800518
519STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
520STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
521
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800522.PHONY: update_tlcl_structures
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800523update_tlcl_structures: ${BUILD}/utility/tlcl_generator
524 @printf " Rebuilding TLCL structures\n"
525 $(Q)${BUILD}/utility/tlcl_generator > $(STRUCTURES_TMP)
526 $(Q)cmp -s $(STRUCTURES_TMP) $(STRUCTURES_SRC) || \
527 ( echo "%% Updating structures.h %%" && \
528 cp $(STRUCTURES_TMP) $(STRUCTURES_SRC) )
529
530# -----------------------------------------------------------------------------
531# Library to dump kernel config
Randall Spangler17f8d342013-01-11 10:55:11 -0800532# Used by platform/installer
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800533
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800534.PHONY: libdump_kernel_config
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800535libdump_kernel_config: $(DUMPKERNELCONFIGLIB)
536
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800537$(DUMPKERNELCONFIGLIB): ${BUILD}/utility/dump_kernel_config_lib.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800538 @printf " RM $(subst $(BUILD)/,,$(@))\n"
539 $(Q)rm -f $@
540 @printf " AR $(subst $(BUILD)/,,$(@))\n"
541 $(Q)ar qc $@ $^
542
543# -----------------------------------------------------------------------------
544# Tests
545
546# Allow multiple definitions, so tests can mock functions from other libraries
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800547${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
548${BUILD}/tests/%: INCLUDES += -Ihost/include
549${BUILD}/tests/%: LDLIBS += -lrt -luuid
550${BUILD}/tests/%: LIBS += $(TEST_LIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800551
552TEST_NAMES = \
553 cgptlib_test \
554 rollback_index2_tests \
555 rsa_padding_test \
556 rsa_utility_tests \
557 rsa_verify_benchmark \
558 sha_benchmark \
559 sha_tests \
560 stateful_util_tests \
561 tpm_bootmode_tests \
562 utility_string_tests \
563 utility_tests \
564 vboot_nvstorage_test \
565 vboot_api_init_tests \
566 vboot_api_devmode_tests \
567 vboot_api_firmware_tests \
568 vboot_api_kernel_tests \
569 vboot_audio_tests \
570 vboot_common_tests \
571 vboot_common2_tests \
572 vboot_common3_tests \
573 vboot_ec_tests \
574 vboot_firmware_tests
575
576ifneq ($(IN_CHROOT),)
577TEST_NAMES += CgptManagerTests
578endif
579
580TLCL_TEST_NAMES = \
Randall Spangler17f8d342013-01-11 10:55:11 -0800581 tpmtest_earlyextend \
582 tpmtest_earlynvram \
583 tpmtest_earlynvram2 \
584 tpmtest_enable \
585 tpmtest_fastenable \
586 tpmtest_globallock \
587 tpmtest_redefine_unowned \
588 tpmtest_spaceperm \
589 tpmtest_testsetup \
590 tpmtest_timing \
591 tpmtest_writelimit
592TEST_NAMES += $(addprefix tpm_lite/,$(TLCL_TEST_NAMES))
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800593
594TEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES))
595ALL_DEPS += $(addsuffix .d,${TEST_BINS})
596
Randall Spangler17f8d342013-01-11 10:55:11 -0800597.PHONY: tests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800598tests: $(TEST_BINS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800599
600${TEST_LIB}: \
601 ${BUILD}/tests/test_common.o \
602 ${BUILD}/tests/timer_utils.o \
603 ${BUILD}/tests/crc32_test.o
604 @printf " RM $(subst $(BUILD)/,,$(@))\n"
605 $(Q)rm -f $@
606 @printf " AR $(subst $(BUILD)/,,$(@))\n"
607 $(Q)ar qc $@ $^
608
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800609${BUILD}/tests/rollback_index2_tests: OBJS += \
Randall Spangler17f8d342013-01-11 10:55:11 -0800610 ${BUILD}/firmware/lib/rollback_index_for_test.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800611
612${BUILD}/tests/vboot_audio_tests: OBJS += \
Randall Spangler17f8d342013-01-11 10:55:11 -0800613 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800614
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800615.PHONY: cgptmanager_tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800616cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
617
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800618${BUILD}/tests/CgptManagerTests: CFLAGS += $(PC_CFLAGS)
619${BUILD}/tests/CgptManagerTests: LD = $(CXX)
620${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags $(PC_LDLIBS)
621${BUILD}/tests/CgptManagerTests: LIBS = $(CGPTLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800622
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800623${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
624${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800625
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800626${BUILD}/tests/tpm_lite/tpmtest_%: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800627
628# TODO: port these tests to new API, if not already eqivalent
629# functionality in other tests. These don't even compile at present.
630#
631# big_firmware_tests
632# big_kernel_tests
633# firmware_image_tests
634# firmware_rollback_tests
635# firmware_splicing_tests
636# firmware_verify_benchmark
637# kernel_image_tests
638# kernel_rollback_tests
639# kernel_splicing_tests
640# kernel_verify_benchmark
641# rollback_index_test
642# verify_firmware_fuzz_driver
643# verify_kernel_fuzz_driver
644
645# -----------------------------------------------------------------------------
646# Targets to run tests
647
648# Frequently-run tests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800649.PHONY: runtests
650runtests: runbmptests runcgpttests runfuzztests runmisctests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800651
652# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800653.PHONY: genkeys
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800654genkeys:
655 tests/gen_test_keys.sh
656
657# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800658.PHONY: genfuzztestcases
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800659genfuzztestcases:
660 tests/gen_fuzz_test_cases.sh
661
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800662.PHONY: runbmptests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800663runbmptests: utils
664 cd tests/bitmaps && BMPBLK=${BUILD}/utility/bmpblk_utility \
665 ./TestBmpBlock.py -v
666
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800667.PHONY: runcgpttests
668runcgpttests: cgpt tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800669 ${BUILD}/tests/cgptlib_test
670 tests/run_cgpt_tests.sh ${BUILD}/cgpt/cgpt
671ifneq ($(IN_CHROOT),)
672 ${BUILD}/tests/CgptManagerTests --v=1
673endif
674
675# Exercise vbutil_kernel and vbutil_firmware
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800676.PHONY: runfuzztests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800677runfuzztests: genfuzztestcases utils tests
678 tests/run_preamble_tests.sh
679 tests/run_vbutil_kernel_arg_tests.sh
680
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800681.PHONY: runmisctests
682runmisctests: tests utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800683 ${BUILD}/tests/rollback_index2_tests
684 ${BUILD}/tests/rsa_utility_tests
685 ${BUILD}/tests/sha_tests
686 ${BUILD}/tests/stateful_util_tests
687 ${BUILD}/tests/tpm_bootmode_tests
688 ${BUILD}/tests/utility_string_tests
689 ${BUILD}/tests/utility_tests
690 ${BUILD}/tests/vboot_api_devmode_tests
691 ${BUILD}/tests/vboot_api_init_tests
692 ${BUILD}/tests/vboot_api_firmware_tests
693 ${BUILD}/tests/vboot_audio_tests
694 ${BUILD}/tests/vboot_firmware_tests
695 tests/run_rsa_tests.sh
696 tests/run_vboot_common_tests.sh
697 tests/run_vbutil_tests.sh
698
699# Run long tests, including all permutations of encryption keys (instead of
700# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
701# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800702.PHONY: runlongtests
703runlongtests: genkeys genfuzztestcases tests utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800704 tests/run_preamble_tests.sh --all
705 tests/run_vboot_common_tests.sh --all
706 tests/run_vboot_ec_tests.sh
707 tests/run_vbutil_tests.sh --all
708
709# TODO: tests to run when ported to new API
710# ./run_image_verification_tests.sh
711# # Splicing tests
712# ${BUILD}/tests/firmware_splicing_tests
713# ${BUILD}/tests/kernel_splicing_tests
714# # Rollback Tests
715# ${BUILD}/tests/firmware_rollback_tests
716# ${BUILD}/tests/kernel_rollback_tests
717
718# -----------------------------------------------------------------------------
719# Build rules
720
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800721${BUILD}/%: ${BUILD}/%.o $$(OBJS) $$(LIBS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800722 @printf " LD $(subst $(BUILD)/,,$(@))\n"
723 $(Q)$(LD) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
724 $(LIBS) $(LDLIBS)
725
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800726${BUILD}/%.o: %.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800727 @printf " CC $(subst $(BUILD)/,,$(@))\n"
728 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
729
Randall Spangler17f8d342013-01-11 10:55:11 -0800730# Rules to recompile a single source file for library and test
731# TODO: is there a tidier way to do this?
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800732${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
733${BUILD}/%_for_lib.o: %.c
Randall Spangler17f8d342013-01-11 10:55:11 -0800734 @printf " CC-for-lib $(subst $(BUILD)/,,$(@))\n"
735 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800736${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
737${BUILD}/%_for_test.o: %.c
Randall Spangler17f8d342013-01-11 10:55:11 -0800738 @printf " CC-for-test $(subst $(BUILD)/,,$(@))\n"
739 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
740
741# TODO: C++ files don't belong in vboot reference at all. Convert to C.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800742${BUILD}/%.o: %.cc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800743 @printf " CXX $(subst $(BUILD)/,,$(@))\n"
744 $(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
745
746# -----------------------------------------------------------------------------
747# Dependencies must come last after ALL_OBJS has been accumulated
748
749# TODO: I suspect this is missing some object files. Make a temp
750# target which cleans all known obj/exe's and see what's left; those
751# are the files which need deps.
752
753ALL_DEPS += $(ALL_OBJS:%.o=%.o.d)
754
755-include ${ALL_DEPS}