xref: /rk3399_ARM-atf/Makefile (revision d28673971623b33d6078f62362e91d66cb6fd05b)
14f6ad66aSAchin Gupta#
20a33adc0SGovindraj Raja# Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta#
482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta#
64f6ad66aSAchin Gupta
7e35c4045SJeenu Viswambharan#
8aaa3e722SJuan Castillo# Trusted Firmware Version
9aaa3e722SJuan Castillo#
101a0f1121SSoby MathewVERSION_MAJOR			:= 2
11669e2b15SManish V BadarkheVERSION_MINOR			:= 11
12c25d1ccfSYann Gautier# VERSION_PATCH is only used for LTS releases
13c25d1ccfSYann GautierVERSION_PATCH			:= 0
14055ebecaSYann GautierVERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15aaa3e722SJuan Castillo
1688154678SJuan Castillo# Default goal is build all images
1788154678SJuan Castillo.DEFAULT_GOAL			:= all
1888154678SJuan Castillo
1972fc70edSDouglas Raillard# Avoid any implicit propagation of command line variable definitions to
2072fc70edSDouglas Raillard# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
2172fc70edSDouglas Raillard# usage. Other command line options like "-s" are still propagated as usual.
2272fc70edSDouglas RaillardMAKEOVERRIDES =
2372fc70edSDouglas Raillard
24231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := make_helpers/
25231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
27f4dd18c2SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}build-rules.mk
287c4e1eeaSChris Kayinclude ${MAKE_HELPERS_DIRECTORY}common.mk
2973c99d4eSJuan Castillo
3073c99d4eSJuan Castillo################################################################################
312fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
3273c99d4eSJuan Castillo################################################################################
33e35c4045SJeenu Viswambharan
342fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
35872be88aSdp-arm
36cc277de8SChris Kay################################################################################
37cc277de8SChris Kay# Configure the toolchains used to build TF-A and its tools
38cc277de8SChris Kay################################################################################
39cc277de8SChris Kay
40cc277de8SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}toolchain.mk
41cc277de8SChris Kay
42cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
43cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
442fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
452fae4b1eSJeenu ViswambharanPLAT				:= ${DEFAULT_PLAT}
4673c99d4eSJuan Castillo
4773c99d4eSJuan Castillo################################################################################
4873c99d4eSJuan Castillo# Checkpatch script options
4973c99d4eSJuan Castillo################################################################################
5073c99d4eSJuan Castillo
51f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
52f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
534501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
544501843fSGilad Ben-Yossef					include/drivers/arm,		\
554501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
56f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
571a41e8c1SDan Handley					include/lib/libfdt		\
5861f72a34SRoberto Vargas					include/lib/libc,		\
59f0b489c1SDan Handley					$(wildcard include/lib/*)))
60f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
614501843fSGilad Ben-Yossef					include/lib			\
624501843fSGilad Ben-Yossef					include/drivers,		\
63f0b489c1SDan Handley					$(wildcard include/*)))
64f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
65d801fbb0Sdp-arm					lib/compiler-rt			\
6655cdcf75SAntonio Nino Diaz					lib/libfdt%			\
6761f72a34SRoberto Vargas					lib/libc,			\
68a194255dSDaniel Boulby					lib/zlib			\
69f0b489c1SDan Handley					$(wildcard lib/*)))
70f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
71f0b489c1SDan Handley					lib				\
72f0b489c1SDan Handley					include				\
73f0b489c1SDan Handley					docs				\
741ef35512SPaul Beesley					%.rst,				\
75f0b489c1SDan Handley					$(wildcard *)))
76f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
77f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
78f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
794501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
804501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
814501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
8236eaaf37SIan Spray
8373c99d4eSJuan Castillo################################################################################
8473c99d4eSJuan Castillo# Process build options
8573c99d4eSJuan Castillo################################################################################
8673c99d4eSJuan Castillo
877c4e1eeaSChris Kayifeq ($(verbose),)
8836eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
894f6ad66aSAchin Guptaendif
90ee1ba6d4SAndre Przywara
9173c99d4eSJuan Castillo################################################################################
92c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
93c5e1da83SJayanth Dodderi Chidanand################################################################################
94c5e1da83SJayanth Dodderi Chidanand
95c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
96c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
97c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
98c5e1da83SJayanth Dodderi Chidanand
99c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
100c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
101c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
102c5e1da83SJayanth Dodderi Chidanand
103c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
104c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
105c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
106c5e1da83SJayanth Dodderi Chidanand
107c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
108c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
109c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
110c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
11120629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
112c5e1da83SJayanth Dodderi Chidanand
113c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
114c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
115c5e1da83SJayanth Dodderi Chidanand
116c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
117c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
118c5e1da83SJayanth Dodderi Chidanand
119c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
120c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
121c5e1da83SJayanth Dodderi Chidanand
122c5e1da83SJayanth Dodderi Chidanand################################################################################
123c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
124c5e1da83SJayanth Dodderi Chidanand################################################################################
12526e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
12626e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
127d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
12826e63c44SEtienne Carriereelse
12926e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
130c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
131c5e1da83SJayanth Dodderi Chidanand
132c5e1da83SJayanth Dodderi Chidanand################################################################################
133c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
134c5e1da83SJayanth Dodderi Chidanand################################################################################
135c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
136c5e1da83SJayanth Dodderi Chidanand
1378620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1388620bd0bSChris Kay	ifeq ($($(ARCH)-cc-id),arm-clang)
1397794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
1407794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
141c8a992fdSorigin	else
1427794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
1437794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
144641f16e7SAmbroise Vincent	endif
145c8a992fdSorigin
1468620bd0bSChris Kayelse ifeq ($($(ARCH)-cc-id),gnu-gcc)
147edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
148edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
149fa402f38SChris Kay		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
150edbce9aaSzelalem-aweke	endif
151c5e1da83SJayanth Dodderi Chidanandendif #(clang)
152d5461857Sdp-arm
15332b209bfSAhmad Fatoum# Process Debug flag
15432b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
15532b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
15632b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
1574466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
1584466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
15932b209bfSAhmad Fatoum
16032b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
16132b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
16232b209bfSAhmad Fatoumelse
16332b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
16432b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
16532b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
166c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
16732b209bfSAhmad Fatoum
168f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
169f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
170f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
171f1de4c8fSPeiyuan Songendif
172dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
173f1de4c8fSPeiyuan Song
1748fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
1758fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
1768fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
1778fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
1788fd9d4d5SAntonio Nino Diazelse
1798fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
180c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
1818fd9d4d5SAntonio Nino Diaz
182a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
183d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
1849d29c227SSoby Mathew
185c5e1da83SJayanth Dodderi Chidanand##############################################################################
186c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
187c5e1da83SJayanth Dodderi Chidanand###############################################################################
1889ab81b5eSJustin Chadwell# General warnings
1899ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
190b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
191d75a9ecdSBoyan Karatotev				-Wredundant-decls
192d75a9ecdSBoyan Karatotev# stricter warnings
193d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
194d75a9ecdSBoyan Karatotev# too verbose for generic build
195d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
196d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
197d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
198d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
1999ab81b5eSJustin Chadwell
2009ab81b5eSJustin Chadwell# Additional warnings
201d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
202d75a9ecdSBoyan Karatotev# full -Wextra
203d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
204d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
205d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
206e7c645b5SYann Gautier
207d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
208d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
209d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
210d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
211d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
212d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
213d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
214d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
215d141e638SBoyan Karatotev# currently very involved and many platforms set this off
216d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
217e7c645b5SYann Gautier
218d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
219e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
220d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
221d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
222d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
223e7c645b5SYann GautierWARNING3 += -Wcast-qual
224e7c645b5SYann GautierWARNING3 += -Wconversion
225e7c645b5SYann GautierWARNING3 += -Wpacked
226e7c645b5SYann GautierWARNING3 += -Wpointer-arith
227e7c645b5SYann GautierWARNING3 += -Wswitch-default
228e7c645b5SYann Gautier
229d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
230d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
231d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
232d75a9ecdSBoyan Karatotevifdef W
233d75a9ecdSBoyan Karatotev	ifneq (${W},0)
234d75a9ecdSBoyan Karatotev		E	 ?= 0
235d75a9ecdSBoyan Karatotev	endif
236d75a9ecdSBoyan Karatotevendif
237d75a9ecdSBoyan Karatotev
238e7c645b5SYann Gautierifeq (${W},1)
2399ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
240e7c645b5SYann Gautierelse ifeq (${W},2)
2419ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
242e7c645b5SYann Gautierelse ifeq (${W},3)
2439ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
244c5e1da83SJayanth Dodderi Chidanandendif #(W)
245e7c645b5SYann Gautier
2469ab81b5eSJustin Chadwell# Compiler specific warnings
2478620bd0bSChris Kayifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
24893c690ebSJustin Chadwell# not using clang
249d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
250d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
251d7b4cd41SJustin Chadwell				-Wlogical-op
252dea23e24SGovindraj Raja
253dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
254dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
255dea23e24SGovindraj Raja
256538516f5SBipin Raviifeq ($(HARDEN_SLS), 1)
257538516f5SBipin Ravi        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
258538516f5SBipin Raviendif
259538516f5SBipin Ravi
26093c690ebSJustin Chadwellelse
26193c690ebSJustin Chadwell# using clang
262d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
263d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
264c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
26500296576SAmbroise Vincent
2666336b07aSYann Gautierifneq (${E},0)
2676336b07aSYann Gautier	ERRORS := -Werror
268c5e1da83SJayanth Dodderi Chidanandendif #(E)
2696336b07aSYann Gautier
270c5e1da83SJayanth Dodderi Chidanand################################################################################
271c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
272c5e1da83SJayanth Dodderi Chidanand################################################################################
273ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
2749ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
275d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
276d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
27759de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
278ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
279ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
280ebd6efaeSSamuel Holland				-Os -std=gnu99
28173c99d4eSJuan Castillo
2821f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
2831f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
284c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
285c5e1da83SJayanth Dodderi Chidanand
2861f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
2871f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
2881f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
289c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
2901f461979SJustin Chadwell
291291e7182SChris KayGCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
292f7ec31dbSdavid cunado
2931f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
2941f49db5fSMarco Felsch
295641f16e7SAmbroise Vincent# LD = armlink
2968620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
297c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
298c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
299edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
300641f16e7SAmbroise Vincent
301641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
3028620bd0bSChris Kayelse ifeq ($($(ARCH)-ld-id),gnu-gcc)
303edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
30486e489c1SChris Kay	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
305edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
306edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
307ac98b82aSChris Kay
308ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
309ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
310304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	-Wl,--build-id=none
311ac98b82aSChris Kay
312edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
313edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
314edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
31531f80efeSAndrey Skvortsov			TF_LDFLAGS      +=	-flto-partition=one
316edbce9aaSzelalem-aweke		endif
317c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
318c5e1da83SJayanth Dodderi Chidanand
319edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
320edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
321cfe6767fSYann Gautier	ifeq (${ARCH},aarch64)
322edbce9aaSzelalem-aweke		ifneq (${ERRATA_A53_843419},1)
323edbce9aaSzelalem-aweke			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
324edbce9aaSzelalem-aweke		endif
325cfe6767fSYann Gautier	endif
326edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
327edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
328641f16e7SAmbroise Vincent
329641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
330c2ad38ceSVarun Wadekarelse
3311f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
3321f49db5fSMarco Felsch# are not loaded by a elf loader.
3331f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
334ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
335c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
336ac98b82aSChris Kay
337ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
338ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
339304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	--build-id=none
340ac98b82aSChris Kay
341641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
342ebac6922SYabin Cui# therefore don't add those in that case.
343ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
344ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
3458620bd0bSChris Kay	ifneq ($($(ARCH)-ld-id),llvm-lld)
346ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
347edbce9aaSzelalem-aweke	endif
348c5e1da83SJayanth Dodderi Chidanand
349c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
35073c99d4eSJuan Castillo
35173c99d4eSJuan Castillo################################################################################
352f5211420SGovindraj Raja# Setup ARCH_MAJOR/MINOR before parsing arch_features.
353f5211420SGovindraj Raja################################################################################
354f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
3557d5fc98fSAlexeiFedorov	ARM_ARCH_MAJOR := 9
3567d5fc98fSAlexeiFedorov	ARM_ARCH_MINOR := 2
357f5211420SGovindraj Rajaendif
358f5211420SGovindraj Raja
359f5211420SGovindraj Raja################################################################################
36073c99d4eSJuan Castillo# Common sources and include directories
36173c99d4eSJuan Castillo################################################################################
362d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
36373c99d4eSJuan Castillo
364758ccb80SChris Kay# Allow overriding the timestamp, for example for reproducible builds, or to
365758ccb80SChris Kay# synchronize timestamps across multiple projects.
366758ccb80SChris Kay# This must be set to a C string (including quotes where applicable).
367758ccb80SChris KayBUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
368758ccb80SChris Kay
369758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
370758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
371758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
372758ccb80SChris Kay
37373c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
3747f56e9a3SSoby Mathew				common/tf_log.c				\
3759d29c227SSoby Mathew				common/${ARCH}/debug.S			\
37691b48c9fSJulius Werner				drivers/console/multi_console.c		\
3779d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
3789d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
379c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
380566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
3817f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
38275311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
3839d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
38461f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
385d7a6b0f8SRyan Harkin
3868620bd0bSChris Kayifeq ($($(ARCH)-cc-id),arm-clang)
3878422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
3888422a840SAntonio Nino Diazendif
3898422a840SAntonio Nino Diaz
3901f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3911f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
3921f461979SJustin Chadwellendif
3931f461979SJustin Chadwell
39401d237cbSYann GautierINCLUDES		+=	-Iinclude				\
395f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
39609d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
39709d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
39809d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
39909d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
40009d40e0eSAntonio Nino Diaz
401e03dcc8fSNishant SharmaDTC_FLAGS		+=	-I dts -O dtb
402e03dcc8fSNishant SharmaDTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
403e03dcc8fSNishant Sharma				-x assembler-with-cpp $(DEFINES)
404e03dcc8fSNishant Sharma
4059c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4069c6d1c50SAntonio Nino Diaz
40773c99d4eSJuan Castillo################################################################################
4083547270fSGovindraj Raja# Generic definitions
4093547270fSGovindraj Raja################################################################################
4103547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
4113547270fSGovindraj Raja
4123547270fSGovindraj Rajaifeq (${BUILD_BASE},)
4133547270fSGovindraj Raja     BUILD_BASE		:=	./build
4143547270fSGovindraj Rajaendif
4153547270fSGovindraj RajaBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
4163547270fSGovindraj Raja
4173547270fSGovindraj RajaSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
4183547270fSGovindraj Raja
4193547270fSGovindraj Raja# Platforms providing their own TBB makefile may override this value
4203547270fSGovindraj RajaINCLUDE_TBBR_MK		:=	1
4213547270fSGovindraj Raja
4223547270fSGovindraj Raja################################################################################
4233547270fSGovindraj Raja# Include SPD Makefile if one has been specified
4243547270fSGovindraj Raja################################################################################
4253547270fSGovindraj Raja
4263547270fSGovindraj Rajaifneq (${SPD},none)
4273547270fSGovindraj Raja	ifeq (${ARCH},aarch32)
4283547270fSGovindraj Raja                $(error "Error: SPD is incompatible with AArch32.")
4293547270fSGovindraj Raja	endif
4303547270fSGovindraj Raja
4313547270fSGovindraj Raja	ifdef EL3_PAYLOAD_BASE
4323547270fSGovindraj Raja                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
4333547270fSGovindraj Raja                $(warning "The SPD and its BL32 companion will be present but \
4343547270fSGovindraj Raja                ignored.")
4353547270fSGovindraj Raja	endif
4363547270fSGovindraj Raja
4373547270fSGovindraj Raja	ifeq (${SPD},spmd)
4383547270fSGovindraj Raja	# SPMD is located in std_svc directory
4393547270fSGovindraj Raja		SPD_DIR := std_svc
4403547270fSGovindraj Raja
4413547270fSGovindraj Raja		ifeq ($(SPMD_SPM_AT_SEL2),1)
4423547270fSGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
4433547270fSGovindraj Raja			ifeq ($(SPMC_AT_EL3),1)
4443547270fSGovindraj Raja                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
4453547270fSGovindraj Raja			endif
44659bdcc58SMadhukar Pappireddy			ifeq ($(CTX_INCLUDE_SVE_REGS),1)
44759bdcc58SMadhukar Pappireddy                                $(error SVE context management not needed with Hafnium SPMC.)
44859bdcc58SMadhukar Pappireddy			endif
4493547270fSGovindraj Raja		endif
4503547270fSGovindraj Raja
4513547270fSGovindraj Raja		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
4523547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
4533547270fSGovindraj Raja		endif
4543547270fSGovindraj Raja
4550686a01bSArunachalam Ganapathy		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
4560686a01bSArunachalam Ganapathy			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
4570686a01bSArunachalam Ganapathy		endif
4580686a01bSArunachalam Ganapathy
4593547270fSGovindraj Raja		ifeq ($(TS_SP_FW_CONFIG),1)
4603547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
4613547270fSGovindraj Raja		endif
4623547270fSGovindraj Raja
4633547270fSGovindraj Raja		ifneq ($(ARM_BL2_SP_LIST_DTS),)
4643547270fSGovindraj Raja		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
4653547270fSGovindraj Raja		endif
4663547270fSGovindraj Raja
4673547270fSGovindraj Raja		ifneq ($(SP_LAYOUT_FILE),)
4683547270fSGovindraj Raja		BL2_ENABLE_SP_LOAD := 1
4693547270fSGovindraj Raja		endif
470c189adbdSGovindraj Raja
471c189adbdSGovindraj Raja		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
472c189adbdSGovindraj Raja			ifneq ($(SPMC_AT_EL3),1)
473c189adbdSGovindraj Raja			$(error SEL0 SP cannot be enabled without SPMC at EL3)
474c189adbdSGovindraj Raja			endif
475c189adbdSGovindraj Raja		endif
4763547270fSGovindraj Raja	else
4773547270fSGovindraj Raja		# All other SPDs in spd directory
4783547270fSGovindraj Raja		SPD_DIR := spd
4793547270fSGovindraj Raja	endif #(SPD)
4803547270fSGovindraj Raja
4813547270fSGovindraj Raja	# We expect to locate an spd.mk under the specified SPD directory
4823547270fSGovindraj Raja	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
4833547270fSGovindraj Raja
4843547270fSGovindraj Raja	ifeq (${SPD_MAKE},)
4853547270fSGovindraj Raja                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
4863547270fSGovindraj Raja	endif
4873547270fSGovindraj Raja        $(info Including ${SPD_MAKE})
4883547270fSGovindraj Raja        include ${SPD_MAKE}
4893547270fSGovindraj Raja
4903547270fSGovindraj Raja	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
4913547270fSGovindraj Raja	# Makefile would set NEED_BL32 to "yes". In this case, the build system
4923547270fSGovindraj Raja	# supports two mutually exclusive options:
4933547270fSGovindraj Raja	# * BL32 is built from source: then BL32_SOURCES must contain the list
4943547270fSGovindraj Raja	#   of source files to build BL32
4953547270fSGovindraj Raja	# * BL32 is a prebuilt binary: then BL32 must point to the image file
4963547270fSGovindraj Raja	#   that will be included in the FIP
4973547270fSGovindraj Raja	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
4983547270fSGovindraj Raja	# over the sources.
4993547270fSGovindraj Rajaendif #(SPD=none)
5003547270fSGovindraj Raja
5013547270fSGovindraj Rajaifeq (${ENABLE_SPMD_LP}, 1)
5023547270fSGovindraj Rajaifneq (${SPD},spmd)
5033547270fSGovindraj Raja        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
5043547270fSGovindraj Rajaendif
5053547270fSGovindraj Rajaifeq ($(SPMC_AT_EL3),1)
5063547270fSGovindraj Raja        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
5073547270fSGovindraj Rajaendif
5083547270fSGovindraj Rajaendif
5093547270fSGovindraj Raja
5103547270fSGovindraj Raja################################################################################
511f5211420SGovindraj Raja# Process BRANCH_PROTECTION value and set
512f5211420SGovindraj Raja# Pointer Authentication and Branch Target Identification flags
513f5211420SGovindraj Raja################################################################################
514f5211420SGovindraj Rajaifeq (${BRANCH_PROTECTION},0)
515f5211420SGovindraj Raja	# Default value turns off all types of branch protection
516f5211420SGovindraj Raja	BP_OPTION := none
517f5211420SGovindraj Rajaelse ifneq (${ARCH},aarch64)
518f5211420SGovindraj Raja        $(error BRANCH_PROTECTION requires AArch64)
519f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},1)
520f5211420SGovindraj Raja	# Enables all types of branch protection features
521f5211420SGovindraj Raja	BP_OPTION := standard
522f5211420SGovindraj Raja	ENABLE_BTI := 1
523f5211420SGovindraj Raja	ENABLE_PAUTH := 1
524f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},2)
525f5211420SGovindraj Raja	# Return address signing to its standard level
526f5211420SGovindraj Raja	BP_OPTION := pac-ret
527f5211420SGovindraj Raja	ENABLE_PAUTH := 1
528f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},3)
529f5211420SGovindraj Raja	# Extend the signing to include leaf functions
530f5211420SGovindraj Raja	BP_OPTION := pac-ret+leaf
531f5211420SGovindraj Raja	ENABLE_PAUTH := 1
532f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},4)
533f5211420SGovindraj Raja	# Turn on branch target identification mechanism
534f5211420SGovindraj Raja	BP_OPTION := bti
535f5211420SGovindraj Raja	ENABLE_BTI := 1
536f5211420SGovindraj Rajaelse
537f5211420SGovindraj Raja        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
538f5211420SGovindraj Rajaendif #(BRANCH_PROTECTION)
539f5211420SGovindraj Raja
540f5211420SGovindraj Rajaifeq ($(ENABLE_PAUTH),1)
541f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
542f5211420SGovindraj Rajaendif
543f5211420SGovindraj Rajaifneq (${BP_OPTION},none)
544f5211420SGovindraj Raja	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
545f5211420SGovindraj Rajaendif #(BP_OPTION)
546f5211420SGovindraj Raja
547f5211420SGovindraj Raja# Pointer Authentication sources
548f5211420SGovindraj Rajaifeq (${ENABLE_PAUTH}, 1)
549f5211420SGovindraj Raja# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
550f5211420SGovindraj Raja# Pauth support. As it's not secure, it must be reimplemented for real platforms
551f5211420SGovindraj Raja	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
552f5211420SGovindraj Rajaendif
553f5211420SGovindraj Raja
5543547270fSGovindraj Raja################################################################################
5553547270fSGovindraj Raja# Include the platform specific Makefile after the SPD Makefile (the platform
5563547270fSGovindraj Raja# makefile may use all previous definitions in this file)
5573547270fSGovindraj Raja################################################################################
5583547270fSGovindraj Rajainclude ${PLAT_MAKEFILE_FULL}
5593547270fSGovindraj Raja
5603547270fSGovindraj Raja################################################################################
5613547270fSGovindraj Raja# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
5623547270fSGovindraj Raja# platform.
5633547270fSGovindraj Raja################################################################################
5643547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
5653547270fSGovindraj Raja
566f5211420SGovindraj Raja####################################################
567f5211420SGovindraj Raja# Enable required options for Memory Stack Tagging.
568f5211420SGovindraj Raja####################################################
569f5211420SGovindraj Raja
570f5211420SGovindraj Raja# Currently, these options are enabled only for clang and armclang compiler.
571f5211420SGovindraj Rajaifeq (${SUPPORT_STACK_MEMTAG},yes)
572f5211420SGovindraj Raja    ifdef mem_tag_arch_support
573f5211420SGovindraj Raja        # Check for armclang and clang compilers
5748620bd0bSChris Kay        ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
575f5211420SGovindraj Raja        # Add "memtag" architecture feature modifier if not specified
576f5211420SGovindraj Raja            ifeq ( ,$(findstring memtag,$(arch-features)))
577f5211420SGovindraj Raja                arch-features	:=	$(arch-features)+memtag
578f5211420SGovindraj Raja            endif	# memtag
5798620bd0bSChris Kay            ifeq ($($(ARCH)-cc-id),arm-clang)
580f5211420SGovindraj Raja                TF_CFLAGS	+=	-mmemtag-stack
5818620bd0bSChris Kay            else ifeq ($($(ARCH)-cc-id),llvm-clang)
582f5211420SGovindraj Raja                TF_CFLAGS	+=	-fsanitize=memtag
583f5211420SGovindraj Raja            endif	# armclang
584f5211420SGovindraj Raja        endif
585f5211420SGovindraj Raja    else
586f5211420SGovindraj Raja        $(error "Error: stack memory tagging is not supported for  \
587f5211420SGovindraj Raja        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
588f5211420SGovindraj Raja	endif #(mem_tag_arch_support)
589f5211420SGovindraj Rajaendif #(SUPPORT_STACK_MEMTAG)
590f5211420SGovindraj Raja
591f5211420SGovindraj Raja################################################################################
592f5211420SGovindraj Raja# RME dependent flags configuration, Enable optional features for RME.
593f5211420SGovindraj Raja################################################################################
594f5211420SGovindraj Raja# FEAT_RME
595f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
596d638029fSGovindraj Raja	# RME doesn't support BRBE
597d638029fSGovindraj Raja	ENABLE_BRBE_FOR_NS := 0
598d638029fSGovindraj Raja
599f5211420SGovindraj Raja	# RME doesn't support PIE
600f5211420SGovindraj Raja	ifneq (${ENABLE_PIE},0)
601f5211420SGovindraj Raja                $(error ENABLE_RME does not support PIE)
602f5211420SGovindraj Raja	endif
603f5211420SGovindraj Raja
604f5211420SGovindraj Raja	# RME doesn't support BRBE
605f5211420SGovindraj Raja	ifneq (${ENABLE_BRBE_FOR_NS},0)
606f5211420SGovindraj Raja                $(error ENABLE_RME does not support BRBE.)
607f5211420SGovindraj Raja	endif
608f5211420SGovindraj Raja
609f5211420SGovindraj Raja	# RME requires AARCH64
610f5211420SGovindraj Raja	ifneq (${ARCH},aarch64)
611f5211420SGovindraj Raja                $(error ENABLE_RME requires AArch64)
612f5211420SGovindraj Raja	endif
613f5211420SGovindraj Raja
614f5211420SGovindraj Raja	# RME requires el2 context to be saved for now.
615f5211420SGovindraj Raja	CTX_INCLUDE_EL2_REGS := 1
616f5211420SGovindraj Raja	CTX_INCLUDE_AARCH32_REGS := 0
617f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
618f5211420SGovindraj Raja
619f5211420SGovindraj Raja	# RME enables CSV2_2 extension by default.
620f5211420SGovindraj Raja	ENABLE_FEAT_CSV2_2 = 1
621f5211420SGovindraj Rajaendif #(FEAT_RME)
622f5211420SGovindraj Raja
623f5211420SGovindraj Raja################################################################################
6245b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6255b18de09SZelalem Aweke################################################################################
6265b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6275b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6285b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6295b18de09SZelalem Aweke	endif
6301d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6311d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6321d63ae4dSMarc Bonnici	endif
633c5e1da83SJayanth Dodderi Chidanand
6344fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6354fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6364fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6374fba2e1fSBoyan Karatotev		endif
6384fba2e1fSBoyan Karatotev	endif
6395b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6405b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6415b18de09SZelalem Awekeendif
6425b18de09SZelalem Aweke
6433547270fSGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
6443547270fSGovindraj Raja	ifeq (${SPD},none)
6453547270fSGovindraj Raja		ifeq (${ENABLE_RME},0)
6463547270fSGovindraj Raja                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
6473547270fSGovindraj Raja                        or RME is enabled)
6483547270fSGovindraj Raja		endif
6493547270fSGovindraj Raja	endif
6503547270fSGovindraj Rajaendif
6510f21c547SJuan Castillo
6527794d6c8SGovindraj Raja################################################################################
6537794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6547794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6557794d6c8SGovindraj Raja################################################################################
6567794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6577794d6c8SGovindraj Raja
6587794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6597275ac2aSGovindraj RajaASFLAGS		+=	$(march-directive)
6607794d6c8SGovindraj Raja
66142d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
66242d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
66342d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
66442d4d3baSArvind Ram Prakash# BL2 in EL3
66542d4d3baSArvind Ram Prakash
66642d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
66742d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
66842d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
669c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
670c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
67142d4d3baSArvind Ram Prakash	endif
67242d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
67342d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
67442d4d3baSArvind Ram Prakashelse
67542d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
67642d4d3baSArvind Ram Prakashendif
67742d4d3baSArvind Ram Prakash
678f87e54f7SManish Pandey# This internal flag is set to 1 when Firmware First handling of External aborts
679f87e54f7SManish Pandey# is required by lowe ELs. Currently only NS requires this support.
680f87e54f7SManish Pandeyifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
681f87e54f7SManish Pandey	FFH_SUPPORT := 1
682f87e54f7SManish Pandeyelse
683f87e54f7SManish Pandey	FFH_SUPPORT := 0
684f87e54f7SManish Pandeyendif
685f87e54f7SManish Pandey
68626e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
68726e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
68826e63c44SEtienne Carriereendif
68926e63c44SEtienne Carriere
6903bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6913bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6923bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6938620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
6947b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
6957b592418SSamuel Hollandendif
696c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
697320920c1SMasahiro Yamada
6988620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
699320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
700320920c1SMasahiro Yamadaelse
701320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
702320920c1SMasahiro Yamadaendif
703320920c1SMasahiro Yamada
704320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
70542d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
70669af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
707966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
70869af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
70969af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
710c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
711c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
712966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
713320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
714320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
715966660ecSChris Kay
716966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
717d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
718d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
719c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7203bd17c0fSSoby Mathew
721007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
722007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
723007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
724007433d8SBoyan Karatotev
7259cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
72642d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7279cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
728d5e97a1dSMasahiro Yamadaelse
7299cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
730c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
731007433d8SBoyan Karatotev
732007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7339cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7349cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7359cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
736007433d8SBoyan Karatotevelse
737007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
738d5e97a1dSMasahiro Yamadaendif
739d5e97a1dSMasahiro Yamada
74054035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
74154035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
74254035fc4SSandrine Bailleux# This can be overridden by the platform.
74373c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7444f6ad66aSAchin Gupta
745a4409008Sdp-arm################################################################################
746a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
747a4409008Sdp-arm################################################################################
748c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
749c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
750c5e1da83SJayanth Dodderi Chidanand
751a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
752a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
753a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
754a4409008Sdp-arm
755a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
756a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
757a4409008Sdp-arm                endif
758a4409008Sdp-arm                $(info Including ${AARCH32_SP_MAKE})
759a4409008Sdp-arm                include ${AARCH32_SP_MAKE}
760a4409008Sdp-arm        endif
761c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7624f6ad66aSAchin Gupta
76373c99d4eSJuan Castillo################################################################################
76477f1f7a1SVarun Wadekar# Include libc if not overridden
76577f1f7a1SVarun Wadekar################################################################################
76677f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
76777f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
76877f1f7a1SVarun Wadekarendif
76977f1f7a1SVarun Wadekar
77077f1f7a1SVarun Wadekar################################################################################
771c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
772cf2c8a33SAntonio Nino Diaz################################################################################
773cf2c8a33SAntonio Nino Diaz
774c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
775c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
776c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
777c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
778c5e1da83SJayanth Dodderi Chidanand        else
779c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
780c5e1da83SJayanth Dodderi Chidanand        endif
781c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
782c5e1da83SJayanth Dodderi Chidanand
783c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
784c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
785c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
786c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
787c5e1da83SJayanth Dodderi Chidanand        endif
788c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
789c5e1da83SJayanth Dodderi Chidanand
790c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
791c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
792c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
793c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
794c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
795c5e1da83SJayanth Dodderi Chidanandendif
796c5e1da83SJayanth Dodderi Chidanand
797c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
798c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
799c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
800c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
801c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
802c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
803c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
804c5e1da83SJayanth Dodderi Chidanand
805cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
80668450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
80768450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
80868450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
809cf2c8a33SAntonio Nino Diaz	endif
81076580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
811c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
812c5e1da83SJayanth Dodderi Chidanand                build options.")
81376580f3dSQixiang Xu	endif
81476580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
815c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
816c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
81776580f3dSQixiang Xu	endif
818c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
819cf2c8a33SAntonio Nino Diaz
820cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
821cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
822cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
823cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
824cf2c8a33SAntonio Nino Diaz	endif
82568450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
82668450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
827c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
828cf2c8a33SAntonio Nino Diaz	endif
829c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
830cf2c8a33SAntonio Nino Diaz
831d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
832d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
833d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
834d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
835d4593e47SJeenu Viswambharanendif
8361a0a3f06SYatharth Kochar
83742d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
83842d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
83942d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8407d173fc5SJiafei Panendif
8417d173fc5SJiafei Pan
8429202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
84314c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
844c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
845f87e54f7SManish Pandey        and HANDLE_EA_EL3_FIRST_NS instead")
8469202d519SManish Pandeyendif
847c5e1da83SJayanth Dodderi Chidanand
848c5e1da83SJayanth Dodderi Chidanand
8499202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8501a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8516503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8526503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8531a7c1cfeSJeenu Viswambharan	endif
854c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8551a7c1cfeSJeenu Viswambharan
856ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
857209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
858209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
859c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
860c5e1da83SJayanth Dodderi Chidanand                to be set.")
861209a60ccSSoby Mathew	endif
862c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
863209a60ccSSoby Mathew
8642bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8652bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8662bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8672bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8682bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8692bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8702bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8712bf4f27fSManish V Badarkhe# Support hash calculation only
8722bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8732bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8742bf4f27fSManish V Badarkhe# Support authentication verification only
875c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
876c9c56f6eSManish V Badarkheelse
877c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
878c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
879c9c56f6eSManish V Badarkhe
880cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
881cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
882700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
88384ef9cd8SManish V Badarkheendif
88484ef9cd8SManish V Badarkhe
885b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
8869fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
8879fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
888b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
8899fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
8909fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
89106715f85SAlexei Fedorov	endif
892c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
8939fc59639SAlexei Fedorov
89406715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
8959fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
8969fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
897b86048c4SAntonio Nino Diaz	endif
898c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
8999fc59639SAlexei Fedorov
9006a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9016a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
902c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9036a0da736SJayanth Dodderi Chidanand
90403d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
90503d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
906c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
907c5e1da83SJayanth Dodderi Chidanand                to be set")
90803d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
90903d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
91003d3c0d7SJayanth Dodderi Chidanand	endif
911c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
91245007acdSJayanth Dodderi Chidanand
91360e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
91460e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
915c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
916c5e1da83SJayanth Dodderi Chidanand                library v2")
91760e8f3cfSPetre-Ionut Tudor	endif
918c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
91960e8f3cfSPetre-Ionut Tudor
9207cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9217cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
922c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
923c5e1da83SJayanth Dodderi Chidanand                to be set)
9247cda17bbSSumit Garg	endif
925c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9267cda17bbSSumit Garg
927744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
928dc78e62dSjohpow01ifeq (${ARCH},aarch32)
929744ad974Sjohpow01
930744ad974Sjohpow01	# SME/SVE only supported on AArch64
93145007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
932dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
933dc78e62dSjohpow01	endif
93403d3c0d7SJayanth Dodderi Chidanand
935dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
936dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
93724ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
938dc78e62dSjohpow01	endif
939744ad974Sjohpow01
940ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
941744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
942744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
943744ad974Sjohpow01	endif
944744ad974Sjohpow01
945ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
946ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
947ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
948ff86e0b4SJuan Pablo Conde	endif
949c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
950dc78e62dSjohpow01
9510d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9520d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9530d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9540d122947SBoyan Karatotev	endif
955c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9560d122947SBoyan Karatotev
957dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
958dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
959dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
960dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
961dc78e62dSjohpow01	endif
9620d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9630d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9640d122947SBoyan Karatotev	endif
965c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
966c5e1da83SJayanth Dodderi Chidanand
9673524d074SMadhukar Pappireddy# Enabling SVE for SWD requires enabling SVE for NWD due to ENABLE_FEAT
9683524d074SMadhukar Pappireddy# mechanism.
969dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
970dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
971dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
972dc78e62dSjohpow01    endif
9733524d074SMadhukar Pappireddyendif
974dc78e62dSjohpow01
9753524d074SMadhukar Pappireddy# Enabling SVE for both the worlds typically requires the context
9763524d074SMadhukar Pappireddy# management of SVE registers. The only exception being SPMC at S-EL2.
9773524d074SMadhukar Pappireddyifeq (${ENABLE_SVE_FOR_SWD}, 1)
9783524d074SMadhukar Pappireddy    ifneq (${ENABLE_SVE_FOR_NS}, 0)
9793524d074SMadhukar Pappireddy        ifeq (${CTX_INCLUDE_SVE_REGS}-$(SPMD_SPM_AT_SEL2),0-0)
9803524d074SMadhukar Pappireddy            $(warning "ENABLE_SVE_FOR_SWD and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
9813524d074SMadhukar Pappireddy        endif
9823524d074SMadhukar Pappireddy    endif
9833524d074SMadhukar Pappireddyendif
9843524d074SMadhukar Pappireddy
9853524d074SMadhukar Pappireddy# Enabling SVE in either world while enabling CTX_INCLUDE_FPREGS requires
9863524d074SMadhukar Pappireddy# CTX_INCLUDE_SVE_REGS to be enabled due to architectural dependency between FP
9873524d074SMadhukar Pappireddy# and SVE registers.
9883524d074SMadhukar Pappireddyifeq (${CTX_INCLUDE_FPREGS}, 1)
9893524d074SMadhukar Pappireddy    ifneq (${ENABLE_SVE_FOR_NS},0)
9903524d074SMadhukar Pappireddy        ifeq (${CTX_INCLUDE_SVE_REGS},0)
9913524d074SMadhukar Pappireddy	    # Warning instead of error due to CI dependency on this
9923524d074SMadhukar Pappireddy            $(warning "CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
9933524d074SMadhukar Pappireddy            $(warning "Forced ENABLE_SVE_FOR_NS=0")
9943524d074SMadhukar Pappireddy	    override ENABLE_SVE_FOR_NS	:= 0
9953524d074SMadhukar Pappireddy        endif
9963524d074SMadhukar Pappireddy    endif
9973524d074SMadhukar Pappireddyendif #(CTX_INCLUDE_FPREGS)
9983524d074SMadhukar Pappireddy
9993524d074SMadhukar Pappireddy# SVE context management is only required if secure world has access to SVE/FP
10003524d074SMadhukar Pappireddy# functionality.
10013524d074SMadhukar Pappireddyifeq (${CTX_INCLUDE_SVE_REGS},1)
10023524d074SMadhukar Pappireddy    ifeq (${ENABLE_SVE_FOR_SWD},0)
10033524d074SMadhukar Pappireddy        $(error "CTX_INCLUDE_SVE_REGS requires ENABLE_SVE_FOR_SWD to also be enabled")
10043524d074SMadhukar Pappireddy    endif
10053524d074SMadhukar Pappireddyendif
10063524d074SMadhukar Pappireddy
10073524d074SMadhukar Pappireddy# SME cannot be used with CTX_INCLUDE_FPREGS since SPM does its own context
10083524d074SMadhukar Pappireddy# management including FPU registers.
1009dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
101045007acdSJayanth Dodderi Chidanand    ifneq (${ENABLE_SME_FOR_NS},0)
1011dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1012dc78e62dSjohpow01    endif
1013c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1014dc78e62dSjohpow01
101500e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
101600e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
101700e28874SManish V Badarkheendif
101800e28874SManish V Badarkhe
10193ba2c151SRaymond Maoifeq (${TRANSFER_LIST},1)
10203ba2c151SRaymond Mao        $(info TRANSFER_LIST is an experimental feature)
10213ba2c151SRaymond Maoendif
10223ba2c151SRaymond Mao
1023274a69e7SChris Kayifeq (${ENABLE_RME},1)
1024274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1025274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1026274a69e7SChris Kay	endif
1027274a69e7SChris Kayendif
1028274a69e7SChris Kay
10295782b890SManish V Badarkheifeq ($(PSA_CRYPTO),1)
10305782b890SManish V Badarkhe        $(info PSA_CRYPTO is an experimental feature)
10315782b890SManish V Badarkheendif
10325782b890SManish V Badarkhe
103382222db8SManish V Badarkheifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
103482222db8SManish V Badarkhe        $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
103582222db8SManish V Badarkheendif
103682222db8SManish V Badarkhe
1037cf2c8a33SAntonio Nino Diaz################################################################################
103873c99d4eSJuan Castillo# Process platform overrideable behaviour
103973c99d4eSJuan Castillo################################################################################
10404f6ad66aSAchin Gupta
10415f24ce96SManish Pandeyifdef BL1_SOURCES
10425f24ce96SManish Pandey	NEED_BL1 := yes
1043c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10445f24ce96SManish Pandey
10455f24ce96SManish Pandeyifdef BL2_SOURCES
10465f24ce96SManish Pandey	NEED_BL2 := yes
10475f24ce96SManish Pandey
1048bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1049bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1050cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1051cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1052cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10534c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1054cf2c8a33SAntonio Nino Diaz	else
105568450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1056cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1057cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1058cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1059cf2c8a33SAntonio Nino Diaz		else
1060cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1061cf2c8a33SAntonio Nino Diaz		endif
10624c117f6cSSandrine Bailleux	endif
1063c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10646f971622SJuan Castillo
10655f24ce96SManish Pandeyifdef BL2U_SOURCES
10665f24ce96SManish Pandey	NEED_BL2U := yes
1067c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10685f24ce96SManish Pandey
10694d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10704d045d0eSMasahiro Yamadaifdef SCP_BL2
10714d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1072c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10734d045d0eSMasahiro Yamada
10745744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10755744e874SSoby Mathewifneq (${ARCH},aarch32)
10765744e874SSoby Mathew	ifdef BL31_SOURCES
1077c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1078c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10795744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10805744e874SSoby Mathew			NEED_BL31 := yes
10815744e874SSoby Mathew		endif
10825744e874SSoby Mathew	endif
1083c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10845744e874SSoby Mathew
108573c99d4eSJuan Castillo# Process TBB related flags
10866f971622SJuan Castilloifneq (${GENERATE_COT},0)
108773c99d4eSJuan Castillo	# Common cert_create options
10886f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10896f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10900191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1091fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1092fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10930191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1094fd34e7baSJuan Castillo		endif
10956f971622SJuan Castillo	endif
109673c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
109773c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
109873c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
109973c99d4eSJuan Castillo	endif
1100c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11016f971622SJuan Castillo
11021c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11031c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1104c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11051c75d5dfSMasahiro Yamada
11065f24ce96SManish Pandeyifdef FDT_SOURCES
11075f24ce96SManish Pandey	NEED_FDT := yes
1108c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11095f24ce96SManish Pandey
111073c99d4eSJuan Castillo################################################################################
111146e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
111246e5e035SMichalis Pappas################################################################################
111346e5e035SMichalis Pappas
111446e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
111546e5e035SMichalis Pappas
111646e5e035SMichalis Pappas################################################################################
11178a86052dSSoby Mathew# Include BL specific makefiles
11188a86052dSSoby Mathew################################################################################
11195f24ce96SManish Pandey
11205f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11218a86052dSSoby Mathewinclude bl1/bl1.mk
11228a86052dSSoby Mathewendif
11238a86052dSSoby Mathew
11245f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11258a86052dSSoby Mathewinclude bl2/bl2.mk
11268a86052dSSoby Mathewendif
11278a86052dSSoby Mathew
11285f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11298a86052dSSoby Mathewinclude bl2u/bl2u.mk
11308a86052dSSoby Mathewendif
11318a86052dSSoby Mathew
11325744e874SSoby Mathewifeq (${NEED_BL31},yes)
11338a86052dSSoby Mathewinclude bl31/bl31.mk
11348a86052dSSoby Mathewendif
113503b397a8SNishanth Menon
113673c99d4eSJuan Castillo################################################################################
113773c99d4eSJuan Castillo# Build options checks
113873c99d4eSJuan Castillo################################################################################
113973c99d4eSJuan Castillo
1140c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1141327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1142327131c4SLeonardo Sandoval    $(sort \
1143327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
114446789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1145327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1146327131c4SLeonardo Sandoval	CREATE_KEYS \
1147327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1148327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
114942422622SMadhukar Pappireddy	CTX_INCLUDE_SVE_REGS \
1150327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
11519acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1152327131c4SLeonardo Sandoval	DEBUG \
1153327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1154327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11551fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1156742ca230SChris Kay	ENABLE_AMU_FCONF \
1157873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1158327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1159327131c4SLeonardo Sandoval	ENABLE_PIE \
1160327131c4SLeonardo Sandoval	ENABLE_PMF \
1161327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1162327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1163dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11640c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1165970a4a8dSManish Pandey	ENABLE_FEAT_RAS	\
1166f87e54f7SManish Pandey	FFH_SUPPORT	\
1167327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1168327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1169327131c4SLeonardo Sandoval	GENERATE_COT \
1170327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
117146cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1172538516f5SBipin Ravi	HARDEN_SLS \
1173327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1174327131c4SLeonardo Sandoval	MEASURED_BOOT \
1175e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
117600e28874SManish V Badarkhe	DRTM_SUPPORT \
1177327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1178327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1179327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1180327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1181327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
118264b4710bSWing Li	PSCI_OS_INIT_MODE \
1183327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1184327131c4SLeonardo Sandoval	SAVE_KEYS \
1185327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
118696a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1187327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1188308ebfa1SMadhukar Pappireddy	SEPARATE_SIMD_SECTION \
1189327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1190327131c4SLeonardo Sandoval	SPM_MM \
11911d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1192801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1193327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1194890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
11953ba2c151SRaymond Mao	TRANSFER_LIST \
1196327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1197327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1198327131c4SLeonardo Sandoval	USE_DEBUGFS \
1199327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1200327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1201327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1202327131c4SLeonardo Sandoval	USE_ROMLIB \
1203327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1204327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
120542d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1206327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1207327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1208327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1209327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1210327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1211327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
121200e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1213327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1214327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1215396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
121611d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
121768120783SChris Kay	ENABLE_MPMM \
121868120783SChris Kay	ENABLE_MPMM_FCONF \
12196a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12200b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1221ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1222ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
122304c7303bSOkash Khawaja	CONDITIONAL_CMO \
12245782b890SManish V Badarkhe	PSA_CRYPTO	\
122585bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1226183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1227bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1228ae770fedSYann Gautier	EARLY_CONSOLE \
1229f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1230327131c4SLeonardo Sandoval)))
123173c99d4eSJuan Castillo
1232c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1233327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1234327131c4SLeonardo Sandoval    $(sort \
1235327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1236327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1237327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12386a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12396a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12402bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
124183a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12421298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
124347c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12446a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12456a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1246d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12476a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12486a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
124930019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
125083271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
12516a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12526a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12536a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
125433e6aaacSArvind Ram Prakash	ENABLE_FEAT_FGT2 \
12556a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12568e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
12576a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12586a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1259ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12606a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1261d3331603SMark Brown	ENABLE_FEAT_TCR2 \
12620e4daed2SGovindraj Raja	ENABLE_FEAT_SB \
1263062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1264062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1265062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1266062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1267688ab57bSMark Brown	ENABLE_FEAT_GCS \
12686a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
1269edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
12706a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12716437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1272603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
127345007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
127403d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12752b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12766a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1277327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12785357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12795357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1280781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1281781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1282bebcf27fSMark Brown	SVE_VECTOR_LEN \
12830ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1284327131c4SLeonardo Sandoval)))
1285c877b414SJeenu Viswambharan
1286aacff749SJustin Chadwellifdef KEY_SIZE
1287aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1288aacff749SJustin Chadwellendif
1289aacff749SJustin Chadwell
12901f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12911f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12921f461979SJustin Chadwellendif
12931f461979SJustin Chadwell
129473c99d4eSJuan Castillo################################################################################
129573c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
129673c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
129773c99d4eSJuan Castillo# platform to overwrite the default options
129873c99d4eSJuan Castillo################################################################################
129973c99d4eSJuan Castillo
1300327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1301327131c4SLeonardo Sandoval    $(sort \
1302327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1303327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1304327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
130546789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1306327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1307327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1308327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
130942422622SMadhukar Pappireddy	CTX_INCLUDE_SVE_REGS \
1310327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
13119acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1312327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1313327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1314062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1315327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13160063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1317d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13181fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1319742ca230SChris Kay	ENABLE_AMU_FCONF \
1320873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1321327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1322327131c4SLeonardo Sandoval	ENABLE_BTI \
132383271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
1324edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
1325327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1326327131c4SLeonardo Sandoval	ENABLE_PIE \
1327327131c4SLeonardo Sandoval	ENABLE_PMF \
1328327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13295b18de09SZelalem Aweke	ENABLE_RME \
1330327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1331dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
133203d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1333dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
133490118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1335327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13360c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1337970a4a8dSManish Pandey	ENABLE_FEAT_RAS \
1338f87e54f7SManish Pandey	FFH_SUPPORT \
1339327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1340327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1341327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1342327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1343327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
134446cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1345327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1346327131c4SLeonardo Sandoval	LOG_LEVEL \
1347327131c4SLeonardo Sandoval	MEASURED_BOOT \
1348e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
134900e28874SManish V Badarkhe	DRTM_SUPPORT \
1350327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1351327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1352327131c4SLeonardo Sandoval	PLAT_${PLAT} \
1353327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1354327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
135564b4710bSWing Li	PSCI_OS_INIT_MODE \
1356327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1357d766084fSAlexeiFedorov	RME_GPT_BITLOCK_BLOCK \
1358ec0088bbSAlexeiFedorov	RME_GPT_MAX_BLOCK \
1359327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
136096a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1361327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1362308ebfa1SMadhukar Pappireddy	SEPARATE_SIMD_SECTION \
1363327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1364327131c4SLeonardo Sandoval	SPD_${SPD} \
1365327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1366327131c4SLeonardo Sandoval	SPM_MM \
13671d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1368801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1369327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
13703ba2c151SRaymond Mao	TRANSFER_LIST \
1371327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1372c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13737dfb9911SJimmy Brisson	TRNG_SUPPORT \
1374ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1375ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1376327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1377327131c4SLeonardo Sandoval	USE_DEBUGFS \
1378327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1379327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1380327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1381327131c4SLeonardo Sandoval	USE_ROMLIB \
1382327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1383327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
138442d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
138542d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1386327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1387327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1388327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1389327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
139000e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1391327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1392327131c4SLeonardo Sandoval	USE_SP804_TIMER \
139312cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1394ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13954e04478aSChris Kay	ENABLE_FEAT_SB \
13967d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13975357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13985357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1399396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
140011d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
1401744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1402813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1403d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
14048fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1405cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
140668120783SChris Kay	ENABLE_MPMM \
140768120783SChris Kay	ENABLE_MPMM_FCONF \
1408f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
140933e6aaacSArvind Ram Prakash	ENABLE_FEAT_FGT2 \
1410f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
14116a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
14126a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
14136a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
14146a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
141530019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
14166a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1417d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1418062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1419062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1420062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1421062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1422688ab57bSMark Brown	ENABLE_FEAT_GCS \
14238e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
14246a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1425781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1426781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
142704c7303bSOkash Khawaja	CONDITIONAL_CMO \
14280ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1429a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1430890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
14315782b890SManish V Badarkhe	PSA_CRYPTO	\
143285bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1433183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1434bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1435ae770fedSYann Gautier	EARLY_CONSOLE \
1436f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1437327131c4SLeonardo Sandoval)))
14382fae4b1eSJeenu Viswambharan
1439bfef8b90SJuan Pablo Condeifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1440bfef8b90SJuan Pablo Condeifeq (${DEBUG}, 0)
1441bfef8b90SJuan Pablo Conde        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1442bfef8b90SJuan Pablo Conde        override PLATFORM_REPORT_CTX_MEM_USE := 0
1443bfef8b90SJuan Pablo Condeendif
1444bfef8b90SJuan Pablo Condeendif
1445bfef8b90SJuan Pablo Conde
14461f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14471f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1448c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14491f461979SJustin Chadwell
14504c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14514c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14524c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1453cf2c8a33SAntonio Nino Diazelse
145468450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
145568450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
145668450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
145768450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14584c117f6cSSandrine Bailleux	endif
1459c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
146073c99d4eSJuan Castillo
1461209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1462209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1463209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1464209a60ccSSoby Mathewendif
1465209a60ccSSoby Mathew
14668620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
1467c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1468c2ad38ceSVarun Wadekarendif
1469c2ad38ceSVarun Wadekar
1470ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1471ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1472c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1473ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1474ce2b1ec6SManish Pandey	FIP_DEPS += sp
147507c44475SManish Pandey	CRT_DEPS += sp
1476ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1477ce2b1ec6SManish Pandeyelse
1478c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1479c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1480c33ff198SOlivier Deprez	endif
1481c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1482c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1483ce2b1ec6SManish Pandey
148473c99d4eSJuan Castillo################################################################################
148573c99d4eSJuan Castillo# Build targets
148673c99d4eSJuan Castillo################################################################################
148773c99d4eSJuan Castillo
14882329e22bSHarrison Mutai.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
148973c99d4eSJuan Castillo.SUFFIXES:
149073c99d4eSJuan Castillo
149173c99d4eSJuan Castilloall: msg_start
149273c99d4eSJuan Castillo
149373c99d4eSJuan Castillomsg_start:
14947c4e1eeaSChris Kay	$(s)echo "Building ${PLAT}"
149573c99d4eSJuan Castillo
14967a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1497d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
14988620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1499c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1500c2ad38ceSVarun Wadekarelse
1501bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
15027a24cba5SSoby Mathewendif
1503c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
15047a24cba5SSoby Mathew
150561f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
15065fee0287SRoberto Vargas
150773c99d4eSJuan Castillo# Expand build macros for the different images
150873c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1509b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1510434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1511c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
151273c99d4eSJuan Castillo
151373c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1514c5e1da83SJayanth Dodderi Chidanand
151542d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1516c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1517c9b31ae8SRoberto Vargasendif
1518c9b31ae8SRoberto Vargas
1519eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1520eb1acfb6SChris Kay
152133950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1522434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1523c5e1da83SJayanth Dodderi Chidanand
1524c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
152573c99d4eSJuan Castillo
15264d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
152733950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1528c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
15294d045d0eSMasahiro Yamada
153073c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
153173c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
153226d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
153326d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1534c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1535c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1536434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1537c6ba9b45SSumit Gargelse
153833950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1539434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1540c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1541c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
154273c99d4eSJuan Castillo
154370d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1544c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
154570d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
154673c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
154726d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
154826d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15499cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15509cd15239SMasahiro Yamada
1551c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1552434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1553c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1554c6ba9b45SSumit Gargelse
1555434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
155633950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1557c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1558c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
155973c99d4eSJuan Castillo
15605b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15615b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15625b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15635b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15645b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15655b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15665b18de09SZelalem Aweke
15675b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15685b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1569c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15705b18de09SZelalem Aweke
157173c99d4eSJuan Castillo# Add the BL33 image if required by the platform
157273c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
157333950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1574c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1575db6071c9SJuan Castillo
15769003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
157733950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1578434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1579c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15809003fa0bSYatharth Kochar
158103b397a8SNishanth Menon# Expand build macros for the different images
158203b397a8SNishanth Menonifeq (${NEED_FDT},yes)
158303b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1584c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
158503b397a8SNishanth Menon
1586ce2b1ec6SManish Pandey# Add Secure Partition packages
1587ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1588fd74ca0dSChris Kay$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
15897c4e1eeaSChris Kay	$(q)${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1590822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
15917c4e1eeaSChris Kay	$(s)echo
15927c4e1eeaSChris Kay	$(s)echo "Built SP Images successfully"
15937c4e1eeaSChris Kay	$(s)echo
1594c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1595ce2b1ec6SManish Pandey
159636eaaf37SIan Spraylocate-checkpatch:
159736eaaf37SIan Sprayifndef CHECKPATCH
159866079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
159936eaaf37SIan Sprayelse
160036eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
160166079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
160236eaaf37SIan Sprayendif
1603c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
160436eaaf37SIan Spray
16054f6ad66aSAchin Guptaclean:
16067c4e1eeaSChris Kay	$(s)echo "  CLEAN"
1607f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
160888a1cf1eSSami Mujawarifdef UNIX_MK
16097c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
161088a1cf1eSSami Mujawarelse
161188a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
161288a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16137c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1614c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16157c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
16167c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
16177c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16184f6ad66aSAchin Gupta
1619eaaeece2SJames Morrisseyrealclean distclean:
16207c4e1eeaSChris Kay	$(s)echo "  REALCLEAN"
1621f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1622f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
162388a1cf1eSSami Mujawarifdef UNIX_MK
16247c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
162588a1cf1eSSami Mujawarelse
162688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
162788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16287c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1629c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16307c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
16317c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
16327c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16334f6ad66aSAchin Gupta
163436eaaf37SIan Spraycheckcodebase:		locate-checkpatch
16357c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16367c4e1eeaSChris Kay	$(q)if test -d .git ; then						\
16371ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16381a41e8c1SDan Handley		while read GIT_FILE ;					\
16391a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16401a41e8c1SDan Handley		done ;							\
164136eaaf37SIan Spray	else								\
16421a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16431a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16441a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
164561f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16461a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16471ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16481a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
164936eaaf37SIan Spray	fi
165036eaaf37SIan Spray
165136eaaf37SIan Spraycheckpatch:		locate-checkpatch
16527c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16537c4e1eeaSChris Kay	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
165402a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
165502a76d5fSYann Gautier	fi
16567c4e1eeaSChris Kay	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
165777a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
165877a0a7f1SYann Gautier	do								\
165951d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
16601a721748SYann Gautier		( git log --format=email "$$commit~..$$commit"		\
16611a721748SYann Gautier			-- ${CHECK_PATHS} ;				\
166251d28937SAntonio Nino Diaz		  git diff --format=email "$$commit~..$$commit"		\
16631a721748SYann Gautier			-- ${CHECK_PATHS}; ) |				\
166402a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
166551d28937SAntonio Nino Diaz	done
166636eaaf37SIan Spray
166773c99d4eSJuan Castillocerttool: ${CRTTOOL}
166873c99d4eSJuan Castillo
1669a9812206SPali Rohár${CRTTOOL}: FORCE
16707c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
16717c4e1eeaSChris Kay	$(s)echo
16727c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16737c4e1eeaSChris Kay	$(s)echo
16746f971622SJuan Castillo
16756f971622SJuan Castilloifneq (${GENERATE_COT},0)
167673c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16777c4e1eeaSChris Kay	$(q)${CRTTOOL} ${CRT_ARGS}
16787c4e1eeaSChris Kay	$(s)echo
16797c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16807c4e1eeaSChris Kay	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
16817c4e1eeaSChris Kay	$(s)echo
1682c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
168327713fb4SSoby Mathew
168473c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16854727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
16867c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FIP_ARGS} $@
16877c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
16887c4e1eeaSChris Kay	$(s)echo
16897c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16907c4e1eeaSChris Kay	$(s)echo
1691f58ad36fSHarry Liebel
16920191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16930191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16947c4e1eeaSChris Kay	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
16957c4e1eeaSChris Kay	$(s)echo
16967c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16977c4e1eeaSChris Kay	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
16987c4e1eeaSChris Kay	$(s)echo
1699c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
17000191262dSYatharth Kochar
17010191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
17024727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
17037c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
17047c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
17057c4e1eeaSChris Kay	$(s)echo
17067c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17077c4e1eeaSChris Kay	$(s)echo
17080191262dSYatharth Kochar
170973c99d4eSJuan Castillofiptool: ${FIPTOOL}
171073c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
17110191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
171273c99d4eSJuan Castillo
1713a9812206SPali Rohár${FIPTOOL}: FORCE
171488a1cf1eSSami Mujawarifdef UNIX_MK
17157c4e1eeaSChris Kay	$(q)${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
171688a1cf1eSSami Mujawarelse
171788a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
171888a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
17197c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1720c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1721f58ad36fSHarry Liebel
1722a9812206SPali Rohárromlib.bin: libraries FORCE
17237c4e1eeaSChris Kay	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
17245accce5bSRoberto Vargas
1725cfe83910SLouis Mayencourtmemmap: all
1726af5b49e9SHarrison Mutaiifdef UNIX_MK
17277c4e1eeaSChris Kay	$(q)PYTHONPATH=${CURDIR}/tools/memory \
1728af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1729af5b49e9SHarrison Mutaielse
17307c4e1eeaSChris Kay	$(q)set PYTHONPATH=${CURDIR}/tools/memory && \
1731af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1732af5b49e9SHarrison Mutaiendif
1733cfe83910SLouis Mayencourt
17342329e22bSHarrison Mutaitl: ${BUILD_PLAT}/tl.bin
17352329e22bSHarrison Mutai${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
1736*d2867397SChris Kay	$(if $(host-poetry),$(q)poetry -q install)
1737*d2867397SChris Kay	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
17382329e22bSHarrison Mutai
17396de32378SMadhukar Pappireddydoc:
17407c4e1eeaSChris Kay	$(s)echo "  BUILD DOCUMENTATION"
17417c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
17426de32378SMadhukar Pappireddy
174390aa901fSSumit Gargenctool: ${ENCTOOL}
174490aa901fSSumit Garg
1745a9812206SPali Rohár${ENCTOOL}: FORCE
17467c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
17477c4e1eeaSChris Kay	$(s)echo
17487c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17497c4e1eeaSChris Kay	$(s)echo
175090aa901fSSumit Garg
175135fab8c9SJoakim Bechcscope:
17527c4e1eeaSChris Kay	$(s)echo "  CSCOPE"
17537c4e1eeaSChris Kay	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
17547c4e1eeaSChris Kay	$(q)cscope -b -q -k
175535fab8c9SJoakim Bech
175672ee3314SRyan Harkinhelp:
17577c4e1eeaSChris Kay	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
17587c4e1eeaSChris Kay	$(s)echo ""
17597c4e1eeaSChris Kay	$(s)echo "PLAT is used to specify which platform you wish to build."
17607c4e1eeaSChris Kay	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
17617c4e1eeaSChris Kay	$(s)echo ""
17627c4e1eeaSChris Kay	$(s)echo "platform = ${PLATFORM_LIST}"
17637c4e1eeaSChris Kay	$(s)echo ""
17647c4e1eeaSChris Kay	$(s)echo "Please refer to the User Guide for a list of all supported options."
17657c4e1eeaSChris Kay	$(s)echo "Note that the build system doesn't track dependencies for build "
17667c4e1eeaSChris Kay	$(s)echo "options. Therefore, if any of the build options are changed "
17677c4e1eeaSChris Kay	$(s)echo "from a previous build, a clean build must be performed."
17687c4e1eeaSChris Kay	$(s)echo ""
17697c4e1eeaSChris Kay	$(s)echo "Supported Targets:"
17707c4e1eeaSChris Kay	$(s)echo "  all            Build all individual bootloader binaries"
17717c4e1eeaSChris Kay	$(s)echo "  bl1            Build the BL1 binary"
17727c4e1eeaSChris Kay	$(s)echo "  bl2            Build the BL2 binary"
17737c4e1eeaSChris Kay	$(s)echo "  bl2u           Build the BL2U binary"
17747c4e1eeaSChris Kay	$(s)echo "  bl31           Build the BL31 binary"
17757c4e1eeaSChris Kay	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17767c4e1eeaSChris Kay	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
17777c4e1eeaSChris Kay	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17787c4e1eeaSChris Kay	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
17797c4e1eeaSChris Kay	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
17807c4e1eeaSChris Kay	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
17817c4e1eeaSChris Kay	$(s)echo "  checkpatch     Check the coding style on changes in the current"
17827c4e1eeaSChris Kay	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
17837c4e1eeaSChris Kay	$(s)echo "  clean          Clean the build for the selected platform"
17847c4e1eeaSChris Kay	$(s)echo "  cscope         Generate cscope index"
17857c4e1eeaSChris Kay	$(s)echo "  distclean      Remove all build artifacts for all platforms"
17867c4e1eeaSChris Kay	$(s)echo "  certtool       Build the Certificate generation tool"
17877c4e1eeaSChris Kay	$(s)echo "  enctool        Build the Firmware encryption tool"
17887c4e1eeaSChris Kay	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
17897c4e1eeaSChris Kay	$(s)echo "  sp             Build the Secure Partition Packages"
17907c4e1eeaSChris Kay	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
17917c4e1eeaSChris Kay	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
17927c4e1eeaSChris Kay	$(s)echo "  memmap         Print the memory map of the built binaries"
17937c4e1eeaSChris Kay	$(s)echo "  doc            Build html based documentation using Sphinx tool"
17947c4e1eeaSChris Kay	$(s)echo ""
17957c4e1eeaSChris Kay	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
17967c4e1eeaSChris Kay	$(s)echo ""
17977c4e1eeaSChris Kay	$(s)echo "example: build all targets for the FVP platform:"
17987c4e1eeaSChris Kay	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1799a9812206SPali Rohár
1800a9812206SPali Rohár.PHONY: FORCE
1801a9812206SPali RohárFORCE:;
1802