Randall Spangler | e8cfa31 | 2013-01-02 16:49:38 -0800 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 5 | ifneq ($(V),1) |
| 6 | Q := @ |
| 7 | endif |
| 8 | |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 9 | # This Makefile normally builds in a 'build' subdir, but use |
| 10 | # |
| 11 | # make BUILD=<dir> |
| 12 | # |
| 13 | # to put the output somewhere else |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 14 | BUILD ?= $(shell pwd)/build |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 15 | export BUILD |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 16 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 17 | # Target for 'make install' |
| 18 | DESTDIR ?= /usr/bin |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 19 | INSTALL ?= install |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 20 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 21 | # Provide default CC and CFLAGS for firmware builds; if you have any -D flags, |
| 22 | # please add them after this point (e.g., -DVBOOT_DEBUG). |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 23 | # |
Che-Liang Chiou | 6b0003c | 2011-10-14 11:11:28 +0800 | [diff] [blame] | 24 | # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just |
| 25 | # temporarily. As we are still investigating which flags are necessary for |
| 26 | # maintaining a compatible ABI, etc. between u-boot and vboot_reference. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 27 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 28 | # As a first step, this makes the setting of CC and CFLAGS here optional, to |
| 29 | # permit a calling script or Makefile to set these. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 30 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 31 | # Flag ordering: arch, then -f, then -m, then -W |
| 32 | DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os) |
| 33 | COMMON_FLAGS := -nostdinc -pipe \ |
| 34 | -ffreestanding -fno-builtin -fno-stack-protector \ |
| 35 | -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS) |
| 36 | |
Che-Liang Chiou | 7604a7d | 2011-06-21 17:40:34 -0700 | [diff] [blame] | 37 | ifeq ($(FIRMWARE_ARCH), arm) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 38 | CC ?= armv7a-cros-linux-gnueabi-gcc |
| 39 | CFLAGS ?= -march=armv5 \ |
| 40 | -fno-common -ffixed-r8 \ |
Doug Anderson | d50b27d | 2012-05-11 12:08:02 -0700 | [diff] [blame] | 41 | -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \ |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 42 | $(COMMON_FLAGS) |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 43 | else ifeq ($(FIRMWARE_ARCH), i386) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 44 | CC ?= i686-pc-linux-gnu-gcc |
| 45 | # Drop -march=i386 to permit use of SSE instructions |
| 46 | CFLAGS ?= \ |
| 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) |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 51 | else ifeq ($(FIRMWARE_ARCH), x86_64) |
Simon Glass | 8e85e98 | 2011-11-22 13:54:50 -0800 | [diff] [blame] | 52 | CFLAGS ?= $(COMMON_FLAGS) \ |
| 53 | -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 54 | else |
| 55 | $(info FIRMWARE_ARCH not defined; assuming local compile.) |
Simon Glass | 8e85e98 | 2011-11-22 13:54:50 -0800 | [diff] [blame] | 56 | endif |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 57 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 58 | # Architecture detection |
| 59 | HOST_ARCH ?= $(shell uname -m) |
| 60 | |
| 61 | # Pick a sane target architecture if none defined (building outside emake) |
Randall Spangler | 287beae | 2011-04-11 12:46:40 -0700 | [diff] [blame] | 62 | ifeq ($(ARCH),) |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 63 | ARCH := $(HOST_ARCH) |
| 64 | ifeq ($(ARCH), x86_64) |
| 65 | ARCH := amd64 |
| 66 | endif |
| 67 | endif |
| 68 | |
| 69 | # Determine QEMU architecture needed, if any |
| 70 | ifeq ($(ARCH),$(HOST_ARCH)) |
| 71 | # Same architecture; no need for QEMU |
| 72 | QEMU_ARCH := |
| 73 | else ifeq ($(HOST_ARCH)-$(ARCH),x86_64-i386) |
| 74 | # 64-bit host can run 32-bit targets directly |
| 75 | QEMU_ARCH := |
| 76 | else ifeq ($(HOST_ARCH)-$(ARCH),x86_64-amd64) |
| 77 | # 64-bit host can run 64-bit directly |
| 78 | QEMU_ARCH := |
| 79 | else ifeq ($(ARCH),amd64) |
| 80 | QEMU_ARCH := x86_64 |
| 81 | else |
| 82 | QEMU_ARCH := $(ARCH) |
| 83 | endif |
| 84 | |
| 85 | # The top of the chroot for qemu must be passed in via the SYSROOT environment |
| 86 | # variable. In the Chromium OS chroot, this is done automatically by the |
| 87 | # ebuild. |
| 88 | |
| 89 | # If SYSROOT is not defined, disable QEMU testing |
| 90 | # TODO: which probably means attempting to test should simply fail |
| 91 | ifneq ($(QEMU_ARCH),) |
| 92 | ifeq ($(SYSROOT),) |
| 93 | $(warning SYSROOT must be set to the top of the target-specific root \ |
| 94 | when cross-compiling for qemu-based tests to run properly.) |
| 95 | QEMU_ARCH := |
| 96 | endif |
| 97 | endif |
| 98 | |
| 99 | ifeq ($(QEMU_ARCH),) |
| 100 | # Path to build output for running tests is same as for building |
| 101 | BUILD_RUN = $(BUILD) |
| 102 | else |
| 103 | $(info Using qemu for testing.) |
| 104 | # Path to build output for running tests is different in the chroot |
| 105 | BUILD_RUN = $(subst $(SYSROOT),,$(BUILD)) |
| 106 | |
| 107 | QEMU_BIN = qemu-$(QEMU_ARCH) |
| 108 | QEMU_OPTS = -drop-ld-preload \ |
| 109 | -E LD_LIBRARY_PATH=/lib64:/lib:/usr/lib64:/usr/lib \ |
| 110 | -E HOME=$(HOME) \ |
| 111 | -E BUILD=$(BUILD_RUN) |
| 112 | QEMU_CMD = sudo chroot $(SYSROOT) $(BUILD_RUN)/$(QEMU_BIN) $(QEMU_OPTS) -- |
| 113 | RUNTEST = $(QEMU_CMD) |
Randall Spangler | 287beae | 2011-04-11 12:46:40 -0700 | [diff] [blame] | 114 | endif |
| 115 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 116 | # Some things only compile inside the Chromium OS chroot |
| 117 | # TODO: is there a better way to detect this? |
| 118 | ifneq ($(CROS_WORKON_SRCROOT),) |
| 119 | IN_CHROOT = 1 |
| 120 | endif |
| 121 | |
| 122 | CC ?= gcc |
| 123 | CXX ?= g++ |
| 124 | LD = $(CC) |
| 125 | PKG_CONFIG ?= pkg-config |
| 126 | |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 127 | ifeq ($(FIRMWARE_ARCH),) |
Bill Richardson | f472919 | 2012-05-02 23:30:16 -0700 | [diff] [blame] | 128 | CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 129 | endif |
| 130 | |
| 131 | ifneq (${DEBUG},) |
| 132 | CFLAGS += -DVBOOT_DEBUG |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 133 | endif |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 134 | |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 135 | ifeq (${DISABLE_NDEBUG},) |
| 136 | CFLAGS += -DNDEBUG |
| 137 | endif |
| 138 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 139 | # Create / use dependency files |
| 140 | CFLAGS += -MMD -MF $@.d |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 141 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 142 | # Code coverage |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 143 | # Run like this: COV=1 make runtests coverage |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 144 | ifneq (${COV},) |
| 145 | #COV_FLAGS = -O0 -fprofile-arcs -ftest-coverage |
| 146 | COV_FLAGS = -O0 --coverage |
| 147 | CFLAGS += $(COV_FLAGS) |
| 148 | LDFLAGS += $(COV_FLAGS) |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 149 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 150 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 151 | INCLUDES += \ |
| 152 | -Ifirmware/include \ |
| 153 | -Ifirmware/lib/include \ |
| 154 | -Ifirmware/lib/cgptlib/include \ |
| 155 | -Ifirmware/lib/cryptolib/include \ |
| 156 | -Ifirmware/lib/tpm_lite/include |
Bill Richardson | 0b8f35c | 2010-05-26 09:18:38 -0700 | [diff] [blame] | 157 | |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 158 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 159 | INCLUDES += -Ifirmware/stub/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 160 | else |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 161 | INCLUDES += -Ifirmware/arch/$(FIRMWARE_ARCH)/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 162 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 163 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 164 | # Output libraries |
| 165 | CGPTLIB := ${BUILD}/cgpt/libcgpt-cc.a |
| 166 | DUMPKERNELCONFIGLIB := ${BUILD}/libdump_kernel_config.a |
| 167 | FWLIB := ${BUILD}/vboot_fw.a |
| 168 | HOSTLIB := ${BUILD}/vboot_host.a |
| 169 | TEST_LIB := ${BUILD}/tests/test.a |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 170 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 171 | CRYPTO_LIBS := $(shell $(PKG_CONFIG) --libs libcrypto) |
Jay Srinivasan | 5fac757 | 2012-02-23 10:59:01 -0800 | [diff] [blame] | 172 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 173 | ifneq ($(IN_CHROOT),) |
| 174 | PC_BASE_VER ?= 125070 |
| 175 | PC_DEPS = libchrome-$(PC_BASE_VER) |
| 176 | PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS)) |
| 177 | PC_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS)) |
| 178 | endif |
Jay Srinivasan | 5fac757 | 2012-02-23 10:59:01 -0800 | [diff] [blame] | 179 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 180 | # Link with hostlib and crypto libs by default |
| 181 | LIBS = $(HOSTLIB) |
| 182 | LDLIBS = $(CRYPTO_LIBS) |
| 183 | |
| 184 | # Create output directories if necessary. Do this via explicit shell commands |
| 185 | # so it happens before trying to generate/include dependencies. |
| 186 | SUBDIRS := firmware host utility cgpt tests tests/tpm_lite |
| 187 | _dir_create := $(foreach d, \ |
| 188 | $(shell find $(SUBDIRS) -name '*.c' -exec dirname {} \; | sort -u), \ |
| 189 | $(shell [ -d $(BUILD)/$(d) ] || mkdir -p $(BUILD)/$(d))) |
| 190 | |
| 191 | # First target |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 192 | .PHONY: all |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 193 | all: fwlib $(if $(FIRMWARE_ARCH),,host_stuff) |
| 194 | |
| 195 | # Host targets |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 196 | .PHONY: host_stuff |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 197 | host_stuff: fwlib hostlib cgpt utils tests |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 198 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 199 | .PHONY: clean |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 200 | clean: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 201 | $(Q)/bin/rm -rf ${BUILD} |
Bill Richardson | 371df8b | 2010-05-27 14:19:47 -0700 | [diff] [blame] | 202 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 203 | .PHONY: install |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 204 | install: cgpt_install utils_install |
Gaurav Shah | e642198 | 2010-06-03 07:49:32 -0700 | [diff] [blame] | 205 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 206 | # Coverage |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 207 | # TODO: only if COV=1 |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 208 | COV_INFO = $(BUILD)/coverage.info |
| 209 | #coverage: runtests |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 210 | .PHONY: coverage |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 211 | coverage: |
| 212 | rm -f $(COV_INFO)* |
| 213 | lcov --capture --directory . --base-directory . -o $(COV_INFO).1 |
| 214 | lcov --remove $(COV_INFO).1 '/usr/*' -o $(COV_INFO) |
| 215 | genhtml $(COV_INFO) --output-directory $(BUILD)/coverage |
Luigi Semenzato | 18b814d | 2010-07-08 17:17:02 -0700 | [diff] [blame] | 216 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 217 | # Don't delete intermediate object files |
| 218 | .SECONDARY: |
Randall Spangler | e8cfa31 | 2013-01-02 16:49:38 -0800 | [diff] [blame] | 219 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 220 | # Use second expansion phase for $$(LIBS) so dependencies on libraries are |
| 221 | # properly evaluated for implicit rules. |
| 222 | .SECONDEXPANSION: |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 223 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 224 | # ----------------------------------------------------------------------------- |
| 225 | # Firmware library |
Bill Richardson | 856e072 | 2011-02-07 15:39:45 -0800 | [diff] [blame] | 226 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 227 | # TPM-specific flags. These depend on the particular TPM we're targeting for. |
| 228 | # They are needed here only for compiling parts of the firmware code into |
| 229 | # user-level tests. |
| 230 | |
| 231 | # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until |
| 232 | # the self test has completed. |
| 233 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 234 | $(FWLIB): CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 235 | |
| 236 | # TPM_MANUAL_SELFTEST is defined if the self test must be started manually |
| 237 | # (with a call to TPM_ContinueSelfTest) instead of starting automatically at |
| 238 | # power on. |
| 239 | # |
| 240 | # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST |
| 241 | # are not both defined at the same time. (See comment in code.) |
| 242 | |
| 243 | # CFLAGS += -DTPM_MANUAL_SELFTEST |
| 244 | |
| 245 | ifeq ($(FIRMWARE_ARCH),i386) |
| 246 | # Unrolling loops in cryptolib makes it faster |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 247 | $(FWLIB): CFLAGS += -DUNROLL_LOOPS |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 248 | |
| 249 | # Workaround for coreboot on x86, which will power off asynchronously |
| 250 | # without giving us a chance to react. This is not an example of the Right |
| 251 | # Way to do things. See chrome-os-partner:7689, and the commit message |
| 252 | # that made this change. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 253 | $(FWLIB): CFLAGS += -DSAVE_LOCALE_IMMEDIATELY |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 254 | |
| 255 | # On x86 we don't actually read the GBB data into RAM until it is needed. |
| 256 | # Therefore it makes sense to cache it rather than reading it each time. |
| 257 | # Enable this feature. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 258 | $(FWLIB): CFLAGS += -DCOPY_BMP_DATA |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 259 | endif |
| 260 | |
| 261 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 262 | # Disable rollback TPM when compiling locally, since otherwise |
| 263 | # load_kernel_test attempts to talk to the TPM. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 264 | $(FWLIB): CFLAGS += -DDISABLE_ROLLBACK_TPM |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 265 | endif |
| 266 | |
| 267 | # find lib -iname '*.c' | sort |
| 268 | FWLIB_SRCS = \ |
| 269 | firmware/lib/cgptlib/cgptlib.c \ |
| 270 | firmware/lib/cgptlib/cgptlib_internal.c \ |
| 271 | firmware/lib/cgptlib/crc32.c \ |
| 272 | firmware/lib/crc8.c \ |
| 273 | firmware/lib/cryptolib/padding.c \ |
| 274 | firmware/lib/cryptolib/rsa.c \ |
| 275 | firmware/lib/cryptolib/rsa_utility.c \ |
| 276 | firmware/lib/cryptolib/sha1.c \ |
| 277 | firmware/lib/cryptolib/sha256.c \ |
| 278 | firmware/lib/cryptolib/sha512.c \ |
| 279 | firmware/lib/cryptolib/sha_utility.c \ |
| 280 | firmware/lib/stateful_util.c \ |
| 281 | firmware/lib/utility.c \ |
| 282 | firmware/lib/utility_string.c \ |
| 283 | firmware/lib/vboot_api_init.c \ |
| 284 | firmware/lib/vboot_api_firmware.c \ |
| 285 | firmware/lib/vboot_api_kernel.c \ |
| 286 | firmware/lib/vboot_audio.c \ |
| 287 | firmware/lib/vboot_common.c \ |
| 288 | firmware/lib/vboot_display.c \ |
| 289 | firmware/lib/vboot_firmware.c \ |
| 290 | firmware/lib/vboot_kernel.c \ |
| 291 | firmware/lib/vboot_nvstorage.c |
| 292 | |
| 293 | ifeq ($(MOCK_TPM),) |
| 294 | FWLIB_SRCS += \ |
| 295 | firmware/lib/rollback_index.c \ |
| 296 | firmware/lib/tpm_bootmode.c \ |
| 297 | firmware/lib/tpm_lite/tlcl.c |
| 298 | else |
| 299 | FWLIB_SRCS += \ |
| 300 | firmware/lib/mocked_rollback_index.c \ |
| 301 | firmware/lib/mocked_tpm_bootmode.c \ |
| 302 | firmware/lib/tpm_lite/mocked_tlcl.c |
| 303 | endif |
| 304 | |
| 305 | ifeq ($(FIRMWARE_ARCH),) |
| 306 | # Include stub into firmware lib if compiling for host |
| 307 | FWLIB_SRCS += \ |
| 308 | firmware/stub/tpm_lite_stub.c \ |
| 309 | firmware/stub/utility_stub.c \ |
| 310 | firmware/stub/vboot_api_stub.c \ |
| 311 | firmware/stub/vboot_api_stub_disk.c |
| 312 | endif |
| 313 | |
| 314 | FWLIB_OBJS = $(FWLIB_SRCS:%.c=${BUILD}/%.o) |
| 315 | ALL_OBJS += ${FWLIB_OBJS} |
| 316 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 317 | .PHONY: fwlib |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 318 | ifeq ($(FIRMWARE_ARCH),) |
| 319 | # Link test ensures firmware lib doesn't rely on outside libraries |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 320 | ${BUILD}/firmware/linktest/main: LIBS = $(FWLIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 321 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 322 | fwlib: ${BUILD}/firmware/linktest/main |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 323 | else |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 324 | fwlib: $(FWLIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 325 | endif |
| 326 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 327 | $(FWLIB): $(FWLIB_OBJS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 328 | @printf " RM $(subst $(BUILD)/,,$(@))\n" |
| 329 | $(Q)rm -f $@ |
| 330 | @printf " AR $(subst $(BUILD)/,,$(@))\n" |
| 331 | $(Q)ar qc $@ $^ |
| 332 | |
| 333 | # ----------------------------------------------------------------------------- |
| 334 | # Host library |
| 335 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 336 | .PHONY: hostlib |
| 337 | hostlib: $(HOSTLIB) ${BUILD}/host/linktest/main |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 338 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 339 | ${BUILD}/host/% ${HOSTLIB}: INCLUDES += \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 340 | -Ihost/include\ |
| 341 | -Ihost/arch/$(ARCH)/include |
| 342 | |
| 343 | HOSTLIB_SRCS = \ |
| 344 | host/arch/$(ARCH)/lib/crossystem_arch.c \ |
| 345 | host/lib/crossystem.c \ |
| 346 | host/lib/file_keys.c \ |
| 347 | host/lib/fmap.c \ |
| 348 | host/lib/host_common.c \ |
| 349 | host/lib/host_key.c \ |
| 350 | host/lib/host_keyblock.c \ |
| 351 | host/lib/host_misc.c \ |
| 352 | host/lib/host_signature.c \ |
| 353 | host/lib/signature_digest.c |
| 354 | |
| 355 | HOSTLIB_OBJS = $(HOSTLIB_SRCS:%.c=${BUILD}/%.o) |
| 356 | ALL_OBJS += ${HOSTLIB_OBJS} |
| 357 | |
| 358 | # TODO: better way to make .a than duplicating this recipe each time? |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 359 | $(HOSTLIB): $(HOSTLIB_OBJS) $(FWLIB_OBJS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 360 | @printf " RM $(subst $(BUILD)/,,$(@))\n" |
| 361 | $(Q)rm -f $@ |
| 362 | @printf " AR $(subst $(BUILD)/,,$(@))\n" |
| 363 | $(Q)ar qc $@ $^ |
| 364 | |
| 365 | # ----------------------------------------------------------------------------- |
| 366 | # CGPT library and utility |
| 367 | |
| 368 | CGPT = ${BUILD}/cgpt/cgpt |
| 369 | |
| 370 | CGPT_SRCS = \ |
| 371 | cgpt/cgpt.c \ |
| 372 | cgpt/cgpt_add.c \ |
| 373 | cgpt/cgpt_boot.c \ |
| 374 | cgpt/cgpt_common.c \ |
| 375 | cgpt/cgpt_create.c \ |
| 376 | cgpt/cgpt_find.c \ |
| 377 | cgpt/cgpt_legacy.c \ |
| 378 | cgpt/cgpt_prioritize.c \ |
| 379 | cgpt/cgpt_repair.c \ |
| 380 | cgpt/cgpt_show.c \ |
| 381 | cgpt/cmd_add.c \ |
| 382 | cgpt/cmd_boot.c \ |
| 383 | cgpt/cmd_create.c \ |
| 384 | cgpt/cmd_find.c \ |
| 385 | cgpt/cmd_legacy.c \ |
| 386 | cgpt/cmd_prioritize.c \ |
| 387 | cgpt/cmd_repair.c \ |
| 388 | cgpt/cmd_show.c |
| 389 | |
| 390 | CGPT_OBJS = $(CGPT_SRCS:%.c=${BUILD}/%.o) |
| 391 | ALL_OBJS += ${CGPT_OBJS} |
| 392 | |
| 393 | # TODO: why not make this include *all* the cgpt files, and simply have |
| 394 | # cgpt link against it? |
| 395 | # TODO: CgptManager.cc should move to the installer project. Shouldn't be |
| 396 | # in libcgpt-cc.a. |
| 397 | CGPTLIB_SRCS = \ |
| 398 | cgpt/CgptManager.cc \ |
| 399 | cgpt/cgpt_create.c \ |
| 400 | cgpt/cgpt_add.c \ |
| 401 | cgpt/cgpt_boot.c \ |
| 402 | cgpt/cgpt_show.c \ |
| 403 | cgpt/cgpt_repair.c \ |
| 404 | cgpt/cgpt_prioritize.c \ |
| 405 | cgpt/cgpt_common.c \ |
| 406 | firmware/lib/cgptlib/crc32.c \ |
| 407 | firmware/lib/cgptlib/cgptlib_internal.c \ |
| 408 | firmware/stub/utility_stub.c |
| 409 | |
| 410 | CGPTLIB_OBJS = $(filter %.o, \ |
| 411 | $(CGPTLIB_SRCS:%.c=${BUILD}/%.o) \ |
| 412 | $(CGPTLIB_SRCS:%.cc=${BUILD}/%.o)) |
| 413 | ALL_OBJS += $(CGPTLIB_OBJS) |
| 414 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 415 | .PHONY: cgpt |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 416 | cgpt: $(CGPT) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 417 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 418 | .PHONY: libcgpt_cc |
| 419 | libcgpt_cc: $(CGPTLIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 420 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 421 | $(CGPTLIB): INCLUDES += -Ifirmware/lib/cgptlib/include |
| 422 | $(CGPTLIB): $(CGPTLIB_OBJS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 423 | @printf " RM $(subst $(BUILD)/,,$(@))\n" |
| 424 | $(Q)rm -f $@ |
| 425 | @printf " AR $(subst $(BUILD)/,,$(@))\n" |
| 426 | $(Q)ar qc $@ $^ |
| 427 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 428 | $(CGPT): INCLUDES += -Ifirmware/lib/cgptlib/include |
| 429 | $(CGPT): LDLIBS = -luuid |
| 430 | $(CGPT): LDFLAGS += -static |
| 431 | $(CGPT): $(CGPT_OBJS) $$(LIBS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 432 | @printf " LDcgpt $(subst $(BUILD)/,,$(@))\n" |
| 433 | $(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS) |
| 434 | |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 435 | C_DESTDIR = $(DESTDIR) |
| 436 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 437 | .PHONY: cgpt_install |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 438 | cgpt_install: $(CGPT) |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 439 | @printf " INSTALL CGPT\n" |
| 440 | ${Q}mkdir -p $(C_DESTDIR) |
| 441 | ${Q}$(INSTALL) -t $(C_DESTDIR) $^ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 442 | |
| 443 | # ----------------------------------------------------------------------------- |
| 444 | # Utilities |
| 445 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 446 | ${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include |
| 447 | ${BUILD}/utility/%: CFLAGS += $(PC_CFLAGS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 448 | |
| 449 | AU_NAMES = \ |
| 450 | crossystem \ |
| 451 | dump_fmap \ |
| 452 | gbb_utility |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 453 | AU_BINS:= $(addprefix ${BUILD}/utility/,$(AU_NAMES)) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 454 | |
| 455 | # Utilities for auto-update toolkits must be statically linked, and don't |
| 456 | # use the crypto libs. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 457 | ${AU_BINS}: LDFLAGS += -static |
| 458 | ${AU_BINS}: CRYPTO_LIBS = |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 459 | |
| 460 | # Scripts to install |
| 461 | UTIL_SCRIPTS = \ |
| 462 | utility/dev_debug_vboot \ |
| 463 | utility/dev_make_keypair \ |
| 464 | utility/enable_dev_usb_boot \ |
| 465 | utility/vbutil_what_keys |
| 466 | |
| 467 | UTIL_NAMES = $(AU_NAMES) \ |
| 468 | dev_sign_file \ |
| 469 | dump_kernel_config \ |
| 470 | dumpRSAPublicKey \ |
| 471 | load_kernel_test \ |
| 472 | pad_digest_utility \ |
| 473 | signature_digest_utility \ |
| 474 | tpm_init_temp_fix \ |
| 475 | tpmc \ |
| 476 | vbutil_ec \ |
| 477 | vbutil_firmware \ |
| 478 | vbutil_kernel \ |
| 479 | vbutil_key \ |
| 480 | vbutil_keyblock \ |
| 481 | verify_data |
| 482 | |
| 483 | ifneq ($(IN_CHROOT),) |
| 484 | UTIL_NAMES += mount-encrypted |
| 485 | endif |
| 486 | |
| 487 | ifeq ($(MINIMAL),) |
| 488 | UTIL_NAMES += \ |
| 489 | bmpblk_font \ |
| 490 | bmpblk_utility \ |
| 491 | eficompress \ |
| 492 | efidecompress |
| 493 | endif |
| 494 | |
| 495 | UTIL_BINS = $(addprefix ${BUILD}/utility/,$(UTIL_NAMES)) |
| 496 | ALL_DEPS += $(addsuffix .d,${UTIL_BINS}) |
| 497 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 498 | .PHONY: utils |
| 499 | utils: $(UTIL_BINS) $(UTIL_SCRIPTS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 500 | # TODO: change ebuild to pull scripts directly out of utility dir |
| 501 | $(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility |
| 502 | $(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS)) |
| 503 | |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 504 | U_DESTDIR = $(DESTDIR) |
| 505 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 506 | .PHONY: utils_install |
| 507 | utils_install: $(UTIL_BINS) $(UTIL_SCRIPTS) |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 508 | @printf " INSTALL UTILS\n" |
| 509 | ${Q}mkdir -p $(U_DESTDIR) |
| 510 | ${Q}$(INSTALL) -t $(U_DESTDIR) $^ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 511 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 512 | ${BUILD}/utility/dump_kernel_config: LIBS += $(DUMPKERNELCONFIGLIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 513 | |
| 514 | # GBB utility needs C++ linker |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 515 | ${BUILD}/utility/gbb_utility: LD = $(CXX) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 516 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 517 | ${BUILD}/utility/bmpblk_utility: LD = $(CXX) |
| 518 | ${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml |
| 519 | ${BUILD}/utility/bmpblk_utility: OBJS = \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 520 | ${BUILD}/utility/bmpblk_util.o \ |
| 521 | ${BUILD}/utility/image_types.o \ |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 522 | ${BUILD}/utility/eficompress_for_lib.o \ |
| 523 | ${BUILD}/utility/efidecompress_for_lib.o |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 524 | |
| 525 | ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o |
| 526 | |
| 527 | # TODO: fix load_firmware_test util; it never got refactored for the new APIs |
| 528 | |
| 529 | # ----------------------------------------------------------------------------- |
| 530 | # Mount-encrypted utility for cryptohome |
| 531 | |
| 532 | # TODO: mount-encrypted should move to cryptohome and just link against |
| 533 | # vboot-host.a for tlcl and crossystem. |
| 534 | |
| 535 | # The embedded libcrypto conflicts with the shipped openssl, |
| 536 | # so mount-* builds without the common CFLAGS (and those includes). |
| 537 | |
| 538 | ${BUILD}/utility/mount-helpers.o: \ |
| 539 | utility/mount-helpers.c \ |
| 540 | utility/mount-helpers.h \ |
| 541 | utility/mount-encrypted.h |
| 542 | @printf " CCm-e $(subst $(BUILD)/,,$(@))\n" |
| 543 | $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ |
| 544 | $(COV_FLAGS) \ |
| 545 | $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \ |
| 546 | -c $< -o $@ |
| 547 | |
| 548 | ${BUILD}/utility/mount-encrypted: \ |
| 549 | utility/mount-encrypted.c \ |
| 550 | utility/mount-encrypted.h \ |
| 551 | ${BUILD}/utility/mount-helpers.o $$(LIBS) |
| 552 | @printf " CCm-exe $(subst $(BUILD)/,,$(@))\n" |
| 553 | $(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ |
| 554 | $(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \ |
| 555 | -Ifirmware/include \ |
| 556 | -Ihost/include \ |
| 557 | $(COV_FLAGS) \ |
| 558 | $(LDFLAGS) \ |
| 559 | $< -o $@ \ |
| 560 | ${BUILD}/utility/mount-helpers.o $(LIBS) \ |
| 561 | $(shell $(PKG_CONFIG) --libs glib-2.0 openssl) \ |
| 562 | -lm |
| 563 | ifneq (${COV},) |
| 564 | $(Q)mv -f mount-encrypted.gcno ${BUILD}/utility |
| 565 | endif |
| 566 | |
| 567 | # ----------------------------------------------------------------------------- |
| 568 | # Utility to generate TLCL structure definition header file. |
| 569 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 570 | ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct |
| 571 | ${BUILD}/utility/tlcl_generator: LIBS = |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 572 | |
| 573 | STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp |
| 574 | STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h |
| 575 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 576 | .PHONY: update_tlcl_structures |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 577 | update_tlcl_structures: ${BUILD}/utility/tlcl_generator |
| 578 | @printf " Rebuilding TLCL structures\n" |
| 579 | $(Q)${BUILD}/utility/tlcl_generator > $(STRUCTURES_TMP) |
| 580 | $(Q)cmp -s $(STRUCTURES_TMP) $(STRUCTURES_SRC) || \ |
| 581 | ( echo "%% Updating structures.h %%" && \ |
| 582 | cp $(STRUCTURES_TMP) $(STRUCTURES_SRC) ) |
| 583 | |
| 584 | # ----------------------------------------------------------------------------- |
| 585 | # Library to dump kernel config |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 586 | # Used by platform/installer |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 587 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 588 | .PHONY: libdump_kernel_config |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 589 | libdump_kernel_config: $(DUMPKERNELCONFIGLIB) |
| 590 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 591 | $(DUMPKERNELCONFIGLIB): ${BUILD}/utility/dump_kernel_config_lib.o |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 592 | @printf " RM $(subst $(BUILD)/,,$(@))\n" |
| 593 | $(Q)rm -f $@ |
| 594 | @printf " AR $(subst $(BUILD)/,,$(@))\n" |
| 595 | $(Q)ar qc $@ $^ |
| 596 | |
| 597 | # ----------------------------------------------------------------------------- |
| 598 | # Tests |
| 599 | |
| 600 | # Allow multiple definitions, so tests can mock functions from other libraries |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 601 | ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition |
| 602 | ${BUILD}/tests/%: INCLUDES += -Ihost/include |
| 603 | ${BUILD}/tests/%: LDLIBS += -lrt -luuid |
| 604 | ${BUILD}/tests/%: LIBS += $(TEST_LIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 605 | |
| 606 | TEST_NAMES = \ |
| 607 | cgptlib_test \ |
| 608 | rollback_index2_tests \ |
| 609 | rsa_padding_test \ |
| 610 | rsa_utility_tests \ |
| 611 | rsa_verify_benchmark \ |
| 612 | sha_benchmark \ |
| 613 | sha_tests \ |
| 614 | stateful_util_tests \ |
| 615 | tpm_bootmode_tests \ |
| 616 | utility_string_tests \ |
| 617 | utility_tests \ |
| 618 | vboot_nvstorage_test \ |
| 619 | vboot_api_init_tests \ |
| 620 | vboot_api_devmode_tests \ |
| 621 | vboot_api_firmware_tests \ |
| 622 | vboot_api_kernel_tests \ |
| 623 | vboot_audio_tests \ |
| 624 | vboot_common_tests \ |
| 625 | vboot_common2_tests \ |
| 626 | vboot_common3_tests \ |
| 627 | vboot_ec_tests \ |
| 628 | vboot_firmware_tests |
| 629 | |
| 630 | ifneq ($(IN_CHROOT),) |
| 631 | TEST_NAMES += CgptManagerTests |
| 632 | endif |
| 633 | |
| 634 | TLCL_TEST_NAMES = \ |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 635 | tpmtest_earlyextend \ |
| 636 | tpmtest_earlynvram \ |
| 637 | tpmtest_earlynvram2 \ |
| 638 | tpmtest_enable \ |
| 639 | tpmtest_fastenable \ |
| 640 | tpmtest_globallock \ |
| 641 | tpmtest_redefine_unowned \ |
| 642 | tpmtest_spaceperm \ |
| 643 | tpmtest_testsetup \ |
| 644 | tpmtest_timing \ |
| 645 | tpmtest_writelimit |
| 646 | TEST_NAMES += $(addprefix tpm_lite/,$(TLCL_TEST_NAMES)) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 647 | |
| 648 | TEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES)) |
| 649 | ALL_DEPS += $(addsuffix .d,${TEST_BINS}) |
| 650 | |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 651 | .PHONY: tests |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 652 | tests: $(TEST_BINS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 653 | |
| 654 | ${TEST_LIB}: \ |
| 655 | ${BUILD}/tests/test_common.o \ |
| 656 | ${BUILD}/tests/timer_utils.o \ |
| 657 | ${BUILD}/tests/crc32_test.o |
| 658 | @printf " RM $(subst $(BUILD)/,,$(@))\n" |
| 659 | $(Q)rm -f $@ |
| 660 | @printf " AR $(subst $(BUILD)/,,$(@))\n" |
| 661 | $(Q)ar qc $@ $^ |
| 662 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 663 | ${BUILD}/tests/rollback_index2_tests: OBJS += \ |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 664 | ${BUILD}/firmware/lib/rollback_index_for_test.o |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 665 | |
| 666 | ${BUILD}/tests/vboot_audio_tests: OBJS += \ |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 667 | ${BUILD}/firmware/lib/vboot_audio_for_test.o |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 668 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 669 | .PHONY: cgptmanager_tests |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 670 | cgptmanager_tests: ${BUILD}/tests/CgptManagerTests |
| 671 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 672 | ${BUILD}/tests/CgptManagerTests: CFLAGS += $(PC_CFLAGS) |
| 673 | ${BUILD}/tests/CgptManagerTests: LD = $(CXX) |
| 674 | ${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags $(PC_LDLIBS) |
| 675 | ${BUILD}/tests/CgptManagerTests: LIBS = $(CGPTLIB) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 676 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 677 | ${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include |
| 678 | ${BUILD}/tests/rollback_index_test: LIBS += -ltlcl |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 679 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 680 | ${BUILD}/tests/tpm_lite/tpmtest_%: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 681 | |
| 682 | # TODO: port these tests to new API, if not already eqivalent |
| 683 | # functionality in other tests. These don't even compile at present. |
| 684 | # |
| 685 | # big_firmware_tests |
| 686 | # big_kernel_tests |
| 687 | # firmware_image_tests |
| 688 | # firmware_rollback_tests |
| 689 | # firmware_splicing_tests |
| 690 | # firmware_verify_benchmark |
| 691 | # kernel_image_tests |
| 692 | # kernel_rollback_tests |
| 693 | # kernel_splicing_tests |
| 694 | # kernel_verify_benchmark |
| 695 | # rollback_index_test |
| 696 | # verify_firmware_fuzz_driver |
| 697 | # verify_kernel_fuzz_driver |
| 698 | |
| 699 | # ----------------------------------------------------------------------------- |
| 700 | # Targets to run tests |
| 701 | |
| 702 | # Frequently-run tests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 703 | TEST_TARGETS = runcgpttests runmisctests |
| 704 | |
| 705 | ifeq ($(MINIMAL),) |
| 706 | # Bitmap utility isn't compiled for minimal variant |
| 707 | TEST_TARGETS += runbmptests |
| 708 | # Scripts don't work under qemu testing |
| 709 | # TODO: convert scripts to makefile so they can be called directly |
| 710 | TEST_TARGETS += runtestscripts |
| 711 | endif |
| 712 | |
| 713 | # Qemu setup for cross-compiled tests. Need to copy qemu binary into the |
| 714 | # sysroot. |
| 715 | ifneq ($(QEMU_ARCH),) |
| 716 | TEST_SETUP += qemu_install |
| 717 | |
| 718 | .PHONY: qemu_install |
| 719 | qemu_install: |
| 720 | @printf " Copying qemu binary.\n" |
| 721 | $(Q)cp -fu /usr/bin/$(QEMU_BIN) $(BUILD)/$(QEMU_BIN) |
| 722 | $(Q)chmod a+rx $(BUILD)/$(QEMU_BIN) |
| 723 | endif |
| 724 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 725 | .PHONY: runtests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 726 | runtests: $(TEST_TARGETS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 727 | |
| 728 | # Generate test keys |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 729 | .PHONY: genkeys |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 730 | genkeys: utils |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 731 | tests/gen_test_keys.sh |
| 732 | |
| 733 | # Generate test cases for fuzzing |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 734 | .PHONY: genfuzztestcases |
Randall Spangler | a808dc9 | 2013-01-14 12:59:05 -0800 | [diff] [blame] | 735 | genfuzztestcases: utils |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 736 | tests/gen_fuzz_test_cases.sh |
| 737 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 738 | .PHONY: runbmptests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 739 | runbmptests: $(TEST_SETUP) utils |
| 740 | cd tests/bitmaps && BMPBLK=$(BUILD_RUN)/utility/bmpblk_utility \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 741 | ./TestBmpBlock.py -v |
| 742 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 743 | .PHONY: runcgpttests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 744 | runcgpttests: $(TEST_SETUP) cgpt tests |
| 745 | $(RUNTEST) $(BUILD_RUN)/tests/cgptlib_test |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 746 | ifneq ($(IN_CHROOT),) |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 747 | $(RUNTEST) $(BUILD_RUN)/tests/CgptManagerTests --v=1 |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 748 | endif |
| 749 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 750 | .PHONY: runtestscripts |
| 751 | runtestscripts: $(TEST_SETUP) genfuzztestcases utils tests |
| 752 | tests/run_cgpt_tests.sh $(BUILD_RUN)/cgpt/cgpt |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 753 | tests/run_preamble_tests.sh |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 754 | tests/run_rsa_tests.sh |
| 755 | tests/run_vboot_common_tests.sh |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 756 | tests/run_vbutil_kernel_arg_tests.sh |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 757 | tests/run_vbutil_tests.sh |
| 758 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 759 | .PHONY: runmisctests |
| 760 | runmisctests: $(TEST_SETUP) tests utils |
| 761 | $(RUNTEST) $(BUILD_RUN)/tests/rollback_index2_tests |
| 762 | $(RUNTEST) $(BUILD_RUN)/tests/rsa_utility_tests |
| 763 | $(RUNTEST) $(BUILD_RUN)/tests/sha_tests |
| 764 | $(RUNTEST) $(BUILD_RUN)/tests/stateful_util_tests |
| 765 | $(RUNTEST) $(BUILD_RUN)/tests/tpm_bootmode_tests |
| 766 | $(RUNTEST) $(BUILD_RUN)/tests/utility_string_tests |
| 767 | $(RUNTEST) $(BUILD_RUN)/tests/utility_tests |
| 768 | $(RUNTEST) $(BUILD_RUN)/tests/vboot_api_devmode_tests |
| 769 | $(RUNTEST) $(BUILD_RUN)/tests/vboot_api_init_tests |
| 770 | $(RUNTEST) $(BUILD_RUN)/tests/vboot_api_firmware_tests |
| 771 | $(RUNTEST) $(BUILD_RUN)/tests/vboot_audio_tests |
| 772 | $(RUNTEST) $(BUILD_RUN)/tests/vboot_firmware_tests |
| 773 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 774 | # Run long tests, including all permutations of encryption keys (instead of |
| 775 | # just the ones we use) and tests of currently-unused code (e.g. vboot_ec). |
| 776 | # Not run by automated build. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 777 | .PHONY: runlongtests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame^] | 778 | runlongtests: $(TEST_SETUP) genkeys genfuzztestcases tests utils |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 779 | tests/run_preamble_tests.sh --all |
| 780 | tests/run_vboot_common_tests.sh --all |
| 781 | tests/run_vboot_ec_tests.sh |
| 782 | tests/run_vbutil_tests.sh --all |
| 783 | |
| 784 | # TODO: tests to run when ported to new API |
| 785 | # ./run_image_verification_tests.sh |
| 786 | # # Splicing tests |
| 787 | # ${BUILD}/tests/firmware_splicing_tests |
| 788 | # ${BUILD}/tests/kernel_splicing_tests |
| 789 | # # Rollback Tests |
| 790 | # ${BUILD}/tests/firmware_rollback_tests |
| 791 | # ${BUILD}/tests/kernel_rollback_tests |
| 792 | |
| 793 | # ----------------------------------------------------------------------------- |
| 794 | # Build rules |
| 795 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 796 | ${BUILD}/%: ${BUILD}/%.o $$(OBJS) $$(LIBS) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 797 | @printf " LD $(subst $(BUILD)/,,$(@))\n" |
| 798 | $(Q)$(LD) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \ |
| 799 | $(LIBS) $(LDLIBS) |
| 800 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 801 | ${BUILD}/%.o: %.c |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 802 | @printf " CC $(subst $(BUILD)/,,$(@))\n" |
| 803 | $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< |
| 804 | |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 805 | # Rules to recompile a single source file for library and test |
| 806 | # TODO: is there a tidier way to do this? |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 807 | ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY |
| 808 | ${BUILD}/%_for_lib.o: %.c |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 809 | @printf " CC-for-lib $(subst $(BUILD)/,,$(@))\n" |
| 810 | $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 811 | ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST |
| 812 | ${BUILD}/%_for_test.o: %.c |
Randall Spangler | 17f8d34 | 2013-01-11 10:55:11 -0800 | [diff] [blame] | 813 | @printf " CC-for-test $(subst $(BUILD)/,,$(@))\n" |
| 814 | $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< |
| 815 | |
| 816 | # TODO: C++ files don't belong in vboot reference at all. Convert to C. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 817 | ${BUILD}/%.o: %.cc |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 818 | @printf " CXX $(subst $(BUILD)/,,$(@))\n" |
| 819 | $(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< |
| 820 | |
| 821 | # ----------------------------------------------------------------------------- |
| 822 | # Dependencies must come last after ALL_OBJS has been accumulated |
| 823 | |
| 824 | # TODO: I suspect this is missing some object files. Make a temp |
| 825 | # target which cleans all known obj/exe's and see what's left; those |
| 826 | # are the files which need deps. |
| 827 | |
| 828 | ALL_DEPS += $(ALL_OBJS:%.o=%.o.d) |
| 829 | |
| 830 | -include ${ALL_DEPS} |