Makefile revision 2559338dbdacbcbd3ae426337403196135bbc7e8
16f3961507e73f90cec665896dece884e86be560aBill Richardson# Copyright 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)
4064ddad77e58b9892c72f49977f479a585dce095cBill Richardsonexport SRCDIR
41c8c87b3264e02df2842e20866f717607a07c5ab4Mike FrysingerBUILD = ${SRCDIR}/build
42844bce57471153664c78993dab453e87891bb969Randall Spanglerexport BUILD
435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
44c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Stuff for 'make install'
45feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonINSTALL = install
46efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill RichardsonDESTDIR = /usr/local
47feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
48cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson# Default values
49cfe83a827d40b310003fc6996b9978d8cf301444Bill RichardsonDEV_DEBUG_FORCE=
50cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson
51feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson# Where exactly do the pieces go?
526f3961507e73f90cec665896dece884e86be560aBill Richardson#  UB_DIR = utility binary directory
53cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson#  DF_DIR = utility defaults directory
546f3961507e73f90cec665896dece884e86be560aBill Richardson#  VB_DIR = vboot binary directory for dev-mode-only scripts
55c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonifeq (${MINIMAL},)
566f3961507e73f90cec665896dece884e86be560aBill Richardson# Host install just puts everything where it's told
57efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill RichardsonUB_DIR=${DESTDIR}/bin
58cfe83a827d40b310003fc6996b9978d8cf301444Bill RichardsonDF_DIR=${DESTDIR}/default
59efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill RichardsonVB_DIR=${DESTDIR}/bin
60c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonelse
61efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill Richardson# Target install puts things into different places
626f3961507e73f90cec665896dece884e86be560aBill RichardsonUB_DIR=${DESTDIR}/usr/bin
63cfe83a827d40b310003fc6996b9978d8cf301444Bill RichardsonDF_DIR=${DESTDIR}/etc/default
64c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonVB_DIR=${DESTDIR}/usr/share/vboot/bin
65c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
666d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass
67eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Where to install the (exportable) executables for testing?
68eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_INSTALL_DIR = ${BUILD}/install_for_test
69eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
70eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Verbose? Use V=1
71eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${V},)
72eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonQ := @
73eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
74eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
75661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass# Quiet? Use QUIET=1
76c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysingerifeq (${QUIET},)
77661ae9e9cbaad430b87b443712d2608f9ce59883Simon GlassPRINTF := printf
78661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glasselse
79661ae9e9cbaad430b87b443712d2608f9ce59883Simon GlassPRINTF := :
80661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glassendif
81661ae9e9cbaad430b87b443712d2608f9ce59883Simon Glass
8261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# Architecture detection
8361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler_machname := $(shell uname -m)
8461a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall SpanglerHOST_ARCH ?= ${_machname}
8561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
8661a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
8761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# Pick a sane target architecture if none is defined.
8861a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerifeq (${ARCH},)
8961a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  ARCH := ${HOST_ARCH}
9061a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${ARCH},i386)
9161a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override ARCH := x86
9261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${ARCH},amd64)
9361a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override ARCH := x86_64
9461a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerendif
9561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
9661a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
9761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# for a firmware target (such as u-boot or depthcharge). It must map
9861a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler# to the same consistent set of architectures as the host.
9961a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerifeq (${FIRMWARE_ARCH},i386)
10061a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override FIRMWARE_ARCH := x86
10161a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${FIRMWARE_ARCH},amd64)
10261a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler  override FIRMWARE_ARCH := x86_64
103d96b25d0c0a739d351b8f09b128782ca12b7b0e1Stefan Reinauerelse ifeq (${FIRMWARE_ARCH},armv7)
104d96b25d0c0a739d351b8f09b128782ca12b7b0e1Stefan Reinauer  override FIRMWARE_ARCH := arm
10561a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerendif
10661a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spangler
107b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
108b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# please add them after this point (e.g., -DVBOOT_DEBUG).
10974359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
1106b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
1116b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# temporarily. As we are still investigating which flags are necessary for
1126b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
11374359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
114b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# As a first step, this makes the setting of CC and CFLAGS here optional, to
115b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# permit a calling script or Makefile to set these.
11674359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
117b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Flag ordering: arch, then -f, then -m, then -W
118b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassDEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
119b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCOMMON_FLAGS := -nostdinc -pipe \
120b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffreestanding -fno-builtin -fno-stack-protector \
121eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	-Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
122b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
123eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
124eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH}, arm)
125b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= armv7a-cros-linux-gnueabi-gcc
126b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= -march=armv5 \
127b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fno-common -ffixed-r8 \
128d50b27d15de8cc9e37410fc52d3184f17e0db5bbDoug Anderson	-mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
129eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
13061a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${FIRMWARE_ARCH}, x86)
131b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= i686-pc-linux-gnu-gcc
132b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Drop -march=i386 to permit use of SSE instructions
133b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= \
134b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
135b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
13646e00e63805f85c05449ce09cd843a18b76ca665Gabe Black	-mpreferred-stack-boundary=2 \
137eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${COMMON_FLAGS}
138eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonelse ifeq (${FIRMWARE_ARCH}, x86_64)
139eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS ?= ${COMMON_FLAGS} \
1408e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glass	-fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
141844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
142eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# FIRMWARE_ARCH not defined; assuming local compile.
143eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCC ?= gcc
144d462101f06e1bf817295a6cdd2b82e7e87eaeef3Bill RichardsonCFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
1458e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glassendif
14634be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiou
147eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${DEBUG},)
148eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DVBOOT_DEBUG
149eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
150844bce57471153664c78993dab453e87891bb969Randall Spangler
151eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${DISABLE_NDEBUG},)
152eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -DNDEBUG
153eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
154eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
155feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonifneq (${FORCE_LOGGING_ON},)
156feb2518166b1cd181e607c611cbb610f0c7300daBill RichardsonCFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
157feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsonendif
158feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
1596014c048131f7c3d055e97c0aaa44494edc4f813Randall Spanglerifneq (${PD_SYNC},)
1606014c048131f7c3d055e97c0aaa44494edc4f813Randall SpanglerCFLAGS += -DPD_SYNC
1616014c048131f7c3d055e97c0aaa44494edc4f813Randall Spanglerendif
1626014c048131f7c3d055e97c0aaa44494edc4f813Randall Spangler
163eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create / use dependency files
164eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCFLAGS += -MMD -MF $@.d
165eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
166f8f807a5ef00e8d5360fc2c9093bd0b5da8c0507Bertrand SIMONNETifeq (${FIRMWARE_ARCH},)
167f8f807a5ef00e8d5360fc2c9093bd0b5da8c0507Bertrand SIMONNET# Creates position independent code for non firmware target.
168f8f807a5ef00e8d5360fc2c9093bd0b5da8c0507Bertrand SIMONNETCFLAGS += -fPIE
169f8f807a5ef00e8d5360fc2c9093bd0b5da8c0507Bertrand SIMONNETendif
170f8f807a5ef00e8d5360fc2c9093bd0b5da8c0507Bertrand SIMONNET
1710c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson# These are required to access large disks and files on 32-bit systems.
1720c3ba249abb1dc60f5ebabccf84ff13206440b83Bill RichardsonCFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
1730c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
17459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
175eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${COV},)
176d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardson  COV_FLAGS = -O0 --coverage -DCOVERAGE
17759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  CFLAGS += ${COV_FLAGS}
17859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  LDFLAGS += ${COV_FLAGS}
17959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler  COV_INFO = ${BUILD}/coverage.info
180eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
181eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
182eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more default utilities
183eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonLD = ${CC}
1846df3e33912baf2633ed27fce6fe166d87e2f04a8Bill RichardsonCXX ?= g++
185eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonPKG_CONFIG ?= pkg-config
186eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1870b789c56fc5ff34309e935bab15f130a386a1140Mike Frysinger# Static?
1880b789c56fc5ff34309e935bab15f130a386a1140Mike Frysingerifneq (${STATIC},)
1890b789c56fc5ff34309e935bab15f130a386a1140Mike FrysingerLDFLAGS += -static
1900b789c56fc5ff34309e935bab15f130a386a1140Mike FrysingerPKG_CONFIG += --static
1910b789c56fc5ff34309e935bab15f130a386a1140Mike Frysingerendif
1920b789c56fc5ff34309e935bab15f130a386a1140Mike Frysinger
193844bce57471153664c78993dab453e87891bb969Randall Spangler# Determine QEMU architecture needed, if any
194eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${ARCH},${HOST_ARCH})
195844bce57471153664c78993dab453e87891bb969Randall Spangler  # Same architecture; no need for QEMU
196844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
19761a2eb389d9903b1b5a88d3e11ad5d713b3a364aRandall Spanglerelse ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
198844bce57471153664c78993dab453e87891bb969Randall Spangler  # 64-bit host can run 32-bit targets directly
199844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
200844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
201eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_ARCH := ${ARCH}
202844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
203844bce57471153664c78993dab453e87891bb969Randall Spangler
204844bce57471153664c78993dab453e87891bb969Randall Spangler# The top of the chroot for qemu must be passed in via the SYSROOT environment
205844bce57471153664c78993dab453e87891bb969Randall Spangler# variable.  In the Chromium OS chroot, this is done automatically by the
206844bce57471153664c78993dab453e87891bb969Randall Spangler# ebuild.
207844bce57471153664c78993dab453e87891bb969Randall Spangler
208eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${QEMU_ARCH},)
209844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is same as for building
210eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = ${BUILD}
211e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = ${SRCDIR}
212844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
213844bce57471153664c78993dab453e87891bb969Randall Spangler  $(info Using qemu for testing.)
214844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is different in the chroot
215eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
216e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
217844bce57471153664c78993dab453e87891bb969Randall Spangler
218eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson  QEMU_BIN = qemu-${QEMU_ARCH}
219e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
220e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  export QEMU_RUN
221287beaed7f8ceff679c57664d4da008c6234edfdRandall Spangler
222e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler  RUNTEST = tests/test_using_qemu.sh
223e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerendif
2245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
225e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spanglerexport BUILD_RUN
2265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
227eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
228eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now we need to describe everything we might want or need to build
229b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
230eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Everything wants these headers.
2315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += \
2325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/include \
2335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/include \
2345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cgptlib/include \
2355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cryptolib/include \
236786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	-Ifirmware/lib/tpm_lite/include \
237786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	-Ifirmware/2lib/include
2380b8f35c6a56a0e645254dd7f07ca68e01c8ee629Bill Richardson
239eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# If we're not building for a specific target, just stub out things like the
240eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM commands and various external functions that are provided by the BIOS.
241eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
2420e6ae29eec7a58eeeeba67356c3a3ee384ba6687Bill RichardsonINCLUDES += -Ihost/include -Ihost/lib/include
2435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
245782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Firmware library, used by the other firmware components (depthcharge,
246782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# coreboot, etc.). It doesn't need exporting to some other place; they'll build
247782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# this source tree locally and link to it directly.
248eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB = ${BUILD}/vboot_fw.a
2495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
25006eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# Smaller firmware library common to all vboot 2.x, used only for
25106eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# 1) compile-time tests of the public API or
25206eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# 2) linking with an actual 2.0 or 2.1 implementation
2536f1b82ac14f341d9733d6e95d518b3ee352002efRandall SpanglerFWLIB2X = ${BUILD}/vboot_fw2x.a
25406eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson
25506eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# Vboot 2.0 (deprecated - see firmware/README)
25606eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill RichardsonFWLIB20 = ${BUILD}/vboot_fw20.a
25706eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# Vboot 2.1 (not yet ready - see firmware/README)
258a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerFWLIB21 = ${BUILD}/vboot_fw21.a
259786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
26093943266c597ad66300445a04afa01270f2b5763Randall Spangler# Firmware library sources needed by VbInit() call
26193943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS = \
2625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/crc8.c \
26393943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility.c \
26493943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_api_init.c \
26593943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common_init.c \
26693943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_nvstorage.c \
267782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/vboot_nvstorage_rollback.c \
268527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-init.c \
26993943266c597ad66300445a04afa01270f2b5763Randall Spangler
27093943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectFirmware() call
27193943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS = \
2725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/padding.c \
2735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa.c \
2745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa_utility.c \
2755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha1.c \
2765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha256.c \
2775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha512.c \
2785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha_utility.c \
2795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/stateful_util.c \
2805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_firmware.c \
28193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/vboot_common.c \
282527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/vboot_firmware.c \
283527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-fw.c \
28493943266c597ad66300445a04afa01270f2b5763Randall Spangler
28593943266c597ad66300445a04afa01270f2b5763Randall Spangler# Additional firmware library sources needed by VbSelectAndLoadKernel() call
28693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS = \
28793943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib.c \
28893943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/cgptlib_internal.c \
28993943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/cgptlib/crc32.c \
2907c2beb08380410ca6847abdac23e11ded2d1b625Dan Ehrenberg	firmware/lib/gpt_misc.c \
29193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/utility_string.c \
2925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_kernel.c \
2935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_audio.c \
2945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_display.c \
295527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/vboot_kernel.c \
296527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/lib/region-kernel.c \
2975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
29806eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson# Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
29906eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill RichardsonFWLIB2X_SRCS = \
300a7ab8b50b8923afcfd7a9e6181892c4c8a2de250Randall Spangler	firmware/2lib/2api.c \
301786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	firmware/2lib/2common.c \
3023333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2crc8.c \
3033333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2misc.c \
3043333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2nvstorage.c \
305e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2rsa.c \
3063333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	firmware/2lib/2secdata.c \
307e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha1.c \
308e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha256.c \
309e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	firmware/2lib/2sha512.c \
310a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	firmware/2lib/2sha_utility.c
311a5b69b02e039d7267390fea10266d45e14630559Randall Spangler
312108d991c678f80c99967bd07035de7418c81a072Randall SpanglerFWLIB20_SRCS = \
3136f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	firmware/lib20/api.c \
3146f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	firmware/lib20/common.c \
3156f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	firmware/lib20/misc.c \
3166f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	firmware/lib20/packed_key.c
317108d991c678f80c99967bd07035de7418c81a072Randall Spangler
318a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerFWLIB21_SRCS = \
319a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	firmware/lib21/api.c \
320a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	firmware/lib21/common.c \
321a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	firmware/lib21/misc.c \
322a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	firmware/lib21/packed_key.c
323786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
324eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Support real TPM unless BIOS sets MOCK_TPM
325eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MOCK_TPM},)
32693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
3275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/rollback_index.c \
3285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/tlcl.c
32993943266c597ad66300445a04afa01270f2b5763Randall Spangler
33093943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
33193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/tpm_bootmode.c
3325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerelse
33393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
3345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/mocked_rollback_index.c \
3355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/mocked_tlcl.c
33693943266c597ad66300445a04afa01270f2b5763Randall Spangler
33793943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
33893943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/lib/mocked_tpm_bootmode.c
3395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
341eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
342eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Include BIOS stubs in the firmware library when compiling for host
34393943266c597ad66300445a04afa01270f2b5763Randall Spangler# TODO: split out other stub funcs too
34493943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_SRCS += \
3455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/tpm_lite_stub.c \
3465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/utility_stub.c \
347527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/stub/vboot_api_stub_init.c \
348527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	firmware/stub/vboot_api_stub_region.c
34993943266c597ad66300445a04afa01270f2b5763Randall Spangler
35093943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += \
35193943266c597ad66300445a04afa01270f2b5763Randall Spangler	firmware/stub/vboot_api_stub_sf.c
35293943266c597ad66300445a04afa01270f2b5763Randall Spangler
35393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSLK_SRCS += \
3545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub.c \
3555dc75d16b6d5cb0ebc677e6572a2559c6157b8e4Dan Ehrenberg	firmware/stub/vboot_api_stub_disk.c \
3565dc75d16b6d5cb0ebc677e6572a2559c6157b8e4Dan Ehrenberg	firmware/stub/vboot_api_stub_stream.c
357da2b49cf08a27551fd910626f669910a636378d4Randall Spangler
35806eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill RichardsonFWLIB2X_SRCS += \
359da2b49cf08a27551fd910626f669910a636378d4Randall Spangler	firmware/2lib/2stub.c
360da2b49cf08a27551fd910626f669910a636378d4Randall Spangler
3615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
36393943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_SRCS += ${VBINIT_SRCS}
36493943266c597ad66300445a04afa01270f2b5763Randall SpanglerFWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
36593943266c597ad66300445a04afa01270f2b5763Randall Spangler
36693943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
36793943266c597ad66300445a04afa01270f2b5763Randall SpanglerVBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
368a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerALL_OBJS +=  ${VBINIT_OBJS} ${VBSF_OBJS}
36993943266c597ad66300445a04afa01270f2b5763Randall Spangler
370eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
37106eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill RichardsonFWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
372aaaff86467823e0d3d29c383402275eeae481256Randall SpanglerFWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
373a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerFWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
37406eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill RichardsonALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
3755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
376782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Intermediate library for the vboot_reference utilities to link against.
377782990277ac7d6730db4c43c2b5632de93396921Bill RichardsonUTILLIB = ${BUILD}/libvboot_util.a
378108d991c678f80c99967bd07035de7418c81a072Randall SpanglerUTILLIB21 = ${BUILD}/libvboot_util21.a
3795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
380782990277ac7d6730db4c43c2b5632de93396921Bill RichardsonUTILLIB_SRCS = \
38181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_create.c \
38281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_add.c \
38381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_boot.c \
38481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_show.c \
38581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_repair.c \
38681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_prioritize.c \
38781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_common.c \
3886f3961507e73f90cec665896dece884e86be560aBill Richardson	futility/dump_kernel_config_lib.c \
389eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	host/arch/${ARCH}/lib/crossystem_arch.c \
3905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/crossystem.c \
3915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/file_keys.c \
3925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/fmap.c \
3935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_common.c \
3945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_key.c \
3955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_keyblock.c \
3965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_misc.c \
397782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	host/lib/util_misc.c \
3985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_signature.c \
3996f3961507e73f90cec665896dece884e86be560aBill Richardson	host/lib/signature_digest.c
4005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
401aaaff86467823e0d3d29c383402275eeae481256Randall SpanglerUTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
402aaaff86467823e0d3d29c383402275eeae481256Randall SpanglerALL_OBJS += ${UTILLIB_OBJS}
403aaaff86467823e0d3d29c383402275eeae481256Randall Spangler
404a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerUTILLIB21_SRCS += \
405a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	host/lib21/host_fw_preamble.c \
406a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	host/lib21/host_key.c \
407a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	host/lib21/host_keyblock.c \
408a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	host/lib21/host_misc.c \
409a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	host/lib21/host_signature.c
41002e11b323b819140590d99b6af440d36c12d161bRandall Spangler
411a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerUTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
412a5b69b02e039d7267390fea10266d45e14630559Randall SpanglerALL_OBJS += ${UTILLIB21_OBJS}
413782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
414782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Externally exported library for some target userspace apps to link with
415782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# (cryptohome, updater, etc.)
416782990277ac7d6730db4c43c2b5632de93396921Bill RichardsonHOSTLIB = ${BUILD}/libvboot_host.a
417782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
418782990277ac7d6730db4c43c2b5632de93396921Bill RichardsonHOSTLIB_SRCS = \
419782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_add.c \
420782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_boot.c \
421782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_common.c \
422782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_create.c \
423782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_prioritize.c \
424782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/cgptlib/cgptlib_internal.c \
425782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/cgptlib/crc32.c \
426782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/crc8.c \
42732a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/lib/gpt_misc.c \
428782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/tpm_lite/tlcl.c \
429782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/utility_string.c \
430782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/vboot_nvstorage.c \
431782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/stub/tpm_lite_stub.c \
432782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/stub/utility_stub.c \
43332a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/stub/vboot_api_stub_disk.c \
434782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/stub/vboot_api_stub_init.c \
43532a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/stub/vboot_api_stub_sf.c \
4366f3961507e73f90cec665896dece884e86be560aBill Richardson	futility/dump_kernel_config_lib.c \
437782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	host/arch/${ARCH}/lib/crossystem_arch.c \
438782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	host/lib/crossystem.c \
4396ee52d9a929d00e871e7316240b54f381146fbc6Nam T. Nguyen	host/lib/fmap.c \
4406f3961507e73f90cec665896dece884e86be560aBill Richardson	host/lib/host_misc.c
441782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
442eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonHOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
4435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${HOSTLIB_OBJS}
4445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
44581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Sigh. For historical reasons, the autoupdate installer must sometimes be a
44681a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# 32-bit executable, even when everything else is 64-bit. But it only needs a
44781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# few functions, so let's just build those.
44881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
44981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
45081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_SRCS = \
45181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_add.c \
45281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_boot.c \
45381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	cgpt/cgpt_common.c \
454782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_create.c \
455782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	cgpt/cgpt_prioritize.c \
456782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/cgptlib/cgptlib_internal.c \
457782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/lib/cgptlib/crc32.c \
45832a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/lib/gpt_misc.c \
4595fed2a667096341160db8643a4a057e328953a1dBill Richardson	firmware/lib/utility_string.c \
46032a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/stub/vboot_api_stub_disk.c \
46132a999d2c0e5bf8a1c0f6141d3db77a1dcc6f5afDan Ehrenberg	firmware/stub/vboot_api_stub_sf.c \
462782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	firmware/stub/utility_stub.c \
463ab899591808dd3e5f955ab7693b54a83389cd35fNam T. Nguyen	futility/dump_kernel_config_lib.c
46481a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
46581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill RichardsonTINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
466eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
467eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
468eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Now for the userspace binaries
4695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT = ${BUILD}/cgpt/cgpt
4715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT_SRCS = \
4735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt.c \
4745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_add.c \
4755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_boot.c \
4765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_common.c \
4775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_create.c \
4785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_find.c \
4795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_legacy.c \
480d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	cgpt/cgpt_nor.c \
4815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_prioritize.c \
4825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_repair.c \
4835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_show.c \
4845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_add.c \
4855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_boot.c \
4865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_create.c \
4875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_find.c \
4885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_legacy.c \
4895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_prioritize.c \
4905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_repair.c \
4918577b5360ca4c9514d9091ed9aded2bb3193f1f0Nam T. Nguyen	cgpt/cmd_show.c
4925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
493eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonCGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
494d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
4955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${CGPT_OBJS}
4965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
497d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. NguyenCGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
498d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
499d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. NguyenCGPT_WRAPPER_SRCS = \
500d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	cgpt/cgpt_nor.c \
501d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	cgpt/cgpt_wrapper.c
502d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
503d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. NguyenCGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
504d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
505d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. NguyenALL_OBJS += ${CGPT_WRAPPER_OBJS}
506d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
507cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson# Utility defaults
508cfe83a827d40b310003fc6996b9978d8cf301444Bill RichardsonUTIL_DEFAULTS = ${BUILD}/default/vboot_reference
5095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
510eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Scripts to install directly (not compiled)
5115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_SCRIPTS = \
5125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/dev_debug_vboot \
5134d49d34c4ba5aa64ca7aeb26c77e170b2cf2462fBill Richardson	utility/enable_dev_usb_boot
5145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
515c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonifeq (${MINIMAL},)
516c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonUTIL_SCRIPTS += \
5174d49d34c4ba5aa64ca7aeb26c77e170b2cf2462fBill Richardson	utility/dev_make_keypair \
5184d49d34c4ba5aa64ca7aeb26c77e170b2cf2462fBill Richardson	utility/vbutil_what_keys
519c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonendif
520c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
521eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These utilities should be linked statically.
522eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES_STATIC = \
5236f3961507e73f90cec665896dece884e86be560aBill Richardson	utility/crossystem
524eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
525eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonUTIL_NAMES = ${UTIL_NAMES_STATIC} \
526339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/tpm_init_temp_fix \
5270f07867e6fe186ea460afd557e830c1e49f1ff85Duncan Laurie	utility/dumpRSAPublicKey \
5286f3961507e73f90cec665896dece884e86be560aBill Richardson	utility/tpmc
5295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5306f3961507e73f90cec665896dece884e86be560aBill Richardson# TODO: Do we still need eficompress and efidecompress for anything?
531eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
5325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES += \
533339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/bmpblk_font \
534339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/bmpblk_utility \
535339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/eficompress \
536339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/efidecompress \
537339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/load_kernel_test \
538339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/pad_digest_utility \
539339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/signature_digest_utility \
540339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	utility/verify_data
5415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
5425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
543339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonUTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
544339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonUTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
5451912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
5465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
547c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
548c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Scripts for signing stuff.
549c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS = \
550c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/tpm-nvsize \
551c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	utility/chromeos-tpm-recovery
552c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
553c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# These go in a different place.
554c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_SCRIPTS_DEV = \
555c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/resign_firmwarefd.sh \
556c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_firmware.sh \
557c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/make_dev_ssd.sh \
558c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	scripts/image_signing/set_gbb_flags.sh
559c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
560c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# Installed, but not made executable.
561c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill RichardsonSIGNING_COMMON = scripts/image_signing/common_minimal.sh
562eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
563eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
564eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# The unified firmware utility will eventually replace all the others
565eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonFUTIL_BIN = ${BUILD}/futility/futility
5666db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson# But we still need both static (tiny) and dynamic (with openssl) versions.
5676db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_STATIC_BIN = ${FUTIL_BIN}_s
568eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
5696f3961507e73f90cec665896dece884e86be560aBill Richardson# These are the executables that are now built in to futility. We'll create
5706f3961507e73f90cec665896dece884e86be560aBill Richardson# symlinks for these so the old names will still work.
571a1d9fe6eecf82540d31d34bba988e4838d295302Bill RichardsonFUTIL_SYMLINKS = \
572e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	dump_fmap \
573e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	dump_kernel_config \
574e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	gbb_utility \
575e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	vbutil_firmware \
576e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	vbutil_kernel \
577e155044a7bbb9b8c6eb751af051726cfe1b411a4Bill Richardson	vbutil_key \
5786f3961507e73f90cec665896dece884e86be560aBill Richardson	vbutil_keyblock
579feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson
5806db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_STATIC_SRCS = \
581feb2518166b1cd181e607c611cbb610f0c7300daBill Richardson	futility/futility.c \
58220807b6158b6a43baf0974bc763890888ba1f841Bill Richardson	futility/cmd_dump_fmap.c \
583cf6e78dbd54684ebba0c3bfc2524426f61193416Bill Richardson	futility/cmd_gbb_utility.c \
584cf6e78dbd54684ebba0c3bfc2524426f61193416Bill Richardson	futility/misc.c
585eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
5866db8c75021e2edfa400ae707a8544d041e3c415fBill RichardsonFUTIL_SRCS = \
587c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	${FUTIL_STATIC_SRCS} \
5886f3961507e73f90cec665896dece884e86be560aBill Richardson	futility/cmd_dump_kernel_config.c \
5892e25e813419f2cd437164929543e452b28b89260Bill Richardson	futility/cmd_load_fmap.c \
590f4f395e1ca724ef8795cfe86a9edbf15f14eacd1Bill Richardson	futility/cmd_pcr.c \
591f318ee205cc8d92def925c6158272da8a63bf1edBill Richardson	futility/cmd_show.c \
592f318ee205cc8d92def925c6158272da8a63bf1edBill Richardson	futility/cmd_sign.c \
5936f3961507e73f90cec665896dece884e86be560aBill Richardson	futility/cmd_vbutil_firmware.c \
5946f3961507e73f90cec665896dece884e86be560aBill Richardson	futility/cmd_vbutil_kernel.c \
595b84b81dc265a766a968bf126905447d442558218Bill Richardson	futility/cmd_vbutil_key.c \
596b8ff397674fb98c1d7eea864e7fa571369675131Randall Spangler	futility/cmd_vbutil_keyblock.c \
5972559338dbdacbcbd3ae426337403196135bbc7e8Bill Richardson	futility/file_type.c \
598f318ee205cc8d92def925c6158272da8a63bf1edBill Richardson	futility/traversal.c \
599f318ee205cc8d92def925c6158272da8a63bf1edBill Richardson	futility/vb1_helper.c
6006db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson
601e08ee28548934e933733babf0bc0c418142d095dAlex Deymo# List of commands built in futility and futility_s.
602e08ee28548934e933733babf0bc0c418142d095dAlex DeymoFUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
603e08ee28548934e933733babf0bc0c418142d095dAlex DeymoFUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
604eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
60591852e7f58d50a031bcb5c02e68473cefb10ebb0Bill Richardson# Workaround for TODO(crbug.com/437107).
60691852e7f58d50a031bcb5c02e68473cefb10ebb0Bill RichardsonFUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
60791852e7f58d50a031bcb5c02e68473cefb10ebb0Bill Richardson
608e08ee28548934e933733babf0bc0c418142d095dAlex DeymoFUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
60991852e7f58d50a031bcb5c02e68473cefb10ebb0Bill Richardson	${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
610e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${FUTIL_STATIC_CMD_LIST:%.c=%.o}
611e08ee28548934e933733babf0bc0c418142d095dAlex DeymoFUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
612eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
613eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonALL_OBJS += ${FUTIL_OBJS}
614eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
615eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
616eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Library of handy test functions.
617eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB = ${BUILD}/tests/test.a
618eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
619eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_SRCS = \
620eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/test_common.c \
621eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/timer_utils.c \
622eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/crc32_test.c
623eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
624eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
62580872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${TESTLIB_OBJS}
626eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
627eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
628eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And some compiled tests.
629eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES = \
630339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/cgptlib_test \
631339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rollback_index2_tests \
632339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rollback_index3_tests \
633339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_padding_test \
634339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_utility_tests \
635339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/rsa_verify_benchmark \
636339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/sha_benchmark \
637339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/sha_tests \
638339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/stateful_util_tests \
639339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tlcl_tests \
640339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_bootmode_tests \
641339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/utility_string_tests \
642339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/utility_tests \
643339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_init_tests \
644339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_devmode_tests \
645339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_firmware_tests \
646339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel_tests \
647339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel2_tests \
648339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel3_tests \
649339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_api_kernel4_tests \
650339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_audio_tests \
651339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common_tests \
652339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common2_tests \
653339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_common3_tests \
654339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_display_tests \
655339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_firmware_tests \
656339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_kernel_tests \
657339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/vboot_nvstorage_test \
658a77541f94f731f5f7755264e9b49b7826aa48dfeBill Richardson	tests/verify_kernel \
6596f3961507e73f90cec665896dece884e86be560aBill Richardson	tests/futility/binary_editor \
660339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/futility/test_not_really
661eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
662527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassifdef REGION_READ
663527ba810eff4006cf69579f6b96cb4350cb1e189Simon GlassTEST_NAMES += tests/vboot_region_tests
664527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassendif
665527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
6666f1b82ac14f341d9733d6e95d518b3ee352002efRandall SpanglerTEST2X_NAMES = \
667a7ab8b50b8923afcfd7a9e6181892c4c8a2de250Randall Spangler	tests/vb2_api_tests \
668786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	tests/vb2_common_tests \
6693333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_misc_tests \
6703333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_nvstorage_tests \
671e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_rsa_utility_tests \
6723333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	tests/vb2_secdata_tests \
673108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb2_sha_tests
674108d991c678f80c99967bd07035de7418c81a072Randall Spangler
6756f1b82ac14f341d9733d6e95d518b3ee352002efRandall SpanglerTEST20_NAMES = \
6766f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	tests/vb20_api_tests \
6776f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	tests/vb20_common_tests \
6786f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	tests/vb20_common2_tests \
6795fb14634b9f7618592b9e88d9aa74b2111f15ee1Bill Richardson	tests/vb20_verify_fw.c \
6806f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	tests/vb20_common3_tests \
6816f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	tests/vb20_misc_tests \
6825fb14634b9f7618592b9e88d9aa74b2111f15ee1Bill Richardson	tests/vb20_rsa_padding_tests \
6835fb14634b9f7618592b9e88d9aa74b2111f15ee1Bill Richardson	tests/vb20_verify_fw
6846f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler
685108d991c678f80c99967bd07035de7418c81a072Randall SpanglerTEST21_NAMES = \
686108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_api_tests \
687108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_common_tests \
688108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_common2_tests \
689108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_misc_tests \
690108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_host_fw_preamble_tests \
691108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_host_key_tests \
692108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_host_keyblock_tests \
693108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_host_misc_tests \
694108d991c678f80c99967bd07035de7418c81a072Randall Spangler	tests/vb21_host_sig_tests
695786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
6966f1b82ac14f341d9733d6e95d518b3ee352002efRandall SpanglerTEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES}
697786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
698eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# And a few more...
699339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTLCL_TEST_NAMES = \
700339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_earlyextend \
701339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_earlynvram \
702339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_earlynvram2 \
703339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_enable \
704339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_fastenable \
705339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_globallock \
706339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_redefine_unowned \
707339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_spaceperm \
708339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_testsetup \
709339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	tests/tpm_lite/tpmtest_timing \
710339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson        tests/tpm_lite/tpmtest_writelimit
711eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
712eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonTEST_NAMES += ${TLCL_TEST_NAMES}
713eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
714339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson# Finally
715339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
71680872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += $(addsuffix .o,${TEST_BINS})
717eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
7186f1b82ac14f341d9733d6e95d518b3ee352002efRandall SpanglerTEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
719aaaff86467823e0d3d29c383402275eeae481256Randall SpanglerTEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
720108d991c678f80c99967bd07035de7418c81a072Randall SpanglerTEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
721aaaff86467823e0d3d29c383402275eeae481256Randall Spangler
722e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler# Directory containing test keys
723e061a256549607a56d771eb8ddae5d0dd90d519cRandall SpanglerTEST_KEYS = ${SRC_RUN}/tests/testkeys
724eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
725eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
726eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
727eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Finally, some targets. High-level ones first.
728eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
729eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Create output directories if necessary.  Do this via explicit shell commands
730eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# so it happens before trying to generate/include dependencies.
731eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonSUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
732eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson_dir_create := $(foreach d, \
733eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell find ${SUBDIRS} -name '*.c' -exec  dirname {} \; | sort -u), \
734eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
735eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
736eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
737eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Default target.
738eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: all
73906eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardsonall: fwlib fwlib2x fwlib20 fwlib21 \
740aaaff86467823e0d3d29c383402275eeae481256Randall Spangler	$(if ${FIRMWARE_ARCH},,host_stuff) \
741786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	$(if ${COV},coverage)
742eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
743eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Host targets
744eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: host_stuff
74506eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardsonhost_stuff: utillib hostlib cgpt utils futil tests utillib21
746eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
747eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: clean
748eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonclean:
749eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}/bin/rm -rf ${BUILD}
750eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
751eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: install
752c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsoninstall: cgpt_install utils_install signing_install futil_install
753eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
754d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen.PHONY: install_mtd
755d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyeninstall_mtd: install cgpt_wrapper_install
756d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
7573e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardson.PHONY: install_for_test
7583e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardsoninstall_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
7593e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardsoninstall_for_test: install
7603e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardson
761eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Don't delete intermediate object files
762eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.SECONDARY:
763eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
764eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
765eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Firmware library
766eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
767eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM-specific flags.  These depend on the particular TPM we're targeting for.
768eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# They are needed here only for compiling parts of the firmware code into
769eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# user-level tests.
770eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
771eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
772eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# the self test has completed.
773eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
77445cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
775eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
776eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
777eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
778eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# power on.
779eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson#
780eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
781eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# are not both defined at the same time.  (See comment in code.)
782eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
783eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CFLAGS += -DTPM_MANUAL_SELFTEST
784eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
785eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},i386)
786eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Unrolling loops in cryptolib makes it faster
78745cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
78806eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
789aaaff86467823e0d3d29c383402275eeae481256Randall Spangler${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
790a5b69b02e039d7267390fea10266d45e14630559Randall Spangler${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
791eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
792eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Workaround for coreboot on x86, which will power off asynchronously
793eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# without giving us a chance to react. This is not an example of the Right
794eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Way to do things. See chrome-os-partner:7689, and the commit message
795eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# that made this change.
79645cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
797eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
798eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# On x86 we don't actually read the GBB data into RAM until it is needed.
799eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Therefore it makes sense to cache it rather than reading it each time.
800eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Enable this feature.
80145cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
802eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
803eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
804527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassifdef REGION_READ
805527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass${FWLIB_OBJS}: CFLAGS += -DREGION_READ
806527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassendif
807527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
808eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${FIRMWARE_ARCH},)
809eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Disable rollback TPM when compiling locally, since otherwise
810eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# load_kernel_test attempts to talk to the TPM.
81145cc0f2c0a48b377520842597769a5813cf55902Randall Spangler${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
812eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
813eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
8146f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${FWLIB20_OBJS}: INCLUDES += -Ifirmware/lib20/include
815108d991c678f80c99967bd07035de7418c81a072Randall Spangler${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
816108d991c678f80c99967bd07035de7418c81a072Randall Spangler
817a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson# Linktest ensures firmware lib doesn't rely on outside libraries
818a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
81993943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
82080872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
821a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
82293943266c597ad66300445a04afa01270f2b5763Randall Spangler${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
82380872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
824a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main: ${FWLIB}
825a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
82680872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/linktest/main.o
82793943266c597ad66300445a04afa01270f2b5763Randall Spangler
828d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardson.PHONY: fwlinktest
829d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardsonfwlinktest: \
83093943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbinit \
83193943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main_vbsf \
83293943266c597ad66300445a04afa01270f2b5763Randall Spangler	${BUILD}/firmware/linktest/main
83393943266c597ad66300445a04afa01270f2b5763Randall Spangler
834eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: fwlib
835a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardsonfwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
836eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
837a5b69b02e039d7267390fea10266d45e14630559Randall Spangler${FWLIB}: ${FWLIB_OBJS}
838c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
839a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	${Q}rm -f $@
840c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
841a5b69b02e039d7267390fea10266d45e14630559Randall Spangler	${Q}ar qc $@ $^
842a5b69b02e039d7267390fea10266d45e14630559Randall Spangler
8436f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler.PHONY: fwlib2x
8446f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spanglerfwlib2x: ${FWLIB2X}
8456f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler
84606eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FWLIB2X}: ${FWLIB2X_OBJS}
847c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
8486f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${Q}rm -f $@
849c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
8506f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${Q}ar qc $@ $^
8516f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler
85206eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson.PHONY: fwlib20
85306eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardsonfwlib20: ${FWLIB20}
854786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
85506eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
856c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
857eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
858c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
859eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
860eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
861a5b69b02e039d7267390fea10266d45e14630559Randall Spangler.PHONY: fwlib21
862a5b69b02e039d7267390fea10266d45e14630559Randall Spanglerfwlib21: ${FWLIB21}
863a5b69b02e039d7267390fea10266d45e14630559Randall Spangler
86406eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
865c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
866786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${Q}rm -f $@
867c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
868786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${Q}ar qc $@ $^
869786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
870eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
871782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Host library(s)
872eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
873782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Link tests for local utilities
874782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${BUILD}/host/linktest/main: ${UTILLIB}
875782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
87680872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/host/linktest/main.o
877782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
878782990277ac7d6730db4c43c2b5632de93396921Bill Richardson.PHONY: utillib
879782990277ac7d6730db4c43c2b5632de93396921Bill Richardsonutillib: ${UTILLIB} \
880782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	${BUILD}/host/linktest/main
881eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
882eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: better way to make .a than duplicating this recipe each time?
883aaaff86467823e0d3d29c383402275eeae481256Randall Spangler${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
884c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
885aaaff86467823e0d3d29c383402275eeae481256Randall Spangler	${Q}rm -f $@
886c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
887aaaff86467823e0d3d29c383402275eeae481256Randall Spangler	${Q}ar qc $@ $^
888aaaff86467823e0d3d29c383402275eeae481256Randall Spangler
889a5b69b02e039d7267390fea10266d45e14630559Randall Spangler.PHONY: utillib21
890a5b69b02e039d7267390fea10266d45e14630559Randall Spanglerutillib21: ${UTILLIB21}
891aaaff86467823e0d3d29c383402275eeae481256Randall Spangler
892108d991c678f80c99967bd07035de7418c81a072Randall Spangler${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
89306eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
894c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
895782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	${Q}rm -f $@
896c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
897782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	${Q}ar qc $@ $^
898782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
899782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
900782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# Link tests for external repos
901782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${BUILD}/host/linktest/extern: ${HOSTLIB}
902782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
903782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${BUILD}/host/linktest/extern: LDLIBS += -static
90480872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/host/linktest/extern.o
905782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
906782990277ac7d6730db4c43c2b5632de93396921Bill Richardson.PHONY: hostlib
907782990277ac7d6730db4c43c2b5632de93396921Bill Richardsonhostlib: ${HOSTLIB} \
908782990277ac7d6730db4c43c2b5632de93396921Bill Richardson	${BUILD}/host/linktest/extern
909782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
910782990277ac7d6730db4c43c2b5632de93396921Bill Richardson# TODO: better way to make .a than duplicating this recipe each time?
911782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${HOSTLIB}: ${HOSTLIB_OBJS}
912c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
913eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
914c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
915eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
916eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
91781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
91881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
91981a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson.PHONY: tinyhostlib
92081a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardsontinyhostlib: ${TINYHOSTLIB}
92181a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
92281a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
92381a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
924c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
92581a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}rm -f $@
926c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
92781a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson	${Q}ar qc $@ $^
92881a0b3de707b4e00958faf36f41b8f3d7bac6808Bill Richardson
929eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
930eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# CGPT library and utility
931eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
932d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen.PHONY: cgpt_wrapper
933d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyencgpt_wrapper: ${CGPT_WRAPPER}
934d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
935d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
936d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	@$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
937d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
938d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
939eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt
940d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyencgpt: ${CGPT} ${CGPT_WRAPPER}
941eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
942eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDFLAGS += -static
943eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${CGPT}: LDLIBS += -luuid
944eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
945782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${CGPT}: ${CGPT_OBJS} ${UTILLIB}
946c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    LDcgpt        $(subst ${BUILD}/,,$@)\n"
9476db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
948eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
949eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: cgpt_install
950eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsoncgpt_install: ${CGPT}
951c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    INSTALL       CGPT\n"
952c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
953c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} $^
954eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
955d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen.PHONY: cgpt_wrapper_install
956d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyencgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
957d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	@$(PRINTF) "    INSTALL       cgpt_wrapper\n"
958d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
959d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
960d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen		${UB_DIR}/$(notdir ${CGPT}).bin
961d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen	${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
962d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen		${UB_DIR}/$(notdir ${CGPT})
963d1236e4be6a7fe1c2b132ca8f63a513949d59775Nam T. Nguyen
964eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
965eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities
966eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
967eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# These have their own headers too.
9680f6679e8582219b40e2ab5485992827a92c18bcdBill Richardson${BUILD}/utility/%: INCLUDES += -Iutility/include
9690f6679e8582219b40e2ab5485992827a92c18bcdBill Richardson
9700f6679e8582219b40e2ab5485992827a92c18bcdBill Richardson${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
9710f6679e8582219b40e2ab5485992827a92c18bcdBill Richardson${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
972eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
973eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Utilities for auto-update toolkits must be statically linked.
974eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${UTIL_BINS_STATIC}: LDFLAGS += -static
975eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
976a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardson
977acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils
978c7c6e5d2f7076fe512b692411f0d05d4bf76d91fBill Richardsonutils: ${UTIL_BINS} ${UTIL_SCRIPTS}
979eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
980eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
981826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson
982acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils_install
983cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardsonutils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
984c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    INSTALL       UTILS\n"
985c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}mkdir -p ${UB_DIR}
986c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
987cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}mkdir -p ${DF_DIR}
988cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
989c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson
990c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson# And some signing stuff for the target
991c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson.PHONY: signing_install
992c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardsonsigning_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
993c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    INSTALL       SIGNING\n"
9946f3961507e73f90cec665896dece884e86be560aBill Richardson	${Q}mkdir -p ${UB_DIR} ${VB_DIR}
995c9bf348239af9bcf6c1e9eb6b83cd0ad9b3ea084Bill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
9966f3961507e73f90cec665896dece884e86be560aBill Richardson	${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
9976f3961507e73f90cec665896dece884e86be560aBill Richardson	${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
9985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
999eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
1000eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# new Firmware Utility
10015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1002eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil
10036db8c75021e2edfa400ae707a8544d041e3c415fBill Richardsonfutil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
10046db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson
100506eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
1006c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
10076db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
10085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1009b84b81dc265a766a968bf126905447d442558218Bill Richardson${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
101006eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardson${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB}
1011c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
10126db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
10135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1014eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: futil_install
1015efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill Richardsonfutil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1016c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    INSTALL       futility\n"
10176f3961507e73f90cec665896dece884e86be560aBill Richardson	${Q}mkdir -p ${UB_DIR}
10186f3961507e73f90cec665896dece884e86be560aBill Richardson	${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1019a1d9fe6eecf82540d31d34bba988e4838d295302Bill Richardson	${Q}for prog in ${FUTIL_SYMLINKS}; do \
10206f3961507e73f90cec665896dece884e86be560aBill Richardson		ln -sf futility "${UB_DIR}/$$prog"; done
10215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1022eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
10235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utility to generate TLCL structure definition header file.
10245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1025acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
10265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
10285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
10295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1030acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: update_tlcl_structures
10315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerupdate_tlcl_structures: ${BUILD}/utility/tlcl_generator
1032c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    Rebuilding TLCL structures\n"
1033eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1034eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
10355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		( echo "%% Updating structures.h %%" && \
1036eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson		  cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
10375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1038eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
10395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Tests
10405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1041eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: tests
1042eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontests: ${TEST_BINS}
10435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1044782990277ac7d6730db4c43c2b5632de93396921Bill Richardson${TEST_BINS}: ${UTILLIB} ${TESTLIB}
1045339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson${TEST_BINS}: INCLUDES += -Itests
1046efa37b87f2b4cd4b4f515e96201502ae0408cec7Randall Spangler${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
10475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10486f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${TEST2X_BINS}: ${FWLIB2X}
10496f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${TEST2X_BINS}: LIBS += ${FWLIB2X}
10506f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler
1051108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST20_BINS}: ${FWLIB20}
10526f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${TEST20_BINS}: INCLUDES += -Ifirmware/lib20/include
1053108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST20_BINS}: LIBS += ${FWLIB20}
1054108d991c678f80c99967bd07035de7418c81a072Randall Spangler
1055108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST21_BINS}: ${UTILLIB21}
1056108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
1057108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST21_BINS}: LIBS += ${UTILLIB21}
1058aaaff86467823e0d3d29c383402275eeae481256Randall Spangler
1059eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TESTLIB}: ${TESTLIB_OBJS}
1060c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1061eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}rm -f $@
1062c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1063eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}ar qc $@ $^
10645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
10655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1066eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
1067eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1068eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# rules for specific targets.
10695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1070eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
1071c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
10726db8c75021e2edfa400ae707a8544d041e3c415fBill Richardson	${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
1073eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1074eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.c
1075c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1076eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1077eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1078e08ee28548934e933733babf0bc0c418142d095dAlex Deymo${BUILD}/%.o: ${BUILD}/%.c
1079c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1080e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1081e08ee28548934e933733babf0bc0c418142d095dAlex Deymo
1082eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Rules to recompile a single source file for library and test
1083eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: is there a tidier way to do this?
1084eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1085eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_lib.o: %.c
1086c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CC-for-lib    $(subst ${BUILD}/,,$@)\n"
1087eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1088eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1089eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1090eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%_for_test.o: %.c
1091c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CC-for-test   $(subst ${BUILD}/,,$@)\n"
1092eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1093eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1094eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# TODO: C++ files don't belong in vboot reference at all.  Convert to C.
1095eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/%.o: %.cc
1096c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CXX           $(subst ${BUILD}/,,$@)\n"
1097eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1098eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1099eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# ----------------------------------------------------------------------------
1100eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Here are the special tweaks to the generic rules.
1101eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1102cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson# Always create the defaults file, since it depends on input variables
1103cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson.PHONY: ${UTIL_DEFAULTS}
1104cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson${UTIL_DEFAULTS}:
1105c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    CREATE        $(subst ${BUILD}/,,$@)\n"
1106cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}rm -f $@
1107cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}mkdir -p $(dir $@)
1108cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}echo '# Generated file. Do not edit.' > $@.tmp
1109cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1110cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson	${Q}mv -f $@.tmp $@
1111cfe83a827d40b310003fc6996b9978d8cf301444Bill Richardson
1112eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Some utilities need external crypto functions
1113782990277ac7d6730db4c43c2b5632de93396921Bill RichardsonCRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1114782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
1115eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1116eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1117eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1118eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1119eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1120eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1121eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
11226f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
11236f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1124a77541f94f731f5f7755264e9b49b7826aa48dfeBill Richardson${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
1125108d991c678f80c99967bd07035de7418c81a072Randall Spangler
1126108d991c678f80c99967bd07035de7418c81a072Randall Spangler${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
1127eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
11280b789c56fc5ff34309e935bab15f130a386a1140Mike FrysingerLZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
11290b789c56fc5ff34309e935bab15f130a386a1140Mike FrysingerYAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
11300b789c56fc5ff34309e935bab15f130a386a1140Mike Frysinger
1131eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: LD = ${CXX}
11320b789c56fc5ff34309e935bab15f130a386a1140Mike Frysinger${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
1133eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1134eecc18fc953bd367d3cb5aa006df4b153d20a45eBill RichardsonBMPBLK_UTILITY_DEPS = \
1135eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/bmpblk_util.o \
1136eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/image_types.o \
1137eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/eficompress_for_lib.o \
1138eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/utility/efidecompress_for_lib.o
11391912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson
1140eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1141eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
11421912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BMPBLK_UTILITY_DEPS}
1143eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1144eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1145eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
11461912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_OBJS += ${BUILD}/utility/image_types.o
1147eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1148eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Allow multiple definitions, so tests can mock functions from other libraries
1149eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
1150eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LDLIBS += -lrt -luuid
1151eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/%: LIBS += ${TESTLIB}
11525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
11535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/rollback_index2_tests: OBJS += \
115417f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/rollback_index_for_test.o
1155eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/rollback_index2_tests: \
1156eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/rollback_index_for_test.o
115780872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
11585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1159c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: OBJS += \
1160c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1161c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler${BUILD}/tests/tlcl_tests: \
1162c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
116380872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1164c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler
11655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/vboot_audio_tests: OBJS += \
116617f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/vboot_audio_for_test.o
1167eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${BUILD}/tests/vboot_audio_tests: \
1168eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${BUILD}/firmware/lib/vboot_audio_for_test.o
116980872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
11705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1171339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill RichardsonTLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1172eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1173eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
117480872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
11755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1176e08ee28548934e933733babf0bc0c418142d095dAlex Deymo# ----------------------------------------------------------------------------
1177e08ee28548934e933733babf0bc0c418142d095dAlex Deymo# Here are the special rules that don't fit in the generic rules.
1178e08ee28548934e933733babf0bc0c418142d095dAlex Deymo
1179e08ee28548934e933733babf0bc0c418142d095dAlex Deymo# Generates the list of commands defined in futility by running grep in the
1180e08ee28548934e933733babf0bc0c418142d095dAlex Deymo# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1181e08ee28548934e933733babf0bc0c418142d095dAlex Deymo${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1182e08ee28548934e933733babf0bc0c418142d095dAlex Deymo${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1183e08ee28548934e933733babf0bc0c418142d095dAlex Deymo${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1184c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    GEN           $(subst ${BUILD}/,,$@)\n"
1185e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}rm -f $@ $@_t $@_commands
1186e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}mkdir -p ${BUILD}/gen
1187779796f57e1e0236ea502248ede2cbea986fca21Bill Richardson	${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
1188e08ee28548934e933733babf0bc0c418142d095dAlex Deymo		| sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1189e08ee28548934e933733babf0bc0c418142d095dAlex Deymo		| sort >>$@_commands
1190e1486c3234b7dc6fc5b58681b271a65a09141e20Bill Richardson	${Q}./scripts/getversion.sh >> $@_t
1191e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo '#define _CMD(NAME) extern const struct' \
1192e08ee28548934e933733babf0bc0c418142d095dAlex Deymo		'futil_cmd_t __cmd_##NAME;' >> $@_t
1193e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}cat $@_commands >> $@_t
1194e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo '#undef _CMD' >> $@_t
1195e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1196e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1197e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}cat $@_commands >> $@_t
1198e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo '0};  /* null-terminated */' >> $@_t
1199e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}echo '#undef _CMD' >> $@_t
1200e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}mv $@_t $@
1201e08ee28548934e933733babf0bc0c418142d095dAlex Deymo	${Q}rm -f $@_commands
1202e08ee28548934e933733babf0bc0c418142d095dAlex Deymo
1203eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson##############################################################################
1204eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson# Targets that exist just to run tests
12055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
12065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Frequently-run tests
1207eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_targets
120806eb78c0f64c898c8d564b3efbffe349a8ae79b2Bill Richardsontest_targets:: runcgpttests runmisctests run2tests
1209844bce57471153664c78993dab453e87891bb969Randall Spangler
1210eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${MINIMAL},)
1211844bce57471153664c78993dab453e87891bb969Randall Spangler# Bitmap utility isn't compiled for minimal variant
1212feb2518166b1cd181e607c611cbb610f0c7300daBill Richardsontest_targets:: runbmptests runfutiltests
1213844bce57471153664c78993dab453e87891bb969Randall Spangler# Scripts don't work under qemu testing
1214844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: convert scripts to makefile so they can be called directly
1215eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_targets:: runtestscripts
1216844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
1217844bce57471153664c78993dab453e87891bb969Randall Spangler
1218eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: test_setup
12193e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardsontest_setup:: cgpt utils futil tests install_for_test
1220eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1221844bce57471153664c78993dab453e87891bb969Randall Spangler# Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
1222844bce57471153664c78993dab453e87891bb969Randall Spangler# sysroot.
1223eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifneq (${QEMU_ARCH},)
1224eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsontest_setup:: qemu_install
1225844bce57471153664c78993dab453e87891bb969Randall Spangler
1226844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: qemu_install
1227844bce57471153664c78993dab453e87891bb969Randall Spanglerqemu_install:
1228eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonifeq (${SYSROOT},)
1229eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	$(error SYSROOT must be set to the top of the target-specific root \
1230eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonwhen cross-compiling for qemu-based tests to run properly.)
1231eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonendif
1232c8c87b3264e02df2842e20866f717607a07c5ab4Mike Frysinger	@${PRINTF} "    Copying qemu binary.\n"
1233eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1234eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
1235844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
1236844bce57471153664c78993dab453e87891bb969Randall Spangler
1237acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runtests
1238a130e0b0a38efa01195f5a7be635a66f0dd60c29Bill Richardsonruntests: test_setup test_targets
12395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
12405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test keys
1241acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genkeys
1242844bce57471153664c78993dab453e87891bb969Randall Spanglergenkeys: utils
12435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_test_keys.sh
12445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
12455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test cases for fuzzing
1246acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genfuzztestcases
1247a808dc944284e6eba39a8f19ddb46bc61c34de8aRandall Spanglergenfuzztestcases: utils
12485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_fuzz_test_cases.sh
12495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1250acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runbmptests
1251eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunbmptests: test_setup
1252eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
12535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		./TestBmpBlock.py -v
12545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1255acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runcgpttests
1256eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruncgpttests: test_setup
1257eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
12585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1259844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runtestscripts
1260eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonruntestscripts: test_setup genfuzztestcases
1261b8ff397674fb98c1d7eea864e7fa571369675131Randall Spangler	tests/load_kernel_tests.sh
1262eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
1263ab899591808dd3e5f955ab7693b54a83389cd35fNam T. Nguyen	tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
12645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh
12655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_rsa_tests.sh
1266844bce57471153664c78993dab453e87891bb969Randall Spangler	tests/run_vbutil_kernel_arg_tests.sh
12675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh
1268e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	tests/vb2_rsa_tests.sh
1269539cbc27305b6aef9643adffc3297c7079fe7457Randall Spangler	tests/vb2_firmware_tests.sh
12705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1271844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runmisctests
1272eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunmisctests: test_setup
1273eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
1274a3eac79f5070747e326da631c1eec155f0389919Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
1275eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1276eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1277eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
1278c3d488d155961d2849dfdaa4f0461df1aa95c2caRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1279eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1280eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1281eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1282eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
1283eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
12840714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
12850714d9de56da3a5c686b26755d15aa6788c727d4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
12867f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
12877f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
12887f43669630cb42e40ca6ddc1128eefea8fd339d9Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
1289eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
1290e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1291e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1292e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
1293786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
1294eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
129549cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
12966dbf9d9160b2927d76017d0f51919e0880f9b2ccRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
1297eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson
1298786acdabcc15f023330d7c628aca9679e757a238Randall Spangler.PHONY: run2tests
1299786acdabcc15f023330d7c628aca9679e757a238Randall Spanglerrun2tests: test_setup
1300a7ab8b50b8923afcfd7a9e6181892c4c8a2de250Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
1301786acdabcc15f023330d7c628aca9679e757a238Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
13023333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
13033333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1304e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
13053333e578497aafc4eb8c6e1e359f6e2b1dee633aRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
1306e166d04e797b605dd2f6784bc863a262c418c0c4Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
13076f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
13086f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
13096f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
13106f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
13116f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
1312108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1313108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1314108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1315108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1316108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1317108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1318108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1319108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1320108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
1321786acdabcc15f023330d7c628aca9679e757a238Randall Spangler
1322eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardson.PHONY: runfutiltests
13233e3790d00827e75d39b77a14bca2756a14a51b3cBill Richardsonrunfutiltests: test_setup
1324efa8756c5e7068e57f5e98f0e7f2f42fb8d969d6Bill Richardson	tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
1325339f7e030cebe98a072d37acccbd1f0b4c1dea9bBill Richardson	${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1326844bce57471153664c78993dab453e87891bb969Randall Spangler
13275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Run long tests, including all permutations of encryption keys (instead of
1328786a5dca74387de5ffdc51ca5a099a4e90f406daRandall Spangler# just the ones we use) and tests of currently-unused code.
13295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Not run by automated build.
1330acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runlongtests
1331eecc18fc953bd367d3cb5aa006df4b153d20a45eBill Richardsonrunlongtests: test_setup genkeys genfuzztestcases
1332e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1333e061a256549607a56d771eb8ddae5d0dd90d519cRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
13346f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
13356f1b82ac14f341d9733d6e95d518b3ee352002efRandall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
1336108d991c678f80c99967bd07035de7418c81a072Randall Spangler	${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
13375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh --all
13385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh --all
13395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
134078d59bffec45da47b4e8a763186723192dd24f87Bill Richardson# TODO: There were a number of ancient tests that hadn't been run in years.
134178d59bffec45da47b4e8a763186723192dd24f87Bill Richardson# They were removed with https://chromium-review.googlesource.com/#/c/214610/
134278d59bffec45da47b4e8a763186723192dd24f87Bill Richardson# Some day it might be nice to see what they were supposed to do.
13435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1344782990277ac7d6730db4c43c2b5632de93396921Bill Richardson.PHONY: runalltests
1345782990277ac7d6730db4c43c2b5632de93396921Bill Richardsonrunalltests: runtests runfutiltests runlongtests
1346782990277ac7d6730db4c43c2b5632de93396921Bill Richardson
134759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler# Code coverage
134859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_init
134959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_init: test_setup
135059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	rm -f ${COV_INFO}*
135159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -i -d . -b . -o ${COV_INFO}.initial
135259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
135359d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage_html
135459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage_html:
135559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -c -d . -b . -o ${COV_INFO}.tests
135659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
135759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
135859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1359d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardson# Generate addtional coverage stats just for firmware subdir, because the stats
1360d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardson# for the whole project don't include subdirectory summaries. This will print
1361d2d08b2cc68f720a485cdfa6f044ddb234e8c42bBill Richardson# the summary for just the firmware sources.
136249cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
136349cb0d3471e768da11fe76b65769bd57dca38bd7Randall Spangler	lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
136459d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler		-o ${COV_INFO}.firmware
136559d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler
136659d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler.PHONY: coverage
136759d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerifeq (${COV},)
136859d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage:
136959d7508c2261a8371715b28f663b8b2efbb5a895Randall Spangler	$(error Build coverage like this: make clean && COV=1 make)
137059d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerelse
137159d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglercoverage: coverage_init runtests coverage_html
137259d7508c2261a8371715b28f663b8b2efbb5a895Randall Spanglerendif
13731912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson
13741912bbae89b82c10819b01d039e140e39c668fc7Bill Richardson# Include generated dependencies
13751912bbae89b82c10819b01d039e140e39c668fc7Bill RichardsonALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
137680872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonTEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
137780872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson
137880872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson# We want to use only relative paths in cscope.files, especially since the
137980872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson# paths inside and outside the chroot are different.
138080872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill RichardsonSRCDIRPAT=$(subst /,\/,${SRCDIR}/)
138180872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson
13828db64da0926e95c4cc19145e911aa270e06a83c0Bill Richardson# Note: vboot 2.0 is deprecated, so don't index those files
138380872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson${BUILD}/cscope.files: test_setup
138480872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson	${Q}rm -f $@
138580872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson	${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
13868db64da0926e95c4cc19145e911aa270e06a83c0Bill Richardson		grep -v /lib20/ | \
138780872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson		sed -e "s/${SRCDIRPAT}//" | \
138880872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson		egrep '\.[chS]$$' | sort | uniq > $@
138980872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson
139080872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardsoncmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
139180872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardsoncmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
139280872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardsonrun_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
139380872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson
139480872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson.PHONY: tags TAGS xrefs
139580872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardsontags TAGS xrefs: ${BUILD}/cscope.files
139680872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson	${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
139780872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson	${Q}$(call run_if_prog,etags,${cmd_etags})
139880872dbffcb2e0079bfe095d770ccc6c8bd5fd7aBill Richardson	${Q}$(call run_if_prog,ctags,${cmd_ctags})
1399