xref: /rk3399_ARM-atf/Makefile (revision 83271d5a5aae06c23c59a32c30a0fe83fb82e79f)
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
277c4e1eeaSChris Kayinclude ${MAKE_HELPERS_DIRECTORY}common.mk
2873c99d4eSJuan Castillo
2973c99d4eSJuan Castillo################################################################################
302fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
3173c99d4eSJuan Castillo################################################################################
32e35c4045SJeenu Viswambharan
332fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
34872be88aSdp-arm
35cc277de8SChris Kay################################################################################
36cc277de8SChris Kay# Configure the toolchains used to build TF-A and its tools
37cc277de8SChris Kay################################################################################
38cc277de8SChris Kay
39291e7182SChris Kay#
40291e7182SChris Kay# The clean and check targets do not behave correctly if the user's environment
41291e7182SChris Kay# does not appropriately configure a toolchain. While we try to find a permanent
42291e7182SChris Kay# solution to this, do not try to detect any toolchains if we are building
43291e7182SChris Kay# exclusively with targets which do not use any toolchain tools.
44291e7182SChris Kay#
45291e7182SChris Kay
46291e7182SChris Kayifeq ($(filter-out check% %clean doc %tool,$(or $(MAKECMDGOALS),all)),)
47291e7182SChris Kay        toolchains :=
48291e7182SChris Kayendif
49291e7182SChris Kay
50cc277de8SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}toolchain.mk
51cc277de8SChris Kay
52cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
53cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
542fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
552fae4b1eSJeenu ViswambharanPLAT				:= ${DEFAULT_PLAT}
5673c99d4eSJuan Castillo
5773c99d4eSJuan Castillo################################################################################
5873c99d4eSJuan Castillo# Checkpatch script options
5973c99d4eSJuan Castillo################################################################################
6073c99d4eSJuan Castillo
61f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
62f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
634501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
644501843fSGilad Ben-Yossef					include/drivers/arm,		\
654501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
66f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
671a41e8c1SDan Handley					include/lib/libfdt		\
6861f72a34SRoberto Vargas					include/lib/libc,		\
69f0b489c1SDan Handley					$(wildcard include/lib/*)))
70f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
714501843fSGilad Ben-Yossef					include/lib			\
724501843fSGilad Ben-Yossef					include/drivers,		\
73f0b489c1SDan Handley					$(wildcard include/*)))
74f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
75d801fbb0Sdp-arm					lib/compiler-rt			\
7655cdcf75SAntonio Nino Diaz					lib/libfdt%			\
7761f72a34SRoberto Vargas					lib/libc,			\
78a194255dSDaniel Boulby					lib/zlib			\
79f0b489c1SDan Handley					$(wildcard lib/*)))
80f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
81f0b489c1SDan Handley					lib				\
82f0b489c1SDan Handley					include				\
83f0b489c1SDan Handley					docs				\
841ef35512SPaul Beesley					%.rst,				\
85f0b489c1SDan Handley					$(wildcard *)))
86f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
87f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
88f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
894501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
904501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
914501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
9236eaaf37SIan Spray
9373c99d4eSJuan Castillo################################################################################
9473c99d4eSJuan Castillo# Process build options
9573c99d4eSJuan Castillo################################################################################
9673c99d4eSJuan Castillo
977c4e1eeaSChris Kayifeq ($(verbose),)
9836eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
994f6ad66aSAchin Guptaendif
100ee1ba6d4SAndre Przywara
10173c99d4eSJuan Castillo################################################################################
102c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
103c5e1da83SJayanth Dodderi Chidanand################################################################################
104c5e1da83SJayanth Dodderi Chidanand
105c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
106c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
107c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
108c5e1da83SJayanth Dodderi Chidanand
109c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
110c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
111c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
112c5e1da83SJayanth Dodderi Chidanand
113c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
114c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
115c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
116c5e1da83SJayanth Dodderi Chidanand
117c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
118c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
119c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
120c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
12120629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
122c5e1da83SJayanth Dodderi Chidanand
123c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
124c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
125c5e1da83SJayanth Dodderi Chidanand
126c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
127c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
128c5e1da83SJayanth Dodderi Chidanand
129c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
130c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
131c5e1da83SJayanth Dodderi Chidanand
132c5e1da83SJayanth Dodderi Chidanand################################################################################
133c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
134c5e1da83SJayanth Dodderi Chidanand################################################################################
13526e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
13626e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
137d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
13826e63c44SEtienne Carriereelse
13926e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
140c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
141c5e1da83SJayanth Dodderi Chidanand
142c5e1da83SJayanth Dodderi Chidanand################################################################################
143c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
144c5e1da83SJayanth Dodderi Chidanand################################################################################
145c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
146c5e1da83SJayanth Dodderi Chidanand
1478620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1488620bd0bSChris Kay	ifeq ($($(ARCH)-cc-id),arm-clang)
1497794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
1507794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
151c8a992fdSorigin	else
1527794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
1537794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
154641f16e7SAmbroise Vincent	endif
155c8a992fdSorigin
1568620bd0bSChris Kayelse ifeq ($($(ARCH)-cc-id),gnu-gcc)
157edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
158edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
159fa402f38SChris Kay		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
160edbce9aaSzelalem-aweke	endif
161c5e1da83SJayanth Dodderi Chidanandendif #(clang)
162d5461857Sdp-arm
16332b209bfSAhmad Fatoum# Process Debug flag
16432b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
16532b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
16632b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
1674466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
1684466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
16932b209bfSAhmad Fatoum
17032b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
17132b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
17232b209bfSAhmad Fatoumelse
17332b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
17432b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
17532b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
176c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
17732b209bfSAhmad Fatoum
178f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
179f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
180f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
181f1de4c8fSPeiyuan Songendif
182dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
183f1de4c8fSPeiyuan Song
1848fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
1858fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
1868fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
1878fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
1888fd9d4d5SAntonio Nino Diazelse
1898fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
190c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
1918fd9d4d5SAntonio Nino Diaz
192a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
193d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
1949d29c227SSoby Mathew
195c5e1da83SJayanth Dodderi Chidanand##############################################################################
196c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
197c5e1da83SJayanth Dodderi Chidanand###############################################################################
1989ab81b5eSJustin Chadwell# General warnings
1999ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
200b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
201d75a9ecdSBoyan Karatotev				-Wredundant-decls
202d75a9ecdSBoyan Karatotev# stricter warnings
203d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
204d75a9ecdSBoyan Karatotev# too verbose for generic build
205d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
206d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
207d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
208d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
2099ab81b5eSJustin Chadwell
2109ab81b5eSJustin Chadwell# Additional warnings
211d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
212d75a9ecdSBoyan Karatotev# full -Wextra
213d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
214d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
215d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
216e7c645b5SYann Gautier
217d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
218d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
219d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
220d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
221d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
222d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
223d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
224d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
225d141e638SBoyan Karatotev# currently very involved and many platforms set this off
226d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
227e7c645b5SYann Gautier
228d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
229e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
230d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
231d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
232d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
233e7c645b5SYann GautierWARNING3 += -Wcast-qual
234e7c645b5SYann GautierWARNING3 += -Wconversion
235e7c645b5SYann GautierWARNING3 += -Wpacked
236e7c645b5SYann GautierWARNING3 += -Wpointer-arith
237e7c645b5SYann GautierWARNING3 += -Wswitch-default
238e7c645b5SYann Gautier
239d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
240d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
241d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
242d75a9ecdSBoyan Karatotevifdef W
243d75a9ecdSBoyan Karatotev	ifneq (${W},0)
244d75a9ecdSBoyan Karatotev		E	 ?= 0
245d75a9ecdSBoyan Karatotev	endif
246d75a9ecdSBoyan Karatotevendif
247d75a9ecdSBoyan Karatotev
248e7c645b5SYann Gautierifeq (${W},1)
2499ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
250e7c645b5SYann Gautierelse ifeq (${W},2)
2519ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
252e7c645b5SYann Gautierelse ifeq (${W},3)
2539ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
254c5e1da83SJayanth Dodderi Chidanandendif #(W)
255e7c645b5SYann Gautier
2569ab81b5eSJustin Chadwell# Compiler specific warnings
2578620bd0bSChris Kayifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
25893c690ebSJustin Chadwell# not using clang
259d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
260d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
261d7b4cd41SJustin Chadwell				-Wlogical-op
262dea23e24SGovindraj Raja
263dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
264dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
265dea23e24SGovindraj Raja
266538516f5SBipin Raviifeq ($(HARDEN_SLS), 1)
267538516f5SBipin Ravi        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
268538516f5SBipin Raviendif
269538516f5SBipin Ravi
27093c690ebSJustin Chadwellelse
27193c690ebSJustin Chadwell# using clang
272d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
273d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
274c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
27500296576SAmbroise Vincent
2766336b07aSYann Gautierifneq (${E},0)
2776336b07aSYann Gautier	ERRORS := -Werror
278c5e1da83SJayanth Dodderi Chidanandendif #(E)
2796336b07aSYann Gautier
280c5e1da83SJayanth Dodderi Chidanand################################################################################
281c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
282c5e1da83SJayanth Dodderi Chidanand################################################################################
283ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
2849ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
285d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
286d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
28759de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
288ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
289ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
290ebd6efaeSSamuel Holland				-Os -std=gnu99
29173c99d4eSJuan Castillo
2921f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
2931f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
294c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
295c5e1da83SJayanth Dodderi Chidanand
2961f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
2971f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
2981f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
299c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
3001f461979SJustin Chadwell
301291e7182SChris KayGCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
302f7ec31dbSdavid cunado
3031f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
3041f49db5fSMarco Felsch
305641f16e7SAmbroise Vincent# LD = armlink
3068620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
307c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
308c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
309edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
310641f16e7SAmbroise Vincent
311641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
3128620bd0bSChris Kayelse ifeq ($($(ARCH)-ld-id),gnu-gcc)
313edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
31486e489c1SChris Kay	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
315edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
316edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
317ac98b82aSChris Kay
318ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
319ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
320304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	-Wl,--build-id=none
321ac98b82aSChris Kay
322edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
323edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
324edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
32531f80efeSAndrey Skvortsov			TF_LDFLAGS      +=	-flto-partition=one
326edbce9aaSzelalem-aweke		endif
327c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
328c5e1da83SJayanth Dodderi Chidanand
329edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
330edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
331cfe6767fSYann Gautier	ifeq (${ARCH},aarch64)
332edbce9aaSzelalem-aweke		ifneq (${ERRATA_A53_843419},1)
333edbce9aaSzelalem-aweke			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
334edbce9aaSzelalem-aweke		endif
335cfe6767fSYann Gautier	endif
336edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
337edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
338641f16e7SAmbroise Vincent
339641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
340c2ad38ceSVarun Wadekarelse
3411f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
3421f49db5fSMarco Felsch# are not loaded by a elf loader.
3431f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
344ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
345c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
346ac98b82aSChris Kay
347ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
348ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
349304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	--build-id=none
350ac98b82aSChris Kay
351641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
352ebac6922SYabin Cui# therefore don't add those in that case.
353ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
354ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
3558620bd0bSChris Kay	ifneq ($($(ARCH)-ld-id),llvm-lld)
356ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
357edbce9aaSzelalem-aweke	endif
358c5e1da83SJayanth Dodderi Chidanand
359c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
36073c99d4eSJuan Castillo
36173c99d4eSJuan Castillo################################################################################
362f5211420SGovindraj Raja# Setup ARCH_MAJOR/MINOR before parsing arch_features.
363f5211420SGovindraj Raja################################################################################
364f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
3657d5fc98fSAlexeiFedorov	ARM_ARCH_MAJOR := 9
3667d5fc98fSAlexeiFedorov	ARM_ARCH_MINOR := 2
367f5211420SGovindraj Rajaendif
368f5211420SGovindraj Raja
369f5211420SGovindraj Raja################################################################################
37073c99d4eSJuan Castillo# Common sources and include directories
37173c99d4eSJuan Castillo################################################################################
372d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
37373c99d4eSJuan Castillo
374758ccb80SChris Kay# Allow overriding the timestamp, for example for reproducible builds, or to
375758ccb80SChris Kay# synchronize timestamps across multiple projects.
376758ccb80SChris Kay# This must be set to a C string (including quotes where applicable).
377758ccb80SChris KayBUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
378758ccb80SChris Kay
379758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
380758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
381758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
382758ccb80SChris Kay
38373c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
3847f56e9a3SSoby Mathew				common/tf_log.c				\
3859d29c227SSoby Mathew				common/${ARCH}/debug.S			\
38691b48c9fSJulius Werner				drivers/console/multi_console.c		\
3879d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
3889d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
389c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
390566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
3917f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
39275311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
3939d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
39461f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
395d7a6b0f8SRyan Harkin
3968620bd0bSChris Kayifeq ($($(ARCH)-cc-id),arm-clang)
3978422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
3988422a840SAntonio Nino Diazendif
3998422a840SAntonio Nino Diaz
4001f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4011f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
4021f461979SJustin Chadwellendif
4031f461979SJustin Chadwell
40401d237cbSYann GautierINCLUDES		+=	-Iinclude				\
405f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
40609d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
40709d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
40809d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
40909d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
41009d40e0eSAntonio Nino Diaz
411e03dcc8fSNishant SharmaDTC_FLAGS		+=	-I dts -O dtb
412e03dcc8fSNishant SharmaDTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
413e03dcc8fSNishant Sharma				-x assembler-with-cpp $(DEFINES)
414e03dcc8fSNishant Sharma
4159c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4169c6d1c50SAntonio Nino Diaz
41773c99d4eSJuan Castillo################################################################################
4183547270fSGovindraj Raja# Generic definitions
4193547270fSGovindraj Raja################################################################################
4203547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
4213547270fSGovindraj Raja
4223547270fSGovindraj Rajaifeq (${BUILD_BASE},)
4233547270fSGovindraj Raja     BUILD_BASE		:=	./build
4243547270fSGovindraj Rajaendif
4253547270fSGovindraj RajaBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
4263547270fSGovindraj Raja
4273547270fSGovindraj RajaSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
4283547270fSGovindraj Raja
4293547270fSGovindraj Raja# Platforms providing their own TBB makefile may override this value
4303547270fSGovindraj RajaINCLUDE_TBBR_MK		:=	1
4313547270fSGovindraj Raja
4323547270fSGovindraj Raja################################################################################
4333547270fSGovindraj Raja# Include SPD Makefile if one has been specified
4343547270fSGovindraj Raja################################################################################
4353547270fSGovindraj Raja
4363547270fSGovindraj Rajaifneq (${SPD},none)
4373547270fSGovindraj Raja	ifeq (${ARCH},aarch32)
4383547270fSGovindraj Raja                $(error "Error: SPD is incompatible with AArch32.")
4393547270fSGovindraj Raja	endif
4403547270fSGovindraj Raja
4413547270fSGovindraj Raja	ifdef EL3_PAYLOAD_BASE
4423547270fSGovindraj Raja                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
4433547270fSGovindraj Raja                $(warning "The SPD and its BL32 companion will be present but \
4443547270fSGovindraj Raja                ignored.")
4453547270fSGovindraj Raja	endif
4463547270fSGovindraj Raja
4473547270fSGovindraj Raja	ifeq (${SPD},spmd)
4483547270fSGovindraj Raja	# SPMD is located in std_svc directory
4493547270fSGovindraj Raja		SPD_DIR := std_svc
4503547270fSGovindraj Raja
4513547270fSGovindraj Raja		ifeq ($(SPMD_SPM_AT_SEL2),1)
4523547270fSGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
4533547270fSGovindraj Raja			ifeq ($(SPMC_AT_EL3),1)
4543547270fSGovindraj Raja                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
4553547270fSGovindraj Raja			endif
4563547270fSGovindraj Raja		endif
4573547270fSGovindraj Raja
4583547270fSGovindraj Raja		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
4593547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
4603547270fSGovindraj Raja		endif
4613547270fSGovindraj Raja
4620686a01bSArunachalam Ganapathy		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
4630686a01bSArunachalam Ganapathy			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
4640686a01bSArunachalam Ganapathy		endif
4650686a01bSArunachalam Ganapathy
4663547270fSGovindraj Raja		ifeq ($(TS_SP_FW_CONFIG),1)
4673547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
4683547270fSGovindraj Raja		endif
4693547270fSGovindraj Raja
4703547270fSGovindraj Raja		ifneq ($(ARM_BL2_SP_LIST_DTS),)
4713547270fSGovindraj Raja		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
4723547270fSGovindraj Raja		endif
4733547270fSGovindraj Raja
4743547270fSGovindraj Raja		ifneq ($(SP_LAYOUT_FILE),)
4753547270fSGovindraj Raja		BL2_ENABLE_SP_LOAD := 1
4763547270fSGovindraj Raja		endif
477c189adbdSGovindraj Raja
478c189adbdSGovindraj Raja		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
479c189adbdSGovindraj Raja			ifneq ($(SPMC_AT_EL3),1)
480c189adbdSGovindraj Raja			$(error SEL0 SP cannot be enabled without SPMC at EL3)
481c189adbdSGovindraj Raja			endif
482c189adbdSGovindraj Raja		endif
4833547270fSGovindraj Raja	else
4843547270fSGovindraj Raja		# All other SPDs in spd directory
4853547270fSGovindraj Raja		SPD_DIR := spd
4863547270fSGovindraj Raja	endif #(SPD)
4873547270fSGovindraj Raja
4883547270fSGovindraj Raja	# We expect to locate an spd.mk under the specified SPD directory
4893547270fSGovindraj Raja	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
4903547270fSGovindraj Raja
4913547270fSGovindraj Raja	ifeq (${SPD_MAKE},)
4923547270fSGovindraj Raja                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
4933547270fSGovindraj Raja	endif
4943547270fSGovindraj Raja        $(info Including ${SPD_MAKE})
4953547270fSGovindraj Raja        include ${SPD_MAKE}
4963547270fSGovindraj Raja
4973547270fSGovindraj Raja	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
4983547270fSGovindraj Raja	# Makefile would set NEED_BL32 to "yes". In this case, the build system
4993547270fSGovindraj Raja	# supports two mutually exclusive options:
5003547270fSGovindraj Raja	# * BL32 is built from source: then BL32_SOURCES must contain the list
5013547270fSGovindraj Raja	#   of source files to build BL32
5023547270fSGovindraj Raja	# * BL32 is a prebuilt binary: then BL32 must point to the image file
5033547270fSGovindraj Raja	#   that will be included in the FIP
5043547270fSGovindraj Raja	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
5053547270fSGovindraj Raja	# over the sources.
5063547270fSGovindraj Rajaendif #(SPD=none)
5073547270fSGovindraj Raja
5083547270fSGovindraj Rajaifeq (${ENABLE_SPMD_LP}, 1)
5093547270fSGovindraj Rajaifneq (${SPD},spmd)
5103547270fSGovindraj Raja        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
5113547270fSGovindraj Rajaendif
5123547270fSGovindraj Rajaifeq ($(SPMC_AT_EL3),1)
5133547270fSGovindraj Raja        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
5143547270fSGovindraj Rajaendif
5153547270fSGovindraj Rajaendif
5163547270fSGovindraj Raja
5173547270fSGovindraj Raja################################################################################
518f5211420SGovindraj Raja# Process BRANCH_PROTECTION value and set
519f5211420SGovindraj Raja# Pointer Authentication and Branch Target Identification flags
520f5211420SGovindraj Raja################################################################################
521f5211420SGovindraj Rajaifeq (${BRANCH_PROTECTION},0)
522f5211420SGovindraj Raja	# Default value turns off all types of branch protection
523f5211420SGovindraj Raja	BP_OPTION := none
524f5211420SGovindraj Rajaelse ifneq (${ARCH},aarch64)
525f5211420SGovindraj Raja        $(error BRANCH_PROTECTION requires AArch64)
526f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},1)
527f5211420SGovindraj Raja	# Enables all types of branch protection features
528f5211420SGovindraj Raja	BP_OPTION := standard
529f5211420SGovindraj Raja	ENABLE_BTI := 1
530f5211420SGovindraj Raja	ENABLE_PAUTH := 1
531f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},2)
532f5211420SGovindraj Raja	# Return address signing to its standard level
533f5211420SGovindraj Raja	BP_OPTION := pac-ret
534f5211420SGovindraj Raja	ENABLE_PAUTH := 1
535f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},3)
536f5211420SGovindraj Raja	# Extend the signing to include leaf functions
537f5211420SGovindraj Raja	BP_OPTION := pac-ret+leaf
538f5211420SGovindraj Raja	ENABLE_PAUTH := 1
539f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},4)
540f5211420SGovindraj Raja	# Turn on branch target identification mechanism
541f5211420SGovindraj Raja	BP_OPTION := bti
542f5211420SGovindraj Raja	ENABLE_BTI := 1
543f5211420SGovindraj Rajaelse
544f5211420SGovindraj Raja        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
545f5211420SGovindraj Rajaendif #(BRANCH_PROTECTION)
546f5211420SGovindraj Raja
547f5211420SGovindraj Rajaifeq ($(ENABLE_PAUTH),1)
548f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
549f5211420SGovindraj Rajaendif
550f5211420SGovindraj Rajaifneq (${BP_OPTION},none)
551f5211420SGovindraj Raja	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
552f5211420SGovindraj Rajaendif #(BP_OPTION)
553f5211420SGovindraj Raja
554f5211420SGovindraj Raja# Pointer Authentication sources
555f5211420SGovindraj Rajaifeq (${ENABLE_PAUTH}, 1)
556f5211420SGovindraj Raja# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
557f5211420SGovindraj Raja# Pauth support. As it's not secure, it must be reimplemented for real platforms
558f5211420SGovindraj Raja	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
559f5211420SGovindraj Rajaendif
560f5211420SGovindraj Raja
5613547270fSGovindraj Raja################################################################################
5623547270fSGovindraj Raja# Include the platform specific Makefile after the SPD Makefile (the platform
5633547270fSGovindraj Raja# makefile may use all previous definitions in this file)
5643547270fSGovindraj Raja################################################################################
5653547270fSGovindraj Rajainclude ${PLAT_MAKEFILE_FULL}
5663547270fSGovindraj Raja
5673547270fSGovindraj Raja################################################################################
5683547270fSGovindraj Raja# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
5693547270fSGovindraj Raja# platform.
5703547270fSGovindraj Raja################################################################################
5713547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
5723547270fSGovindraj Raja
573f5211420SGovindraj Raja####################################################
574f5211420SGovindraj Raja# Enable required options for Memory Stack Tagging.
575f5211420SGovindraj Raja####################################################
576f5211420SGovindraj Raja
577f5211420SGovindraj Raja# Currently, these options are enabled only for clang and armclang compiler.
578f5211420SGovindraj Rajaifeq (${SUPPORT_STACK_MEMTAG},yes)
579f5211420SGovindraj Raja    ifdef mem_tag_arch_support
580f5211420SGovindraj Raja        # Check for armclang and clang compilers
5818620bd0bSChris Kay        ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
582f5211420SGovindraj Raja        # Add "memtag" architecture feature modifier if not specified
583f5211420SGovindraj Raja            ifeq ( ,$(findstring memtag,$(arch-features)))
584f5211420SGovindraj Raja                arch-features	:=	$(arch-features)+memtag
585f5211420SGovindraj Raja            endif	# memtag
5868620bd0bSChris Kay            ifeq ($($(ARCH)-cc-id),arm-clang)
587f5211420SGovindraj Raja                TF_CFLAGS	+=	-mmemtag-stack
5888620bd0bSChris Kay            else ifeq ($($(ARCH)-cc-id),llvm-clang)
589f5211420SGovindraj Raja                TF_CFLAGS	+=	-fsanitize=memtag
590f5211420SGovindraj Raja            endif	# armclang
591f5211420SGovindraj Raja        endif
592f5211420SGovindraj Raja    else
593f5211420SGovindraj Raja        $(error "Error: stack memory tagging is not supported for  \
594f5211420SGovindraj Raja        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
595f5211420SGovindraj Raja	endif #(mem_tag_arch_support)
596f5211420SGovindraj Rajaendif #(SUPPORT_STACK_MEMTAG)
597f5211420SGovindraj Raja
598f5211420SGovindraj Raja################################################################################
599f5211420SGovindraj Raja# RME dependent flags configuration, Enable optional features for RME.
600f5211420SGovindraj Raja################################################################################
601f5211420SGovindraj Raja# FEAT_RME
602f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
603d638029fSGovindraj Raja	# RME doesn't support BRBE
604d638029fSGovindraj Raja	ENABLE_BRBE_FOR_NS := 0
605d638029fSGovindraj Raja
606f5211420SGovindraj Raja	# RME doesn't support PIE
607f5211420SGovindraj Raja	ifneq (${ENABLE_PIE},0)
608f5211420SGovindraj Raja                $(error ENABLE_RME does not support PIE)
609f5211420SGovindraj Raja	endif
610f5211420SGovindraj Raja
611f5211420SGovindraj Raja	# RME doesn't support BRBE
612f5211420SGovindraj Raja	ifneq (${ENABLE_BRBE_FOR_NS},0)
613f5211420SGovindraj Raja                $(error ENABLE_RME does not support BRBE.)
614f5211420SGovindraj Raja	endif
615f5211420SGovindraj Raja
616f5211420SGovindraj Raja	# RME requires AARCH64
617f5211420SGovindraj Raja	ifneq (${ARCH},aarch64)
618f5211420SGovindraj Raja                $(error ENABLE_RME requires AArch64)
619f5211420SGovindraj Raja	endif
620f5211420SGovindraj Raja
621f5211420SGovindraj Raja	# RME requires el2 context to be saved for now.
622f5211420SGovindraj Raja	CTX_INCLUDE_EL2_REGS := 1
623f5211420SGovindraj Raja	CTX_INCLUDE_AARCH32_REGS := 0
624f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
625f5211420SGovindraj Raja
626f5211420SGovindraj Raja	# RME enables CSV2_2 extension by default.
627f5211420SGovindraj Raja	ENABLE_FEAT_CSV2_2 = 1
628f5211420SGovindraj Rajaendif #(FEAT_RME)
629f5211420SGovindraj Raja
630f5211420SGovindraj Raja################################################################################
6315b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6325b18de09SZelalem Aweke################################################################################
6335b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6345b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6355b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6365b18de09SZelalem Aweke	endif
6371d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6381d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6391d63ae4dSMarc Bonnici	endif
640c5e1da83SJayanth Dodderi Chidanand
6414fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6424fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6434fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6444fba2e1fSBoyan Karatotev		endif
6454fba2e1fSBoyan Karatotev	endif
6465b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6475b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6485b18de09SZelalem Awekeendif
6495b18de09SZelalem Aweke
6503547270fSGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
6513547270fSGovindraj Raja	ifeq (${SPD},none)
6523547270fSGovindraj Raja		ifeq (${ENABLE_RME},0)
6533547270fSGovindraj Raja                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
6543547270fSGovindraj Raja                        or RME is enabled)
6553547270fSGovindraj Raja		endif
6563547270fSGovindraj Raja	endif
6573547270fSGovindraj Rajaendif
6580f21c547SJuan Castillo
6597794d6c8SGovindraj Raja################################################################################
6607794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6617794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6627794d6c8SGovindraj Raja################################################################################
6637794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6647794d6c8SGovindraj Raja
6657794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6667275ac2aSGovindraj RajaASFLAGS		+=	$(march-directive)
6677794d6c8SGovindraj Raja
66842d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
66942d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
67042d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
67142d4d3baSArvind Ram Prakash# BL2 in EL3
67242d4d3baSArvind Ram Prakash
67342d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
67442d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
67542d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
676c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
677c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
67842d4d3baSArvind Ram Prakash	endif
67942d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
68042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68142d4d3baSArvind Ram Prakashelse
68242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
68342d4d3baSArvind Ram Prakashendif
68442d4d3baSArvind Ram Prakash
685f87e54f7SManish Pandey# This internal flag is set to 1 when Firmware First handling of External aborts
686f87e54f7SManish Pandey# is required by lowe ELs. Currently only NS requires this support.
687f87e54f7SManish Pandeyifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
688f87e54f7SManish Pandey	FFH_SUPPORT := 1
689f87e54f7SManish Pandeyelse
690f87e54f7SManish Pandey	FFH_SUPPORT := 0
691f87e54f7SManish Pandeyendif
692f87e54f7SManish Pandey
6938012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6948012cc5cSMasahiro Yamada
69526e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
69626e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
69726e63c44SEtienne Carriereendif
69826e63c44SEtienne Carriere
6993bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7003bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7013bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7028620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
7037b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7047b592418SSamuel Hollandendif
705c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
706320920c1SMasahiro Yamada
7078620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
708320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
709320920c1SMasahiro Yamadaelse
710320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
711320920c1SMasahiro Yamadaendif
712320920c1SMasahiro Yamada
713320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71442d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71569af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
716966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
71769af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
71869af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
719c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
720c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
721966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
722320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
723320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
724966660ecSChris Kay
725966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
726d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
727d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
728c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7293bd17c0fSSoby Mathew
730007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
731007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
732007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
733007433d8SBoyan Karatotev
7349cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73542d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7369cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
737d5e97a1dSMasahiro Yamadaelse
7389cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
739c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
740007433d8SBoyan Karatotev
741007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7429cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7439cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7449cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
745007433d8SBoyan Karatotevelse
746007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
747d5e97a1dSMasahiro Yamadaendif
748d5e97a1dSMasahiro Yamada
74954035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
75054035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
75154035fc4SSandrine Bailleux# This can be overridden by the platform.
75273c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7534f6ad66aSAchin Gupta
754a4409008Sdp-arm################################################################################
755a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
756a4409008Sdp-arm################################################################################
757c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
758c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
759c5e1da83SJayanth Dodderi Chidanand
760a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
761a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
762a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
763a4409008Sdp-arm
764a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
765a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
766a4409008Sdp-arm                endif
767a4409008Sdp-arm                $(info Including ${AARCH32_SP_MAKE})
768a4409008Sdp-arm                include ${AARCH32_SP_MAKE}
769a4409008Sdp-arm        endif
770c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7714f6ad66aSAchin Gupta
77273c99d4eSJuan Castillo################################################################################
77377f1f7a1SVarun Wadekar# Include libc if not overridden
77477f1f7a1SVarun Wadekar################################################################################
77577f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
77677f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
77777f1f7a1SVarun Wadekarendif
77877f1f7a1SVarun Wadekar
77977f1f7a1SVarun Wadekar################################################################################
780c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
781cf2c8a33SAntonio Nino Diaz################################################################################
782cf2c8a33SAntonio Nino Diaz
783c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
784c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
785c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
786c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
787c5e1da83SJayanth Dodderi Chidanand        else
788c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
789c5e1da83SJayanth Dodderi Chidanand        endif
790c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
791c5e1da83SJayanth Dodderi Chidanand
792c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
793c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
794c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
795c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
796c5e1da83SJayanth Dodderi Chidanand        endif
797c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
798c5e1da83SJayanth Dodderi Chidanand
799c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
800c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
801c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
802c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
803c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
804c5e1da83SJayanth Dodderi Chidanandendif
805c5e1da83SJayanth Dodderi Chidanand
806c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
807c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
808c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
809c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
810c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
811c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
812c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
813c5e1da83SJayanth Dodderi Chidanand
814cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81568450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
81668450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
81768450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
818cf2c8a33SAntonio Nino Diaz	endif
81976580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
820c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
821c5e1da83SJayanth Dodderi Chidanand                build options.")
82276580f3dSQixiang Xu	endif
82376580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
824c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
825c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
82676580f3dSQixiang Xu	endif
827c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
828cf2c8a33SAntonio Nino Diaz
829cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
830cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
831cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
832cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
833cf2c8a33SAntonio Nino Diaz	endif
83468450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83568450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
836c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
837cf2c8a33SAntonio Nino Diaz	endif
838c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
839cf2c8a33SAntonio Nino Diaz
840d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
841d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
842d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
843d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
844d4593e47SJeenu Viswambharanendif
8451a0a3f06SYatharth Kochar
84642d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
84742d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
84842d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8497d173fc5SJiafei Panendif
8507d173fc5SJiafei Pan
8519202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85214c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
853c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
854f87e54f7SManish Pandey        and HANDLE_EA_EL3_FIRST_NS instead")
8559202d519SManish Pandeyendif
856c5e1da83SJayanth Dodderi Chidanand
857c5e1da83SJayanth Dodderi Chidanand
8589202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8591a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8606503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8616503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8621a7c1cfeSJeenu Viswambharan	endif
863c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8641a7c1cfeSJeenu Viswambharan
865ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
866209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
867209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
868c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
869c5e1da83SJayanth Dodderi Chidanand                to be set.")
870209a60ccSSoby Mathew	endif
871c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
872209a60ccSSoby Mathew
8732bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8742bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8752bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8762bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8772bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8782bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8792bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8802bf4f27fSManish V Badarkhe# Support hash calculation only
8812bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8822bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8832bf4f27fSManish V Badarkhe# Support authentication verification only
884c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
885c9c56f6eSManish V Badarkheelse
886c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
887c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
888c9c56f6eSManish V Badarkhe
889cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
890cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
891700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
89284ef9cd8SManish V Badarkheendif
89384ef9cd8SManish V Badarkhe
894b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
8959fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
8969fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
897b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
8989fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
8999fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
90006715f85SAlexei Fedorov	endif
901c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9029fc59639SAlexei Fedorov
90306715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9049fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9059fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
906b86048c4SAntonio Nino Diaz	endif
907c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9089fc59639SAlexei Fedorov
9096a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9106a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
911c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9126a0da736SJayanth Dodderi Chidanand
91303d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
91403d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
915c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
916c5e1da83SJayanth Dodderi Chidanand                to be set")
91703d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
91803d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
91903d3c0d7SJayanth Dodderi Chidanand	endif
920c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
92145007acdSJayanth Dodderi Chidanand
92260e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
92360e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
924c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
925c5e1da83SJayanth Dodderi Chidanand                library v2")
92660e8f3cfSPetre-Ionut Tudor	endif
927c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
92860e8f3cfSPetre-Ionut Tudor
9297cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9307cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
931c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
932c5e1da83SJayanth Dodderi Chidanand                to be set)
9337cda17bbSSumit Garg	endif
934c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9357cda17bbSSumit Garg
936744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
937dc78e62dSjohpow01ifeq (${ARCH},aarch32)
938744ad974Sjohpow01
939744ad974Sjohpow01	# SME/SVE only supported on AArch64
94045007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
941dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
942dc78e62dSjohpow01	endif
94303d3c0d7SJayanth Dodderi Chidanand
944dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
945dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
94624ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
947dc78e62dSjohpow01	endif
948744ad974Sjohpow01
949ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
950744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
951744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
952744ad974Sjohpow01	endif
953744ad974Sjohpow01
954ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
955ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
956ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
957ff86e0b4SJuan Pablo Conde	endif
958c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
959dc78e62dSjohpow01
9600d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9610d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9620d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9630d122947SBoyan Karatotev	endif
964c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9650d122947SBoyan Karatotev
966dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
967dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
968dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
969dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
970dc78e62dSjohpow01	endif
9710d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9720d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9730d122947SBoyan Karatotev	endif
974c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
975c5e1da83SJayanth Dodderi Chidanand
976dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
977dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
978dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
979dc78e62dSjohpow01	endif
980c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
981dc78e62dSjohpow01
982dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
983dc78e62dSjohpow01# its own context management including FPU registers.
984dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
98545007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
986dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
987dc78e62dSjohpow01	endif
98803d3c0d7SJayanth Dodderi Chidanand
989dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
990dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
991dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
992dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
993dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
994dc78e62dSjohpow01	endif
995c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
996dc78e62dSjohpow01
99700e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
99800e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
99900e28874SManish V Badarkheendif
100000e28874SManish V Badarkhe
10013ba2c151SRaymond Maoifeq (${TRANSFER_LIST},1)
10023ba2c151SRaymond Mao        $(info TRANSFER_LIST is an experimental feature)
10033ba2c151SRaymond Maoendif
10043ba2c151SRaymond Mao
1005274a69e7SChris Kayifeq (${ENABLE_RME},1)
1006274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1007274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1008274a69e7SChris Kay	endif
1009274a69e7SChris Kayendif
1010274a69e7SChris Kay
10115782b890SManish V Badarkheifeq ($(PSA_CRYPTO),1)
10125782b890SManish V Badarkhe        $(info PSA_CRYPTO is an experimental feature)
10135782b890SManish V Badarkheendif
10145782b890SManish V Badarkhe
101582222db8SManish V Badarkheifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
101682222db8SManish V Badarkhe        $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
101782222db8SManish V Badarkheendif
101882222db8SManish V Badarkhe
1019cf2c8a33SAntonio Nino Diaz################################################################################
102073c99d4eSJuan Castillo# Process platform overrideable behaviour
102173c99d4eSJuan Castillo################################################################################
10224f6ad66aSAchin Gupta
10235f24ce96SManish Pandeyifdef BL1_SOURCES
10245f24ce96SManish Pandey	NEED_BL1 := yes
1025c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10265f24ce96SManish Pandey
10275f24ce96SManish Pandeyifdef BL2_SOURCES
10285f24ce96SManish Pandey	NEED_BL2 := yes
10295f24ce96SManish Pandey
1030bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1031bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1032cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1033cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1034cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10354c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1036cf2c8a33SAntonio Nino Diaz	else
103768450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1038cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1039cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1040cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1041cf2c8a33SAntonio Nino Diaz		else
1042cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1043cf2c8a33SAntonio Nino Diaz		endif
10444c117f6cSSandrine Bailleux	endif
1045c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10466f971622SJuan Castillo
10475f24ce96SManish Pandeyifdef BL2U_SOURCES
10485f24ce96SManish Pandey	NEED_BL2U := yes
1049c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10505f24ce96SManish Pandey
10514d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10524d045d0eSMasahiro Yamadaifdef SCP_BL2
10534d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1054c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10554d045d0eSMasahiro Yamada
10565744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10575744e874SSoby Mathewifneq (${ARCH},aarch32)
10585744e874SSoby Mathew	ifdef BL31_SOURCES
1059c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1060c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10615744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10625744e874SSoby Mathew			NEED_BL31 := yes
10635744e874SSoby Mathew		endif
10645744e874SSoby Mathew	endif
1065c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10665744e874SSoby Mathew
106773c99d4eSJuan Castillo# Process TBB related flags
10686f971622SJuan Castilloifneq (${GENERATE_COT},0)
106973c99d4eSJuan Castillo	# Common cert_create options
10706f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10716f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10720191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1073fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1074fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10750191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1076fd34e7baSJuan Castillo		endif
10776f971622SJuan Castillo	endif
107873c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
107973c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
108073c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
108173c99d4eSJuan Castillo	endif
1082c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
10836f971622SJuan Castillo
10841c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
10851c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1086c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
10871c75d5dfSMasahiro Yamada
10885f24ce96SManish Pandeyifdef FDT_SOURCES
10895f24ce96SManish Pandey	NEED_FDT := yes
1090c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
10915f24ce96SManish Pandey
109273c99d4eSJuan Castillo################################################################################
109346e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
109446e5e035SMichalis Pappas################################################################################
109546e5e035SMichalis Pappas
109646e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
109746e5e035SMichalis Pappas
109846e5e035SMichalis Pappas################################################################################
10998a86052dSSoby Mathew# Include BL specific makefiles
11008a86052dSSoby Mathew################################################################################
11015f24ce96SManish Pandey
11025f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11038a86052dSSoby Mathewinclude bl1/bl1.mk
11048a86052dSSoby Mathewendif
11058a86052dSSoby Mathew
11065f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11078a86052dSSoby Mathewinclude bl2/bl2.mk
11088a86052dSSoby Mathewendif
11098a86052dSSoby Mathew
11105f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11118a86052dSSoby Mathewinclude bl2u/bl2u.mk
11128a86052dSSoby Mathewendif
11138a86052dSSoby Mathew
11145744e874SSoby Mathewifeq (${NEED_BL31},yes)
11158a86052dSSoby Mathewinclude bl31/bl31.mk
11168a86052dSSoby Mathewendif
111703b397a8SNishanth Menon
111873c99d4eSJuan Castillo################################################################################
111973c99d4eSJuan Castillo# Build options checks
112073c99d4eSJuan Castillo################################################################################
112173c99d4eSJuan Castillo
1122c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1123327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1124327131c4SLeonardo Sandoval    $(sort \
1125327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
112646789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1127327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1128327131c4SLeonardo Sandoval	CREATE_KEYS \
1129327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1130327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1131327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
11329acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1133327131c4SLeonardo Sandoval	DEBUG \
1134327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1135327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11361fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1137742ca230SChris Kay	ENABLE_AMU_FCONF \
1138873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1139327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1140327131c4SLeonardo Sandoval	ENABLE_PIE \
1141327131c4SLeonardo Sandoval	ENABLE_PMF \
1142327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1143327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1144dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11450c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1146970a4a8dSManish Pandey	ENABLE_FEAT_RAS	\
1147f87e54f7SManish Pandey	FFH_SUPPORT	\
1148327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1149327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1150327131c4SLeonardo Sandoval	GENERATE_COT \
1151327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
115246cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1153538516f5SBipin Ravi	HARDEN_SLS \
1154327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1155327131c4SLeonardo Sandoval	MEASURED_BOOT \
1156e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
115700e28874SManish V Badarkhe	DRTM_SUPPORT \
1158327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1159327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1160327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1161327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1162327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
116364b4710bSWing Li	PSCI_OS_INIT_MODE \
1164327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1165327131c4SLeonardo Sandoval	SAVE_KEYS \
1166327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
116796a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1168327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1169327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1170327131c4SLeonardo Sandoval	SPM_MM \
11711d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1172801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1173327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1174890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
11753ba2c151SRaymond Mao	TRANSFER_LIST \
1176327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1177327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1178327131c4SLeonardo Sandoval	USE_DEBUGFS \
1179327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1180327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1181327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1182327131c4SLeonardo Sandoval	USE_ROMLIB \
1183327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1184327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
118542d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1186327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1187327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1188327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1189327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1190327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1191327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
119200e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1193327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1194327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1195396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
119611d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
119768120783SChris Kay	ENABLE_MPMM \
119868120783SChris Kay	ENABLE_MPMM_FCONF \
11996a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12000b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1201ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1202ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
120304c7303bSOkash Khawaja	CONDITIONAL_CMO \
12045782b890SManish V Badarkhe	PSA_CRYPTO	\
120585bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1206183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1207bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1208ae770fedSYann Gautier	EARLY_CONSOLE \
1209f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1210327131c4SLeonardo Sandoval)))
121173c99d4eSJuan Castillo
1212c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1213327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1214327131c4SLeonardo Sandoval    $(sort \
1215327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1216327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1217327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12186a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12196a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12202bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
122183a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12221298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
122347c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12246a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12256a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1226d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12276a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12286a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
122930019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
1230*83271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
12316a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12326a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12336a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12346a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12358e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
12366a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12376a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1238ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12396a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1240d3331603SMark Brown	ENABLE_FEAT_TCR2 \
12410e4daed2SGovindraj Raja	ENABLE_FEAT_SB \
1242062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1243062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1244062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1245062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1246688ab57bSMark Brown	ENABLE_FEAT_GCS \
12476a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
1248edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
12496a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12506437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1251603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
125245007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
125303d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12542b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12556a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1256327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12575357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12585357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1259781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1260781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1261bebcf27fSMark Brown	SVE_VECTOR_LEN \
12620ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1263327131c4SLeonardo Sandoval)))
1264c877b414SJeenu Viswambharan
1265aacff749SJustin Chadwellifdef KEY_SIZE
1266aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1267aacff749SJustin Chadwellendif
1268aacff749SJustin Chadwell
12691f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12701f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12711f461979SJustin Chadwellendif
12721f461979SJustin Chadwell
127373c99d4eSJuan Castillo################################################################################
127473c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
127573c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
127673c99d4eSJuan Castillo# platform to overwrite the default options
127773c99d4eSJuan Castillo################################################################################
127873c99d4eSJuan Castillo
1279327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1280327131c4SLeonardo Sandoval    $(sort \
1281327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1282327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1283327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
128446789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1285327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1286327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1287327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1288327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
12899acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1290327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1291327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1292062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1293327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
12940063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1295d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12961fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1297742ca230SChris Kay	ENABLE_AMU_FCONF \
1298873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1299327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1300327131c4SLeonardo Sandoval	ENABLE_BTI \
1301*83271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
1302edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
1303327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1304327131c4SLeonardo Sandoval	ENABLE_PIE \
1305327131c4SLeonardo Sandoval	ENABLE_PMF \
1306327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13075b18de09SZelalem Aweke	ENABLE_RME \
1308327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1309dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131003d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1311dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
131290118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1313327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13140c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1315970a4a8dSManish Pandey	ENABLE_FEAT_RAS \
1316f87e54f7SManish Pandey	FFH_SUPPORT \
1317327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1318327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1319327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1320327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1321327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132246cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1323327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1324327131c4SLeonardo Sandoval	LOG_LEVEL \
1325327131c4SLeonardo Sandoval	MEASURED_BOOT \
1326e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
132700e28874SManish V Badarkhe	DRTM_SUPPORT \
1328327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1329327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1330327131c4SLeonardo Sandoval	PLAT_${PLAT} \
1331327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1332327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
133364b4710bSWing Li	PSCI_OS_INIT_MODE \
1334327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1335d766084fSAlexeiFedorov	RME_GPT_BITLOCK_BLOCK \
1336ec0088bbSAlexeiFedorov	RME_GPT_MAX_BLOCK \
1337327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
133896a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1339327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1340327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1341327131c4SLeonardo Sandoval	SPD_${SPD} \
1342327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1343327131c4SLeonardo Sandoval	SPM_MM \
13441d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1345801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1346327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
13473ba2c151SRaymond Mao	TRANSFER_LIST \
1348327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1349c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13507dfb9911SJimmy Brisson	TRNG_SUPPORT \
1351ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1352ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1353327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1354327131c4SLeonardo Sandoval	USE_DEBUGFS \
1355327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1356327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1357327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1358327131c4SLeonardo Sandoval	USE_ROMLIB \
1359327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1360327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
136142d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
136242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1363327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1364327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1365327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1366327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
136700e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1368327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1369327131c4SLeonardo Sandoval	USE_SP804_TIMER \
137012cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1371ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13724e04478aSChris Kay	ENABLE_FEAT_SB \
13737d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13745357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13755357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1376396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
137711d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
1378744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1379813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1380d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13818fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1382cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
138368120783SChris Kay	ENABLE_MPMM \
138468120783SChris Kay	ENABLE_MPMM_FCONF \
1385f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1386f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13876a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13886a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13896a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13906a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
139130019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
13926a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1393d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1394062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1395062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1396062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1397062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1398688ab57bSMark Brown	ENABLE_FEAT_GCS \
13998e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
14006a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1401781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1402781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
140304c7303bSOkash Khawaja	CONDITIONAL_CMO \
14040ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1405a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1406890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
14075782b890SManish V Badarkhe	PSA_CRYPTO	\
140885bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1409183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1410bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1411ae770fedSYann Gautier	EARLY_CONSOLE \
1412f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1413327131c4SLeonardo Sandoval)))
14142fae4b1eSJeenu Viswambharan
1415bfef8b90SJuan Pablo Condeifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1416bfef8b90SJuan Pablo Condeifeq (${DEBUG}, 0)
1417bfef8b90SJuan Pablo Conde        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1418bfef8b90SJuan Pablo Conde        override PLATFORM_REPORT_CTX_MEM_USE := 0
1419bfef8b90SJuan Pablo Condeendif
1420bfef8b90SJuan Pablo Condeendif
1421bfef8b90SJuan Pablo Conde
14221f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14231f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1424c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14251f461979SJustin Chadwell
14264c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14274c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14284c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1429cf2c8a33SAntonio Nino Diazelse
143068450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
143168450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
143268450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
143368450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14344c117f6cSSandrine Bailleux	endif
1435c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
143673c99d4eSJuan Castillo
1437209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1438209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1439209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1440209a60ccSSoby Mathewendif
1441209a60ccSSoby Mathew
14428620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
1443c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1444c2ad38ceSVarun Wadekarendif
1445c2ad38ceSVarun Wadekar
1446ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1447ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1448c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1449ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1450ce2b1ec6SManish Pandey	FIP_DEPS += sp
145107c44475SManish Pandey	CRT_DEPS += sp
1452ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1453ce2b1ec6SManish Pandeyelse
1454c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1455c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1456c33ff198SOlivier Deprez	endif
1457c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1458c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1459ce2b1ec6SManish Pandey
146073c99d4eSJuan Castillo################################################################################
146173c99d4eSJuan Castillo# Build targets
146273c99d4eSJuan Castillo################################################################################
146373c99d4eSJuan Castillo
146490aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
146573c99d4eSJuan Castillo.SUFFIXES:
146673c99d4eSJuan Castillo
146773c99d4eSJuan Castilloall: msg_start
146873c99d4eSJuan Castillo
146973c99d4eSJuan Castillomsg_start:
14707c4e1eeaSChris Kay	$(s)echo "Building ${PLAT}"
147173c99d4eSJuan Castillo
14727a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1473d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
14748620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1475c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1476c2ad38ceSVarun Wadekarelse
1477bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14787a24cba5SSoby Mathewendif
1479c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14807a24cba5SSoby Mathew
14815accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
148261f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14835fee0287SRoberto Vargas
148473c99d4eSJuan Castillo# Expand build macros for the different images
148573c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1486b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1487434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1488c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
148973c99d4eSJuan Castillo
149073c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1491c5e1da83SJayanth Dodderi Chidanand
149242d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1493c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1494c9b31ae8SRoberto Vargasendif
1495c9b31ae8SRoberto Vargas
1496eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1497eb1acfb6SChris Kay
149833950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1499434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1500c5e1da83SJayanth Dodderi Chidanand
1501c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
150273c99d4eSJuan Castillo
15034d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
150433950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1505c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
15064d045d0eSMasahiro Yamada
150773c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
150873c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
150926d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
151026d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1511c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1512c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1513434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1514c6ba9b45SSumit Gargelse
151533950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1516434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1517c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1518c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
151973c99d4eSJuan Castillo
152070d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1521c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
152270d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
152373c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
152426d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
152526d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15269cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15279cd15239SMasahiro Yamada
1528c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1529434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1530c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1531c6ba9b45SSumit Gargelse
1532434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
153333950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1534c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1535c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
153673c99d4eSJuan Castillo
15375b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15385b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15395b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15405b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15415b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15425b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15435b18de09SZelalem Aweke
15445b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15455b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1546c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15475b18de09SZelalem Aweke
154873c99d4eSJuan Castillo# Add the BL33 image if required by the platform
154973c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
155033950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1551c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1552db6071c9SJuan Castillo
15539003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
155433950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1555434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1556c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15579003fa0bSYatharth Kochar
155803b397a8SNishanth Menon# Expand build macros for the different images
155903b397a8SNishanth Menonifeq (${NEED_FDT},yes)
156003b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1561c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
156203b397a8SNishanth Menon
1563ce2b1ec6SManish Pandey# Add Secure Partition packages
1564ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1565ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
15667c4e1eeaSChris Kay	$(q)${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1567822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
15687c4e1eeaSChris Kay	$(s)echo
15697c4e1eeaSChris Kay	$(s)echo "Built SP Images successfully"
15707c4e1eeaSChris Kay	$(s)echo
1571c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1572ce2b1ec6SManish Pandey
157336eaaf37SIan Spraylocate-checkpatch:
157436eaaf37SIan Sprayifndef CHECKPATCH
157566079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
157636eaaf37SIan Sprayelse
157736eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
157866079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
157936eaaf37SIan Sprayendif
1580c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
158136eaaf37SIan Spray
15824f6ad66aSAchin Guptaclean:
15837c4e1eeaSChris Kay	$(s)echo "  CLEAN"
1584f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
158588a1cf1eSSami Mujawarifdef UNIX_MK
15867c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
158788a1cf1eSSami Mujawarelse
158888a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
158988a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
15907c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1591c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15927c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
15937c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15947c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15954f6ad66aSAchin Gupta
1596eaaeece2SJames Morrisseyrealclean distclean:
15977c4e1eeaSChris Kay	$(s)echo "  REALCLEAN"
1598f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1599f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
160088a1cf1eSSami Mujawarifdef UNIX_MK
16017c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
160288a1cf1eSSami Mujawarelse
160388a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
160488a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16057c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1606c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16077c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
16087c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
16097c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16104f6ad66aSAchin Gupta
161136eaaf37SIan Spraycheckcodebase:		locate-checkpatch
16127c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16137c4e1eeaSChris Kay	$(q)if test -d .git ; then						\
16141ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16151a41e8c1SDan Handley		while read GIT_FILE ;					\
16161a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16171a41e8c1SDan Handley		done ;							\
161836eaaf37SIan Spray	else								\
16191a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16201a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16211a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
162261f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16231a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16241ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16251a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
162636eaaf37SIan Spray	fi
162736eaaf37SIan Spray
162836eaaf37SIan Spraycheckpatch:		locate-checkpatch
16297c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16307c4e1eeaSChris Kay	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
163102a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
163202a76d5fSYann Gautier	fi
16337c4e1eeaSChris Kay	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
163477a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
163577a0a7f1SYann Gautier	do								\
163651d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
163751d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
163802a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
163902a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
164051d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
164102a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
164202a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
164351d28937SAntonio Nino Diaz	done
164436eaaf37SIan Spray
164573c99d4eSJuan Castillocerttool: ${CRTTOOL}
164673c99d4eSJuan Castillo
1647a9812206SPali Rohár${CRTTOOL}: FORCE
16487c4e1eeaSChris 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
16497c4e1eeaSChris Kay	$(s)echo
16507c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16517c4e1eeaSChris Kay	$(s)echo
16526f971622SJuan Castillo
16536f971622SJuan Castilloifneq (${GENERATE_COT},0)
165473c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16557c4e1eeaSChris Kay	$(q)${CRTTOOL} ${CRT_ARGS}
16567c4e1eeaSChris Kay	$(s)echo
16577c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16587c4e1eeaSChris Kay	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
16597c4e1eeaSChris Kay	$(s)echo
1660c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
166127713fb4SSoby Mathew
166273c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16634727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
16647c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FIP_ARGS} $@
16657c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
16667c4e1eeaSChris Kay	$(s)echo
16677c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16687c4e1eeaSChris Kay	$(s)echo
1669f58ad36fSHarry Liebel
16700191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16710191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16727c4e1eeaSChris Kay	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
16737c4e1eeaSChris Kay	$(s)echo
16747c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16757c4e1eeaSChris Kay	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
16767c4e1eeaSChris Kay	$(s)echo
1677c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16780191262dSYatharth Kochar
16790191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16804727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
16817c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
16827c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
16837c4e1eeaSChris Kay	$(s)echo
16847c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16857c4e1eeaSChris Kay	$(s)echo
16860191262dSYatharth Kochar
168773c99d4eSJuan Castillofiptool: ${FIPTOOL}
168873c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16890191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
169073c99d4eSJuan Castillo
1691a9812206SPali Rohár${FIPTOOL}: FORCE
169288a1cf1eSSami Mujawarifdef UNIX_MK
16937c4e1eeaSChris Kay	$(q)${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
169488a1cf1eSSami Mujawarelse
169588a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
169688a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16977c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1698c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1699f58ad36fSHarry Liebel
1700a9812206SPali Rohárromlib.bin: libraries FORCE
17017c4e1eeaSChris 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
17025accce5bSRoberto Vargas
1703cfe83910SLouis Mayencourtmemmap: all
1704af5b49e9SHarrison Mutaiifdef UNIX_MK
17057c4e1eeaSChris Kay	$(q)PYTHONPATH=${CURDIR}/tools/memory \
1706af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1707af5b49e9SHarrison Mutaielse
17087c4e1eeaSChris Kay	$(q)set PYTHONPATH=${CURDIR}/tools/memory && \
1709af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1710af5b49e9SHarrison Mutaiendif
1711cfe83910SLouis Mayencourt
17126de32378SMadhukar Pappireddydoc:
17137c4e1eeaSChris Kay	$(s)echo "  BUILD DOCUMENTATION"
17147c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
17156de32378SMadhukar Pappireddy
171690aa901fSSumit Gargenctool: ${ENCTOOL}
171790aa901fSSumit Garg
1718a9812206SPali Rohár${ENCTOOL}: FORCE
17197c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
17207c4e1eeaSChris Kay	$(s)echo
17217c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17227c4e1eeaSChris Kay	$(s)echo
172390aa901fSSumit Garg
172435fab8c9SJoakim Bechcscope:
17257c4e1eeaSChris Kay	$(s)echo "  CSCOPE"
17267c4e1eeaSChris Kay	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
17277c4e1eeaSChris Kay	$(q)cscope -b -q -k
172835fab8c9SJoakim Bech
172972ee3314SRyan Harkinhelp:
17307c4e1eeaSChris Kay	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
17317c4e1eeaSChris Kay	$(s)echo ""
17327c4e1eeaSChris Kay	$(s)echo "PLAT is used to specify which platform you wish to build."
17337c4e1eeaSChris Kay	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
17347c4e1eeaSChris Kay	$(s)echo ""
17357c4e1eeaSChris Kay	$(s)echo "platform = ${PLATFORM_LIST}"
17367c4e1eeaSChris Kay	$(s)echo ""
17377c4e1eeaSChris Kay	$(s)echo "Please refer to the User Guide for a list of all supported options."
17387c4e1eeaSChris Kay	$(s)echo "Note that the build system doesn't track dependencies for build "
17397c4e1eeaSChris Kay	$(s)echo "options. Therefore, if any of the build options are changed "
17407c4e1eeaSChris Kay	$(s)echo "from a previous build, a clean build must be performed."
17417c4e1eeaSChris Kay	$(s)echo ""
17427c4e1eeaSChris Kay	$(s)echo "Supported Targets:"
17437c4e1eeaSChris Kay	$(s)echo "  all            Build all individual bootloader binaries"
17447c4e1eeaSChris Kay	$(s)echo "  bl1            Build the BL1 binary"
17457c4e1eeaSChris Kay	$(s)echo "  bl2            Build the BL2 binary"
17467c4e1eeaSChris Kay	$(s)echo "  bl2u           Build the BL2U binary"
17477c4e1eeaSChris Kay	$(s)echo "  bl31           Build the BL31 binary"
17487c4e1eeaSChris Kay	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17497c4e1eeaSChris Kay	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
17507c4e1eeaSChris Kay	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17517c4e1eeaSChris Kay	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
17527c4e1eeaSChris Kay	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
17537c4e1eeaSChris Kay	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
17547c4e1eeaSChris Kay	$(s)echo "  checkpatch     Check the coding style on changes in the current"
17557c4e1eeaSChris Kay	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
17567c4e1eeaSChris Kay	$(s)echo "  clean          Clean the build for the selected platform"
17577c4e1eeaSChris Kay	$(s)echo "  cscope         Generate cscope index"
17587c4e1eeaSChris Kay	$(s)echo "  distclean      Remove all build artifacts for all platforms"
17597c4e1eeaSChris Kay	$(s)echo "  certtool       Build the Certificate generation tool"
17607c4e1eeaSChris Kay	$(s)echo "  enctool        Build the Firmware encryption tool"
17617c4e1eeaSChris Kay	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
17627c4e1eeaSChris Kay	$(s)echo "  sp             Build the Secure Partition Packages"
17637c4e1eeaSChris Kay	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
17647c4e1eeaSChris Kay	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
17657c4e1eeaSChris Kay	$(s)echo "  memmap         Print the memory map of the built binaries"
17667c4e1eeaSChris Kay	$(s)echo "  doc            Build html based documentation using Sphinx tool"
17677c4e1eeaSChris Kay	$(s)echo ""
17687c4e1eeaSChris Kay	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
17697c4e1eeaSChris Kay	$(s)echo ""
17707c4e1eeaSChris Kay	$(s)echo "example: build all targets for the FVP platform:"
17717c4e1eeaSChris Kay	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1772a9812206SPali Rohár
1773a9812206SPali Rohár.PHONY: FORCE
1774a9812206SPali RohárFORCE:;
1775