Makefile revision 0c3ba249abb1dc60f5ebabccf84ff13206440b83
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
10261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerendif
10361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
104b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
105b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# please add them after this point (e.g., -DVBOOT_DEBUG).
10674359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
1076b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
1086b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# temporarily. As we are still investigating which flags are necessary for
1096b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
11074359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
111b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# As a first step, this makes the setting of CC and CFLAGS here optional, to
112b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# permit a calling script or Makefile to set these.
11374359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
114b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Flag ordering: arch, then -f, then -m, then -W
115b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassDEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
116b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCOMMON_FLAGS := -nostdinc -pipe \
117b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffreestanding -fno-builtin -fno-stack-protector \
118eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	-Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
119b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
120eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
121eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH}, arm)
122b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= armv7a-cros-linux-gnueabi-gcc
123b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= -march=armv5 \
124b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fno-common -ffixed-r8 \
125d50b27d15de8cc9e37410fc52d3184f17e0db5bbDoug Anderson	-mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
126eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
12761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${FIRMWARE_ARCH}, x86)
128b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= i686-pc-linux-gnu-gcc
129b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Drop -march=i386 to permit use of SSE instructions
130b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= \
131b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
132b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
133b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-mpreferred-stack-boundary=2 -mregparm=3 \
134eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
135eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonelse ifeq (${FIRMWARE_ARCH}, x86_64)
136eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS ?= ${COMMON_FLAGS} \
1378e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glass	-fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
138844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
139eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# FIRMWARE_ARCH not defined; assuming local compile.
140eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCC ?= gcc
141eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror # HEY: always want last two?
1428e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glassendif
14334be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiou
144feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${OLDDIR},)
145feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonCFLAGS += -DOLDDIR=${OLDDIR}
146feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonendif
147feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
148eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${DEBUG},)
149eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DVBOOT_DEBUG
150eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
151844bce57471153664c78993dab453e87891bb969Randall Spangler
152eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${DISABLE_NDEBUG},)
153eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DNDEBUG
154eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
155eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
156feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${FORCE_LOGGING_ON},)
157feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonCFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
158feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonendif
159feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
160eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create / use dependency files
161eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -MMD -MF $@.d
162eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1630c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson# These are required to access large disks and files on 32-bit systems.
1640c3ba249abb1dc60f5ebabccf84ff13206440b83Bill RichardsonCFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
1650c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
16659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
167eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${COV},)
16859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  COV_FLAGS = -O0 --coverage
16959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  CFLAGS += ${COV_FLAGS}
17059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  LDFLAGS += ${COV_FLAGS}
17159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  COV_INFO = ${BUILD}/coverage.info
172eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
173eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
174eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more default utilities
175eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonLD = ${CC}
176eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCXX ?= g++ # HEY: really?
177eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonPKG_CONFIG ?= pkg-config
178eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
179844bce57471153664c78993dab453e87891bb969Randall Spangler# Determine QEMU architecture needed, if any
180eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${ARCH},${HOST_ARCH})
181844bce57471153664c78993dab453e87891bb969Randall Spangler  # Same architecture; no need for QEMU
182844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
18361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
184844bce57471153664c78993dab453e87891bb969Randall Spangler  # 64-bit host can run 32-bit targets directly
185844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
186844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
187eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_ARCH := ${ARCH}
188844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
189844bce57471153664c78993dab453e87891bb969Randall Spangler
190844bce57471153664c78993dab453e87891bb969Randall Spangler# The top of the chroot for qemu must be passed in via the SYSROOT environment
191844bce57471153664c78993dab453e87891bb969Randall Spangler# variable.  In the Chromium OS chroot, this is done automatically by the
192844bce57471153664c78993dab453e87891bb969Randall Spangler# ebuild.
193844bce57471153664c78993dab453e87891bb969Randall Spangler
194eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${QEMU_ARCH},)
195844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is same as for building
196eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = ${BUILD}
197e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = ${SRCDIR}
198844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
199844bce57471153664c78993dab453e87891bb969Randall Spangler  $(info Using qemu for testing.)
200844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is different in the chroot
201eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
202e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
203844bce57471153664c78993dab453e87891bb969Randall Spangler
204eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_BIN = qemu-${QEMU_ARCH}
205e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
206e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  export QEMU_RUN
207287beaed7f8ceff679c57664d4da008c6234edfdRandall Spangler
208e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  RUNTEST = tests/test_using_qemu.sh
209e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerendif
2105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
211e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerexport BUILD_RUN
2125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
213eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
214eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now we need to describe everything we might want or need to build
215b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
216eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Everything wants these headers.
2175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += \
2185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/include \
2195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/include \
2205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cgptlib/include \
2215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cryptolib/include \
2225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/tpm_lite/include
2230b8f35c6a56a0e645254dd7f07ca68e01c8ee629Bill Richardson
224eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# If we're not building for a specific target, just stub out things like the
225eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM commands and various external functions that are provided by the BIOS.
226eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
2275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += -Ifirmware/stub/include
2280a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiouelse
229eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonINCLUDES += -Ifirmware/arch/${FIRMWARE_ARCH}/include
2305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
232eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Firmware library. TODO: Do we still need to export this?
233eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB = ${BUILD}/vboot_fw.a
2345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
23593943266c597ad66300445a04afa01270f2b5763Randall Spangler# Firmware library sources needed by VbInit() call
23693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS = \
2375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/crc8.c \
23893943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility.c \
23993943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_api_init.c \
24093943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common_init.c \
24193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_nvstorage.c \
24293943266c597ad66300445a04afa01270f2b5763Randall Spangler
24393943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectFirmware() call
24493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS = \
2455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/padding.c \
2465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa.c \
2475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa_utility.c \
2485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha1.c \
2495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha256.c \
2505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha512.c \
2515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha_utility.c \
2525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/stateful_util.c \
2535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_firmware.c \
25493943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common.c \
25593943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_firmware.c
25693943266c597ad66300445a04afa01270f2b5763Randall Spangler
25793943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectAndLoadKernel() call
25893943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS = \
25993943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib.c \
26093943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib_internal.c \
26193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/crc32.c \
26293943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility_string.c \
2635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_kernel.c \
2645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_audio.c \
2655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_display.c \
26693943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_kernel.c
2675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
268eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Support real TPM unless BIOS sets MOCK_TPM
269eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MOCK_TPM},)
27093943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
2715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/rollback_index.c \
2725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/tlcl.c
27393943266c597ad66300445a04afa01270f2b5763Randall Spangler
27493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
27593943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/tpm_bootmode.c
2765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerelse
27793943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
2785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/mocked_rollback_index.c \
2795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/mocked_tlcl.c
28093943266c597ad66300445a04afa01270f2b5763Randall Spangler
28193943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
28293943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/mocked_tpm_bootmode.c
2835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
285eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
286eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Include BIOS stubs in the firmware library when compiling for host
28793943266c597ad66300445a04afa01270f2b5763Randall Spangler# TODO: split out other stub funcs too
28893943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
2895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/tpm_lite_stub.c \
2905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/utility_stub.c \
29193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/stub/vboot_api_stub_init.c
29293943266c597ad66300445a04afa01270f2b5763Randall Spangler
29393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
29493943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/stub/vboot_api_stub_sf.c
29593943266c597ad66300445a04afa01270f2b5763Randall Spangler
29693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS += \
2975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub.c \
2985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub_disk.c
2995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
30193943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += ${VBINIT_SRCS}
30293943266c597ad66300445a04afa01270f2b5763Randall SpanglerFWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
30393943266c597ad66300445a04afa01270f2b5763Randall Spangler
30493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
30593943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
30693943266c597ad66300445a04afa01270f2b5763Randall Spangler
307eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
3085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${FWLIB_OBJS}
3095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
311eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Library to build the utilities. "HOST" mostly means "userspace".
312c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill RichardsonHOSTLIB = ${BUILD}/libvboot_host.a
3135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerHOSTLIB_SRCS = \
31581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_create.c \
31681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_add.c \
31781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_boot.c \
31881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_show.c \
31981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_repair.c \
32081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_prioritize.c \
32181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_common.c \
322eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	host/arch/${ARCH}/lib/crossystem_arch.c \
3235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/crossystem.c \
3245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/file_keys.c \
3255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/fmap.c \
3265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_common.c \
3275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_key.c \
3285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_keyblock.c \
3295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_misc.c \
3305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_signature.c \
33181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	host/lib/signature_digest.c \
33281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	utility/dump_kernel_config_lib.c
3335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
334eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonHOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
3355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${HOSTLIB_OBJS}
3365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
337eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Link with hostlib by default
338eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonLIBS = $(HOSTLIB)
339eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
340eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Might need this too.
341eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
342eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
34381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Sigh. For historical reasons, the autoupdate installer must sometimes be a
34481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# 32-bit executable, even when everything else is 64-bit. But it only needs a
34581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# few functions, so let's just build those.
34681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
34781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
34881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_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 \
35681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	utility/dump_kernel_config_lib.c \
35781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/lib/cgptlib/crc32.c \
35881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/lib/cgptlib/cgptlib_internal.c \
3595fed2a667096341160db8643a4a057e328953a1dBill Richardson	firmware/lib/utility_string.c \
36081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	firmware/stub/utility_stub.c
36181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
36281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
363eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
364eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
365eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now for the userspace binaries
3665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT = ${BUILD}/cgpt/cgpt
3685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT_SRCS = \
3705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt.c \
3715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_add.c \
3725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_boot.c \
3735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_common.c \
3745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_create.c \
3755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_find.c \
3765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_legacy.c \
3775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_prioritize.c \
3785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_repair.c \
3795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_show.c \
3805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_add.c \
3815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_boot.c \
3825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_create.c \
3835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_find.c \
3845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_legacy.c \
3855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_prioritize.c \
3865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_repair.c \
3875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_show.c
3885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
389eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
3905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${CGPT_OBJS}
3915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
393eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Scripts to install directly (not compiled)
3945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_SCRIPTS = \
3955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/dev_debug_vboot \
3965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/enable_dev_usb_boot \
3975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/vbutil_what_keys
3985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
399c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonifeq (${MINIMAL},)
400c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonUTIL_SCRIPTS += \
401c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/dev_make_keypair
402c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
403c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
404eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These utilities should be linked statically.
405eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES_STATIC = \
406eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	crossystem \
407eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	dump_fmap \
408eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	gbb_utility
409eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
410eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES = ${UTIL_NAMES_STATIC} \
4115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dev_sign_file \
4125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dump_kernel_config \
4135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dumpRSAPublicKey \
4145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tpm_init_temp_fix \
4155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tpmc \
4165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_firmware \
4175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_kernel \
4185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_key \
4195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_keyblock \
4205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
421eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
4225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES += \
4235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	bmpblk_font \
4245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	bmpblk_utility \
4255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	eficompress \
426c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	efidecompress \
427c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	load_kernel_test \
428c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	pad_digest_utility \
429c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	signature_digest_utility \
430c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	verify_data
4315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
4325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
433eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_BINS_STATIC := $(addprefix ${BUILD}/utility/,${UTIL_NAMES_STATIC})
434eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_BINS = $(addprefix ${BUILD}/utility/,${UTIL_NAMES})
4355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_DEPS += $(addsuffix .d,${UTIL_BINS})
4365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
437c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
438c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Scripts for signing stuff.
439c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS = \
440c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/tpm-nvsize \
441c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/chromeos-tpm-recovery
442c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
443c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# These go in a different place.
444c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS_DEV = \
445c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/resign_firmwarefd.sh \
446c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_firmware.sh \
447c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_ssd.sh \
448c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/set_gbb_flags.sh
449c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
450c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Installed, but not made executable.
451c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_COMMON = scripts/image_signing/common_minimal.sh
452eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
453eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
454eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# The unified firmware utility will eventually replace all the others
455eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_BIN = ${BUILD}/futility/futility
456eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
457feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# These are the others it will replace.
458feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonFUTIL_OLD = $(notdir ${CGPT} ${UTIL_BINS} ${UTIL_SCRIPTS} \
459feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson		${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV})
460feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
461eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_SRCS = \
462feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/futility.c \
463feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/cmd_foo.c
464eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
465eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_LDS = futility/futility.lds
466eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
467eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o}
468eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
469eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_DEPS += $(addsuffix .d,${FUTIL_BIN})
470eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_OBJS += ${FUTIL_OBJS}
471eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
472eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
473eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Library of handy test functions.
474eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB = ${BUILD}/tests/test.a
475eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
476eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_SRCS = \
477eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/test_common.c \
478eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/timer_utils.c \
479eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/crc32_test.c
480eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
481eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
482eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_OBJS += ${TESTLIB_OBJS}
483eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
484eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
485eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And some compiled tests.
486eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES = \
487eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	cgptlib_test \
488eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	rollback_index2_tests \
489a3eac79f5070747e326da631c1eec155f0389919Randall Spangler	rollback_index3_tests \
490eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	rsa_padding_test \
491eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	rsa_utility_tests \
492eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	rsa_verify_benchmark \
493eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	sha_benchmark \
494eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	sha_tests \
495eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	stateful_util_tests \
496c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	tlcl_tests \
497eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpm_bootmode_tests \
498eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	utility_string_tests \
499eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	utility_tests \
500eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_api_init_tests \
501eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_api_devmode_tests \
502eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_api_firmware_tests \
503eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_api_kernel_tests \
5047f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	vboot_api_kernel2_tests \
5057f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	vboot_api_kernel3_tests \
5067f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	vboot_api_kernel4_tests \
507eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_audio_tests \
508eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_common_tests \
509eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_common2_tests \
510eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	vboot_common3_tests \
511786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler	vboot_display_tests \
5126dbf9d9160b2927d76017d0f51919e0880f9b2ccRandall Spangler	vboot_firmware_tests \
51349cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	vboot_kernel_tests \
5146dbf9d9160b2927d76017d0f51919e0880f9b2ccRandall Spangler	vboot_nvstorage_test
515eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
516eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: port these tests to new API, if not already eqivalent
517eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# functionality in other tests.  These don't even compile at present.
518eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
519eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		big_firmware_tests
520eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		big_kernel_tests
521eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_image_tests
522eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_rollback_tests
523eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_splicing_tests
524eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		firmware_verify_benchmark
525eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_image_tests
526eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_rollback_tests
527eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_splicing_tests
528eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		kernel_verify_benchmark
529eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		rollback_index_test
530eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		verify_firmware_fuzz_driver
531eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#		verify_kernel_fuzz_driver
532eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#               utility/load_firmware_test
533eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
534eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more...
535eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTLCL_TESTS = \
536eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_earlyextend \
537eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_earlynvram \
538eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson        tpmtest_earlynvram2 \
539eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_enable \
540eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_fastenable \
541eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_globallock \
542eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson        tpmtest_redefine_unowned \
543eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson        tpmtest_spaceperm \
544eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_testsetup \
545eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tpmtest_timing \
546eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson        tpmtest_writelimit
547eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTLCL_TEST_NAMES = $(addprefix tpm_lite/,${TLCL_TESTS})
548eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTLCL_TEST_BINS = $(addprefix ${BUILD}/tests/,${TLCL_TEST_NAMES})
549eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
550eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES += ${TLCL_TEST_NAMES}
551eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
552eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_BINS = $(addprefix ${BUILD}/tests/,${TEST_NAMES})
553eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_DEPS += $(addsuffix .d,${TEST_BINS})
554eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
555e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler# Directory containing test keys
556e061a256549607a56d771eb8ddae5d0dd90d519cRandall SpanglerTEST_KEYS = ${SRC_RUN}/tests/testkeys
557eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
558eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
559eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
560eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Finally, some targets. High-level ones first.
561eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
562eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create output directories if necessary.  Do this via explicit shell commands
563eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# so it happens before trying to generate/include dependencies.
564eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonSUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
565eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson_dir_create := $(foreach d, \
566eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell find ${SUBDIRS} -name '*.c' -exec  dirname {} \; | sort -u), \
567eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
568eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
569eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
570eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Default target.
571eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: all
57259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerall: fwlib $(if ${FIRMWARE_ARCH},,host_stuff) $(if ${COV},coverage)
573eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
574eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Host targets
575eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: host_stuff
576eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonhost_stuff: hostlib cgpt utils futil tests
577eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
578eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: clean
579eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonclean:
580eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}/bin/rm -rf ${BUILD}
581eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
582eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: install
583c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsoninstall: cgpt_install utils_install signing_install futil_install
584eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
585eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Don't delete intermediate object files
586eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.SECONDARY:
587eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
588eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: I suspect this is missing some object files.  Make a temp
589eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# target which cleans all known obj/exe's and see what's left; those
590eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# are the files which need deps.
591eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
592eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson-include ${ALL_DEPS}
593eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
594eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
595eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Firmware library
596eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
597eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM-specific flags.  These depend on the particular TPM we're targeting for.
598eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# They are needed here only for compiling parts of the firmware code into
599eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# user-level tests.
600eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
601eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
602eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# the self test has completed.
603eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
60445cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
605eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
606eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
607eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
608eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# power on.
609eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
610eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
611eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# are not both defined at the same time.  (See comment in code.)
612eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
613eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CFLAGS += -DTPM_MANUAL_SELFTEST
614eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
615eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},i386)
616eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Unrolling loops in cryptolib makes it faster
61745cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
618eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
619eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Workaround for coreboot on x86, which will power off asynchronously
620eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# without giving us a chance to react. This is not an example of the Right
621eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Way to do things. See chrome-os-partner:7689, and the commit message
622eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# that made this change.
62345cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
624eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
625eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# On x86 we don't actually read the GBB data into RAM until it is needed.
626eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Therefore it makes sense to cache it rather than reading it each time.
627eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Enable this feature.
62845cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
629eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
630eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
631eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
632eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Disable rollback TPM when compiling locally, since otherwise
633eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# load_kernel_test attempts to talk to the TPM.
63445cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
635eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
636eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
63793943266c597ad66300445a04afa01270f2b5763Randall Spangler# Link tests
63893943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbinit: LIBS =
63993943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
64093943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbsf: LIBS =
64193943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
64293943266c597ad66300445a04afa01270f2b5763Randall Spangler
64393943266c597ad66300445a04afa01270f2b5763Randall Spangler.phony: fwlinktest
64493943266c597ad66300445a04afa01270f2b5763Randall Spanglerfwlinktest: ${FWLIB} \
64593943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbinit \
64693943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbsf \
64793943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main
64893943266c597ad66300445a04afa01270f2b5763Randall Spangler
649eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: fwlib
65093943266c597ad66300445a04afa01270f2b5763Randall Spanglerfwlib: ${FWLIB} $(if ${FIRMWARE_ARCH},,fwlinktest)
651eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
652eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${FWLIB}: ${FWLIB_OBJS}
653661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
654eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
655661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
656eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
657eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
658eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
659eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Host library
660eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
661eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: hostlib
662eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonhostlib: ${HOSTLIB} ${BUILD}/host/linktest/main
663eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
664eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
6650c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/include \
6660c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/arch/${ARCH}/include \
6670c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/lib/include
668eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
669eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: better way to make .a than duplicating this recipe each time?
670eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${HOSTLIB}: ${HOSTLIB_OBJS} ${FWLIB_OBJS}
671661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
672eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
673661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
674eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
675eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
67681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
67781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
67881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson.PHONY: tinyhostlib
67981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardsontinyhostlib: ${TINYHOSTLIB}
68081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
68181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
68281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
683661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
68481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}rm -f $@
685661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
68681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}ar qc $@ $^
68781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
688eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
689eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CGPT library and utility
690eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
691eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt
692eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsoncgpt: ${CGPT}
693eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
6940c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${CGPT_OBJS}: INCLUDES += -Ihost/include
6950c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
696eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDFLAGS += -static
697eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDLIBS += -luuid
698eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
699eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: ${CGPT_OBJS} ${LIBS}
700661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LDcgpt        $(subst ${BUILD}/,,$@)\n"
701eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${LD} -o ${CGPT} ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
702eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
703eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt_install
704eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsoncgpt_install: ${CGPT}
705661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       CGPT\n"
706c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
707c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} $^
708eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
709eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
710eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities
711eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
712eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These have their own headers too.
7130c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${BUILD}/utility/%: INCLUDES += \
7140c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/include \
7150c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Ihost/lib/include \
7160c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	-Iutility/include
717eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
718eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities for auto-update toolkits must be statically linked.
719eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${UTIL_BINS_STATIC}: LDFLAGS += -static
720eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
721acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils
722c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill Richardsonutils: ${UTIL_BINS} ${UTIL_SCRIPTS}
723eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
724eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
725826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson
726acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils_install
727c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill Richardsonutils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
728661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       UTILS\n"
729c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
730c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
731c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
732c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# And some signing stuff for the target
733c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson.PHONY: signing_install
734c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonsigning_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
735661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       SIGNING\n"
736c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
737c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
738feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS_DEV}
739feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}${INSTALL} -t ${UB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
740feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${VB_DIR},)
741c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${VB_DIR}
742feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}for prog in $(notdir ${SIGNING_SCRIPTS_DEV}); do \
743feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson		ln -sf "${FT_DIR}/futility" "${VB_DIR}/$$prog"; done
744c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
7455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
746eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
747eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# new Firmware Utility
7485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
749eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil
750eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonfutil: ${FUTIL_BIN}
7515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
752eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS}
753661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
754eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${LD} -o $@ ${CFLAGS} $^ ${LDFLAGS} ${LDLIBS}
7555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
756eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil_install
757eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonfutil_install: ${FUTIL_BIN}
758661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    INSTALL       futility\n"
759feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}mkdir -p ${F_DIR}
760feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}${INSTALL} -t ${F_DIR} ${FUTIL_BIN}
761feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	${Q}for prog in ${FUTIL_OLD}; do \
762feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson		ln -sf futility "${F_DIR}/$$prog"; done
7635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
764eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
7655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utility to generate TLCL structure definition header file.
7665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
767acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
7685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
7705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
7715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
772acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: update_tlcl_structures
7735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerupdate_tlcl_structures: ${BUILD}/utility/tlcl_generator
774661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    Rebuilding TLCL structures\n"
775eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
776eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
7775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		( echo "%% Updating structures.h %%" && \
778eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson		  cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
7795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
780eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
7815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Tests
7825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
783eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: tests
784eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontests: ${TEST_BINS}
7855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
786eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TEST_BINS}: ${TESTLIB}
7875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
788eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TESTLIB}: ${TESTLIB_OBJS}
789661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    RM            $(subst ${BUILD}/,,$@)\n"
790eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
791661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    AR            $(subst ${BUILD}/,,$@)\n"
792eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
7935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
795eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
796eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
797eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# rules for specific targets.
7985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
799eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
800661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
801eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${LD} -o $@ ${CFLAGS} $< ${OBJS} ${LIBS} ${LDFLAGS} ${LDLIBS}
802eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
803eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.c
804661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC            $(subst ${BUILD}/,,$@)\n"
805eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
806eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
807eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Rules to recompile a single source file for library and test
808eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: is there a tidier way to do this?
809eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
810eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: %.c
811661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC-for-lib    $(subst ${BUILD}/,,$@)\n"
812eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
813eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
814eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
815eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: %.c
816661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CC-for-test   $(subst ${BUILD}/,,$@)\n"
817eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
818eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
819eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: C++ files don't belong in vboot reference at all.  Convert to C.
820eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.cc
821661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    CXX           $(subst ${BUILD}/,,$@)\n"
822eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
823eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
824eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
825eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Here are the special tweaks to the generic rules.
826eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
827eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Linktest ensures firmware lib doesn't rely on outside libraries
828eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
829eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
830eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# GBB utility needs C++ linker. TODO: It shouldn't.
831eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/gbb_utility: LD = ${CXX}
832eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
833feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# Because we play some clever linker script games to add new commands without
834feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# changing any header files, futility must be linked with ld.bfd, not gold.
835feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd
836feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
837eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Some utilities need external crypto functions
838eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
839eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
840eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
841eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/dev_sign_file: LDLIBS += ${CRYPTO_LIBS}
842eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_firmware: LDLIBS += ${CRYPTO_LIBS}
843eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_kernel: LDLIBS += ${CRYPTO_LIBS}
844eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_key: LDLIBS += ${CRYPTO_LIBS}
845eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/vbutil_keyblock: LDLIBS += ${CRYPTO_LIBS}
846eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
847eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
848eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
849eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
850eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
851eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: LD = ${CXX}
852eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
853eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
854eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonBMPBLK_UTILITY_DEPS = \
855eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/bmpblk_util.o \
856eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/image_types.o \
857eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/eficompress_for_lib.o \
858eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/efidecompress_for_lib.o
859eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
860eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
861eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
862eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
863eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
864eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
865eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Allow multiple definitions, so tests can mock functions from other libraries
866eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
8670c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson${BUILD}/tests/%: INCLUDES += -Ihost/include -Ihost/lib/include
868eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LDLIBS += -lrt -luuid
869eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LIBS += ${TESTLIB}
8705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
8715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/rollback_index2_tests: OBJS += \
87217f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/rollback_index_for_test.o
873eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/rollback_index2_tests: \
874eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/rollback_index_for_test.o
8755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
876c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: OBJS += \
877c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
878c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: \
879c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
880c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler
8815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/vboot_audio_tests: OBJS += \
88217f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/vboot_audio_for_test.o
883eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_audio_tests: \
884eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/vboot_audio_for_test.o
8855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
886acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
887acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
8885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
889eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
890eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
8915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
892eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
893eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Targets that exist just to run tests
8945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
8955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Frequently-run tests
896eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_targets
897eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_targets:: runcgpttests runmisctests
898844bce57471153664c78993dab453e87891bb969Randall Spangler
899eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
900844bce57471153664c78993dab453e87891bb969Randall Spangler# Bitmap utility isn't compiled for minimal variant
901feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsontest_targets:: runbmptests runfutiltests
902844bce57471153664c78993dab453e87891bb969Randall Spangler# Scripts don't work under qemu testing
903844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: convert scripts to makefile so they can be called directly
904eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_targets:: runtestscripts
905844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
906844bce57471153664c78993dab453e87891bb969Randall Spangler
907eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_setup
908eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_setup:: cgpt utils futil tests
909eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
910844bce57471153664c78993dab453e87891bb969Randall Spangler# Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
911844bce57471153664c78993dab453e87891bb969Randall Spangler# sysroot.
912eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${QEMU_ARCH},)
913eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_setup:: qemu_install
914844bce57471153664c78993dab453e87891bb969Randall Spangler
915844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: qemu_install
916844bce57471153664c78993dab453e87891bb969Randall Spanglerqemu_install:
917eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${SYSROOT},)
918eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(error SYSROOT must be set to the top of the target-specific root \
919eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonwhen cross-compiling for qemu-based tests to run properly.)
920eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
921661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass	@$(PRINTF) "    Copying qemu binary.\n"
922eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
923eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
924844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
925844bce57471153664c78993dab453e87891bb969Randall Spangler
926acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runtests
927eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruntests: test_targets
9285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
9295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test keys
930acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genkeys
931844bce57471153664c78993dab453e87891bb969Randall Spanglergenkeys: utils
9325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_test_keys.sh
9335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
9345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test cases for fuzzing
935acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genfuzztestcases
936a808dc944284e6eba39a8f19ddb46bc61c34de8aRandall Spanglergenfuzztestcases: utils
9375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_fuzz_test_cases.sh
9385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
939acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runbmptests
940eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunbmptests: test_setup
941eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
9425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		./TestBmpBlock.py -v
9435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
944acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runcgpttests
945eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruncgpttests: test_setup
946eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
9475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
948844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runtestscripts
949eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruntestscripts: test_setup genfuzztestcases
950eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
9515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh
9525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_rsa_tests.sh
953844bce57471153664c78993dab453e87891bb969Randall Spangler	tests/run_vbutil_kernel_arg_tests.sh
9545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh
9555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
956844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runmisctests
957eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunmisctests: test_setup
958eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
959a3eac79f5070747e326da631c1eec155f0389919Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
960eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
961eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/sha_tests
962eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
963c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
964eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
965eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
966eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_tests
967eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
968eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
9690714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
9700714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
9717f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
9727f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
9737f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
974eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
975e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
976e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
977e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
978786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
979eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
98049cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
9816dbf9d9160b2927d76017d0f51919e0880f9b2ccRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
982eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
983eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: runfutiltests
984feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonrunfutiltests: override DESTDIR = ${TEST_INSTALL_DIR}
985eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunfutiltests: test_setup install
986feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/tests/run_futility_tests.sh ${DESTDIR}
987844bce57471153664c78993dab453e87891bb969Randall Spangler
9885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Run long tests, including all permutations of encryption keys (instead of
989786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler# just the ones we use) and tests of currently-unused code.
9905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Not run by automated build.
991acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runlongtests
992eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunlongtests: test_setup genkeys genfuzztestcases
993e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
994e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
9955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh --all
9965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh --all
9975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
9985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: tests to run when ported to new API
9995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	./run_image_verification_tests.sh
10005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Splicing tests
10015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_splicing_tests
10025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_splicing_tests
10035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Rollback Tests
10045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_rollback_tests
10055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_rollback_tests
10065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
100759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
100859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_init
100959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_init: test_setup
101059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	rm -f ${COV_INFO}*
101159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -i -d . -b . -o ${COV_INFO}.initial
101259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
101359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_html
101459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_html:
101559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -d . -b . -o ${COV_INFO}.tests
101659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
101759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
101859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	genhtml ${COV_INFO}.local -o ${BUILD}/coverage
101959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
102059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Generate addtional coverage stats just for firmware subdir, because the
102159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# per-directory stats for the whole project don't include their own subdirs.
102249cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
102349cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
102459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler		-o ${COV_INFO}.firmware
102559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
102659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage
102759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerifeq (${COV},)
102859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage:
102959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	$(error Build coverage like this: make clean && COV=1 make)
103059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerelse
103159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage: coverage_init runtests coverage_html
103259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerendif
1033