summaryrefslogtreecommitdiff
path: root/board/cr50/build.mk
blob: 7e96fe6ef2323b8ad4b0e110641214310a6f15d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- makefile -*-
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Board-specific build requirements

# Define the SoC used by this board
CHIP:=g
CHIP_FAMILY:=cr50
CHIP_VARIANT ?= cr50_fpga

# This file is included twice by the Makefile, once to determine the CHIP info
# and then again after defining all the CONFIG_ and HAS_TASK variables. We use
# a guard so that recipe definitions and variable extensions only happen the
# second time.
ifeq ($(BOARD_MK_INCLUDED_ONCE),)

# List of variables which can be defined in the environment or set in the make
# command line.
ENV_VARS := CR50_DEV CRYPTO_TEST H1_RED_BOARD

ifneq ($(CRYPTO_TEST),)
CPPFLAGS += -DCRYPTO_TEST_SETUP
endif


BOARD_MK_INCLUDED_ONCE=1
SIG_EXTRA = --cros
else

# Need to generate a .hex file
all: hex

# The simulator components have their own subdirectory
CFLAGS += -I$(realpath $(BDIR)/dcrypto)
CFLAGS += -I$(realpath $(BDIR)/tpm2)
dirs-y += $(BDIR)/dcrypto
dirs-y += $(BDIR)/tpm2

# Objects that we need to build
board-y =  board.o
board-y += ap_state.o
board-y += closed_source_set1.o
board-y += ec_state.o
board-y += int_ap_extension.o
board-y += power_button.o
board-y += servo_state.o
board-y += ap_uart_state.o
board-y += factory_mode.o
board-y += fips.o
board-y += fips_rand.o
board-${CONFIG_RDD} += rdd.o
board-${CONFIG_USB_SPI} += usb_spi.o
board-${CONFIG_USB_I2C} += usb_i2c.o
board-y += recovery_button.o

board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/aes.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/app_cipher.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/app_key.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/bn.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/dcrypto_bn.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/dcrypto_p256.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/compare.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/dcrypto_runtime.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/gcm.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/hkdf.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/hmac.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/hmac_drbg.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/key_ladder.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/p256.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/p256_ec.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/rsa.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/sha1.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/sha256.o
ifeq ($(CONFIG_UPTO_SHA512),y)
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/sha384.o
ifeq ($(CONFIG_DCRYPTO_SHA512),y)
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/dcrypto_sha512.o
else
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/sha512.o
endif
endif
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/x509.o
board-$(CONFIG_DCRYPTO_BOARD)+= dcrypto/trng.o

board-y += tpm2/NVMem.o
board-y += tpm2/aes.o
board-y += tpm2/ecc.o
board-y += tpm2/ecies.o
board-y += tpm2/endorsement.o
board-y += tpm2/hash.o
board-y += tpm2/hash_data.o
board-y += tpm2/hkdf.o
board-y += tpm2/manufacture.o
board-y += tpm2/nvmem_ops.o
board-y += tpm2/platform.o
board-y += tpm2/rsa.o
board-y += tpm2/stubs.o
board-y += tpm2/tpm_mode.o
board-y += tpm2/tpm_state.o
board-y += tpm2/trng.o
board-y += tpm2/virtual_nvmem.o
board-y += tpm_nvmem_ops.o
board-y += wp.o
board-$(CONFIG_U2F) += u2f.o

ifneq ($(H1_RED_BOARD),)
CPPFLAGS += -DH1_RED_BOARD=$(EMPTY)
endif

# Build and link with an external library
EXTLIB := $(realpath ../../third_party/tpm2)
CFLAGS += -I$(EXTLIB)

# For the benefit of the tpm2 library.
INCLUDE_ROOT := $(abspath ./include)
CFLAGS += -I$(INCLUDE_ROOT)
CPPFLAGS += -I$(abspath ./builtin)
CPPFLAGS += -I$(abspath ./chip/$(CHIP))
# For core includes
CPPFLAGS += -I$(abspath .)
CPPFLAGS += -I$(abspath $(BDIR))
CPPFLAGS += -I$(abspath ./fuzz)
CPPFLAGS += -I$(abspath ./test)
ifeq ($(CONFIG_UPTO_SHA512),y)
CPPFLAGS += -DSHA512_SUPPORT
endif

# Make sure the context of the software sha512 implementation fits. If it ever
# increases, a compile time assert will fire in tpm2/hash.c.
ifeq ($(CONFIG_UPTO_SHA512),y)
CFLAGS += -DUSER_MIN_HASH_STATE_SIZE=208
else
CFLAGS += -DUSER_MIN_HASH_STATE_SIZE=112
endif
# Configure TPM2 headers accordingly.
CFLAGS += -DEMBEDDED_MODE=1
# Configure cryptoc headers to handle unaligned accesses.
CFLAGS += -DSUPPORT_UNALIGNED=1

# Use absolute path as the destination to ensure that TPM2 makefile finds the
# place for output.
outdir := $(realpath $(out))/tpm2
cmd_tpm2_base = $(MAKE) obj=$(outdir) EMBEDDED_MODE=1 \
		-C $(EXTLIB) --no-print-directory

TPM2_OBJS := $(shell $(cmd_tpm2_base) list_copied_objs)

TPM2_TARGET := $(outdir)/.copied_objs

# Add dependencies on that library
$(out)/RW/ec.RW.elf $(out)/RW/ec.RW_B.elf: LDFLAGS_EXTRA += $(TPM2_OBJS)
$(out)/RW/ec.RW.elf $(out)/RW/ec.RW_B.elf: $(TPM2_TARGET)

cmd_tpm2lib = $(cmd_tpm2_base) $(TPM2_TARGET)

tpm2lib_check_clean = $(cmd_tpm2lib) -q && echo clean

ifneq ($(shell $(tpm2lib_check_clean)),clean)
# Force the external build only if it is needed.
.PHONY: $(TPM2_TARGET)
endif

$(TPM2_TARGET):
	$(call quiet,tpm2lib,TPM2   )

endif   # BOARD_MK_INCLUDED_ONCE is nonempty

board-$(CONFIG_PINWEAVER)+=pinweaver_tpm_imports.o