Makefile revision da2b49cf08a27551fd910626f669910a636378d4
1e8cfa31d548c069d73c304fea522b527fe7c7dd6Randall Spangler# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah# Use of this source code is governed by a BSD-style license that can be
3322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah# found in the LICENSE file.
4322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah
56d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass# This Makefile normally builds in a 'build' subdir, but use
66d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#
76d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#    make BUILD=<dir>
86d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#
9eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# to put the output somewhere else.
10eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
11eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
12eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Make variables come in two flavors, immediate or deferred.
13eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
14eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#   Variable definitions are parsed like this:
15eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
16eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#        IMMEDIATE = DEFERRED
17eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#    or
18eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#        IMMEDIATE := IMMEDIATE
19eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
20eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#   Rules are parsed this way:
21eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
22eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#        IMMEDIATE : IMMEDIATE
23eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#           DEFERRED
24eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
25eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# So you can assign variables in any order if they're only to be used in
26eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# actions, but if you use a variable in either the target or prerequisite of a
27eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# rule, the rule will be constructed using only the top-down, immediate value.
28eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
29eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# So we'll try to define all the variables first. Then the rules.
30eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
31eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
32eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
33eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Configuration variables come first.
34eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
35eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Our convention is that we only use := for variables that will never be
36eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# changed or appended. They must be defined before being used anywhere.
37eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
38c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# We should only run pwd once, not every time we refer to ${BUILD}.
39e061a256549607a56d771eb8ddae5d0dd90d519cRandall SpanglerSRCDIR := $(shell pwd)
40feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonBUILD = $(SRCDIR)/build
41844bce57471153664c78993dab453e87891bb969Randall Spanglerexport BUILD
425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
43c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Stuff for 'make install'
44feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonINSTALL = install
45feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonDESTDIR = /usr/local/bin
46feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonOLDDIR = old_bins
47feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
48feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# Where exactly do the pieces go?
49feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson#  FT_DIR = futility target directory - where it will be on the target
50feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson#  F_DIR  = futility install directory - where it gets put right now
51feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson#  UB_DIR = userspace binary directory for futility's exec() targets
52feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson#  VB_DIR = target vboot directory - for dev-mode-only helpers, keys, etc.
53c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonifeq (${MINIMAL},)
54c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Host install just puts everything in one place
55feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonFT_DIR=${DESTDIR}
56feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonF_DIR=${DESTDIR}
57feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonUB_DIR=${DESTDIR}/${OLDDIR}
58c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonelse
59c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Target install puts things into DESTDIR subdirectories
60feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonFT_DIR=/usr/bin
61feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonF_DIR=${DESTDIR}${FT_DIR}
62feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonUB_DIR=${F_DIR}/${OLDDIR}
63c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonVB_DIR=${DESTDIR}/usr/share/vboot/bin
64c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
656d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass
66eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Where to install the (exportable) executables for testing?
67eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_INSTALL_DIR = ${BUILD}/install_for_test
68eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
69eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Verbose? Use V=1
70eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${V},)
71eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonQ := @
72eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
73eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
74661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass# Quiet? Use QUIET=1
75661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glassifeq ($(QUIET),)
76661ae9e9cbaad430b87b443712d2608f9ce59883Simon GlassPRINTF := printf
77661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glasselse
78661ae9e9cbaad430b87b443712d2608f9ce59883Simon GlassPRINTF := :
79661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glassendif
80661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass
8161a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# Architecture detection
8261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler_machname := $(shell uname -m)
8361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall SpanglerHOST_ARCH ?= ${_machname}
8461a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
8561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
8661a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# Pick a sane target architecture if none is defined.
8761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerifeq (${ARCH},)
8861a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  ARCH := ${HOST_ARCH}
8961a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${ARCH},i386)
9061a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override ARCH := x86
9161a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${ARCH},amd64)
9261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override ARCH := x86_64
9361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerendif
9461a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
9561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
9661a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# for a firmware target (such as u-boot or depthcharge). It must map
9761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# to the same consistent set of architectures as the host.
9861a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerifeq (${FIRMWARE_ARCH},i386)
9961a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override FIRMWARE_ARCH := x86
10061a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${FIRMWARE_ARCH},amd64)
10161a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override FIRMWARE_ARCH := x86_64
102d96b25d0c0a739d351b8f09b128782ca12b7b0e1Stefan Reinauerelse ifeq (${FIRMWARE_ARCH},armv7)
103d96b25d0c0a739d351b8f09b128782ca12b7b0e1Stefan Reinauer  override FIRMWARE_ARCH := arm
10461a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerendif
10561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
106b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
107b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# please add them after this point (e.g., -DVBOOT_DEBUG).
10874359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
1096b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
1106b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# temporarily. As we are still investigating which flags are necessary for
1116b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
11274359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
113b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# As a first step, this makes the setting of CC and CFLAGS here optional, to
114b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# permit a calling script or Makefile to set these.
11574359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
116b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Flag ordering: arch, then -f, then -m, then -W
117b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassDEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
118b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCOMMON_FLAGS := -nostdinc -pipe \
119b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffreestanding -fno-builtin -fno-stack-protector \
120eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	-Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
121b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
122eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
123eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH}, arm)
124b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= armv7a-cros-linux-gnueabi-gcc
125b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= -march=armv5 \
126b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fno-common -ffixed-r8 \
127d50b27d15de8cc9e37410fc52d3184f17e0db5bbDoug Anderson	-mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
128eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
12961a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${FIRMWARE_ARCH}, x86)
130b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= i686-pc-linux-gnu-gcc
131b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Drop -march=i386 to permit use of SSE instructions
132b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= \
133b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
134b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
13546e00e63805f85c05449ce09cd843a18b76ca665Gabe Black	-mpreferred-stack-boundary=2 \
136eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
137eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonelse ifeq (${FIRMWARE_ARCH}, x86_64)
138eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS ?= ${COMMON_FLAGS} \
1398e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glass	-fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
140844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
141eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# FIRMWARE_ARCH not defined; assuming local compile.
142eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCC ?= gcc
143eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
1448e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glassendif
14534be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiou
146feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${OLDDIR},)
147feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonCFLAGS += -DOLDDIR=${OLDDIR}
148feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonendif
149feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
150eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${DEBUG},)
151eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DVBOOT_DEBUG
152eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
153844bce57471153664c78993dab453e87891bb969Randall Spangler
154eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${DISABLE_NDEBUG},)
155eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DNDEBUG
156eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
157eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
158feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${FORCE_LOGGING_ON},)
159feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonCFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
160feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonendif
161feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
162eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create / use dependency files
163eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -MMD -MF $@.d
164eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1650c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson# These are required to access large disks and files on 32-bit systems.
1660c3ba249abb1dc60f5ebabccf84ff13206440b83Bill RichardsonCFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
1670c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
16859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
169eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${COV},)
17059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  COV_FLAGS = -O0 --coverage
17159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  CFLAGS += ${COV_FLAGS}
17259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  LDFLAGS += ${COV_FLAGS}
17359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  COV_INFO = ${BUILD}/coverage.info
174eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
175eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
176eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more default utilities
177eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonLD = ${CC}
178eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCXX ?= g++ # HEY: really?
179eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonPKG_CONFIG ?= pkg-config
180eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
181844bce57471153664c78993dab453e87891bb969Randall Spangler# Determine QEMU architecture needed, if any
182eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${ARCH},${HOST_ARCH})
183844bce57471153664c78993dab453e87891bb969Randall Spangler  # Same architecture; no need for QEMU
184844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
18561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
186844bce57471153664c78993dab453e87891bb969Randall Spangler  # 64-bit host can run 32-bit targets directly
187844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
188844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
189eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_ARCH := ${ARCH}
190844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
191844bce57471153664c78993dab453e87891bb969Randall Spangler
192844bce57471153664c78993dab453e87891bb969Randall Spangler# The top of the chroot for qemu must be passed in via the SYSROOT environment
193844bce57471153664c78993dab453e87891bb969Randall Spangler# variable.  In the Chromium OS chroot, this is done automatically by the
194844bce57471153664c78993dab453e87891bb969Randall Spangler# ebuild.
195844bce57471153664c78993dab453e87891bb969Randall Spangler
196eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${QEMU_ARCH},)
197844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is same as for building
198eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = ${BUILD}
199e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = ${SRCDIR}
200844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
201844bce57471153664c78993dab453e87891bb969Randall Spangler  $(info Using qemu for testing.)
202844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is different in the chroot
203eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
204e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
205844bce57471153664c78993dab453e87891bb969Randall Spangler
206eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_BIN = qemu-${QEMU_ARCH}
207e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
208e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  export QEMU_RUN
209287beaed7f8ceff679c57664d4da008c6234edfdRandall Spangler
210e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  RUNTEST = tests/test_using_qemu.sh
211e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerendif
2125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
213e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerexport BUILD_RUN
2145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
215eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
216eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now we need to describe everything we might want or need to build
217b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
218eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Everything wants these headers.
2195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += \
2205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/include \
2215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/include \
2225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cgptlib/include \
2235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cryptolib/include \
224786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	-Ifirmware/lib/tpm_lite/include \
225786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	-Ifirmware/2lib/include
2260b8f35c6a56a0e645254dd7f07ca68e01c8ee629Bill Richardson
227eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# If we're not building for a specific target, just stub out things like the
228eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM commands and various external functions that are provided by the BIOS.
229eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
2305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += -Ifirmware/stub/include
2310a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiouelse
232eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonINCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
2335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
235eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Firmware library. TODO: Do we still need to export this?
236eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB = ${BUILD}/vboot_fw.a
2375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
238786acdabcc15f023330d7c628aca9679e757a238Randall Spangler# Smaller firmware library. TODO: Do we still need to export this?
239786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerifneq (${VBOOT2},)
240786acdabcc15f023330d7c628aca9679e757a238Randall SpanglerFWLIB2 = ${BUILD}/vboot_fw2.a
241786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerendif
242786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
24393943266c597ad66300445a04afa01270f2b5763Randall Spangler# Firmware library sources needed by VbInit() call
24493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS = \
2455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/crc8.c \
24693943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility.c \
24793943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_api_init.c \
24893943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common_init.c \
24993943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_nvstorage.c \
250527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-init.c \
25193943266c597ad66300445a04afa01270f2b5763Randall Spangler
25293943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectFirmware() call
25393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS = \
2545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/padding.c \
2555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa.c \
2565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa_utility.c \
2575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha1.c \
2585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha256.c \
2595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha512.c \
2605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha_utility.c \
2615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/stateful_util.c \
2625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_firmware.c \
26393943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common.c \
264527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/vboot_firmware.c \
265527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-fw.c \
26693943266c597ad66300445a04afa01270f2b5763Randall Spangler
26793943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectAndLoadKernel() call
26893943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS = \
26993943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib.c \
27093943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib_internal.c \
27193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/crc32.c \
2725c9e4532b9bc45cff22f37d3556da679809a60a7Albert Chaulk	firmware/lib/cgptlib/mtdlib.c \
27393943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility_string.c \
2745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_kernel.c \
2755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_audio.c \
2765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_display.c \
277527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/vboot_kernel.c \
278527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-kernel.c \
2795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
280786acdabcc15f023330d7c628aca9679e757a238Randall Spangler# Firmware library source needed for smaller library 2
281786acdabcc15f023330d7c628aca9679e757a238Randall SpanglerFWLIB2_SRCS = \
282786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	firmware/2lib/2common.c \
2833333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2crc8.c \
2843333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2misc.c \
2853333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2nvstorage.c \
286e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2rsa.c \
2873333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2secdata.c \
288e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha1.c \
289e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha256.c \
290e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha512.c \
291e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha_utility.c \
292786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
293eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Support real TPM unless BIOS sets MOCK_TPM
294eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MOCK_TPM},)
29593943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
2965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/rollback_index.c \
2975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/tlcl.c
29893943266c597ad66300445a04afa01270f2b5763Randall Spangler
29993943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
30093943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/tpm_bootmode.c
3015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerelse
30293943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
3035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/mocked_rollback_index.c \
3045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/mocked_tlcl.c
30593943266c597ad66300445a04afa01270f2b5763Randall Spangler
30693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
30793943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/mocked_tpm_bootmode.c
3085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
310eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
311eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Include BIOS stubs in the firmware library when compiling for host
31293943266c597ad66300445a04afa01270f2b5763Randall Spangler# TODO: split out other stub funcs too
31393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
3145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/tpm_lite_stub.c \
3155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/utility_stub.c \
316527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/stub/vboot_api_stub_init.c \
317527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/stub/vboot_api_stub_region.c
31893943266c597ad66300445a04afa01270f2b5763Randall Spangler
31993943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
32093943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/stub/vboot_api_stub_sf.c
32193943266c597ad66300445a04afa01270f2b5763Randall Spangler
32293943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS += \
3235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub.c \
3245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub_disk.c
325da2b49cf08a27551fd910626f669910a636378d4Randall Spangler
326da2b49cf08a27551fd910626f669910a636378d4Randall SpanglerFWLIB2_SRCS += \
327da2b49cf08a27551fd910626f669910a636378d4Randall Spangler	firmware/2lib/2stub.c
328da2b49cf08a27551fd910626f669910a636378d4Randall Spangler
3295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
33193943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += ${VBINIT_SRCS}
33293943266c597ad66300445a04afa01270f2b5763Randall SpanglerFWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
33393943266c597ad66300445a04afa01270f2b5763Randall Spangler
33493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
33593943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
33693943266c597ad66300445a04afa01270f2b5763Randall Spangler
337eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
3381912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson
339786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerifneq (${VBOOT2},)
340786acdabcc15f023330d7c628aca9679e757a238Randall SpanglerFWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
341786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerendif
3425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
343786acdabcc15f023330d7c628aca9679e757a238Randall SpanglerALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${VBINIT_OBJS} ${VBSF_OBJS}
3445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
345eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Library to build the utilities. "HOST" mostly means "userspace".
346c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill RichardsonHOSTLIB = ${BUILD}/libvboot_host.a
3475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerHOSTLIB_SRCS = \
34981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_create.c \
35081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_add.c \
35181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_boot.c \
35281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_show.c \
35381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_repair.c \
35481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_prioritize.c \
35581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_common.c \
356534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	cgpt/flash_ts_drv.c \
357b334e651a597a10d562bc882613f0b482b24e3caAlbert Chaulk	firmware/lib/cgptlib/mtdlib.c \
358534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	firmware/lib/flash_ts.c \
359eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	host/arch/${ARCH}/lib/crossystem_arch.c \
3605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/crossystem.c \
3615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/file_keys.c \
3625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/fmap.c \
3635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_common.c \
3645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_key.c \
3655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_keyblock.c \
3665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_misc.c \
3675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_signature.c \
36881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	host/lib/signature_digest.c \
36981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	utility/dump_kernel_config_lib.c
3705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
371eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonHOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
3725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${HOSTLIB_OBJS}
3735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
374eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Might need this too.
375eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
376eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
37781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Sigh. For historical reasons, the autoupdate installer must sometimes be a
37881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# 32-bit executable, even when everything else is 64-bit. But it only needs a
37981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# few functions, so let's just build those.
38081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
38181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
38281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_SRCS = \
38381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_create.c \
38481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_add.c \
38581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_boot.c \
38681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_show.c \
38781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_repair.c \
38881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_prioritize.c \
38981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_common.c \
390534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	cgpt/flash_ts_drv.c \
391b334e651a597a10d562bc882613f0b482b24e3caAlbert Chaulk	firmware/lib/cgptlib/mtdlib.c \
392534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	firmware/lib/flash_ts.c \
39381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	utility/dump_kernel_config_lib.c \
39481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/lib/cgptlib/crc32.c \
39581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/lib/cgptlib/cgptlib_internal.c \
3965fed2a667096341160db8643a4a057e328953a1dBill Richardson	firmware/lib/utility_string.c \
39781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/stub/utility_stub.c
39881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
39981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
400eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
401eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
402eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now for the userspace binaries
4035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT = ${BUILD}/cgpt/cgpt
4055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT_SRCS = \
4075d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt.c \
4085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_add.c \
4095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_boot.c \
4105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_common.c \
4115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_create.c \
4125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_find.c \
4135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_legacy.c \
4145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_prioritize.c \
4155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_repair.c \
4165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_show.c \
4175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_add.c \
4185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_boot.c \
4195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_create.c \
4205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_find.c \
4215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_legacy.c \
4225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_prioritize.c \
4235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_repair.c \
424534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	cgpt/cmd_show.c \
425534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	cgpt/flash_ts_drv.c \
426534723a6519267461855441279b321e6fc1e4e90Albert Chaulk	firmware/lib/flash_ts.c
4275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
428eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
4295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${CGPT_OBJS}
4305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
432eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Scripts to install directly (not compiled)
4335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_SCRIPTS = \
4345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/dev_debug_vboot \
4355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/enable_dev_usb_boot \
4365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/vbutil_what_keys
4375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
438c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonifeq (${MINIMAL},)
439c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonUTIL_SCRIPTS += \
440c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/dev_make_keypair
441c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
442c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
443eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These utilities should be linked statically.
444eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES_STATIC = \
445339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/crossystem \
446339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/gbb_utility
447eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
448eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES = ${UTIL_NAMES_STATIC} \
449339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/dev_sign_file \
450339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/dump_kernel_config \
451339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/dumpRSAPublicKey \
452339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/tpm_init_temp_fix \
453339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/tpmc \
454339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/vbutil_firmware \
455339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/vbutil_kernel \
456339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/vbutil_key \
457339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/vbutil_keyblock \
4585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
459eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
4605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES += \
461339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/bmpblk_font \
462339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/bmpblk_utility \
463339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/eficompress \
464339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/efidecompress \
465339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/load_kernel_test \
466339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/pad_digest_utility \
467339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/signature_digest_utility \
468339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/verify_data
4695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
4705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
471339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonUTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
472339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonUTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
4731912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
4745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
475c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
476c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Scripts for signing stuff.
477c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS = \
478c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/tpm-nvsize \
479c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/chromeos-tpm-recovery
480c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
481c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# These go in a different place.
482c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS_DEV = \
483c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/resign_firmwarefd.sh \
484c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_firmware.sh \
485c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_ssd.sh \
486c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/set_gbb_flags.sh
487c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
488c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Installed, but not made executable.
489c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_COMMON = scripts/image_signing/common_minimal.sh
490eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
491eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
492eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# The unified firmware utility will eventually replace all the others
493eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_BIN = ${BUILD}/futility/futility
4946db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson# But we still need both static (tiny) and dynamic (with openssl) versions.
4956db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_STATIC_BIN = ${FUTIL_BIN}_s
496eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
497feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# These are the others it will replace.
49820807b6158b6a43baf0974bc763890888ba1f841Bill RichardsonFUTIL_OLD = bmpblk_font bmpblk_utility cgpt chromeos-tpm-recovery crossystem \
49920807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	dev_debug_vboot dev_make_keypair dev_sign_file dumpRSAPublicKey \
50020807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	dump_fmap dump_kernel_config eficompress efidecompress \
50120807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	enable_dev_usb_boot gbb_utility load_kernel_test \
50220807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	make_dev_firmware.sh make_dev_ssd.sh pad_digest_utility \
50320807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	resign_firmwarefd.sh set_gbb_flags.sh signature_digest_utility \
50420807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	tpm-nvsize tpm_init_temp_fix tpmc vbutil_firmware vbutil_kernel \
50520807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	vbutil_key vbutil_keyblock vbutil_what_keys verify_data
506feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
5076db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_STATIC_SRCS = \
508feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/futility.c \
50920807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	futility/cmd_dump_fmap.c \
510feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/cmd_foo.c
511eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
5126db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_SRCS = \
5136db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	$(FUTIL_STATIC_SRCS) \
5146db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	futility/cmd_hey.c
5156db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson
516eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_LDS = futility/futility.lds
517eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
5186db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o}
519eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
520eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
521eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_OBJS += ${FUTIL_OBJS}
522eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
523eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
524eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Library of handy test functions.
525eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB = ${BUILD}/tests/test.a
526eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
527eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_SRCS = \
528eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/test_common.c \
529eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/timer_utils.c \
530eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/crc32_test.c
531eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
532eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
533eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_OBJS += ${TESTLIB_OBJS}
534eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
535eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
536eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And some compiled tests.
537eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES = \
538339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/cgptlib_test \
539339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rollback_index2_tests \
540339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rollback_index3_tests \
541339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_padding_test \
542339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_utility_tests \
543339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_verify_benchmark \
544339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/sha_benchmark \
545339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/sha_tests \
546339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/stateful_util_tests \
547339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tlcl_tests \
548339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_bootmode_tests \
549339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/utility_string_tests \
550339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/utility_tests \
551339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_init_tests \
552339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_devmode_tests \
553339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_firmware_tests \
554339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel_tests \
555339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel2_tests \
556339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel3_tests \
557339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel4_tests \
558339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_audio_tests \
559339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common_tests \
560339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common2_tests \
561339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common3_tests \
562339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_display_tests \
563339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_firmware_tests \
564339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_kernel_tests \
565339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_nvstorage_test \
566339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/futility/test_not_really
567eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
568527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassifdef REGION_READ
569527ba810eff4006cf69579f6b96cb4350cb1e189Simon GlassTEST_NAMES += tests/vboot_region_tests
570527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassendif
571527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
572786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerifneq (${VBOOT2},)
573786acdabcc15f023330d7c628aca9679e757a238Randall SpanglerTEST_NAMES += \
574786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	tests/vb2_common_tests \
5757141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	tests/vb2_common2_tests \
5767141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	tests/vb2_common3_tests \
5773333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_misc_tests \
5783333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_nvstorage_tests \
579e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_rsa_padding_tests \
580e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_rsa_utility_tests \
5813333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_secdata_tests \
582e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_sha_tests \
583786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
584786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerendif
585786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
586eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: port these tests to new API, if not already eqivalent
587eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# functionality in other tests.  These don't even compile at present.
588eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
589eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		big_firmware_tests
590eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		big_kernel_tests
591eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_image_tests
592eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_rollback_tests
593eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_splicing_tests
594eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_verify_benchmark
595eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_image_tests
596eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_rollback_tests
597eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_splicing_tests
598eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_verify_benchmark
599eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		rollback_index_test
600eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		verify_firmware_fuzz_driver
601eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		verify_kernel_fuzz_driver
602eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#               utility/load_firmware_test
603eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
604eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more...
605339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTLCL_TEST_NAMES = \
606339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_earlyextend \
607339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_earlynvram \
608339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_earlynvram2 \
609339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_enable \
610339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_fastenable \
611339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_globallock \
612339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_redefine_unowned \
613339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_spaceperm \
614339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_testsetup \
615339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_timing \
616339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_writelimit
617eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
618eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES += ${TLCL_TEST_NAMES}
619eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
620339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson# Finally
621339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
6221912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += $(addsuffix .o,${TEST_BINS})
623eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
624e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler# Directory containing test keys
625e061a256549607a56d771eb8ddae5d0dd90d519cRandall SpanglerTEST_KEYS = ${SRC_RUN}/tests/testkeys
626eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
627eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
628eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
629eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Finally, some targets. High-level ones first.
630eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
631eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create output directories if necessary.  Do this via explicit shell commands
632eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# so it happens before trying to generate/include dependencies.
633eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonSUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
634eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson_dir_create := $(foreach d, \
635eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell find ${SUBDIRS} -name '*.c' -exec  dirname {} \; | sort -u), \
636eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
637eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
638eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
639eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Default target.
640eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: all
641786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerall: fwlib $(if ${VBOOT2},fwlib2) $(if ${FIRMWARE_ARCH},,host_stuff) \
642786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	$(if ${COV},coverage)
643eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
644eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Host targets
645eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: host_stuff
646eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonhost_stuff: hostlib cgpt utils futil tests
647eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
648eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: clean
649eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonclean:
650eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}/bin/rm -rf ${BUILD}
651eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
652eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: install
653c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsoninstall: cgpt_install utils_install signing_install futil_install
654eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
655eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Don't delete intermediate object files
656eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.SECONDARY:
657eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
658eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
659eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
660eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Firmware library
661eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
662eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM-specific flags.  These depend on the particular TPM we're targeting for.
663eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# They are needed here only for compiling parts of the firmware code into
664eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# user-level tests.
665eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
666eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
667eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# the self test has completed.
668eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
66945cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
670eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
671eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
672eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
673eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# power on.
674eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
675eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
676eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# are not both defined at the same time.  (See comment in code.)
677eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
678eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CFLAGS += -DTPM_MANUAL_SELFTEST
679eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
680eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},i386)
681eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Unrolling loops in cryptolib makes it faster
68245cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
683786acdabcc15f023330d7c628aca9679e757a238Randall Spangler${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
684eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
685eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Workaround for coreboot on x86, which will power off asynchronously
686eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# without giving us a chance to react. This is not an example of the Right
687eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Way to do things. See chrome-os-partner:7689, and the commit message
688eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# that made this change.
68945cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
690eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
691eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# On x86 we don't actually read the GBB data into RAM until it is needed.
692eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Therefore it makes sense to cache it rather than reading it each time.
693eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Enable this feature.
69445cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
695eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
696eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
697527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassifdef REGION_READ
698527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass${FWLIB_OBJS}: CFLAGS += -DREGION_READ
699527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassendif
700527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
701eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
702eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Disable rollback TPM when compiling locally, since otherwise
703eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# load_kernel_test attempts to talk to the TPM.
70445cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
705eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
706eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
707a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson# Linktest ensures firmware lib doesn't rely on outside libraries
708a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
70993943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
7101912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
711a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
71293943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
7131912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
714a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main: ${FWLIB}
715a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
7161912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/linktest/main.o
71793943266c597ad66300445a04afa01270f2b5763Randall Spangler
71893943266c597ad66300445a04afa01270f2b5763Randall Spangler.phony: fwlinktest
71993943266c597ad66300445a04afa01270f2b5763Randall Spanglerfwlinktest: ${FWLIB} \
72093943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbinit \
72193943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbsf \
72293943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main
72393943266c597ad66300445a04afa01270f2b5763Randall Spangler
724eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: fwlib
725a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardsonfwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
726eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
727786acdabcc15f023330d7c628aca9679e757a238Randall Spangler.PHONY: fwlib2
728786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerfwlib2: ${FWLIB2}
729786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
730eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${FWLIB}: ${FWLIB_OBJS}
731661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
732eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
733661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
734eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
735eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
736786acdabcc15f023330d7c628aca9679e757a238Randall Spangler${FWLIB2}: ${FWLIB2_OBJS}
737786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
738786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${Q}rm -f $@
739786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
740786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${Q}ar qc $@ $^
741786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
742eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
743eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Host library
744eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
745a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson
746a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson# Link tests
747a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/host/linktest/main: ${HOSTLIB}
748a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/host/linktest/main: LIBS = ${HOSTLIB}
7491912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/host/linktest/main.o
750a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson
751eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: hostlib
752a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardsonhostlib: ${BUILD}/host/linktest/main
753eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
754eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
7550c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/include \
7560c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/arch/${ARCH}/include \
7570c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/lib/include
758eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
759eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: better way to make .a than duplicating this recipe each time?
760786acdabcc15f023330d7c628aca9679e757a238Randall Spangler${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS} $(if ${VBOOT2},${FWLIB2_OBJS})
761661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
762eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
763661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
764eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
765eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
76681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
76781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
76881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson.PHONY: tinyhostlib
76981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardsontinyhostlib: ${TINYHOSTLIB}
77081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
77181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
77281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
773661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
77481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}rm -f $@
775661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
77681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}ar qc $@ $^
77781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
778eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
779eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CGPT library and utility
780eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
781eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt
782eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsoncgpt: ${CGPT}
783eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
7840c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${CGPT_OBJS}: INCLUDES += -Ihost/include
7850c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
786eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDFLAGS += -static
787eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDLIBS += -luuid
788eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
789a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${CGPT}: ${CGPT_OBJS} ${HOSTLIB}
790661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LDcgpt        $(subst ${BUILD}/,,$@)\n"
7916db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
792eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
793eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt_install
794eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsoncgpt_install: ${CGPT}
795661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       CGPT\n"
796c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
797c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} $^
798eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
799eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
800eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities
801eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
802eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These have their own headers too.
8030c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${BUILD}/utility/%: INCLUDES += \
8040c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/include \
8050c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/lib/include \
8060c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Iutility/include
807eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
808eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities for auto-update toolkits must be statically linked.
809eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${UTIL_BINS_STATIC}: LDFLAGS += -static
810eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
811a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson
812acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils
813c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill Richardsonutils: ${UTIL_BINS} ${UTIL_SCRIPTS}
814eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
815eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
816826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson
817a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${UTIL_BINS} ${UTIL_BINS_STATIC}: ${HOSTLIB}
818a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${HOSTLIB}
819a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson
820acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils_install
821c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill Richardsonutils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
822661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       UTILS\n"
823c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
824c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
825c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
826c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# And some signing stuff for the target
827c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson.PHONY: signing_install
828c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonsigning_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
829661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       SIGNING\n"
830c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
831c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
832feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS_DEV}
833feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}${INSTALL} -t ${UB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
834feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${VB_DIR},)
835c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${VB_DIR}
836feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}for prog in $(notdir ${SIGNING_SCRIPTS_DEV}); do \
837feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson		ln -sf "${FT_DIR}/futility" "${VB_DIR}/$$prog"; done
838c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
8395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
840eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
841eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# new Firmware Utility
8425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
843eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil
8446db8c75021e2edfa400ae707a8544d041e3c415fBill Richardsonfutil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
8456db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson
8466db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS}
8476db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
8486db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
8495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
850eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
851661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
8526db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
8535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
854eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil_install
855eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonfutil_install: ${FUTIL_BIN}
856661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       futility\n"
857feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}mkdir -p ${F_DIR}
8586db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${INSTALL} -t ${F_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
859feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}for prog in ${FUTIL_OLD}; do \
860feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson		ln -sf futility "${F_DIR}/$$prog"; done
8615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
86220807b6158b6a43baf0974bc763890888ba1f841Bill Richardson# TODO(wfrichar): This will need some refactoring (crbug.com/228932)
86320807b6158b6a43baf0974bc763890888ba1f841Bill Richardson${BUILD}/futility/% ${HOSTLIB}: INCLUDES += \
86420807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	-Ihost/include \
86520807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	-Ihost/arch/${ARCH}/include \
86620807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	-Ihost/lib/include
86720807b6158b6a43baf0974bc763890888ba1f841Bill Richardson${FUTIL_STATIC_BIN} ${FUTIL_BIN}: ${HOSTLIB}
86820807b6158b6a43baf0974bc763890888ba1f841Bill Richardson${FUTIL_STATIC_BIN} ${FUTIL_BIN}: LIBS = ${HOSTLIB}
86920807b6158b6a43baf0974bc763890888ba1f841Bill Richardson
870eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
8715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utility to generate TLCL structure definition header file.
8725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
873acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
8745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
8755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
8765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
8775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
878acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: update_tlcl_structures
8795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerupdate_tlcl_structures: ${BUILD}/utility/tlcl_generator
880661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    Rebuilding TLCL structures\n"
881eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
882eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
8835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		( echo "%% Updating structures.h %%" && \
884eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson		  cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
8855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
886eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
8875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Tests
8885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
889eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: tests
890eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontests: ${TEST_BINS}
8915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
892a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${TEST_BINS}: ${HOSTLIB} ${TESTLIB}
893339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson${TEST_BINS}: INCLUDES += -Itests
894a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${TEST_BINS}: LIBS = ${HOSTLIB} ${TESTLIB}
8955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
896eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TESTLIB}: ${TESTLIB_OBJS}
897661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
898eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
899661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
900eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
9015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
9025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
903eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
904eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
905eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# rules for specific targets.
9065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
907eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
908661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
9096db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
910eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
911eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.c
912661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC            $(subst ${BUILD}/,,$@)\n"
913eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
914eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
915eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Rules to recompile a single source file for library and test
916eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: is there a tidier way to do this?
917eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
918eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: %.c
919661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC-for-lib    $(subst ${BUILD}/,,$@)\n"
920eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
921eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
922eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
923eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: %.c
924661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC-for-test   $(subst ${BUILD}/,,$@)\n"
925eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
926eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
927eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: C++ files don't belong in vboot reference at all.  Convert to C.
928eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.cc
929661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CXX           $(subst ${BUILD}/,,$@)\n"
930eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
931eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
932eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
933eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Here are the special tweaks to the generic rules.
934eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
935eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# GBB utility needs C++ linker. TODO: It shouldn't.
936eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/gbb_utility: LD = ${CXX}
937eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
938feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# Because we play some clever linker script games to add new commands without
939feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# changing any header files, futility must be linked with ld.bfd, not gold.
940feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
9416db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd
942feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
943eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Some utilities need external crypto functions
944eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
945eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
946eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
947eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
948eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
949eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
950eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
951eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
952eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
953eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
9547141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
9557141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
956eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
957eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
958eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
959eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: LD = ${CXX}
960eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
961eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
962eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonBMPBLK_UTILITY_DEPS = \
963eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/bmpblk_util.o \
964eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/image_types.o \
965eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/eficompress_for_lib.o \
966eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/efidecompress_for_lib.o
9671912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson
968eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
969eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
9701912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BMPBLK_UTILITY_DEPS}
971eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
972eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
973eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
9741912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/utility/image_types.o
975eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
976eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Allow multiple definitions, so tests can mock functions from other libraries
977eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
9780c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${BUILD}/tests/%: INCLUDES += -Ihost/include -Ihost/lib/include
979eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LDLIBS += -lrt -luuid
980eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LIBS += ${TESTLIB}
9815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
9825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/rollback_index2_tests: OBJS += \
98317f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/rollback_index_for_test.o
984eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/rollback_index2_tests: \
985eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/rollback_index_for_test.o
9861912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
9875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
988c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: OBJS += \
989c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
990c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: \
991c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
9921912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
993c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler
9945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/vboot_audio_tests: OBJS += \
99517f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/vboot_audio_for_test.o
996eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_audio_tests: \
997eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/vboot_audio_for_test.o
9981912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
9995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1000acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
1001acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
10025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1003339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1004eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1005eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
10061912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
10075d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1008eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
1009eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Targets that exist just to run tests
10105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Frequently-run tests
1012eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_targets
1013786acdabcc15f023330d7c628aca9679e757a238Randall Spanglertest_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
1014844bce57471153664c78993dab453e87891bb969Randall Spangler
1015eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
1016844bce57471153664c78993dab453e87891bb969Randall Spangler# Bitmap utility isn't compiled for minimal variant
1017feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsontest_targets:: runbmptests runfutiltests
1018844bce57471153664c78993dab453e87891bb969Randall Spangler# Scripts don't work under qemu testing
1019844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: convert scripts to makefile so they can be called directly
1020eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_targets:: runtestscripts
1021844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
1022844bce57471153664c78993dab453e87891bb969Randall Spangler
1023eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_setup
1024eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_setup:: cgpt utils futil tests
1025eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1026844bce57471153664c78993dab453e87891bb969Randall Spangler# Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
1027844bce57471153664c78993dab453e87891bb969Randall Spangler# sysroot.
1028eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${QEMU_ARCH},)
1029eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_setup:: qemu_install
1030844bce57471153664c78993dab453e87891bb969Randall Spangler
1031844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: qemu_install
1032844bce57471153664c78993dab453e87891bb969Randall Spanglerqemu_install:
1033eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${SYSROOT},)
1034eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(error SYSROOT must be set to the top of the target-specific root \
1035eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonwhen cross-compiling for qemu-based tests to run properly.)
1036eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
1037661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    Copying qemu binary.\n"
1038eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1039eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
1040844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
1041844bce57471153664c78993dab453e87891bb969Randall Spangler
1042acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runtests
1043a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardsonruntests: test_setup test_targets
10445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test keys
1046acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genkeys
1047844bce57471153664c78993dab453e87891bb969Randall Spanglergenkeys: utils
10485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_test_keys.sh
10495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test cases for fuzzing
1051acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genfuzztestcases
1052a808dc944284e6eba39a8f19ddb46bc61c34de8aRandall Spanglergenfuzztestcases: utils
10535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_fuzz_test_cases.sh
10545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1055acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runbmptests
1056eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunbmptests: test_setup
1057eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
10585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		./TestBmpBlock.py -v
10595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1060acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runcgpttests
1061eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruncgpttests: test_setup
1062eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
10635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1064844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runtestscripts
1065eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruntestscripts: test_setup genfuzztestcases
1066eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
106742c08cb2dac102509491810361e239fbde52b9e0Albert Chaulk	tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -N=512,32,1,3
10685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh
10695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_rsa_tests.sh
1070844bce57471153664c78993dab453e87891bb969Randall Spangler	tests/run_vbutil_kernel_arg_tests.sh
10715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh
1072e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spanglerifneq (${VBOOT2},)
1073e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_rsa_tests.sh
1074e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spanglerendif
10755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1076844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runmisctests
1077eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunmisctests: test_setup
1078eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
1079a3eac79f5070747e326da631c1eec155f0389919Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
1080eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1081eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1082eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
1083c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1084eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1085eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1086eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1087eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
1088eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
10890714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
10900714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
10917f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
10927f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
10937f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
1094eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
1095e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1096e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1097e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
1098786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
1099eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
110049cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
11016dbf9d9160b2927d76017d0f51919e0880f9b2ccRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
1102eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1103786acdabcc15f023330d7c628aca9679e757a238Randall Spangler.PHONY: run2tests
1104786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerrun2tests: test_setup
1105786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
11067141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
11077141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
11083333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
11093333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1110e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
11113333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
1112e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
1113786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
1114eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: runfutiltests
1115feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonrunfutiltests: override DESTDIR = ${TEST_INSTALL_DIR}
1116eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunfutiltests: test_setup install
1117339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/futility/run_test_scripts.sh ${DESTDIR}
1118339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1119844bce57471153664c78993dab453e87891bb969Randall Spangler
11205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Run long tests, including all permutations of encryption keys (instead of
1121786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler# just the ones we use) and tests of currently-unused code.
11225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Not run by automated build.
1123acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runlongtests
1124eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunlongtests: test_setup genkeys genfuzztestcases
1125e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1126e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
11277141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spanglerifneq (${VBOOT2},)
11287141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
11297141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
11307141d73c149ee203a192f0cb45ca9bfa10c0ff8cRandall Spanglerendif
11315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh --all
11325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh --all
11335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
11345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: tests to run when ported to new API
11355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	./run_image_verification_tests.sh
11365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Splicing tests
11375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_splicing_tests
11385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_splicing_tests
11395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Rollback Tests
11405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_rollback_tests
11415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_rollback_tests
11425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
114359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
114459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_init
114559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_init: test_setup
114659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	rm -f ${COV_INFO}*
114759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -i -d . -b . -o ${COV_INFO}.initial
114859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
114959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_html
115059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_html:
115159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -d . -b . -o ${COV_INFO}.tests
115259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
115359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
115459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	genhtml ${COV_INFO}.local -o ${BUILD}/coverage
115559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
115659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Generate addtional coverage stats just for firmware subdir, because the
115759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# per-directory stats for the whole project don't include their own subdirs.
115849cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
115949cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
116059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler		-o ${COV_INFO}.firmware
116159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
116259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage
116359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerifeq (${COV},)
116459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage:
116559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	$(error Build coverage like this: make clean && COV=1 make)
116659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerelse
116759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage: coverage_init runtests coverage_html
116859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerendif
11691912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson
11701912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson# Include generated dependencies
11711912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
11721912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson-include ${ALL_DEPS}
1173