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 | |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 5 | # This Makefile normally builds in a 'build' subdir, but use |
| 6 | # |
| 7 | # make BUILD=<dir> |
| 8 | # |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 9 | # to put the output somewhere else. |
| 10 | |
| 11 | ############################################################################## |
| 12 | # Make variables come in two flavors, immediate or deferred. |
| 13 | # |
| 14 | # Variable definitions are parsed like this: |
| 15 | # |
| 16 | # IMMEDIATE = DEFERRED |
| 17 | # or |
| 18 | # IMMEDIATE := IMMEDIATE |
| 19 | # |
| 20 | # Rules are parsed this way: |
| 21 | # |
| 22 | # IMMEDIATE : IMMEDIATE |
| 23 | # DEFERRED |
| 24 | # |
| 25 | # So you can assign variables in any order if they're only to be used in |
| 26 | # actions, but if you use a variable in either the target or prerequisite of a |
| 27 | # rule, the rule will be constructed using only the top-down, immediate value. |
| 28 | # |
| 29 | # So we'll try to define all the variables first. Then the rules. |
| 30 | # |
| 31 | |
| 32 | ############################################################################## |
| 33 | # Configuration variables come first. |
| 34 | # |
| 35 | # Our convention is that we only use := for variables that will never be |
| 36 | # changed or appended. They must be defined before being used anywhere. |
| 37 | |
| 38 | # we should only run pwd once, not every time we refer to ${BUILD}. |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 39 | SRCDIR := $(shell pwd) |
| 40 | BUILD ?= $(SRCDIR)/build |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 41 | export BUILD |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 42 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 43 | # Target for 'make install' |
| 44 | DESTDIR ?= /usr/bin |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 45 | INSTALL ?= install |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 46 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 47 | # Where to install the (exportable) executables for testing? |
| 48 | TEST_INSTALL_DIR = ${BUILD}/install_for_test |
| 49 | |
| 50 | # Verbose? Use V=1 |
| 51 | ifeq (${V},) |
| 52 | Q := @ |
| 53 | endif |
| 54 | |
Randall Spangler | 61a2eb3 | 2013-01-23 10:20:16 -0800 | [diff] [blame] | 55 | # Architecture detection |
| 56 | _machname := $(shell uname -m) |
| 57 | HOST_ARCH ?= ${_machname} |
| 58 | |
| 59 | # ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild. |
| 60 | # Pick a sane target architecture if none is defined. |
| 61 | ifeq (${ARCH},) |
| 62 | ARCH := ${HOST_ARCH} |
| 63 | else ifeq (${ARCH},i386) |
| 64 | override ARCH := x86 |
| 65 | else ifeq (${ARCH},amd64) |
| 66 | override ARCH := x86_64 |
| 67 | endif |
| 68 | |
| 69 | # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling |
| 70 | # for a firmware target (such as u-boot or depthcharge). It must map |
| 71 | # to the same consistent set of architectures as the host. |
| 72 | ifeq (${FIRMWARE_ARCH},i386) |
| 73 | override FIRMWARE_ARCH := x86 |
| 74 | else ifeq (${FIRMWARE_ARCH},amd64) |
| 75 | override FIRMWARE_ARCH := x86_64 |
| 76 | endif |
| 77 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 78 | # Provide default CC and CFLAGS for firmware builds; if you have any -D flags, |
| 79 | # please add them after this point (e.g., -DVBOOT_DEBUG). |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 80 | # |
Che-Liang Chiou | 6b0003c | 2011-10-14 11:11:28 +0800 | [diff] [blame] | 81 | # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just |
| 82 | # temporarily. As we are still investigating which flags are necessary for |
| 83 | # maintaining a compatible ABI, etc. between u-boot and vboot_reference. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 84 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 85 | # As a first step, this makes the setting of CC and CFLAGS here optional, to |
| 86 | # permit a calling script or Makefile to set these. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 87 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 88 | # Flag ordering: arch, then -f, then -m, then -W |
| 89 | DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os) |
| 90 | COMMON_FLAGS := -nostdinc -pipe \ |
| 91 | -ffreestanding -fno-builtin -fno-stack-protector \ |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 92 | -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS} |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 93 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 94 | # Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild. |
| 95 | ifeq (${FIRMWARE_ARCH}, arm) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 96 | CC ?= armv7a-cros-linux-gnueabi-gcc |
| 97 | CFLAGS ?= -march=armv5 \ |
| 98 | -fno-common -ffixed-r8 \ |
Doug Anderson | d50b27d | 2012-05-11 12:08:02 -0700 | [diff] [blame] | 99 | -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \ |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 100 | ${COMMON_FLAGS} |
Randall Spangler | 61a2eb3 | 2013-01-23 10:20:16 -0800 | [diff] [blame] | 101 | else ifeq (${FIRMWARE_ARCH}, x86) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 102 | CC ?= i686-pc-linux-gnu-gcc |
| 103 | # Drop -march=i386 to permit use of SSE instructions |
| 104 | CFLAGS ?= \ |
| 105 | -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \ |
| 106 | -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \ |
| 107 | -mpreferred-stack-boundary=2 -mregparm=3 \ |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 108 | ${COMMON_FLAGS} |
| 109 | else ifeq (${FIRMWARE_ARCH}, x86_64) |
| 110 | CFLAGS ?= ${COMMON_FLAGS} \ |
Simon Glass | 8e85e98 | 2011-11-22 13:54:50 -0800 | [diff] [blame] | 111 | -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 112 | else |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 113 | # FIRMWARE_ARCH not defined; assuming local compile. |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 114 | CC ?= gcc |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 115 | CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two? |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 116 | endif |
| 117 | |
| 118 | ifneq (${DEBUG},) |
| 119 | CFLAGS += -DVBOOT_DEBUG |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 120 | endif |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 121 | |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 122 | ifeq (${DISABLE_NDEBUG},) |
| 123 | CFLAGS += -DNDEBUG |
| 124 | endif |
| 125 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 126 | # Create / use dependency files |
| 127 | CFLAGS += -MMD -MF $@.d |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 128 | |
Randall Spangler | 59d7508 | 2013-01-23 09:29:54 -0800 | [diff] [blame] | 129 | # Code coverage |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 130 | ifneq (${COV},) |
Randall Spangler | 59d7508 | 2013-01-23 09:29:54 -0800 | [diff] [blame] | 131 | COV_FLAGS = -O0 --coverage |
| 132 | CFLAGS += ${COV_FLAGS} |
| 133 | LDFLAGS += ${COV_FLAGS} |
| 134 | COV_INFO = ${BUILD}/coverage.info |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 135 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 136 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 137 | # And a few more default utilities |
| 138 | LD = ${CC} |
| 139 | CXX ?= g++ # HEY: really? |
| 140 | PKG_CONFIG ?= pkg-config |
| 141 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 142 | # Determine QEMU architecture needed, if any |
| 143 | ifeq (${ARCH},${HOST_ARCH}) |
| 144 | # Same architecture; no need for QEMU |
| 145 | QEMU_ARCH := |
Randall Spangler | 61a2eb3 | 2013-01-23 10:20:16 -0800 | [diff] [blame] | 146 | else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86) |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 147 | # 64-bit host can run 32-bit targets directly |
| 148 | QEMU_ARCH := |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 149 | else |
| 150 | QEMU_ARCH := ${ARCH} |
| 151 | endif |
| 152 | |
| 153 | # The top of the chroot for qemu must be passed in via the SYSROOT environment |
| 154 | # variable. In the Chromium OS chroot, this is done automatically by the |
| 155 | # ebuild. |
| 156 | |
| 157 | ifeq (${QEMU_ARCH},) |
| 158 | # Path to build output for running tests is same as for building |
| 159 | BUILD_RUN = ${BUILD} |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 160 | SRC_RUN = ${SRCDIR} |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 161 | else |
| 162 | $(info Using qemu for testing.) |
| 163 | # Path to build output for running tests is different in the chroot |
| 164 | BUILD_RUN = $(subst ${SYSROOT},,${BUILD}) |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 165 | SRC_RUN = $(subst ${SYSROOT},,${SRCDIR}) |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 166 | |
| 167 | QEMU_BIN = qemu-${QEMU_ARCH} |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 168 | QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN} |
| 169 | export QEMU_RUN |
| 170 | |
| 171 | RUNTEST = tests/test_using_qemu.sh |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 172 | endif |
| 173 | |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 174 | export BUILD_RUN |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 175 | |
| 176 | # Some things only compile inside the Chromium OS chroot. |
| 177 | # TODO: Those things should be in their own repo, not part of vboot_reference |
| 178 | # TODO: Is there a better way to detect this? |
| 179 | ifneq (${CROS_WORKON_SRCROOT},) |
| 180 | IN_CHROOT := yes |
| 181 | endif |
| 182 | |
| 183 | # TODO: Move to separate repo. |
| 184 | ifneq (${IN_CHROOT},) |
| 185 | PC_BASE_VER ?= 125070 |
| 186 | PC_DEPS := libchrome-${PC_BASE_VER} |
| 187 | PC_CFLAGS := $(shell ${PKG_CONFIG} --cflags ${PC_DEPS}) |
| 188 | PC_LDLIBS := $(shell ${PKG_CONFIG} --libs ${PC_DEPS}) |
| 189 | endif |
| 190 | |
| 191 | |
| 192 | ############################################################################## |
| 193 | # Now we need to describe everything we might want or need to build |
| 194 | |
| 195 | # TODO: This should go in its own repo. |
| 196 | AU_CGPTLIB = ${BUILD}/cgpt/libcgpt-cc.a |
| 197 | # This is just ... Gah. There's no good place for it. |
| 198 | DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a |
| 199 | |
| 200 | # Everything wants these headers. |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 201 | INCLUDES += \ |
| 202 | -Ifirmware/include \ |
| 203 | -Ifirmware/lib/include \ |
| 204 | -Ifirmware/lib/cgptlib/include \ |
| 205 | -Ifirmware/lib/cryptolib/include \ |
| 206 | -Ifirmware/lib/tpm_lite/include |
Bill Richardson | 0b8f35c | 2010-05-26 09:18:38 -0700 | [diff] [blame] | 207 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 208 | # If we're not building for a specific target, just stub out things like the |
| 209 | # TPM commands and various external functions that are provided by the BIOS. |
| 210 | ifeq (${FIRMWARE_ARCH},) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 211 | INCLUDES += -Ifirmware/stub/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 212 | else |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 213 | INCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 214 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 215 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 216 | # Firmware library. TODO: Do we still need to export this? |
| 217 | FWLIB = ${BUILD}/vboot_fw.a |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 218 | |
| 219 | # find lib -iname '*.c' | sort |
| 220 | FWLIB_SRCS = \ |
| 221 | firmware/lib/cgptlib/cgptlib.c \ |
| 222 | firmware/lib/cgptlib/cgptlib_internal.c \ |
| 223 | firmware/lib/cgptlib/crc32.c \ |
| 224 | firmware/lib/crc8.c \ |
| 225 | firmware/lib/cryptolib/padding.c \ |
| 226 | firmware/lib/cryptolib/rsa.c \ |
| 227 | firmware/lib/cryptolib/rsa_utility.c \ |
| 228 | firmware/lib/cryptolib/sha1.c \ |
| 229 | firmware/lib/cryptolib/sha256.c \ |
| 230 | firmware/lib/cryptolib/sha512.c \ |
| 231 | firmware/lib/cryptolib/sha_utility.c \ |
| 232 | firmware/lib/stateful_util.c \ |
| 233 | firmware/lib/utility.c \ |
| 234 | firmware/lib/utility_string.c \ |
| 235 | firmware/lib/vboot_api_init.c \ |
| 236 | firmware/lib/vboot_api_firmware.c \ |
| 237 | firmware/lib/vboot_api_kernel.c \ |
| 238 | firmware/lib/vboot_audio.c \ |
| 239 | firmware/lib/vboot_common.c \ |
| 240 | firmware/lib/vboot_display.c \ |
| 241 | firmware/lib/vboot_firmware.c \ |
| 242 | firmware/lib/vboot_kernel.c \ |
| 243 | firmware/lib/vboot_nvstorage.c |
| 244 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 245 | # Support real TPM unless BIOS sets MOCK_TPM |
| 246 | ifeq (${MOCK_TPM},) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 247 | FWLIB_SRCS += \ |
| 248 | firmware/lib/rollback_index.c \ |
| 249 | firmware/lib/tpm_bootmode.c \ |
| 250 | firmware/lib/tpm_lite/tlcl.c |
| 251 | else |
| 252 | FWLIB_SRCS += \ |
| 253 | firmware/lib/mocked_rollback_index.c \ |
| 254 | firmware/lib/mocked_tpm_bootmode.c \ |
| 255 | firmware/lib/tpm_lite/mocked_tlcl.c |
| 256 | endif |
| 257 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 258 | ifeq (${FIRMWARE_ARCH},) |
| 259 | # Include BIOS stubs in the firmware library when compiling for host |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 260 | FWLIB_SRCS += \ |
| 261 | firmware/stub/tpm_lite_stub.c \ |
| 262 | firmware/stub/utility_stub.c \ |
| 263 | firmware/stub/vboot_api_stub.c \ |
| 264 | firmware/stub/vboot_api_stub_disk.c |
| 265 | endif |
| 266 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 267 | FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 268 | ALL_OBJS += ${FWLIB_OBJS} |
| 269 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 270 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 271 | # Library to build the utilities. "HOST" mostly means "userspace". |
| 272 | HOSTLIB = ${BUILD}/vboot_host.a |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 273 | |
| 274 | HOSTLIB_SRCS = \ |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 275 | host/arch/${ARCH}/lib/crossystem_arch.c \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 276 | host/lib/crossystem.c \ |
| 277 | host/lib/file_keys.c \ |
| 278 | host/lib/fmap.c \ |
| 279 | host/lib/host_common.c \ |
| 280 | host/lib/host_key.c \ |
| 281 | host/lib/host_keyblock.c \ |
| 282 | host/lib/host_misc.c \ |
| 283 | host/lib/host_signature.c \ |
| 284 | host/lib/signature_digest.c |
| 285 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 286 | HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 287 | ALL_OBJS += ${HOSTLIB_OBJS} |
| 288 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 289 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 290 | # Link with hostlib by default |
| 291 | LIBS = $(HOSTLIB) |
| 292 | |
| 293 | # Might need this too. |
| 294 | CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto) |
| 295 | |
| 296 | |
| 297 | # ---------------------------------------------------------------------------- |
| 298 | # Now for the userspace binaries |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 299 | |
| 300 | CGPT = ${BUILD}/cgpt/cgpt |
| 301 | |
| 302 | CGPT_SRCS = \ |
| 303 | cgpt/cgpt.c \ |
| 304 | cgpt/cgpt_add.c \ |
| 305 | cgpt/cgpt_boot.c \ |
| 306 | cgpt/cgpt_common.c \ |
| 307 | cgpt/cgpt_create.c \ |
| 308 | cgpt/cgpt_find.c \ |
| 309 | cgpt/cgpt_legacy.c \ |
| 310 | cgpt/cgpt_prioritize.c \ |
| 311 | cgpt/cgpt_repair.c \ |
| 312 | cgpt/cgpt_show.c \ |
| 313 | cgpt/cmd_add.c \ |
| 314 | cgpt/cmd_boot.c \ |
| 315 | cgpt/cmd_create.c \ |
| 316 | cgpt/cmd_find.c \ |
| 317 | cgpt/cmd_legacy.c \ |
| 318 | cgpt/cmd_prioritize.c \ |
| 319 | cgpt/cmd_repair.c \ |
| 320 | cgpt/cmd_show.c |
| 321 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 322 | CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 323 | ALL_OBJS += ${CGPT_OBJS} |
| 324 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 325 | C_DESTDIR = ${DESTDIR} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 326 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 327 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 328 | # Scripts to install directly (not compiled) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 329 | UTIL_SCRIPTS = \ |
| 330 | utility/dev_debug_vboot \ |
| 331 | utility/dev_make_keypair \ |
| 332 | utility/enable_dev_usb_boot \ |
| 333 | utility/vbutil_what_keys |
| 334 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 335 | # These utilities should be linked statically. |
| 336 | UTIL_NAMES_STATIC = \ |
| 337 | crossystem \ |
| 338 | dump_fmap \ |
| 339 | gbb_utility |
| 340 | |
| 341 | UTIL_NAMES = ${UTIL_NAMES_STATIC} \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 342 | dev_sign_file \ |
| 343 | dump_kernel_config \ |
| 344 | dumpRSAPublicKey \ |
| 345 | load_kernel_test \ |
| 346 | pad_digest_utility \ |
| 347 | signature_digest_utility \ |
| 348 | tpm_init_temp_fix \ |
| 349 | tpmc \ |
| 350 | vbutil_ec \ |
| 351 | vbutil_firmware \ |
| 352 | vbutil_kernel \ |
| 353 | vbutil_key \ |
| 354 | vbutil_keyblock \ |
| 355 | verify_data |
| 356 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 357 | ifneq (${IN_CHROOT},) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 358 | UTIL_NAMES += mount-encrypted |
| 359 | endif |
| 360 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 361 | ifeq (${MINIMAL},) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 362 | UTIL_NAMES += \ |
| 363 | bmpblk_font \ |
| 364 | bmpblk_utility \ |
| 365 | eficompress \ |
| 366 | efidecompress |
| 367 | endif |
| 368 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 369 | UTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC}) |
| 370 | UTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES}) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 371 | ALL_DEPS += $(addsuffix .d,${UTIL_BINS}) |
| 372 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 373 | U_DESTDIR = ${DESTDIR} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 374 | |
Bill Richardson | 826db09 | 2013-01-14 12:37:15 -0800 | [diff] [blame] | 375 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 376 | # The unified firmware utility will eventually replace all the others |
| 377 | FUTIL_BIN = ${BUILD}/futility/futility |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 378 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 379 | FUTIL_SRCS = \ |
| 380 | futility/IGNOREME.c |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 381 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 382 | FUTIL_LDS = futility/futility.lds |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 383 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 384 | FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 385 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 386 | ALL_DEPS += $(addsuffix .d,${FUTIL_BIN}) |
| 387 | ALL_OBJS += ${FUTIL_OBJS} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 388 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 389 | F_DESTDIR = ${DESTDIR} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 390 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 391 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 392 | # Library of handy test functions. |
| 393 | TESTLIB = ${BUILD}/tests/test.a |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 394 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 395 | TESTLIB_SRCS = \ |
| 396 | tests/test_common.c \ |
| 397 | tests/timer_utils.c \ |
| 398 | tests/crc32_test.c |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 399 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 400 | TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o} |
| 401 | ALL_OBJS += ${TESTLIB_OBJS} |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 402 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 403 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 404 | # And some compiled tests. |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 405 | TEST_NAMES = \ |
| 406 | cgptlib_test \ |
| 407 | rollback_index2_tests \ |
| 408 | rsa_padding_test \ |
| 409 | rsa_utility_tests \ |
| 410 | rsa_verify_benchmark \ |
| 411 | sha_benchmark \ |
| 412 | sha_tests \ |
| 413 | stateful_util_tests \ |
| 414 | tpm_bootmode_tests \ |
| 415 | utility_string_tests \ |
| 416 | utility_tests \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 417 | vboot_api_init_tests \ |
| 418 | vboot_api_devmode_tests \ |
| 419 | vboot_api_firmware_tests \ |
| 420 | vboot_api_kernel_tests \ |
| 421 | vboot_audio_tests \ |
| 422 | vboot_common_tests \ |
| 423 | vboot_common2_tests \ |
| 424 | vboot_common3_tests \ |
| 425 | vboot_ec_tests \ |
Randall Spangler | 6dbf9d9 | 2013-01-23 12:25:10 -0800 | [diff] [blame^] | 426 | vboot_firmware_tests \ |
| 427 | vboot_nvstorage_test |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 428 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 429 | # Grrr |
| 430 | ifneq (${IN_CHROOT},) |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 431 | TEST_NAMES += CgptManagerTests |
| 432 | endif |
| 433 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 434 | # TODO: port these tests to new API, if not already eqivalent |
| 435 | # functionality in other tests. These don't even compile at present. |
| 436 | # |
| 437 | # big_firmware_tests |
| 438 | # big_kernel_tests |
| 439 | # firmware_image_tests |
| 440 | # firmware_rollback_tests |
| 441 | # firmware_splicing_tests |
| 442 | # firmware_verify_benchmark |
| 443 | # kernel_image_tests |
| 444 | # kernel_rollback_tests |
| 445 | # kernel_splicing_tests |
| 446 | # kernel_verify_benchmark |
| 447 | # rollback_index_test |
| 448 | # verify_firmware_fuzz_driver |
| 449 | # verify_kernel_fuzz_driver |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 450 | # utility/load_firmware_test |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 451 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 452 | # And a few more... |
| 453 | TLCL_TESTS = \ |
| 454 | tpmtest_earlyextend \ |
| 455 | tpmtest_earlynvram \ |
| 456 | tpmtest_earlynvram2 \ |
| 457 | tpmtest_enable \ |
| 458 | tpmtest_fastenable \ |
| 459 | tpmtest_globallock \ |
| 460 | tpmtest_redefine_unowned \ |
| 461 | tpmtest_spaceperm \ |
| 462 | tpmtest_testsetup \ |
| 463 | tpmtest_timing \ |
| 464 | tpmtest_writelimit |
| 465 | TLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS}) |
| 466 | TLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES}) |
| 467 | |
| 468 | TEST_NAMES += ${TLCL_TEST_NAMES} |
| 469 | |
| 470 | TEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES}) |
| 471 | ALL_DEPS += $(addsuffix .d,${TEST_BINS}) |
| 472 | |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 473 | # Directory containing test keys |
| 474 | TEST_KEYS = ${SRC_RUN}/tests/testkeys |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 475 | |
| 476 | # ---------------------------------------------------------------------------- |
| 477 | # TODO: why not make this include *all* the cgpt files, and simply have |
| 478 | # cgpt link against it? |
| 479 | # TODO: CgptManager.cc should move to the installer project. Shouldn't be |
| 480 | # in libcgpt-cc.a. |
| 481 | AU_CGPTLIB_SRCS = \ |
| 482 | cgpt/CgptManager.cc \ |
| 483 | cgpt/cgpt_create.c \ |
| 484 | cgpt/cgpt_add.c \ |
| 485 | cgpt/cgpt_boot.c \ |
| 486 | cgpt/cgpt_show.c \ |
| 487 | cgpt/cgpt_repair.c \ |
| 488 | cgpt/cgpt_prioritize.c \ |
| 489 | cgpt/cgpt_common.c \ |
| 490 | firmware/lib/cgptlib/crc32.c \ |
| 491 | firmware/lib/cgptlib/cgptlib_internal.c \ |
| 492 | firmware/stub/utility_stub.c |
| 493 | |
| 494 | AU_CGPTLIB_OBJS = $(filter %.o, \ |
| 495 | ${AU_CGPTLIB_SRCS:%.c=${BUILD}/%.o} \ |
| 496 | ${AU_CGPTLIB_SRCS:%.cc=${BUILD}/%.o}) |
| 497 | ALL_OBJS += ${AU_CGPTLIB_OBJS} |
| 498 | |
| 499 | |
| 500 | ############################################################################## |
| 501 | # Finally, some targets. High-level ones first. |
| 502 | |
| 503 | # Create output directories if necessary. Do this via explicit shell commands |
| 504 | # so it happens before trying to generate/include dependencies. |
| 505 | SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite |
| 506 | _dir_create := $(foreach d, \ |
| 507 | $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \ |
| 508 | $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d})) |
| 509 | |
| 510 | |
| 511 | # Default target. |
| 512 | .PHONY: all |
Randall Spangler | 59d7508 | 2013-01-23 09:29:54 -0800 | [diff] [blame] | 513 | all: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage) |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 514 | |
| 515 | # Host targets |
| 516 | .PHONY: host_stuff |
| 517 | host_stuff: hostlib cgpt utils futil tests |
| 518 | |
| 519 | # AU targets |
| 520 | .PHONY: au_stuff |
| 521 | au_stuff: libcgpt_cc libdump_kernel_config cgptmanager_tests |
| 522 | |
| 523 | .PHONY: clean |
| 524 | clean: |
| 525 | ${Q}/bin/rm -rf ${BUILD} |
| 526 | |
| 527 | .PHONY: install |
| 528 | install: cgpt_install utils_install futil_install |
| 529 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 530 | # Don't delete intermediate object files |
| 531 | .SECONDARY: |
| 532 | |
| 533 | # TODO: I suspect this is missing some object files. Make a temp |
| 534 | # target which cleans all known obj/exe's and see what's left; those |
| 535 | # are the files which need deps. |
| 536 | ALL_DEPS += ${ALL_OBJS:%.o=%.o.d} |
| 537 | -include ${ALL_DEPS} |
| 538 | |
| 539 | # ---------------------------------------------------------------------------- |
| 540 | # Firmware library |
| 541 | |
| 542 | # TPM-specific flags. These depend on the particular TPM we're targeting for. |
| 543 | # They are needed here only for compiling parts of the firmware code into |
| 544 | # user-level tests. |
| 545 | |
| 546 | # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until |
| 547 | # the self test has completed. |
| 548 | |
| 549 | ${FWLIB}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST |
| 550 | |
| 551 | # TPM_MANUAL_SELFTEST is defined if the self test must be started manually |
| 552 | # (with a call to TPM_ContinueSelfTest) instead of starting automatically at |
| 553 | # power on. |
| 554 | # |
| 555 | # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST |
| 556 | # are not both defined at the same time. (See comment in code.) |
| 557 | |
| 558 | # CFLAGS += -DTPM_MANUAL_SELFTEST |
| 559 | |
| 560 | ifeq (${FIRMWARE_ARCH},i386) |
| 561 | # Unrolling loops in cryptolib makes it faster |
| 562 | ${FWLIB}: CFLAGS += -DUNROLL_LOOPS |
| 563 | |
| 564 | # Workaround for coreboot on x86, which will power off asynchronously |
| 565 | # without giving us a chance to react. This is not an example of the Right |
| 566 | # Way to do things. See chrome-os-partner:7689, and the commit message |
| 567 | # that made this change. |
| 568 | ${FWLIB}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY |
| 569 | |
| 570 | # On x86 we don't actually read the GBB data into RAM until it is needed. |
| 571 | # Therefore it makes sense to cache it rather than reading it each time. |
| 572 | # Enable this feature. |
| 573 | ${FWLIB}: CFLAGS += -DCOPY_BMP_DATA |
| 574 | endif |
| 575 | |
| 576 | ifeq (${FIRMWARE_ARCH},) |
| 577 | # Disable rollback TPM when compiling locally, since otherwise |
| 578 | # load_kernel_test attempts to talk to the TPM. |
| 579 | ${FWLIB}: CFLAGS += -DDISABLE_ROLLBACK_TPM |
| 580 | endif |
| 581 | |
| 582 | .PHONY: fwlib |
| 583 | fwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,${BUILD}/firmware/linktest/main) |
| 584 | |
| 585 | ${FWLIB}: ${FWLIB_OBJS} |
| 586 | @printf " RM $(subst ${BUILD}/,,$@)\n" |
| 587 | ${Q}rm -f $@ |
| 588 | @printf " AR $(subst ${BUILD}/,,$@)\n" |
| 589 | ${Q}ar qc $@ $^ |
| 590 | |
| 591 | # ---------------------------------------------------------------------------- |
| 592 | # Host library |
| 593 | |
| 594 | .PHONY: hostlib |
| 595 | hostlib: ${HOSTLIB} ${BUILD}/host/linktest/main |
| 596 | |
| 597 | ${BUILD}/host/% ${HOSTLIB}: INCLUDES += \ |
| 598 | -Ihost/include\ |
| 599 | -Ihost/arch/${ARCH}/include |
| 600 | |
| 601 | # TODO: better way to make .a than duplicating this recipe each time? |
| 602 | ${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} |
| 603 | @printf " RM $(subst ${BUILD}/,,$@)\n" |
| 604 | ${Q}rm -f $@ |
| 605 | @printf " AR $(subst ${BUILD}/,,$@)\n" |
| 606 | ${Q}ar qc $@ $^ |
| 607 | |
| 608 | # ---------------------------------------------------------------------------- |
| 609 | # CGPT library and utility |
| 610 | |
| 611 | .PHONY: cgpt |
| 612 | cgpt: ${CGPT} |
| 613 | |
| 614 | ${CGPT}: LDFLAGS += -static |
| 615 | ${CGPT}: LDLIBS += -luuid |
| 616 | |
| 617 | ${CGPT}: ${CGPT_OBJS} ${LIBS} |
| 618 | @printf " LDcgpt $(subst ${BUILD}/,,$@)\n" |
| 619 | ${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS} |
| 620 | |
| 621 | .PHONY: cgpt_install |
| 622 | cgpt_install: ${CGPT} |
| 623 | @printf " INSTALL CGPT\n" |
| 624 | ${Q}mkdir -p ${C_DESTDIR} |
| 625 | ${Q}${INSTALL} -t ${C_DESTDIR} $^ |
| 626 | |
| 627 | # ---------------------------------------------------------------------------- |
| 628 | # Utilities |
| 629 | |
| 630 | # These have their own headers too. |
| 631 | ${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include |
| 632 | |
| 633 | # Utilities for auto-update toolkits must be statically linked. |
| 634 | ${UTIL_BINS_STATIC}: LDFLAGS += -static |
| 635 | |
| 636 | .PHONY: utils |
| 637 | utils: ${UTIL_BINS} ${UTIL_SCRIPTS} |
| 638 | # TODO: change ebuild to pull scripts directly out of utility dir |
| 639 | ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility |
| 640 | ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS}) |
| 641 | |
| 642 | .PHONY: utils_install |
| 643 | utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} |
| 644 | @printf " INSTALL UTILS\n" |
| 645 | ${Q}mkdir -p ${U_DESTDIR} |
| 646 | ${Q}${INSTALL} -t ${U_DESTDIR} $^ |
| 647 | |
| 648 | # ---------------------------------------------------------------------------- |
| 649 | # new Firmware Utility |
| 650 | |
| 651 | .PHONY: futil |
| 652 | futil: ${FUTIL_BIN} |
| 653 | |
| 654 | ${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} |
| 655 | @printf " LD $(subst ${BUILD}/,,$@)\n" |
| 656 | ${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS} |
| 657 | |
| 658 | .PHONY: futil_install |
| 659 | futil_install: ${FUTIL_BIN} |
| 660 | @printf " INSTALL futility\n" |
| 661 | ${Q}mkdir -p ${F_DESTDIR} |
| 662 | ${Q}${INSTALL} -t ${F_DESTDIR} $^ |
| 663 | |
| 664 | |
| 665 | # ---------------------------------------------------------------------------- |
| 666 | # Mount-encrypted utility for cryptohome |
| 667 | |
| 668 | # TODO: mount-encrypted should move to cryptohome and just link against |
| 669 | # vboot-host.a for tlcl and crossystem. |
| 670 | |
| 671 | # The embedded libcrypto conflicts with the shipped openssl, |
| 672 | # so mount-* builds without the common CFLAGS (and those includes). |
| 673 | |
| 674 | ${BUILD}/utility/mount-helpers.o: \ |
| 675 | utility/mount-helpers.c \ |
| 676 | utility/mount-helpers.h \ |
| 677 | utility/mount-encrypted.h |
| 678 | @printf " CCm-e $(subst ${BUILD}/,,$@)\n" |
| 679 | ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ |
| 680 | ${COV_FLAGS} \ |
| 681 | $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \ |
| 682 | -c $< -o $@ |
| 683 | |
| 684 | ${BUILD}/utility/mount-encrypted: \ |
| 685 | utility/mount-encrypted.c \ |
| 686 | utility/mount-encrypted.h \ |
| 687 | ${BUILD}/utility/mount-helpers.o ${LIBS} |
| 688 | @printf " CCm-exe $(subst ${BUILD}/,,$@)\n" |
| 689 | ${Q}${CC} -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \ |
| 690 | $(shell ${PKG_CONFIG} --cflags glib-2.0 openssl) \ |
| 691 | -Ifirmware/include \ |
| 692 | -Ihost/include \ |
| 693 | ${COV_FLAGS} \ |
| 694 | ${LDFLAGS} \ |
| 695 | $< -o $@ \ |
| 696 | ${BUILD}/utility/mount-helpers.o ${LIBS} \ |
| 697 | $(shell ${PKG_CONFIG} --libs glib-2.0 openssl) \ |
| 698 | -lm |
| 699 | ifneq (${COV},) |
| 700 | ${Q}mv -f mount-encrypted.gcno ${BUILD}/utility |
| 701 | endif |
| 702 | |
| 703 | # ---------------------------------------------------------------------------- |
| 704 | # Utility to generate TLCL structure definition header file. |
| 705 | |
| 706 | ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct |
| 707 | |
| 708 | STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp |
| 709 | STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h |
| 710 | |
| 711 | .PHONY: update_tlcl_structures |
| 712 | update_tlcl_structures: ${BUILD}/utility/tlcl_generator |
| 713 | @printf " Rebuilding TLCL structures\n" |
| 714 | ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP} |
| 715 | ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \ |
| 716 | ( echo "%% Updating structures.h %%" && \ |
| 717 | cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} ) |
| 718 | |
| 719 | # ---------------------------------------------------------------------------- |
| 720 | # Library to dump kernel config |
| 721 | # Used by platform/installer, as well as standalone utility. |
| 722 | |
| 723 | .PHONY: libdump_kernel_config |
| 724 | libdump_kernel_config: ${DUMPKERNELCONFIGLIB} |
| 725 | |
| 726 | ${DUMPKERNELCONFIGLIB}: ${BUILD}/utility/dump_kernel_config_lib.o |
| 727 | @printf " RM $(subst ${BUILD}/,,$@)\n" |
| 728 | ${Q}rm -f $@ |
| 729 | @printf " AR $(subst ${BUILD}/,,$@)\n" |
| 730 | ${Q}ar qc $@ $^ |
| 731 | |
| 732 | # ---------------------------------------------------------------------------- |
| 733 | # And this thing. |
| 734 | |
| 735 | .PHONY: libcgpt_cc |
| 736 | libcgpt_cc: ${AU_CGPTLIB} |
| 737 | |
| 738 | ${AU_CGPTLIB}: INCLUDES += -Ifirmware/lib/cgptlib/include |
| 739 | ${AU_CGPTLIB}: ${AU_CGPTLIB_OBJS} |
| 740 | @printf " RM $(subst ${BUILD}/,,$@)\n" |
| 741 | ${Q}rm -f $@ |
| 742 | @printf " AR $(subst ${BUILD}/,,$@)\n" |
| 743 | ${Q}ar qc $@ $^ |
| 744 | |
| 745 | # ---------------------------------------------------------------------------- |
| 746 | # Tests |
| 747 | |
| 748 | .PHONY: tests |
| 749 | tests: ${TEST_BINS} |
| 750 | |
| 751 | ${TEST_BINS}: ${TESTLIB} |
| 752 | |
| 753 | ${TESTLIB}: ${TESTLIB_OBJS} |
| 754 | @printf " RM $(subst ${BUILD}/,,$@)\n" |
| 755 | ${Q}rm -f $@ |
| 756 | @printf " AR $(subst ${BUILD}/,,$@)\n" |
| 757 | ${Q}ar qc $@ $^ |
| 758 | |
| 759 | |
| 760 | # ---------------------------------------------------------------------------- |
| 761 | # Generic build rules. LIBS and OBJS can be overridden to tweak the generic |
| 762 | # rules for specific targets. |
| 763 | |
| 764 | ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS} |
| 765 | @printf " LD $(subst ${BUILD}/,,$@)\n" |
| 766 | ${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS} |
| 767 | |
| 768 | ${BUILD}/%.o: %.c |
| 769 | @printf " CC $(subst ${BUILD}/,,$@)\n" |
| 770 | ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< |
| 771 | |
| 772 | # Rules to recompile a single source file for library and test |
| 773 | # TODO: is there a tidier way to do this? |
| 774 | ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY |
| 775 | ${BUILD}/%_for_lib.o: %.c |
| 776 | @printf " CC-for-lib $(subst ${BUILD}/,,$@)\n" |
| 777 | ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< |
| 778 | |
| 779 | ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST |
| 780 | ${BUILD}/%_for_test.o: %.c |
| 781 | @printf " CC-for-test $(subst ${BUILD}/,,$@)\n" |
| 782 | ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< |
| 783 | |
| 784 | # TODO: C++ files don't belong in vboot reference at all. Convert to C. |
| 785 | ${BUILD}/%.o: %.cc |
| 786 | @printf " CXX $(subst ${BUILD}/,,$@)\n" |
| 787 | ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $< |
| 788 | |
| 789 | # ---------------------------------------------------------------------------- |
| 790 | # Here are the special tweaks to the generic rules. |
| 791 | |
| 792 | # Linktest ensures firmware lib doesn't rely on outside libraries |
| 793 | ${BUILD}/firmware/linktest/main: LIBS = ${FWLIB} |
| 794 | |
| 795 | # Specific dependency here. |
| 796 | ${BUILD}/utility/dump_kernel_config: LIBS += ${DUMPKERNELCONFIGLIB} |
| 797 | ${BUILD}/utility/dump_kernel_config: ${DUMPKERNELCONFIGLIB} |
| 798 | |
| 799 | # GBB utility needs C++ linker. TODO: It shouldn't. |
| 800 | ${BUILD}/utility/gbb_utility: LD = ${CXX} |
| 801 | |
| 802 | # Some utilities need external crypto functions |
| 803 | ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS} |
| 804 | ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS} |
| 805 | ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS} |
| 806 | ${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS} |
| 807 | ${BUILD}/utility/vbutil_ec: LDLIBS += ${CRYPTO_LIBS} |
| 808 | ${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS} |
| 809 | ${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS} |
| 810 | ${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS} |
| 811 | ${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS} |
| 812 | |
| 813 | ${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS} |
| 814 | ${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS} |
| 815 | ${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS} |
| 816 | ${BUILD}/tests/vboot_ec_tests: LDLIBS += ${CRYPTO_LIBS} |
| 817 | |
| 818 | |
| 819 | ${BUILD}/utility/bmpblk_utility: LD = ${CXX} |
| 820 | ${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml |
| 821 | |
| 822 | BMPBLK_UTILITY_DEPS = \ |
| 823 | ${BUILD}/utility/bmpblk_util.o \ |
| 824 | ${BUILD}/utility/image_types.o \ |
| 825 | ${BUILD}/utility/eficompress_for_lib.o \ |
| 826 | ${BUILD}/utility/efidecompress_for_lib.o |
| 827 | ${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS} |
| 828 | ${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS} |
| 829 | |
| 830 | ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o |
| 831 | ${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o |
| 832 | |
| 833 | # Allow multiple definitions, so tests can mock functions from other libraries |
| 834 | ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition |
| 835 | ${BUILD}/tests/%: INCLUDES += -Ihost/include |
| 836 | ${BUILD}/tests/%: LDLIBS += -lrt -luuid |
| 837 | ${BUILD}/tests/%: LIBS += ${TESTLIB} |
| 838 | |
| 839 | ${BUILD}/tests/rollback_index2_tests: OBJS += \ |
| 840 | ${BUILD}/firmware/lib/rollback_index_for_test.o |
| 841 | ${BUILD}/tests/rollback_index2_tests: \ |
| 842 | ${BUILD}/firmware/lib/rollback_index_for_test.o |
| 843 | |
| 844 | ${BUILD}/tests/vboot_audio_tests: OBJS += \ |
| 845 | ${BUILD}/firmware/lib/vboot_audio_for_test.o |
| 846 | ${BUILD}/tests/vboot_audio_tests: \ |
| 847 | ${BUILD}/firmware/lib/vboot_audio_for_test.o |
| 848 | |
| 849 | .PHONY: cgptmanager_tests |
| 850 | cgptmanager_tests: ${BUILD}/tests/CgptManagerTests |
| 851 | |
| 852 | ${BUILD}/tests/CgptManagerTests: CFLAGS += ${PC_CFLAGS} |
| 853 | ${BUILD}/tests/CgptManagerTests: LD = ${CXX} |
| 854 | ${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags ${PC_LDLIBS} |
| 855 | ${BUILD}/tests/CgptManagerTests: LIBS = ${AU_CGPTLIB} |
| 856 | ${BUILD}/tests/CgptManagerTests: ${AU_CGPTLIB} |
| 857 | |
| 858 | ${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include |
| 859 | ${BUILD}/tests/rollback_index_test: LIBS += -ltlcl |
| 860 | |
| 861 | ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o |
| 862 | ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o |
| 863 | |
| 864 | ############################################################################## |
| 865 | # Targets that exist just to run tests |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 866 | |
| 867 | # Frequently-run tests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 868 | .PHONY: test_targets |
| 869 | test_targets:: runcgpttests runmisctests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 870 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 871 | ifeq (${MINIMAL},) |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 872 | # Bitmap utility isn't compiled for minimal variant |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 873 | test_targets:: runbmptests |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 874 | # Scripts don't work under qemu testing |
| 875 | # TODO: convert scripts to makefile so they can be called directly |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 876 | test_targets:: runtestscripts |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 877 | endif |
| 878 | |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 879 | .PHONY: test_setup |
| 880 | test_setup:: cgpt utils futil tests |
| 881 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 882 | # Qemu setup for cross-compiled tests. Need to copy qemu binary into the |
| 883 | # sysroot. |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 884 | ifneq (${QEMU_ARCH},) |
| 885 | test_setup:: qemu_install |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 886 | |
| 887 | .PHONY: qemu_install |
| 888 | qemu_install: |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 889 | ifeq (${SYSROOT},) |
| 890 | $(error SYSROOT must be set to the top of the target-specific root \ |
| 891 | when cross-compiling for qemu-based tests to run properly.) |
| 892 | endif |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 893 | @printf " Copying qemu binary.\n" |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 894 | ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN} |
| 895 | ${Q}chmod a+rx ${BUILD}/${QEMU_BIN} |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 896 | endif |
| 897 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 898 | .PHONY: runtests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 899 | runtests: test_targets |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 900 | |
| 901 | # Generate test keys |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 902 | .PHONY: genkeys |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 903 | genkeys: utils |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 904 | tests/gen_test_keys.sh |
| 905 | |
| 906 | # Generate test cases for fuzzing |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 907 | .PHONY: genfuzztestcases |
Randall Spangler | a808dc9 | 2013-01-14 12:59:05 -0800 | [diff] [blame] | 908 | genfuzztestcases: utils |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 909 | tests/gen_fuzz_test_cases.sh |
| 910 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 911 | .PHONY: runbmptests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 912 | runbmptests: test_setup |
| 913 | cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \ |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 914 | ./TestBmpBlock.py -v |
| 915 | |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 916 | .PHONY: runcgpttests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 917 | runcgpttests: test_setup |
| 918 | ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test |
| 919 | # HEY - elsewhere |
| 920 | ifneq (${IN_CHROOT},) |
| 921 | ${RUNTEST} ${BUILD_RUN}/tests/CgptManagerTests --v=1 |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 922 | endif |
| 923 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 924 | .PHONY: runtestscripts |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 925 | runtestscripts: test_setup genfuzztestcases |
| 926 | tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 927 | tests/run_preamble_tests.sh |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 928 | tests/run_rsa_tests.sh |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 929 | tests/run_vbutil_kernel_arg_tests.sh |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 930 | tests/run_vbutil_tests.sh |
| 931 | |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 932 | .PHONY: runmisctests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 933 | runmisctests: test_setup |
| 934 | ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests |
| 935 | ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests |
| 936 | ${RUNTEST} ${BUILD_RUN}/tests/sha_tests |
| 937 | ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests |
| 938 | ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests |
| 939 | ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests |
| 940 | ${RUNTEST} ${BUILD_RUN}/tests/utility_tests |
| 941 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests |
| 942 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests |
| 943 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests |
| 944 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 945 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests |
| 946 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} |
| 947 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 948 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests |
Randall Spangler | 6dbf9d9 | 2013-01-23 12:25:10 -0800 | [diff] [blame^] | 949 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 950 | |
| 951 | .PHONY: runfutiltests |
| 952 | runfutiltests: DESTDIR := ${TEST_INSTALL_DIR} |
| 953 | runfutiltests: test_setup install |
| 954 | @echo "$@ passed" |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 955 | |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 956 | # Run long tests, including all permutations of encryption keys (instead of |
| 957 | # just the ones we use) and tests of currently-unused code (e.g. vboot_ec). |
| 958 | # Not run by automated build. |
Bill Richardson | acb2ee9 | 2013-01-11 22:53:00 -0800 | [diff] [blame] | 959 | .PHONY: runlongtests |
Bill Richardson | eecc18f | 2013-01-17 15:28:17 -0800 | [diff] [blame] | 960 | runlongtests: test_setup genkeys genfuzztestcases |
Randall Spangler | e061a25 | 2013-01-22 15:34:07 -0800 | [diff] [blame] | 961 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all |
| 962 | ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 963 | tests/run_preamble_tests.sh --all |
Randall Spangler | 5d9bbf2 | 2013-01-08 10:44:23 -0800 | [diff] [blame] | 964 | tests/run_vboot_ec_tests.sh |
| 965 | tests/run_vbutil_tests.sh --all |
| 966 | |
| 967 | # TODO: tests to run when ported to new API |
| 968 | # ./run_image_verification_tests.sh |
| 969 | # # Splicing tests |
| 970 | # ${BUILD}/tests/firmware_splicing_tests |
| 971 | # ${BUILD}/tests/kernel_splicing_tests |
| 972 | # # Rollback Tests |
| 973 | # ${BUILD}/tests/firmware_rollback_tests |
| 974 | # ${BUILD}/tests/kernel_rollback_tests |
| 975 | |
Randall Spangler | 59d7508 | 2013-01-23 09:29:54 -0800 | [diff] [blame] | 976 | # Code coverage |
| 977 | .PHONY: coverage_init |
| 978 | coverage_init: test_setup |
| 979 | rm -f ${COV_INFO}* |
| 980 | lcov -c -i -d . -b . -o ${COV_INFO}.initial |
| 981 | |
| 982 | .PHONY: coverage_html |
| 983 | coverage_html: |
| 984 | lcov -c -d . -b . -o ${COV_INFO}.tests |
| 985 | lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total |
| 986 | lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local |
| 987 | genhtml ${COV_INFO}.local -o ${BUILD}/coverage |
| 988 | |
| 989 | # Generate addtional coverage stats just for firmware subdir, because the |
| 990 | # per-directory stats for the whole project don't include their own subdirs. |
| 991 | lcov -e ${COV_INFO}.local '${SRCDIR}/firmware/*' \ |
| 992 | -o ${COV_INFO}.firmware |
| 993 | |
| 994 | .PHONY: coverage |
| 995 | ifeq (${COV},) |
| 996 | coverage: |
| 997 | $(error Build coverage like this: make clean && COV=1 make) |
| 998 | else |
| 999 | coverage: coverage_init runtests coverage_html |
| 1000 | endif |
| 1001 | |