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