blob: b9e47606f9d0af59c1ee5fedc869a4546995d184 [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
136all: fwlib $(if $(FIRMWARE_ARCH),,host_stuff)
137
138# Host targets
139host_stuff: fwlib hostlib cgpt utils tests
Jay Srinivasan250549d2012-02-16 17:40:45 -0800140
Gaurav Shah322536d2010-01-28 15:01:23 -0800141clean:
Gabe Black0aedbe12012-12-20 00:26:59 -0800142 $(Q)/bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -0700143
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800144install: cgpt_install utils_install
Gaurav Shahe6421982010-06-03 07:49:32 -0700145
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800146# Coverage
147COV_INFO = $(BUILD)/coverage.info
148#coverage: runtests
149coverage:
150 rm -f $(COV_INFO)*
151 lcov --capture --directory . --base-directory . -o $(COV_INFO).1
152 lcov --remove $(COV_INFO).1 '/usr/*' -o $(COV_INFO)
153 genhtml $(COV_INFO) --output-directory $(BUILD)/coverage
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700154
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800155# Don't delete intermediate object files
156.SECONDARY:
Randall Spanglere8cfa312013-01-02 16:49:38 -0800157
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800158# Use second expansion phase for $$(LIBS) so dependencies on libraries are
159# properly evaluated for implicit rules.
160.SECONDEXPANSION:
Jay Srinivasan250549d2012-02-16 17:40:45 -0800161
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800162# -----------------------------------------------------------------------------
163# Firmware library
Bill Richardson856e0722011-02-07 15:39:45 -0800164
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800165# TPM-specific flags. These depend on the particular TPM we're targeting for.
166# They are needed here only for compiling parts of the firmware code into
167# user-level tests.
168
169# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
170# the self test has completed.
171
172$(FWLIB) : CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
173
174# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
175# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
176# power on.
177#
178# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
179# are not both defined at the same time. (See comment in code.)
180
181# CFLAGS += -DTPM_MANUAL_SELFTEST
182
183ifeq ($(FIRMWARE_ARCH),i386)
184# Unrolling loops in cryptolib makes it faster
185$(FWLIB) : CFLAGS += -DUNROLL_LOOPS
186
187# Workaround for coreboot on x86, which will power off asynchronously
188# without giving us a chance to react. This is not an example of the Right
189# Way to do things. See chrome-os-partner:7689, and the commit message
190# that made this change.
191$(FWLIB) : CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
192
193# On x86 we don't actually read the GBB data into RAM until it is needed.
194# Therefore it makes sense to cache it rather than reading it each time.
195# Enable this feature.
196$(FWLIB) : CFLAGS += -DCOPY_BMP_DATA
197endif
198
199ifeq ($(FIRMWARE_ARCH),)
200$(warning FIRMWARE_ARCH not defined; assuming local compile)
201
202# Disable rollback TPM when compiling locally, since otherwise
203# load_kernel_test attempts to talk to the TPM.
204$(FWLIB) : CFLAGS += -DDISABLE_ROLLBACK_TPM
205endif
206
207# find lib -iname '*.c' | sort
208FWLIB_SRCS = \
209 firmware/lib/cgptlib/cgptlib.c \
210 firmware/lib/cgptlib/cgptlib_internal.c \
211 firmware/lib/cgptlib/crc32.c \
212 firmware/lib/crc8.c \
213 firmware/lib/cryptolib/padding.c \
214 firmware/lib/cryptolib/rsa.c \
215 firmware/lib/cryptolib/rsa_utility.c \
216 firmware/lib/cryptolib/sha1.c \
217 firmware/lib/cryptolib/sha256.c \
218 firmware/lib/cryptolib/sha512.c \
219 firmware/lib/cryptolib/sha_utility.c \
220 firmware/lib/stateful_util.c \
221 firmware/lib/utility.c \
222 firmware/lib/utility_string.c \
223 firmware/lib/vboot_api_init.c \
224 firmware/lib/vboot_api_firmware.c \
225 firmware/lib/vboot_api_kernel.c \
226 firmware/lib/vboot_audio.c \
227 firmware/lib/vboot_common.c \
228 firmware/lib/vboot_display.c \
229 firmware/lib/vboot_firmware.c \
230 firmware/lib/vboot_kernel.c \
231 firmware/lib/vboot_nvstorage.c
232
233ifeq ($(MOCK_TPM),)
234FWLIB_SRCS += \
235 firmware/lib/rollback_index.c \
236 firmware/lib/tpm_bootmode.c \
237 firmware/lib/tpm_lite/tlcl.c
238else
239FWLIB_SRCS += \
240 firmware/lib/mocked_rollback_index.c \
241 firmware/lib/mocked_tpm_bootmode.c \
242 firmware/lib/tpm_lite/mocked_tlcl.c
243endif
244
245ifeq ($(FIRMWARE_ARCH),)
246# Include stub into firmware lib if compiling for host
247FWLIB_SRCS += \
248 firmware/stub/tpm_lite_stub.c \
249 firmware/stub/utility_stub.c \
250 firmware/stub/vboot_api_stub.c \
251 firmware/stub/vboot_api_stub_disk.c
252endif
253
254FWLIB_OBJS = $(FWLIB_SRCS:%.c=${BUILD}/%.o)
255ALL_OBJS += ${FWLIB_OBJS}
256
257ifeq ($(FIRMWARE_ARCH),)
258# Link test ensures firmware lib doesn't rely on outside libraries
259${BUILD}/firmware/linktest/main : LIBS = $(FWLIB)
260
261fwlib : ${BUILD}/firmware/linktest/main
262else
263fwlib : $(FWLIB)
264endif
265
266$(FWLIB) : $(FWLIB_OBJS)
267 @printf " RM $(subst $(BUILD)/,,$(@))\n"
268 $(Q)rm -f $@
269 @printf " AR $(subst $(BUILD)/,,$(@))\n"
270 $(Q)ar qc $@ $^
271
272# -----------------------------------------------------------------------------
273# Host library
274
275hostlib : $(HOSTLIB) ${BUILD}/host/linktest/main
276
277${BUILD}/host/% ${HOSTLIB} : INCLUDES += \
278 -Ihost/include\
279 -Ihost/arch/$(ARCH)/include
280
281HOSTLIB_SRCS = \
282 host/arch/$(ARCH)/lib/crossystem_arch.c \
283 host/lib/crossystem.c \
284 host/lib/file_keys.c \
285 host/lib/fmap.c \
286 host/lib/host_common.c \
287 host/lib/host_key.c \
288 host/lib/host_keyblock.c \
289 host/lib/host_misc.c \
290 host/lib/host_signature.c \
291 host/lib/signature_digest.c
292
293HOSTLIB_OBJS = $(HOSTLIB_SRCS:%.c=${BUILD}/%.o)
294ALL_OBJS += ${HOSTLIB_OBJS}
295
296# TODO: better way to make .a than duplicating this recipe each time?
297$(HOSTLIB) : $(HOSTLIB_OBJS) $(FWLIB_OBJS)
298 @printf " RM $(subst $(BUILD)/,,$(@))\n"
299 $(Q)rm -f $@
300 @printf " AR $(subst $(BUILD)/,,$(@))\n"
301 $(Q)ar qc $@ $^
302
303# -----------------------------------------------------------------------------
304# CGPT library and utility
305
306CGPT = ${BUILD}/cgpt/cgpt
307
308CGPT_SRCS = \
309 cgpt/cgpt.c \
310 cgpt/cgpt_add.c \
311 cgpt/cgpt_boot.c \
312 cgpt/cgpt_common.c \
313 cgpt/cgpt_create.c \
314 cgpt/cgpt_find.c \
315 cgpt/cgpt_legacy.c \
316 cgpt/cgpt_prioritize.c \
317 cgpt/cgpt_repair.c \
318 cgpt/cgpt_show.c \
319 cgpt/cmd_add.c \
320 cgpt/cmd_boot.c \
321 cgpt/cmd_create.c \
322 cgpt/cmd_find.c \
323 cgpt/cmd_legacy.c \
324 cgpt/cmd_prioritize.c \
325 cgpt/cmd_repair.c \
326 cgpt/cmd_show.c
327
328CGPT_OBJS = $(CGPT_SRCS:%.c=${BUILD}/%.o)
329ALL_OBJS += ${CGPT_OBJS}
330
331# TODO: why not make this include *all* the cgpt files, and simply have
332# cgpt link against it?
333# TODO: CgptManager.cc should move to the installer project. Shouldn't be
334# in libcgpt-cc.a.
335CGPTLIB_SRCS = \
336 cgpt/CgptManager.cc \
337 cgpt/cgpt_create.c \
338 cgpt/cgpt_add.c \
339 cgpt/cgpt_boot.c \
340 cgpt/cgpt_show.c \
341 cgpt/cgpt_repair.c \
342 cgpt/cgpt_prioritize.c \
343 cgpt/cgpt_common.c \
344 firmware/lib/cgptlib/crc32.c \
345 firmware/lib/cgptlib/cgptlib_internal.c \
346 firmware/stub/utility_stub.c
347
348CGPTLIB_OBJS = $(filter %.o, \
349 $(CGPTLIB_SRCS:%.c=${BUILD}/%.o) \
350 $(CGPTLIB_SRCS:%.cc=${BUILD}/%.o))
351ALL_OBJS += $(CGPTLIB_OBJS)
352
353cgpt : $(CGPT)
354.PHONY: cgpt
355
356libcgpt_cc : $(CGPTLIB)
357
358$(CGPTLIB) : INCLUDES += -Ifirmware/lib/cgptlib/include
359$(CGPTLIB) : $(CGPTLIB_OBJS)
360 @printf " RM $(subst $(BUILD)/,,$(@))\n"
361 $(Q)rm -f $@
362 @printf " AR $(subst $(BUILD)/,,$(@))\n"
363 $(Q)ar qc $@ $^
364
365$(CGPT) : INCLUDES += -Ifirmware/lib/cgptlib/include
366$(CGPT) : LDLIBS = -luuid
367$(CGPT) : LDFLAGS += -static
368$(CGPT) : $(CGPT_OBJS) $$(LIBS)
369 @printf " LDcgpt $(subst $(BUILD)/,,$(@))\n"
370 $(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS)
371
372cgpt_install: $(CGPT)
373 mkdir -p $(DESTDIR)
374 cp -f $^ $(DESTDIR)
375 chmod a+rx $(patsubst ${BUILD}/cgpt/%,$(DESTDIR)/%,$^)
376
377# -----------------------------------------------------------------------------
378# Utilities
379
380${BUILD}/utility/% : INCLUDES += -Ihost/include -Iutility/include
381${BUILD}/utility/% : CFLAGS += $(PC_CFLAGS)
382
383AU_NAMES = \
384 crossystem \
385 dump_fmap \
386 gbb_utility
387AU_BINS := $(addprefix ${BUILD}/utility/,$(AU_NAMES))
388
389# Utilities for auto-update toolkits must be statically linked, and don't
390# use the crypto libs.
391${AU_BINS} : LDFLAGS += -static
392${AU_BINS} : CRYPTO_LIBS =
393
394# Scripts to install
395UTIL_SCRIPTS = \
396 utility/dev_debug_vboot \
397 utility/dev_make_keypair \
398 utility/enable_dev_usb_boot \
399 utility/vbutil_what_keys
400
401UTIL_NAMES = $(AU_NAMES) \
402 dev_sign_file \
403 dump_kernel_config \
404 dumpRSAPublicKey \
405 load_kernel_test \
406 pad_digest_utility \
407 signature_digest_utility \
408 tpm_init_temp_fix \
409 tpmc \
410 vbutil_ec \
411 vbutil_firmware \
412 vbutil_kernel \
413 vbutil_key \
414 vbutil_keyblock \
415 verify_data
416
417ifneq ($(IN_CHROOT),)
418UTIL_NAMES += mount-encrypted
419endif
420
421ifeq ($(MINIMAL),)
422UTIL_NAMES += \
423 bmpblk_font \
424 bmpblk_utility \
425 eficompress \
426 efidecompress
427endif
428
429UTIL_BINS = $(addprefix ${BUILD}/utility/,$(UTIL_NAMES))
430ALL_DEPS += $(addsuffix .d,${UTIL_BINS})
431
432utils : $(UTIL_BINS) $(UTIL_SCRIPTS)
433# TODO: change ebuild to pull scripts directly out of utility dir
434 $(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility
435 $(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS))
436
437utils_install : $(UTIL_BINS) $(UTIL_SCRIPTS)
438 mkdir -p $(DESTDIR)
439 cp -f $(UTIL_BINS) $(DESTDIR)
440 chmod a+rx $(patsubst %,$(DESTDIR)/%,$(UTIL_NAMES))
441 cp -f $(UTIL_SCRIPTS) $(DESTDIR)
442 chmod a+rx $(patsubst utility/%,$(DESTDIR)/%,$(UTIL_SCRIPTS))
443
444${BUILD}/utility/dump_kernel_config : LIBS += $(DUMPKERNELCONFIGLIB)
445${BUILD}/utility/dump_kernel_config : $$(LIBS) \
446 ${BUILD}/utility/dump_kernel_config_main.o
447 @printf " LDdkc $(subst $(BUILD)/,,$(@))\n"
448 $(Q)$(LD) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
449
450# TODO: these build as both standalone utils and libs. Make standalone the
451# default so this is less crufty.
452${BUILD}/utility/eficompress.o : CFLAGS += -DSTANDALONE
453${BUILD}/utility/efidecompress.o : CFLAGS += -DSTANDALONE
454
455${BUILD}/utility/eficompress_lib.o : utility/eficompress.c
456 @printf " CC $(subst $(BUILD)/,,$(@))\n"
457 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
458${BUILD}/utility/efidecompress_lib.o : utility/efidecompress.c
459 @printf " CC $(subst $(BUILD)/,,$(@))\n"
460 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
461
462# GBB utility needs C++ linker
463${BUILD}/utility/gbb_utility : LD = $(CXX)
464${BUILD}/utility/gbb_utility : CFLAGS += -DWITH_UTIL_MAIN
465
466${BUILD}/utility/crossystem : ${BUILD}/utility/crossystem_main.o $$(LIBS)
467 @printf " LDcr $(subst $(BUILD)/,,$(@))\n"
468 $(Q)$(LD) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LIBS) $(LDLIBS)
469
470# TODO: Why isn't this the default? It's the only time this file is compiled.
471# (gbb_utility, too)
472${BUILD}/utility/bmpblk_utility.o : CFLAGS += -DWITH_UTIL_MAIN
473
474${BUILD}/utility/bmpblk_utility : LD = $(CXX)
475${BUILD}/utility/bmpblk_utility : LDLIBS = -llzma -lyaml
476${BUILD}/utility/bmpblk_utility : OBJS = \
477 ${BUILD}/utility/bmpblk_util.o \
478 ${BUILD}/utility/image_types.o \
479 ${BUILD}/utility/eficompress_lib.o \
480 ${BUILD}/utility/efidecompress_lib.o
481
482${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
483
484# TODO: fix load_firmware_test util; it never got refactored for the new APIs
485
486# -----------------------------------------------------------------------------
487# Mount-encrypted utility for cryptohome
488
489# TODO: mount-encrypted should move to cryptohome and just link against
490# vboot-host.a for tlcl and crossystem.
491
492# The embedded libcrypto conflicts with the shipped openssl,
493# so mount-* builds without the common CFLAGS (and those includes).
494
495${BUILD}/utility/mount-helpers.o: \
496 utility/mount-helpers.c \
497 utility/mount-helpers.h \
498 utility/mount-encrypted.h
499 @printf " CCm-e $(subst $(BUILD)/,,$(@))\n"
500 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
501 $(COV_FLAGS) \
502 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
503 -c $< -o $@
504
505${BUILD}/utility/mount-encrypted: \
506 utility/mount-encrypted.c \
507 utility/mount-encrypted.h \
508 ${BUILD}/utility/mount-helpers.o $$(LIBS)
509 @printf " CCm-exe $(subst $(BUILD)/,,$(@))\n"
510 $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
511 $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
512 -Ifirmware/include \
513 -Ihost/include \
514 $(COV_FLAGS) \
515 $(LDFLAGS) \
516 $< -o $@ \
517 ${BUILD}/utility/mount-helpers.o $(LIBS) \
518 $(shell $(PKG_CONFIG) --libs glib-2.0 openssl) \
519 -lm
520ifneq (${COV},)
521 $(Q)mv -f mount-encrypted.gcno ${BUILD}/utility
522endif
523
524# -----------------------------------------------------------------------------
525# Utility to generate TLCL structure definition header file.
526
527${BUILD}/utility/tlcl_generator : CFLAGS += -fpack-struct
528${BUILD}/utility/tlcl_generator : LIBS =
529
530STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
531STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
532
533update_tlcl_structures: ${BUILD}/utility/tlcl_generator
534 @printf " Rebuilding TLCL structures\n"
535 $(Q)${BUILD}/utility/tlcl_generator > $(STRUCTURES_TMP)
536 $(Q)cmp -s $(STRUCTURES_TMP) $(STRUCTURES_SRC) || \
537 ( echo "%% Updating structures.h %%" && \
538 cp $(STRUCTURES_TMP) $(STRUCTURES_SRC) )
539
540# -----------------------------------------------------------------------------
541# Library to dump kernel config
542
543libdump_kernel_config: $(DUMPKERNELCONFIGLIB)
544
545$(DUMPKERNELCONFIGLIB) : ${BUILD}/utility/dump_kernel_config.o
546 @printf " RM $(subst $(BUILD)/,,$(@))\n"
547 $(Q)rm -f $@
548 @printf " AR $(subst $(BUILD)/,,$(@))\n"
549 $(Q)ar qc $@ $^
550
551# -----------------------------------------------------------------------------
552# Tests
553
554# Allow multiple definitions, so tests can mock functions from other libraries
555${BUILD}/tests/% : CFLAGS += -Xlinker --allow-multiple-definition
556${BUILD}/tests/% : INCLUDES += -Ihost/include
557${BUILD}/tests/% : LDLIBS += -lrt -luuid
558${BUILD}/tests/% : LIBS += $(TEST_LIB)
559
560TEST_NAMES = \
561 cgptlib_test \
562 rollback_index2_tests \
563 rsa_padding_test \
564 rsa_utility_tests \
565 rsa_verify_benchmark \
566 sha_benchmark \
567 sha_tests \
568 stateful_util_tests \
569 tpm_bootmode_tests \
570 utility_string_tests \
571 utility_tests \
572 vboot_nvstorage_test \
573 vboot_api_init_tests \
574 vboot_api_devmode_tests \
575 vboot_api_firmware_tests \
576 vboot_api_kernel_tests \
577 vboot_audio_tests \
578 vboot_common_tests \
579 vboot_common2_tests \
580 vboot_common3_tests \
581 vboot_ec_tests \
582 vboot_firmware_tests
583
584ifneq ($(IN_CHROOT),)
585TEST_NAMES += CgptManagerTests
586endif
587
588TLCL_TEST_NAMES = \
589 earlyextend \
590 earlynvram \
591 earlynvram2 \
592 enable \
593 fastenable \
594 globallock \
595 redefine_unowned \
596 spaceperm \
597 testsetup \
598 timing \
599 writelimit
600TEST_NAMES += $(addprefix tpm_lite/tpmtest_,$(TLCL_TEST_NAMES))
601
602TEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES))
603ALL_DEPS += $(addsuffix .d,${TEST_BINS})
604
605tests : $(TEST_BINS)
606
607${TEST_LIB}: \
608 ${BUILD}/tests/test_common.o \
609 ${BUILD}/tests/timer_utils.o \
610 ${BUILD}/tests/crc32_test.o
611 @printf " RM $(subst $(BUILD)/,,$(@))\n"
612 $(Q)rm -f $@
613 @printf " AR $(subst $(BUILD)/,,$(@))\n"
614 $(Q)ar qc $@ $^
615
616# Compile rollback_index.c for unit test, so it uses the same implementation
617# as it does in the firmware.
618${BUILD}/tests/rollback_index_for_test.o : CFLAGS += -DROLLBACK_UNITTEST
619${BUILD}/tests/rollback_index_for_test.o : firmware/lib/rollback_index.c
620 @printf " CC $(subst $(BUILD)/,,$(@))\n"
621 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
622
623${BUILD}/tests/rollback_index2_tests: OBJS += \
624 ${BUILD}/tests/rollback_index_for_test.o
625
626${BUILD}/tests/vboot_audio_for_test.o : CFLAGS += -DCUSTOM_MUSIC
627${BUILD}/tests/vboot_audio_for_test.o : firmware/lib/vboot_audio.c
628 @printf " CC $(subst $(BUILD)/,,$(@))\n"
629 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
630
631${BUILD}/tests/vboot_audio_tests: OBJS += \
632 ${BUILD}/tests/vboot_audio_for_test.o \
633
634cgptmanager_tests: ${BUILD}/tests/CgptManagerTests
635
636${BUILD}/tests/CgptManagerTests : CFLAGS += -DWITH_UTIL_MAIN $(PC_CFLAGS)
637${BUILD}/tests/CgptManagerTests : LD = $(CXX)
638${BUILD}/tests/CgptManagerTests : LDLIBS += -lgtest -lgflags $(PC_LDLIBS)
639${BUILD}/tests/CgptManagerTests : LIBS = $(CGPTLIB)
640
641${BUILD}/tests/rollback_index_test.o : INCLUDES += -I/usr/include
642${BUILD}/tests/rollback_index_test : LIBS += -ltlcl
643
644# TPM tests have special naming
645# TODO: rename .c files to match test names
646${BUILD}/tests/tpm_lite/tpmtest_% : OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
647${BUILD}/tests/tpm_lite/tpmtest_% : ${BUILD}/tests/tpm_lite/%.o $$(OBJS) \
648 $$(LIBS)
649 @printf " LDtpm $(subst $(BUILD)/,,$(@))\n"
650 $(Q)$(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
651 $(LIBS) $(LDLIBS)
652
653# TODO: port these tests to new API, if not already eqivalent
654# functionality in other tests. These don't even compile at present.
655#
656# big_firmware_tests
657# big_kernel_tests
658# firmware_image_tests
659# firmware_rollback_tests
660# firmware_splicing_tests
661# firmware_verify_benchmark
662# kernel_image_tests
663# kernel_rollback_tests
664# kernel_splicing_tests
665# kernel_verify_benchmark
666# rollback_index_test
667# verify_firmware_fuzz_driver
668# verify_kernel_fuzz_driver
669
670# -----------------------------------------------------------------------------
671# Targets to run tests
672
673# Frequently-run tests
674runtests : runbmptests runcgpttests runfuzztests runmisctests
675
676# Generate test keys
677genkeys:
678 tests/gen_test_keys.sh
679
680# Generate test cases for fuzzing
681genfuzztestcases:
682 tests/gen_fuzz_test_cases.sh
683
684runbmptests: utils
685 cd tests/bitmaps && BMPBLK=${BUILD}/utility/bmpblk_utility \
686 ./TestBmpBlock.py -v
687
688runcgpttests : cgpt tests
689 ${BUILD}/tests/cgptlib_test
690 tests/run_cgpt_tests.sh ${BUILD}/cgpt/cgpt
691ifneq ($(IN_CHROOT),)
692 ${BUILD}/tests/CgptManagerTests --v=1
693endif
694
695# Exercise vbutil_kernel and vbutil_firmware
696runfuzztests: genfuzztestcases utils tests
697 tests/run_preamble_tests.sh
698 tests/run_vbutil_kernel_arg_tests.sh
699
700runmisctests : tests utils
701 ${BUILD}/tests/rollback_index2_tests
702 ${BUILD}/tests/rsa_utility_tests
703 ${BUILD}/tests/sha_tests
704 ${BUILD}/tests/stateful_util_tests
705 ${BUILD}/tests/tpm_bootmode_tests
706 ${BUILD}/tests/utility_string_tests
707 ${BUILD}/tests/utility_tests
708 ${BUILD}/tests/vboot_api_devmode_tests
709 ${BUILD}/tests/vboot_api_init_tests
710 ${BUILD}/tests/vboot_api_firmware_tests
711 ${BUILD}/tests/vboot_audio_tests
712 ${BUILD}/tests/vboot_firmware_tests
713 tests/run_rsa_tests.sh
714 tests/run_vboot_common_tests.sh
715 tests/run_vbutil_tests.sh
716
717# Run long tests, including all permutations of encryption keys (instead of
718# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
719# Not run by automated build.
720runlongtests : genkeys genfuzztestcases tests utils
721 tests/run_preamble_tests.sh --all
722 tests/run_vboot_common_tests.sh --all
723 tests/run_vboot_ec_tests.sh
724 tests/run_vbutil_tests.sh --all
725
726# TODO: tests to run when ported to new API
727# ./run_image_verification_tests.sh
728# # Splicing tests
729# ${BUILD}/tests/firmware_splicing_tests
730# ${BUILD}/tests/kernel_splicing_tests
731# # Rollback Tests
732# ${BUILD}/tests/firmware_rollback_tests
733# ${BUILD}/tests/kernel_rollback_tests
734
735# -----------------------------------------------------------------------------
736# Build rules
737
738${BUILD}/% : ${BUILD}/%.o $$(OBJS) $$(LIBS)
739 @printf " LD $(subst $(BUILD)/,,$(@))\n"
740 $(Q)$(LD) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
741 $(LIBS) $(LDLIBS)
742
743${BUILD}/%.o : %.c
744 @printf " CC $(subst $(BUILD)/,,$(@))\n"
745 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
746
747${BUILD}/%.o : %.cc
748 @printf " CXX $(subst $(BUILD)/,,$(@))\n"
749 $(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
750
751# -----------------------------------------------------------------------------
752# Dependencies must come last after ALL_OBJS has been accumulated
753
754# TODO: I suspect this is missing some object files. Make a temp
755# target which cleans all known obj/exe's and see what's left; those
756# are the files which need deps.
757
758ALL_DEPS += $(ALL_OBJS:%.o=%.o.d)
759
760-include ${ALL_DEPS}