blob: 1086f83c20e5c3396f56fe76919ec92800100f59 [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
18
Simon Glassb265c342011-11-16 15:09:51 -080019# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
20# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070021#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080022# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
23# temporarily. As we are still investigating which flags are necessary for
24# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070025#
Simon Glassb265c342011-11-16 15:09:51 -080026# As a first step, this makes the setting of CC and CFLAGS here optional, to
27# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070028#
Simon Glassb265c342011-11-16 15:09:51 -080029# Flag ordering: arch, then -f, then -m, then -W
30DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
31COMMON_FLAGS := -nostdinc -pipe \
32 -ffreestanding -fno-builtin -fno-stack-protector \
33 -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS)
34
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070035ifeq ($(FIRMWARE_ARCH), arm)
Simon Glassb265c342011-11-16 15:09:51 -080036CC ?= armv7a-cros-linux-gnueabi-gcc
37CFLAGS ?= -march=armv5 \
38 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -070039 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Simon Glassb265c342011-11-16 15:09:51 -080040 $(COMMON_FLAGS)
Che-Liang Chiou74359b72011-06-21 15:25:51 -070041endif
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070042ifeq ($(FIRMWARE_ARCH), i386)
Simon Glassb265c342011-11-16 15:09:51 -080043CC ?= i686-pc-linux-gnu-gcc
44# Drop -march=i386 to permit use of SSE instructions
45CFLAGS ?= \
46 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
47 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
48 -mpreferred-stack-boundary=2 -mregparm=3 \
49 $(COMMON_FLAGS)
Che-Liang Chiou34be8272011-01-27 16:44:36 +080050endif
Simon Glass8e85e982011-11-22 13:54:50 -080051ifeq ($(FIRMWARE_ARCH), x86_64)
52CFLAGS ?= $(COMMON_FLAGS) \
53 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
54endif
Che-Liang Chiou34be8272011-01-27 16:44:36 +080055
Randall Spangler287beae2011-04-11 12:46:40 -070056# Fix compiling directly on host (outside of emake)
57ifeq ($(ARCH),)
Randall Spangler5d9bbf22013-01-08 10:44:23 -080058ARCH = amd64
Randall Spangler287beae2011-04-11 12:46:40 -070059endif
60
Randall Spangler5d9bbf22013-01-08 10:44:23 -080061# Some things only compile inside the Chromium OS chroot
62# TODO: is there a better way to detect this?
63ifneq ($(CROS_WORKON_SRCROOT),)
64IN_CHROOT = 1
65endif
66
67CC ?= gcc
68CXX ?= g++
69LD = $(CC)
70PKG_CONFIG ?= pkg-config
71
Che-Liang Chiou34be8272011-01-27 16:44:36 +080072ifeq ($(FIRMWARE_ARCH),)
Bill Richardsonf4729192012-05-02 23:30:16 -070073CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror
Che-Liang Chiou34be8272011-01-27 16:44:36 +080074endif
75
76ifneq (${DEBUG},)
77CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -070078endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080079
vbendebb2b0fcc2010-07-15 15:09:47 -070080ifeq (${DISABLE_NDEBUG},)
81CFLAGS += -DNDEBUG
82endif
83
Randall Spangler5d9bbf22013-01-08 10:44:23 -080084# Create / use dependency files
85CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -080086
Randall Spangler5d9bbf22013-01-08 10:44:23 -080087# Code coverage
88ifneq (${COV},)
89#COV_FLAGS = -O0 -fprofile-arcs -ftest-coverage
90COV_FLAGS = -O0 --coverage
91CFLAGS += $(COV_FLAGS)
92LDFLAGS += $(COV_FLAGS)
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080093endif
Gaurav Shah322536d2010-01-28 15:01:23 -080094
Randall Spangler5d9bbf22013-01-08 10:44:23 -080095INCLUDES += \
96 -Ifirmware/include \
97 -Ifirmware/lib/include \
98 -Ifirmware/lib/cgptlib/include \
99 -Ifirmware/lib/cryptolib/include \
100 -Ifirmware/lib/tpm_lite/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700101
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800102ifeq ($(FIRMWARE_ARCH),)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800103INCLUDES += -Ifirmware/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800104else
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800105INCLUDES += -Ifirmware/arch/$(FIRMWARE_ARCH)/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800106endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800107
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800108# Output libraries
109CGPTLIB := ${BUILD}/cgpt/libcgpt-cc.a
110DUMPKERNELCONFIGLIB := ${BUILD}/libdump_kernel_config.a
111FWLIB := ${BUILD}/vboot_fw.a
112HOSTLIB := ${BUILD}/vboot_host.a
113TEST_LIB := ${BUILD}/tests/test.a
Gaurav Shah322536d2010-01-28 15:01:23 -0800114
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800115CRYPTO_LIBS := $(shell $(PKG_CONFIG) --libs libcrypto)
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800116
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800117ifneq ($(IN_CHROOT),)
118PC_BASE_VER ?= 125070
119PC_DEPS = libchrome-$(PC_BASE_VER)
120PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
121PC_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
122endif
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800123
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800124# Link with hostlib and crypto libs by default
125LIBS = $(HOSTLIB)
126LDLIBS = $(CRYPTO_LIBS)
127
128# Create output directories if necessary. Do this via explicit shell commands
129# so it happens before trying to generate/include dependencies.
130SUBDIRS := firmware host utility cgpt tests tests/tpm_lite
131_dir_create := $(foreach d, \
132 $(shell find $(SUBDIRS) -name '*.c' -exec dirname {} \; | sort -u), \
133 $(shell [ -d $(BUILD)/$(d) ] || mkdir -p $(BUILD)/$(d)))
134
135# First target
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800136.PHONY: all
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800137all: fwlib $(if $(FIRMWARE_ARCH),,host_stuff)
138
139# Host targets
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800140.PHONY: host_stuff
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800141host_stuff: fwlib hostlib cgpt utils tests
Jay Srinivasan250549d2012-02-16 17:40:45 -0800142
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800143.PHONY: clean
Gaurav Shah322536d2010-01-28 15:01:23 -0800144clean:
Gabe Black0aedbe12012-12-20 00:26:59 -0800145 $(Q)/bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -0700146
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800147.PHONY: install
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800148install: cgpt_install utils_install
Gaurav Shahe6421982010-06-03 07:49:32 -0700149
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800150# Coverage
151COV_INFO = $(BUILD)/coverage.info
152#coverage: runtests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800153.PHONY: coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800154coverage:
155 rm -f $(COV_INFO)*
156 lcov --capture --directory . --base-directory . -o $(COV_INFO).1
157 lcov --remove $(COV_INFO).1 '/usr/*' -o $(COV_INFO)
158 genhtml $(COV_INFO) --output-directory $(BUILD)/coverage
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700159
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800160# Don't delete intermediate object files
161.SECONDARY:
Randall Spanglere8cfa312013-01-02 16:49:38 -0800162
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800163# Use second expansion phase for $$(LIBS) so dependencies on libraries are
164# properly evaluated for implicit rules.
165.SECONDEXPANSION:
Jay Srinivasan250549d2012-02-16 17:40:45 -0800166
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800167# -----------------------------------------------------------------------------
168# Firmware library
Bill Richardson856e0722011-02-07 15:39:45 -0800169
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800170# TPM-specific flags. These depend on the particular TPM we're targeting for.
171# They are needed here only for compiling parts of the firmware code into
172# user-level tests.
173
174# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
175# the self test has completed.
176
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800177$(FWLIB): CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800178
179# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
180# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
181# power on.
182#
183# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
184# are not both defined at the same time. (See comment in code.)
185
186# CFLAGS += -DTPM_MANUAL_SELFTEST
187
188ifeq ($(FIRMWARE_ARCH),i386)
189# Unrolling loops in cryptolib makes it faster
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800190$(FWLIB): CFLAGS += -DUNROLL_LOOPS
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800191
192# Workaround for coreboot on x86, which will power off asynchronously
193# without giving us a chance to react. This is not an example of the Right
194# Way to do things. See chrome-os-partner:7689, and the commit message
195# that made this change.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800196$(FWLIB): CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800197
198# On x86 we don't actually read the GBB data into RAM until it is needed.
199# Therefore it makes sense to cache it rather than reading it each time.
200# Enable this feature.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800201$(FWLIB): CFLAGS += -DCOPY_BMP_DATA
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800202endif
203
204ifeq ($(FIRMWARE_ARCH),)
205$(warning FIRMWARE_ARCH not defined; assuming local compile)
206
207# Disable rollback TPM when compiling locally, since otherwise
208# load_kernel_test attempts to talk to the TPM.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800209$(FWLIB): CFLAGS += -DDISABLE_ROLLBACK_TPM
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800210endif
211
212# find lib -iname '*.c' | sort
213FWLIB_SRCS = \
214 firmware/lib/cgptlib/cgptlib.c \
215 firmware/lib/cgptlib/cgptlib_internal.c \
216 firmware/lib/cgptlib/crc32.c \
217 firmware/lib/crc8.c \
218 firmware/lib/cryptolib/padding.c \
219 firmware/lib/cryptolib/rsa.c \
220 firmware/lib/cryptolib/rsa_utility.c \
221 firmware/lib/cryptolib/sha1.c \
222 firmware/lib/cryptolib/sha256.c \
223 firmware/lib/cryptolib/sha512.c \
224 firmware/lib/cryptolib/sha_utility.c \
225 firmware/lib/stateful_util.c \
226 firmware/lib/utility.c \
227 firmware/lib/utility_string.c \
228 firmware/lib/vboot_api_init.c \
229 firmware/lib/vboot_api_firmware.c \
230 firmware/lib/vboot_api_kernel.c \
231 firmware/lib/vboot_audio.c \
232 firmware/lib/vboot_common.c \
233 firmware/lib/vboot_display.c \
234 firmware/lib/vboot_firmware.c \
235 firmware/lib/vboot_kernel.c \
236 firmware/lib/vboot_nvstorage.c
237
238ifeq ($(MOCK_TPM),)
239FWLIB_SRCS += \
240 firmware/lib/rollback_index.c \
241 firmware/lib/tpm_bootmode.c \
242 firmware/lib/tpm_lite/tlcl.c
243else
244FWLIB_SRCS += \
245 firmware/lib/mocked_rollback_index.c \
246 firmware/lib/mocked_tpm_bootmode.c \
247 firmware/lib/tpm_lite/mocked_tlcl.c
248endif
249
250ifeq ($(FIRMWARE_ARCH),)
251# Include stub into firmware lib if compiling for host
252FWLIB_SRCS += \
253 firmware/stub/tpm_lite_stub.c \
254 firmware/stub/utility_stub.c \
255 firmware/stub/vboot_api_stub.c \
256 firmware/stub/vboot_api_stub_disk.c
257endif
258
259FWLIB_OBJS = $(FWLIB_SRCS:%.c=${BUILD}/%.o)
260ALL_OBJS += ${FWLIB_OBJS}
261
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800262.PHONY: fwlib
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800263ifeq ($(FIRMWARE_ARCH),)
264# Link test ensures firmware lib doesn't rely on outside libraries
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800265${BUILD}/firmware/linktest/main: LIBS = $(FWLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800266
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800267fwlib: ${BUILD}/firmware/linktest/main
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800268else
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800269fwlib: $(FWLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800270endif
271
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800272$(FWLIB): $(FWLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800273 @printf " RM $(subst $(BUILD)/,,$(@))\n"
274 $(Q)rm -f $@
275 @printf " AR $(subst $(BUILD)/,,$(@))\n"
276 $(Q)ar qc $@ $^
277
278# -----------------------------------------------------------------------------
279# Host library
280
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800281.PHONY: hostlib
282hostlib: $(HOSTLIB) ${BUILD}/host/linktest/main
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800283
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800284${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800285 -Ihost/include\
286 -Ihost/arch/$(ARCH)/include
287
288HOSTLIB_SRCS = \
289 host/arch/$(ARCH)/lib/crossystem_arch.c \
290 host/lib/crossystem.c \
291 host/lib/file_keys.c \
292 host/lib/fmap.c \
293 host/lib/host_common.c \
294 host/lib/host_key.c \
295 host/lib/host_keyblock.c \
296 host/lib/host_misc.c \
297 host/lib/host_signature.c \
298 host/lib/signature_digest.c
299
300HOSTLIB_OBJS = $(HOSTLIB_SRCS:%.c=${BUILD}/%.o)
301ALL_OBJS += ${HOSTLIB_OBJS}
302
303# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800304$(HOSTLIB): $(HOSTLIB_OBJS) $(FWLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800305 @printf " RM $(subst $(BUILD)/,,$(@))\n"
306 $(Q)rm -f $@
307 @printf " AR $(subst $(BUILD)/,,$(@))\n"
308 $(Q)ar qc $@ $^
309
310# -----------------------------------------------------------------------------
311# CGPT library and utility
312
313CGPT = ${BUILD}/cgpt/cgpt
314
315CGPT_SRCS = \
316 cgpt/cgpt.c \
317 cgpt/cgpt_add.c \
318 cgpt/cgpt_boot.c \
319 cgpt/cgpt_common.c \
320 cgpt/cgpt_create.c \
321 cgpt/cgpt_find.c \
322 cgpt/cgpt_legacy.c \
323 cgpt/cgpt_prioritize.c \
324 cgpt/cgpt_repair.c \
325 cgpt/cgpt_show.c \
326 cgpt/cmd_add.c \
327 cgpt/cmd_boot.c \
328 cgpt/cmd_create.c \
329 cgpt/cmd_find.c \
330 cgpt/cmd_legacy.c \
331 cgpt/cmd_prioritize.c \
332 cgpt/cmd_repair.c \
333 cgpt/cmd_show.c
334
335CGPT_OBJS = $(CGPT_SRCS:%.c=${BUILD}/%.o)
336ALL_OBJS += ${CGPT_OBJS}
337
338# TODO: why not make this include *all* the cgpt files, and simply have
339# cgpt link against it?
340# TODO: CgptManager.cc should move to the installer project. Shouldn't be
341# in libcgpt-cc.a.
342CGPTLIB_SRCS = \
343 cgpt/CgptManager.cc \
344 cgpt/cgpt_create.c \
345 cgpt/cgpt_add.c \
346 cgpt/cgpt_boot.c \
347 cgpt/cgpt_show.c \
348 cgpt/cgpt_repair.c \
349 cgpt/cgpt_prioritize.c \
350 cgpt/cgpt_common.c \
351 firmware/lib/cgptlib/crc32.c \
352 firmware/lib/cgptlib/cgptlib_internal.c \
353 firmware/stub/utility_stub.c
354
355CGPTLIB_OBJS = $(filter %.o, \
356 $(CGPTLIB_SRCS:%.c=${BUILD}/%.o) \
357 $(CGPTLIB_SRCS:%.cc=${BUILD}/%.o))
358ALL_OBJS += $(CGPTLIB_OBJS)
359
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800360.PHONY: cgpt
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800361cgpt: $(CGPT)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800362
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800363.PHONY: libcgpt_cc
364libcgpt_cc: $(CGPTLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800365
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800366$(CGPTLIB): INCLUDES += -Ifirmware/lib/cgptlib/include
367$(CGPTLIB): $(CGPTLIB_OBJS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800368 @printf " RM $(subst $(BUILD)/,,$(@))\n"
369 $(Q)rm -f $@
370 @printf " AR $(subst $(BUILD)/,,$(@))\n"
371 $(Q)ar qc $@ $^
372
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800373$(CGPT): INCLUDES += -Ifirmware/lib/cgptlib/include
374$(CGPT): LDLIBS = -luuid
375$(CGPT): LDFLAGS += -static
376$(CGPT): $(CGPT_OBJS) $$(LIBS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800377 @printf " LDcgpt $(subst $(BUILD)/,,$(@))\n"
378 $(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS)
379
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800380.PHONY: cgpt_install
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800381cgpt_install: $(CGPT)
382 mkdir -p $(DESTDIR)
383 cp -f $^ $(DESTDIR)
384 chmod a+rx $(patsubst ${BUILD}/cgpt/%,$(DESTDIR)/%,$^)
385
386# -----------------------------------------------------------------------------
387# Utilities
388
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800389${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
390${BUILD}/utility/%: CFLAGS += $(PC_CFLAGS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800391
392AU_NAMES = \
393 crossystem \
394 dump_fmap \
395 gbb_utility
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800396AU_BINS:= $(addprefix ${BUILD}/utility/,$(AU_NAMES))
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800397
398# Utilities for auto-update toolkits must be statically linked, and don't
399# use the crypto libs.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800400${AU_BINS}: LDFLAGS += -static
401${AU_BINS}: CRYPTO_LIBS =
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800402
403# Scripts to install
404UTIL_SCRIPTS = \
405 utility/dev_debug_vboot \
406 utility/dev_make_keypair \
407 utility/enable_dev_usb_boot \
408 utility/vbutil_what_keys
409
410UTIL_NAMES = $(AU_NAMES) \
411 dev_sign_file \
412 dump_kernel_config \
413 dumpRSAPublicKey \
414 load_kernel_test \
415 pad_digest_utility \
416 signature_digest_utility \
417 tpm_init_temp_fix \
418 tpmc \
419 vbutil_ec \
420 vbutil_firmware \
421 vbutil_kernel \
422 vbutil_key \
423 vbutil_keyblock \
424 verify_data
425
426ifneq ($(IN_CHROOT),)
427UTIL_NAMES += mount-encrypted
428endif
429
430ifeq ($(MINIMAL),)
431UTIL_NAMES += \
432 bmpblk_font \
433 bmpblk_utility \
434 eficompress \
435 efidecompress
436endif
437
438UTIL_BINS = $(addprefix ${BUILD}/utility/,$(UTIL_NAMES))
439ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
440
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800441.PHONY: utils
442utils: $(UTIL_BINS) $(UTIL_SCRIPTS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800443# TODO: change ebuild to pull scripts directly out of utility dir
444 $(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility
445 $(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS))
446
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800447.PHONY: utils_install
448utils_install: $(UTIL_BINS) $(UTIL_SCRIPTS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800449 mkdir -p $(DESTDIR)
450 cp -f $(UTIL_BINS) $(DESTDIR)
451 chmod a+rx $(patsubst %,$(DESTDIR)/%,$(UTIL_NAMES))
452 cp -f $(UTIL_SCRIPTS) $(DESTDIR)
453 chmod a+rx $(patsubst utility/%,$(DESTDIR)/%,$(UTIL_SCRIPTS))
454
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800455${BUILD}/utility/dump_kernel_config: LIBS += $(DUMPKERNELCONFIGLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800456
457# GBB utility needs C++ linker
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800458${BUILD}/utility/gbb_utility: LD = $(CXX)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800459
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800460${BUILD}/utility/bmpblk_utility: LD = $(CXX)
461${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
462${BUILD}/utility/bmpblk_utility: OBJS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800463 ${BUILD}/utility/bmpblk_util.o \
464 ${BUILD}/utility/image_types.o \
Randall Spangler17f8d342013-01-11 10:55:11 -0800465 ${BUILD}/utility/eficompress_for_lib.o \
466 ${BUILD}/utility/efidecompress_for_lib.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800467
468${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
469
470# TODO: fix load_firmware_test util; it never got refactored for the new APIs
471
472# -----------------------------------------------------------------------------
473# Mount-encrypted utility for cryptohome
474
475# TODO: mount-encrypted should move to cryptohome and just link against
476# vboot-host.a for tlcl and crossystem.
477
478# The embedded libcrypto conflicts with the shipped openssl,
479# so mount-* builds without the common CFLAGS (and those includes).
480
481${BUILD}/utility/mount-helpers.o: \
482 utility/mount-helpers.c \
483 utility/mount-helpers.h \
484 utility/mount-encrypted.h
485 @printf " CCm-e $(subst $(BUILD)/,,$(@))\n"
486 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
487 $(COV_FLAGS) \
488 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
489 -c $< -o $@
490
491${BUILD}/utility/mount-encrypted: \
492 utility/mount-encrypted.c \
493 utility/mount-encrypted.h \
494 ${BUILD}/utility/mount-helpers.o $$(LIBS)
495 @printf " CCm-exe $(subst $(BUILD)/,,$(@))\n"
496 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
497 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
498 -Ifirmware/include \
499 -Ihost/include \
500 $(COV_FLAGS) \
501 $(LDFLAGS) \
502 $< -o $@ \
503 ${BUILD}/utility/mount-helpers.o $(LIBS) \
504 $(shell $(PKG_CONFIG) --libs glib-2.0 openssl) \
505 -lm
506ifneq (${COV},)
507 $(Q)mv -f mount-encrypted.gcno ${BUILD}/utility
508endif
509
510# -----------------------------------------------------------------------------
511# Utility to generate TLCL structure definition header file.
512
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800513${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
514${BUILD}/utility/tlcl_generator: LIBS =
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800515
516STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
517STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
518
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800519.PHONY: update_tlcl_structures
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800520update_tlcl_structures: ${BUILD}/utility/tlcl_generator
521 @printf " Rebuilding TLCL structures\n"
522 $(Q)${BUILD}/utility/tlcl_generator > $(STRUCTURES_TMP)
523 $(Q)cmp -s $(STRUCTURES_TMP) $(STRUCTURES_SRC) || \
524 ( echo "%% Updating structures.h %%" && \
525 cp $(STRUCTURES_TMP) $(STRUCTURES_SRC) )
526
527# -----------------------------------------------------------------------------
528# Library to dump kernel config
Randall Spangler17f8d342013-01-11 10:55:11 -0800529# Used by platform/installer
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800530
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800531.PHONY: libdump_kernel_config
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800532libdump_kernel_config: $(DUMPKERNELCONFIGLIB)
533
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800534$(DUMPKERNELCONFIGLIB): ${BUILD}/utility/dump_kernel_config_lib.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800535 @printf " RM $(subst $(BUILD)/,,$(@))\n"
536 $(Q)rm -f $@
537 @printf " AR $(subst $(BUILD)/,,$(@))\n"
538 $(Q)ar qc $@ $^
539
540# -----------------------------------------------------------------------------
541# Tests
542
543# Allow multiple definitions, so tests can mock functions from other libraries
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800544${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
545${BUILD}/tests/%: INCLUDES += -Ihost/include
546${BUILD}/tests/%: LDLIBS += -lrt -luuid
547${BUILD}/tests/%: LIBS += $(TEST_LIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800548
549TEST_NAMES = \
550 cgptlib_test \
551 rollback_index2_tests \
552 rsa_padding_test \
553 rsa_utility_tests \
554 rsa_verify_benchmark \
555 sha_benchmark \
556 sha_tests \
557 stateful_util_tests \
558 tpm_bootmode_tests \
559 utility_string_tests \
560 utility_tests \
561 vboot_nvstorage_test \
562 vboot_api_init_tests \
563 vboot_api_devmode_tests \
564 vboot_api_firmware_tests \
565 vboot_api_kernel_tests \
566 vboot_audio_tests \
567 vboot_common_tests \
568 vboot_common2_tests \
569 vboot_common3_tests \
570 vboot_ec_tests \
571 vboot_firmware_tests
572
573ifneq ($(IN_CHROOT),)
574TEST_NAMES += CgptManagerTests
575endif
576
577TLCL_TEST_NAMES = \
Randall Spangler17f8d342013-01-11 10:55:11 -0800578 tpmtest_earlyextend \
579 tpmtest_earlynvram \
580 tpmtest_earlynvram2 \
581 tpmtest_enable \
582 tpmtest_fastenable \
583 tpmtest_globallock \
584 tpmtest_redefine_unowned \
585 tpmtest_spaceperm \
586 tpmtest_testsetup \
587 tpmtest_timing \
588 tpmtest_writelimit
589TEST_NAMES += $(addprefix tpm_lite/,$(TLCL_TEST_NAMES))
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800590
591TEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES))
592ALL_DEPS += $(addsuffix .d,${TEST_BINS})
593
Randall Spangler17f8d342013-01-11 10:55:11 -0800594.PHONY: tests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800595tests: $(TEST_BINS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800596
597${TEST_LIB}: \
598 ${BUILD}/tests/test_common.o \
599 ${BUILD}/tests/timer_utils.o \
600 ${BUILD}/tests/crc32_test.o
601 @printf " RM $(subst $(BUILD)/,,$(@))\n"
602 $(Q)rm -f $@
603 @printf " AR $(subst $(BUILD)/,,$(@))\n"
604 $(Q)ar qc $@ $^
605
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800606${BUILD}/tests/rollback_index2_tests: OBJS += \
Randall Spangler17f8d342013-01-11 10:55:11 -0800607 ${BUILD}/firmware/lib/rollback_index_for_test.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800608
609${BUILD}/tests/vboot_audio_tests: OBJS += \
Randall Spangler17f8d342013-01-11 10:55:11 -0800610 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800611
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800612.PHONY: cgptmanager_tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800613cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
614
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800615${BUILD}/tests/CgptManagerTests: CFLAGS += $(PC_CFLAGS)
616${BUILD}/tests/CgptManagerTests: LD = $(CXX)
617${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags $(PC_LDLIBS)
618${BUILD}/tests/CgptManagerTests: LIBS = $(CGPTLIB)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800619
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800620${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
621${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800622
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800623${BUILD}/tests/tpm_lite/tpmtest_%: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800624
625# TODO: port these tests to new API, if not already eqivalent
626# functionality in other tests. These don't even compile at present.
627#
628# big_firmware_tests
629# big_kernel_tests
630# firmware_image_tests
631# firmware_rollback_tests
632# firmware_splicing_tests
633# firmware_verify_benchmark
634# kernel_image_tests
635# kernel_rollback_tests
636# kernel_splicing_tests
637# kernel_verify_benchmark
638# rollback_index_test
639# verify_firmware_fuzz_driver
640# verify_kernel_fuzz_driver
641
642# -----------------------------------------------------------------------------
643# Targets to run tests
644
645# Frequently-run tests
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800646.PHONY: runtests
647runtests: runbmptests runcgpttests runfuzztests runmisctests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800648
649# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800650.PHONY: genkeys
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800651genkeys:
652 tests/gen_test_keys.sh
653
654# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800655.PHONY: genfuzztestcases
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800656genfuzztestcases:
657 tests/gen_fuzz_test_cases.sh
658
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800659.PHONY: runbmptests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800660runbmptests: utils
661 cd tests/bitmaps && BMPBLK=${BUILD}/utility/bmpblk_utility \
662 ./TestBmpBlock.py -v
663
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800664.PHONY: runcgpttests
665runcgpttests: cgpt tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800666 ${BUILD}/tests/cgptlib_test
667 tests/run_cgpt_tests.sh ${BUILD}/cgpt/cgpt
668ifneq ($(IN_CHROOT),)
669 ${BUILD}/tests/CgptManagerTests --v=1
670endif
671
672# Exercise vbutil_kernel and vbutil_firmware
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800673.PHONY: runfuzztests
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800674runfuzztests: genfuzztestcases utils tests
675 tests/run_preamble_tests.sh
676 tests/run_vbutil_kernel_arg_tests.sh
677
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800678.PHONY: runmisctests
679runmisctests: tests utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800680 ${BUILD}/tests/rollback_index2_tests
681 ${BUILD}/tests/rsa_utility_tests
682 ${BUILD}/tests/sha_tests
683 ${BUILD}/tests/stateful_util_tests
684 ${BUILD}/tests/tpm_bootmode_tests
685 ${BUILD}/tests/utility_string_tests
686 ${BUILD}/tests/utility_tests
687 ${BUILD}/tests/vboot_api_devmode_tests
688 ${BUILD}/tests/vboot_api_init_tests
689 ${BUILD}/tests/vboot_api_firmware_tests
690 ${BUILD}/tests/vboot_audio_tests
691 ${BUILD}/tests/vboot_firmware_tests
692 tests/run_rsa_tests.sh
693 tests/run_vboot_common_tests.sh
694 tests/run_vbutil_tests.sh
695
696# Run long tests, including all permutations of encryption keys (instead of
697# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
698# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800699.PHONY: runlongtests
700runlongtests: genkeys genfuzztestcases tests utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800701 tests/run_preamble_tests.sh --all
702 tests/run_vboot_common_tests.sh --all
703 tests/run_vboot_ec_tests.sh
704 tests/run_vbutil_tests.sh --all
705
706# TODO: tests to run when ported to new API
707# ./run_image_verification_tests.sh
708# # Splicing tests
709# ${BUILD}/tests/firmware_splicing_tests
710# ${BUILD}/tests/kernel_splicing_tests
711# # Rollback Tests
712# ${BUILD}/tests/firmware_rollback_tests
713# ${BUILD}/tests/kernel_rollback_tests
714
715# -----------------------------------------------------------------------------
716# Build rules
717
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800718${BUILD}/%: ${BUILD}/%.o $$(OBJS) $$(LIBS)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800719 @printf " LD $(subst $(BUILD)/,,$(@))\n"
720 $(Q)$(LD) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
721 $(LIBS) $(LDLIBS)
722
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800723${BUILD}/%.o: %.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800724 @printf " CC $(subst $(BUILD)/,,$(@))\n"
725 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
726
Randall Spangler17f8d342013-01-11 10:55:11 -0800727# Rules to recompile a single source file for library and test
728# TODO: is there a tidier way to do this?
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800729${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
730${BUILD}/%_for_lib.o: %.c
Randall Spangler17f8d342013-01-11 10:55:11 -0800731 @printf " CC-for-lib $(subst $(BUILD)/,,$(@))\n"
732 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800733${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
734${BUILD}/%_for_test.o: %.c
Randall Spangler17f8d342013-01-11 10:55:11 -0800735 @printf " CC-for-test $(subst $(BUILD)/,,$(@))\n"
736 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
737
738# TODO: C++ files don't belong in vboot reference at all. Convert to C.
Bill Richardsonacb2ee92013-01-11 22:53:00 -0800739${BUILD}/%.o: %.cc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800740 @printf " CXX $(subst $(BUILD)/,,$(@))\n"
741 $(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
742
743# -----------------------------------------------------------------------------
744# Dependencies must come last after ALL_OBJS has been accumulated
745
746# TODO: I suspect this is missing some object files. Make a temp
747# target which cleans all known obj/exe's and see what's left; those
748# are the files which need deps.
749
750ALL_DEPS += $(ALL_OBJS:%.o=%.o.d)
751
752-include ${ALL_DEPS}