1#
2# Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7include lib/libfdt/libfdt.mk
8include lib/xlat_tables_v2/xlat_tables.mk
9
10PLAT_INCLUDES		:=	-Iplat/rpi/common/include		\
11				-Iplat/rpi/rpi3/include
12
13PLAT_BL_COMMON_SOURCES	:=	drivers/ti/uart/aarch64/16550_console.S	\
14				drivers/arm/pl011/aarch64/pl011_console.S \
15				drivers/gpio/gpio.c			\
16				drivers/delay_timer/delay_timer.c	\
17				drivers/rpi3/gpio/rpi3_gpio.c		\
18				plat/rpi/common/aarch64/plat_helpers.S	\
19				plat/rpi/common/rpi3_common.c		\
20				${XLAT_TABLES_LIB_SRCS}
21
22BL1_SOURCES		+=	drivers/io/io_fip.c			\
23				drivers/io/io_memmap.c			\
24				drivers/io/io_storage.c			\
25				lib/cpus/aarch64/cortex_a53.S		\
26				plat/common/aarch64/platform_mp_stack.S	\
27				plat/rpi/rpi3/rpi3_bl1_setup.c		\
28				plat/rpi/common/rpi3_io_storage.c	\
29				drivers/rpi3/mailbox/rpi3_mbox.c	\
30				plat/rpi/rpi3/rpi_mbox_board.c
31
32BL2_SOURCES		+=	common/desc_image_load.c		\
33				drivers/io/io_fip.c			\
34				drivers/io/io_memmap.c			\
35				drivers/io/io_storage.c			\
36				drivers/delay_timer/generic_delay_timer.c \
37				drivers/io/io_block.c			\
38				drivers/mmc/mmc.c			\
39				drivers/rpi3/sdhost/rpi3_sdhost.c	\
40				plat/common/aarch64/platform_mp_stack.S	\
41				plat/rpi/rpi3/aarch64/rpi3_bl2_mem_params_desc.c \
42				plat/rpi/rpi3/rpi3_bl2_setup.c		\
43				plat/rpi/common/rpi3_image_load.c	\
44				plat/rpi/common/rpi3_io_storage.c
45
46BL31_SOURCES		+=	lib/cpus/aarch64/cortex_a53.S		\
47				plat/common/plat_psci_common.c		\
48				plat/rpi/rpi3/rpi3_bl31_setup.c		\
49				plat/rpi/common/rpi3_pm.c		\
50				plat/rpi/common/rpi3_topology.c		\
51				${LIBFDT_SRCS}
52
53# Tune compiler for Cortex-A53
54ifeq ($(notdir $(CC)),armclang)
55    TF_CFLAGS_aarch64	+=	-mcpu=cortex-a53
56else ifneq ($(findstring clang,$(notdir $(CC))),)
57    TF_CFLAGS_aarch64	+=	-mcpu=cortex-a53
58else
59    TF_CFLAGS_aarch64	+=	-mtune=cortex-a53
60endif
61
62# Platform Makefile target
63# ------------------------
64
65RPI3_BL1_PAD_BIN	:=	${BUILD_PLAT}/bl1_pad.bin
66RPI3_ARMSTUB8_BIN	:=	${BUILD_PLAT}/armstub8.bin
67
68# Add new default target when compiling this platform
69all: armstub
70
71# This target concatenates BL1 and the FIP so that the base addresses match the
72# ones defined in the memory map
73armstub: bl1 fip
74	@echo "  CAT     $@"
75	${Q}cp ${BUILD_PLAT}/bl1.bin ${RPI3_BL1_PAD_BIN}
76	${Q}truncate --size=131072 ${RPI3_BL1_PAD_BIN}
77	${Q}cat ${RPI3_BL1_PAD_BIN} ${BUILD_PLAT}/fip.bin > ${RPI3_ARMSTUB8_BIN}
78	@${ECHO_BLANK_LINE}
79	@echo "Built $@ successfully"
80	@${ECHO_BLANK_LINE}
81
82# Build config flags
83# ------------------
84
85# Enable all errata workarounds for Cortex-A53
86ERRATA_A53_826319		:= 1
87ERRATA_A53_835769		:= 1
88ERRATA_A53_836870		:= 1
89ERRATA_A53_843419		:= 1
90ERRATA_A53_855873		:= 1
91
92WORKAROUND_CVE_2017_5715	:= 0
93
94# Disable stack protector by default
95ENABLE_STACK_PROTECTOR	 	:= 0
96
97# Reset to BL31 isn't supported
98RESET_TO_BL31			:= 0
99
100# Have different sections for code and rodata
101SEPARATE_CODE_AND_RODATA	:= 1
102
103# Use Coherent memory
104USE_COHERENT_MEM		:= 1
105
106# Platform build flags
107# --------------------
108
109# BL33 images are in AArch64 by default
110RPI3_BL33_IN_AARCH32		:= 0
111
112# Assume that BL33 isn't the Linux kernel by default
113RPI3_DIRECT_LINUX_BOOT		:= 0
114
115# UART to use at runtime. -1 means the runtime UART is disabled.
116# Any other value means the default UART will be used.
117RPI3_RUNTIME_UART		:= -1
118
119# Use normal memory mapping for ROM, FIP, SRAM and DRAM
120RPI3_USE_UEFI_MAP		:= 0
121
122# BL32 location
123RPI3_BL32_RAM_LOCATION	:= tdram
124ifeq (${RPI3_BL32_RAM_LOCATION}, tsram)
125  RPI3_BL32_RAM_LOCATION_ID = SEC_SRAM_ID
126else ifeq (${RPI3_BL32_RAM_LOCATION}, tdram)
127  RPI3_BL32_RAM_LOCATION_ID = SEC_DRAM_ID
128else
129  $(error "Unsupported RPI3_BL32_RAM_LOCATION value")
130endif
131
132# Process platform flags
133# ----------------------
134
135$(eval $(call add_define,RPI3_BL32_RAM_LOCATION_ID))
136$(eval $(call add_define,RPI3_BL33_IN_AARCH32))
137$(eval $(call add_define,RPI3_DIRECT_LINUX_BOOT))
138ifdef RPI3_PRELOADED_DTB_BASE
139$(eval $(call add_define,RPI3_PRELOADED_DTB_BASE))
140endif
141$(eval $(call add_define,RPI3_RUNTIME_UART))
142$(eval $(call add_define,RPI3_USE_UEFI_MAP))
143
144# Verify build config
145# -------------------
146#
147ifneq (${RPI3_DIRECT_LINUX_BOOT}, 0)
148  ifndef RPI3_PRELOADED_DTB_BASE
149    $(error Error: RPI3_PRELOADED_DTB_BASE needed if RPI3_DIRECT_LINUX_BOOT=1)
150  endif
151endif
152
153ifneq (${RESET_TO_BL31}, 0)
154  $(error Error: rpi3 needs RESET_TO_BL31=0)
155endif
156
157ifeq (${ARCH},aarch32)
158  $(error Error: AArch32 not supported on rpi3)
159endif
160
161ifneq ($(ENABLE_STACK_PROTECTOR), 0)
162PLAT_BL_COMMON_SOURCES	+=	drivers/rpi3/rng/rpi3_rng.c		\
163				plat/rpi/common/rpi3_stack_protector.c
164endif
165
166ifeq (${SPD},opteed)
167BL2_SOURCES	+=							\
168		lib/optee/optee_utils.c
169endif
170
171# Add the build options to pack Trusted OS Extra1 and Trusted OS Extra2 images
172# in the FIP if the platform requires.
173ifneq ($(BL32_EXTRA1),)
174$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1))
175endif
176ifneq ($(BL32_EXTRA2),)
177$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2))
178endif
179
180ifneq (${TRUSTED_BOARD_BOOT},0)
181
182    include drivers/auth/mbedtls/mbedtls_crypto.mk
183    include drivers/auth/mbedtls/mbedtls_x509.mk
184
185    AUTH_SOURCES	:=	drivers/auth/auth_mod.c			\
186				drivers/auth/crypto_mod.c		\
187				drivers/auth/img_parser_mod.c		\
188				drivers/auth/tbbr/tbbr_cot_common.c
189
190    BL1_SOURCES		+=	${AUTH_SOURCES}				\
191				bl1/tbbr/tbbr_img_desc.c		\
192				plat/common/tbbr/plat_tbbr.c		\
193				plat/rpi/common/rpi3_trusted_boot.c    	\
194				plat/rpi/common/rpi3_rotpk.S		\
195				drivers/auth/tbbr/tbbr_cot_bl1.c
196
197    BL2_SOURCES		+=	${AUTH_SOURCES}				\
198				plat/common/tbbr/plat_tbbr.c		\
199				plat/rpi/common/rpi3_trusted_boot.c    	\
200				plat/rpi/common/rpi3_rotpk.S		\
201				drivers/auth/tbbr/tbbr_cot_bl2.c
202
203    ROT_KEY             = $(BUILD_PLAT)/rot_key.pem
204    ROTPK_HASH          = $(BUILD_PLAT)/rotpk_sha256.bin
205
206    $(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"'))
207
208    $(BUILD_PLAT)/bl1/rpi3_rotpk.o: $(ROTPK_HASH)
209    $(BUILD_PLAT)/bl2/rpi3_rotpk.o: $(ROTPK_HASH)
210
211    certificates: $(ROT_KEY)
212
213    $(ROT_KEY): | $(BUILD_PLAT)
214	@echo "  OPENSSL $@"
215	$(Q)openssl genrsa 2048 > $@ 2>/dev/null
216
217    $(ROTPK_HASH): $(ROT_KEY)
218	@echo "  OPENSSL $@"
219	$(Q)openssl rsa -in $< -pubout -outform DER 2>/dev/null |\
220	openssl dgst -sha256 -binary > $@ 2>/dev/null
221endif
222