xref: /rk3399_ARM-atf/Makefile (revision c5e1da836c2e81b37719a3a440b54f049924fd9d)
14f6ad66aSAchin Gupta#
201cf14ddSMaksims Svecovs# Copyright (c) 2013-2023, 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
11b78ad00eSJuan Pablo CondeVERSION_MINOR			:= 9
12dddf4283Slaurenw-armVERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}
13aaa3e722SJuan Castillo
1488154678SJuan Castillo# Default goal is build all images
1588154678SJuan Castillo.DEFAULT_GOAL			:= all
1688154678SJuan Castillo
1772fc70edSDouglas Raillard# Avoid any implicit propagation of command line variable definitions to
1872fc70edSDouglas Raillard# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
1972fc70edSDouglas Raillard# usage. Other command line options like "-s" are still propagated as usual.
2072fc70edSDouglas RaillardMAKEOVERRIDES =
2172fc70edSDouglas Raillard
22231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := make_helpers/
23231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
24e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
2573c99d4eSJuan Castillo
2673c99d4eSJuan Castillo################################################################################
272fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
2873c99d4eSJuan Castillo################################################################################
29e35c4045SJeenu Viswambharan
302fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
31872be88aSdp-arm
32cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
33cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
342fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
352fae4b1eSJeenu ViswambharanPLAT				:= ${DEFAULT_PLAT}
3673c99d4eSJuan Castillo
3773c99d4eSJuan Castillo################################################################################
3873c99d4eSJuan Castillo# Checkpatch script options
3973c99d4eSJuan Castillo################################################################################
4073c99d4eSJuan Castillo
41f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
42f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
434501843fSGilad Ben-YossefINC_ARM_DIRS_TO_CHECK	:=	$(sort $(filter-out                     \
444501843fSGilad Ben-Yossef					include/drivers/arm/cryptocell,	\
454501843fSGilad Ben-Yossef					$(wildcard include/drivers/arm/*)))
464501843fSGilad Ben-YossefINC_ARM_DIRS_TO_CHECK	+=	include/drivers/arm/cryptocell/*.h
474501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
484501843fSGilad Ben-Yossef					include/drivers/arm,		\
494501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
50f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
511a41e8c1SDan Handley					include/lib/libfdt		\
5261f72a34SRoberto Vargas					include/lib/libc,		\
53f0b489c1SDan Handley					$(wildcard include/lib/*)))
54f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
554501843fSGilad Ben-Yossef					include/lib			\
564501843fSGilad Ben-Yossef					include/drivers,		\
57f0b489c1SDan Handley					$(wildcard include/*)))
58f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59d801fbb0Sdp-arm					lib/compiler-rt			\
6055cdcf75SAntonio Nino Diaz					lib/libfdt%			\
6161f72a34SRoberto Vargas					lib/libc,			\
62a194255dSDaniel Boulby					lib/zlib			\
63f0b489c1SDan Handley					$(wildcard lib/*)))
64f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
65f0b489c1SDan Handley					lib				\
66f0b489c1SDan Handley					include				\
67f0b489c1SDan Handley					docs				\
681ef35512SPaul Beesley					%.rst,				\
69f0b489c1SDan Handley					$(wildcard *)))
70f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
71f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
72f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
734501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
744501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
754501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
7636eaaf37SIan Spray
7773c99d4eSJuan Castillo################################################################################
7873c99d4eSJuan Castillo# Process build options
7973c99d4eSJuan Castillo################################################################################
8073c99d4eSJuan Castillo
8173c99d4eSJuan Castillo# Verbose flag
82e35c4045SJeenu Viswambharanifeq (${V},0)
83b169f6a9SEvan Lloyd	Q:=@
84ee1ba6d4SAndre Przywara	ECHO:=@echo
8536eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
864f6ad66aSAchin Guptaelse
87b169f6a9SEvan Lloyd	Q:=
88b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
894f6ad66aSAchin Guptaendif
90ee1ba6d4SAndre Przywara
91ee1ba6d4SAndre Przywaraifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
92ee1ba6d4SAndre Przywara	Q:=@
93b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
94ee1ba6d4SAndre Przywaraendif
95ee1ba6d4SAndre Przywara
96ee1ba6d4SAndre Przywaraexport Q ECHO
972f2cef46SJeenu Viswambharan
9873c99d4eSJuan Castillo################################################################################
9973c99d4eSJuan Castillo# Toolchain
10073c99d4eSJuan Castillo################################################################################
10173c99d4eSJuan Castillo
10272610c41Sdp-armHOSTCC			:=	gcc
10372610c41Sdp-armexport HOSTCC
10472610c41Sdp-arm
10573c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
10673c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
10773c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
10873c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1092adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
11073c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
11173c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
11273c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
11373c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
11438c14d88SSoby MathewDTC			:=	dtc
11573c99d4eSJuan Castillo
116b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
117b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1182adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1192adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
120b25a577fSJulius Wernerendif
121b25a577fSJulius Werner
122*c5e1da83SJayanth Dodderi Chidanand################################################################################
123*c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
124*c5e1da83SJayanth Dodderi Chidanand################################################################################
125*c5e1da83SJayanth Dodderi Chidanand
126*c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
127*c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
128*c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
129*c5e1da83SJayanth Dodderi Chidanand
130*c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
131*c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
132*c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
133*c5e1da83SJayanth Dodderi Chidanand
134*c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
135*c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
136*c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
137*c5e1da83SJayanth Dodderi Chidanand
138*c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
139*c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
140*c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
141*c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
142*c5e1da83SJayanth Dodderi Chidanand
143*c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
144*c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
145*c5e1da83SJayanth Dodderi Chidanand
146*c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
147*c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
148*c5e1da83SJayanth Dodderi Chidanand
149*c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
150*c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
151*c5e1da83SJayanth Dodderi Chidanand
152*c5e1da83SJayanth Dodderi Chidanand################################################################################
153*c5e1da83SJayanth Dodderi Chidanand# Process BRANCH_PROTECTION value and set
154*c5e1da83SJayanth Dodderi Chidanand# Pointer Authentication and Branch Target Identification flags
155*c5e1da83SJayanth Dodderi Chidanand################################################################################
156*c5e1da83SJayanth Dodderi Chidanandifeq (${BRANCH_PROTECTION},0)
157*c5e1da83SJayanth Dodderi Chidanand	# Default value turns off all types of branch protection
158*c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := none
159*c5e1da83SJayanth Dodderi Chidanandelse ifneq (${ARCH},aarch64)
160*c5e1da83SJayanth Dodderi Chidanand        $(error BRANCH_PROTECTION requires AArch64)
161*c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},1)
162*c5e1da83SJayanth Dodderi Chidanand	# Enables all types of branch protection features
163*c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := standard
164*c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
165*c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
166*c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},2)
167*c5e1da83SJayanth Dodderi Chidanand	# Return address signing to its standard level
168*c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret
169*c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
170*c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},3)
171*c5e1da83SJayanth Dodderi Chidanand	# Extend the signing to include leaf functions
172*c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret+leaf
173*c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
174*c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},4)
175*c5e1da83SJayanth Dodderi Chidanand	# Turn on branch target identification mechanism
176*c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := bti
177*c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
178*c5e1da83SJayanth Dodderi Chidanandelse
179*c5e1da83SJayanth Dodderi Chidanand        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
180*c5e1da83SJayanth Dodderi Chidanandendif #(BRANCH_PROTECTION)
181*c5e1da83SJayanth Dodderi Chidanand
182*c5e1da83SJayanth Dodderi Chidanand################################################################################
183*c5e1da83SJayanth Dodderi Chidanand# RME dependent flags configuration
184*c5e1da83SJayanth Dodderi Chidanand################################################################################
185*c5e1da83SJayanth Dodderi Chidanand# FEAT_RME
186*c5e1da83SJayanth Dodderi Chidanandifeq (${ENABLE_RME},1)
187*c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support PIE
188*c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_PIE},0)
189*c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support PIE)
190*c5e1da83SJayanth Dodderi Chidanand	endif
191*c5e1da83SJayanth Dodderi Chidanand
192*c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support BRBE
193*c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_BRBE_FOR_NS},0)
194*c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support BRBE.)
195*c5e1da83SJayanth Dodderi Chidanand	endif
196*c5e1da83SJayanth Dodderi Chidanand
197*c5e1da83SJayanth Dodderi Chidanand	# RME requires AARCH64
198*c5e1da83SJayanth Dodderi Chidanand	ifneq (${ARCH},aarch64)
199*c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME requires AArch64)
200*c5e1da83SJayanth Dodderi Chidanand	endif
201*c5e1da83SJayanth Dodderi Chidanand
202*c5e1da83SJayanth Dodderi Chidanand	# RME requires el2 context to be saved for now.
203*c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_EL2_REGS := 1
204*c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_AARCH32_REGS := 0
205*c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MAJOR := 8
206*c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MINOR := 5
207*c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV = 1
208*c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT = 1
209*c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS := 1
210*c5e1da83SJayanth Dodderi Chidanand
211*c5e1da83SJayanth Dodderi Chidanand	# RME enables CSV2_2 extension by default.
212*c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 = 1
213*c5e1da83SJayanth Dodderi Chidanandendif #(FEAT_RME)
214*c5e1da83SJayanth Dodderi Chidanand
215*c5e1da83SJayanth Dodderi Chidanand################################################################################
216*c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
217*c5e1da83SJayanth Dodderi Chidanand################################################################################
21826e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
21926e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
22026e63c44SEtienne Carriere# Will set march32-directive from platform configuration
22126e63c44SEtienne Carriereelse
22226e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
223fa6f774bSAlexei Fedorov
224f1821790SAlexei Fedorov# Set the compiler's target architecture profile based on
225f1821790SAlexei Fedorov# ARM_ARCH_MAJOR ARM_ARCH_MINOR options
226fa6f774bSAlexei Fedorov	ifeq (${ARM_ARCH_MINOR},0)
227f1821790SAlexei Fedorov		march32-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
228f1821790SAlexei Fedorov		march64-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
229fa6f774bSAlexei Fedorov	else
230f1821790SAlexei Fedorov		march32-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
231f1821790SAlexei Fedorov		march64-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
232*c5e1da83SJayanth Dodderi Chidanand	endif #(ARM_ARCH_MINOR)
233*c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
234*c5e1da83SJayanth Dodderi Chidanand
235*c5e1da83SJayanth Dodderi Chidanand################################################################################
236*c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
237*c5e1da83SJayanth Dodderi Chidanand################################################################################
238*c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
239*c5e1da83SJayanth Dodderi Chidanand
240*c5e1da83SJayanth Dodderi Chidanand####################################################
241*c5e1da83SJayanth Dodderi Chidanand# Enable required options for Memory Stack Tagging.
242*c5e1da83SJayanth Dodderi Chidanand####################################################
24326e63c44SEtienne Carriere
2447ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2457ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2464a565bd8SSami Mujawar	# Check if revision is greater than or equal to 8.5
2474a565bd8SSami Mujawar	ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2487ff088d1SManish V Badarkhe		mem_tag_arch_support	= 	yes
2497ff088d1SManish V Badarkhe	endif
250*c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
2517ff088d1SManish V Badarkhe
252f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2537ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2547ff088d1SManish V Badarkhe	ifdef mem_tag_arch_support
255f1821790SAlexei Fedorov		# Check for armclang and clang compilers
2567ff088d1SManish V Badarkhe		ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
257f1821790SAlexei Fedorov		# Add "memtag" architecture feature modifier if not specified
258f1821790SAlexei Fedorov			ifeq ( ,$(findstring memtag,$(arch-features)))
259f1821790SAlexei Fedorov				arch-features	:=	$(arch-features)+memtag
260f1821790SAlexei Fedorov			endif	# memtag
2617ff088d1SManish V Badarkhe			ifeq ($(notdir $(CC)),armclang)
2627ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-mmemtag-stack
2637ff088d1SManish V Badarkhe			else ifeq ($(notdir $(CC)),clang)
2647ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-fsanitize=memtag
265f1821790SAlexei Fedorov			endif	# armclang
266*c5e1da83SJayanth Dodderi Chidanand		endif
2677ff088d1SManish V Badarkhe	else
268*c5e1da83SJayanth Dodderi Chidanand                $(error "Error: stack memory tagging is not supported for  \
269*c5e1da83SJayanth Dodderi Chidanand                 architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
270*c5e1da83SJayanth Dodderi Chidanand	endif #(mem_tag_arch_support)
271*c5e1da83SJayanth Dodderi Chidanandendif #(SUPPORT_STACK_MEMTAG)
272f1821790SAlexei Fedorov
273f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
274f1821790SAlexei Fedorovifneq ($(arch-features), none)
275f1821790SAlexei Fedorov	# Strip "none+" from arch-features
276f1821790SAlexei Fedorov	arch-features		:=	$(subst none+,,$(arch-features))
277f1821790SAlexei Fedorov	ifeq ($(ARCH), aarch32)
278f1821790SAlexei Fedorov		march32-directive	:=	$(march32-directive)+$(arch-features)
279f1821790SAlexei Fedorov	else
280f1821790SAlexei Fedorov		march64-directive	:=	$(march64-directive)+$(arch-features)
2817ff088d1SManish V Badarkhe	endif
282f1821790SAlexei Fedorov# Print features
283f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
284*c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
2854e04478aSChris Kay
286c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
287fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
288c8a992fdSorigin		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi $(march32-directive)
289c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi $(march64-directive)
290c8a992fdSorigin		LD			:=	$(LINKER)
291c8a992fdSorigin	else
29294eb1277SArvind Ram Prakash		TF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
293c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-elf $(march64-directive)
294c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
295c8a992fdSorigin
296c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
297c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
298c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
299641f16e7SAmbroise Vincent	endif
300c8a992fdSorigin
301c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
302c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
303c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
304edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
305edbce9aaSzelalem-aweke	TF_CFLAGS_aarch32	=	$(march32-directive)
306edbce9aaSzelalem-aweke	TF_CFLAGS_aarch64	=	$(march64-directive)
307edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
308edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
309edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
310edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
311edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
312edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
313edbce9aaSzelalem-aweke		endif
314edbce9aaSzelalem-aweke	endif
315edbce9aaSzelalem-aweke	LD			=	$(LINKER)
316d5461857Sdp-armelse
31726e63c44SEtienne Carriere	TF_CFLAGS_aarch32	=	$(march32-directive)
318fa6f774bSAlexei Fedorov	TF_CFLAGS_aarch64	=	$(march64-directive)
3192adee763SRoberto Vargas	LD			=	$(LINKER)
320*c5e1da83SJayanth Dodderi Chidanandendif #(clang)
321d5461857Sdp-arm
32232b209bfSAhmad Fatoum# Process Debug flag
32332b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
32432b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
32532b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
3264466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
3274466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
32832b209bfSAhmad Fatoum
32932b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
33032b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
33132b209bfSAhmad Fatoumelse
33232b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
33332b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
33432b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
335*c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
33632b209bfSAhmad Fatoum
337f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
338f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
339f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
340f1de4c8fSPeiyuan Songendif
341dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
342f1de4c8fSPeiyuan Song
3438fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3448fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
3458fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3468fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
3478fd9d4d5SAntonio Nino Diazelse
3488fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
349*c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
3508fd9d4d5SAntonio Nino Diaz
351a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
352d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3539d29c227SSoby Mathew
3549fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3559fc59639SAlexei Fedorov	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
356*c5e1da83SJayanth Dodderi Chidanandendif #(BP_OPTION)
3579fc59639SAlexei Fedorov
35826e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
359fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
360b86048c4SAntonio Nino Diaz
361*c5e1da83SJayanth Dodderi Chidanand##############################################################################
362*c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
363*c5e1da83SJayanth Dodderi Chidanand###############################################################################
3649ab81b5eSJustin Chadwell# General warnings
3659ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
366b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
367d75a9ecdSBoyan Karatotev				-Wredundant-decls
368d75a9ecdSBoyan Karatotev# stricter warnings
369d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
370d75a9ecdSBoyan Karatotev# too verbose for generic build
371d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
372d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
373d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
374d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
3759ab81b5eSJustin Chadwell
3769ab81b5eSJustin Chadwell# Additional warnings
377d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
378d75a9ecdSBoyan Karatotev# full -Wextra
379d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
380d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
381d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
382e7c645b5SYann Gautier
383d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
384d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
385d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
386d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
387d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
388d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
389d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
390d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
391d141e638SBoyan Karatotev# currently very involved and many platforms set this off
392d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
393e7c645b5SYann Gautier
394d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
395e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
396d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
397d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
398d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
399e7c645b5SYann GautierWARNING3 += -Wcast-qual
400e7c645b5SYann GautierWARNING3 += -Wconversion
401e7c645b5SYann GautierWARNING3 += -Wpacked
402e7c645b5SYann GautierWARNING3 += -Wpointer-arith
403e7c645b5SYann GautierWARNING3 += -Wswitch-default
404e7c645b5SYann Gautier
405d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
406d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
407d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
408d75a9ecdSBoyan Karatotevifdef W
409d75a9ecdSBoyan Karatotev	ifneq (${W},0)
410d75a9ecdSBoyan Karatotev		E	 ?= 0
411d75a9ecdSBoyan Karatotev	endif
412d75a9ecdSBoyan Karatotevendif
413d75a9ecdSBoyan Karatotev
414e7c645b5SYann Gautierifeq (${W},1)
4159ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
416e7c645b5SYann Gautierelse ifeq (${W},2)
4179ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
418e7c645b5SYann Gautierelse ifeq (${W},3)
4199ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
420*c5e1da83SJayanth Dodderi Chidanandendif #(W)
421e7c645b5SYann Gautier
4229ab81b5eSJustin Chadwell# Compiler specific warnings
42300296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
42493c690ebSJustin Chadwell# not using clang
425d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
426d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
427d7b4cd41SJustin Chadwell				-Wlogical-op
428dea23e24SGovindraj Raja
429dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
430dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
431dea23e24SGovindraj Raja
43293c690ebSJustin Chadwellelse
43393c690ebSJustin Chadwell# using clang
434d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
435d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
436*c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
43700296576SAmbroise Vincent
4386336b07aSYann Gautierifneq (${E},0)
4396336b07aSYann Gautier	ERRORS := -Werror
440*c5e1da83SJayanth Dodderi Chidanandendif #(E)
4416336b07aSYann Gautier
442*c5e1da83SJayanth Dodderi Chidanand################################################################################
443*c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
444*c5e1da83SJayanth Dodderi Chidanand################################################################################
445ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
4469ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
44759de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
448d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
44959de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
450ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
451ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
452ebd6efaeSSamuel Holland				-Os -std=gnu99
45373c99d4eSJuan Castillo
4541f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4551f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
456*c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
457*c5e1da83SJayanth Dodderi Chidanand
4581f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4591f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
4601f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
461*c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
4621f461979SJustin Chadwell
463f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
464f7ec31dbSdavid cunado
4651f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
4661f49db5fSMarco Felsch
467641f16e7SAmbroise Vincent# LD = armlink
468c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
469c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
470c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
471edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
472641f16e7SAmbroise Vincent
473641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
474edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
475edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
476edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
477edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
478ac98b82aSChris Kay
479ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
480ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
481ac98b82aSChris Kay
482edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
483edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
484edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
485edbce9aaSzelalem-aweke		endif
486*c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
487*c5e1da83SJayanth Dodderi Chidanand
488edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
489edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
490edbce9aaSzelalem-aweke	ifneq (${ERRATA_A53_843419},1)
491edbce9aaSzelalem-aweke		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
492edbce9aaSzelalem-aweke	endif
493edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
494edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
495641f16e7SAmbroise Vincent
496641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
497c2ad38ceSVarun Wadekarelse
4981f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
4991f49db5fSMarco Felsch# are not loaded by a elf loader.
5001f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
501ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
502c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
503ac98b82aSChris Kay
504ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
505ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
506ac98b82aSChris Kay
507641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
508ebac6922SYabin Cui# therefore don't add those in that case.
509ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
510ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
511641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
512ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
513edbce9aaSzelalem-aweke	endif
514*c5e1da83SJayanth Dodderi Chidanand
515*c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
51673c99d4eSJuan Castillo
51703b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
518a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
519a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
52003b397a8SNishanth Menon
52173c99d4eSJuan Castillo################################################################################
52273c99d4eSJuan Castillo# Common sources and include directories
52373c99d4eSJuan Castillo################################################################################
5246a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
525d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
52673c99d4eSJuan Castillo
52773c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
5287f56e9a3SSoby Mathew				common/tf_log.c				\
5299d29c227SSoby Mathew				common/${ARCH}/debug.S			\
53091b48c9fSJulius Werner				drivers/console/multi_console.c		\
5319d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
5329d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
533566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
5347f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
53575311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
5369d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
53761f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
538d7a6b0f8SRyan Harkin
53990ce8b87SBoyan Karatotev# Pointer Authentication sources
54090ce8b87SBoyan Karatotevifeq (${ENABLE_PAUTH}, 1)
54190ce8b87SBoyan Karatotev# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
54290ce8b87SBoyan Karatotev# Pauth support. As it's not secure, it must be reimplemented for real platforms
54390ce8b87SBoyan Karatotev	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
54490ce8b87SBoyan Karatotevendif
54590ce8b87SBoyan Karatotev
5468422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
5478422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
5488422a840SAntonio Nino Diazendif
5498422a840SAntonio Nino Diaz
5501f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
5511f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
5521f461979SJustin Chadwellendif
5531f461979SJustin Chadwell
55401d237cbSYann GautierINCLUDES		+=	-Iinclude				\
555f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
55609d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
55709d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
55809d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
55909d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
56009d40e0eSAntonio Nino Diaz
5619c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5629c6d1c50SAntonio Nino Diaz
56373c99d4eSJuan Castillo################################################################################
56473c99d4eSJuan Castillo# Generic definitions
56573c99d4eSJuan Castillo################################################################################
566231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
567231c1470SEvan Lloyd
56829214e95SGrant Likelyifeq (${BUILD_BASE},)
56973c99d4eSJuan Castillo     BUILD_BASE		:=	./build
57029214e95SGrant Likelyendif
57129214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
57273c99d4eSJuan Castillo
573231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
57473c99d4eSJuan Castillo
57573c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
57673c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
57773c99d4eSJuan Castillo
57873c99d4eSJuan Castillo################################################################################
57973c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
58073c99d4eSJuan Castillo################################################################################
58173c99d4eSJuan Castillo
58273c99d4eSJuan Castilloifneq (${SPD},none)
5839d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5849d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5859d29c227SSoby Mathew	endif
58628f39f02SMax Shvetsov
5874c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5884c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
589*c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
590*c5e1da83SJayanth Dodderi Chidanand                ignored.")
5914c117f6cSSandrine Bailleux	endif
59228f39f02SMax Shvetsov
593c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
594c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
595c3fb00d9SAchin Gupta		SPD_DIR := std_svc
59628f39f02SMax Shvetsov
597033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
598f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5991d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
6001d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
6011d63ae4dSMarc Bonnici			endif
60228f39f02SMax Shvetsov		endif
603db1ef41aSOlivier Deprez
604db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
605db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
606db1ef41aSOlivier Deprez		endif
607ca932481SDavidson K
608ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
609ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
610ca932481SDavidson K		endif
61133993a37SBalint Dobszay
61233993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
61333993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
61433993a37SBalint Dobszay		endif
61546789a7cSBalint Dobszay
61646789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
61746789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
61846789a7cSBalint Dobszay		endif
619c3fb00d9SAchin Gupta	else
620c3fb00d9SAchin Gupta		# All other SPDs in spd directory
621c3fb00d9SAchin Gupta		SPD_DIR := spd
622*c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
623c3fb00d9SAchin Gupta
62473c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
625c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
626c3fb00d9SAchin Gupta
62773c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
628c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
62973c99d4eSJuan Castillo	endif
63073c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
63173c99d4eSJuan Castillo        include ${SPD_MAKE}
63273c99d4eSJuan Castillo
63370d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
63470d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
63570d1fc53SJuan Castillo	# supports two mutually exclusive options:
63670d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
63770d1fc53SJuan Castillo	#   of source files to build BL32
63870d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
63970d1fc53SJuan Castillo	#   that will be included in the FIP
64070d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
64170d1fc53SJuan Castillo	# over the sources.
642*c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
643e35c4045SJeenu Viswambharan
644f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
645f1910cc1SGovindraj Raja	ifeq (${SPD},none)
646f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
647*c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
648*c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
649f1910cc1SGovindraj Raja		endif
650f1910cc1SGovindraj Raja	endif
651f1910cc1SGovindraj Rajaendif
652f1910cc1SGovindraj Raja
65351faada7SDouglas Raillard################################################################################
6545b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6555b18de09SZelalem Aweke################################################################################
6565b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6575b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6585b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6595b18de09SZelalem Aweke	endif
6601d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6611d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6621d63ae4dSMarc Bonnici	endif
663*c5e1da83SJayanth Dodderi Chidanand
6644fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6654fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6664fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6674fba2e1fSBoyan Karatotev		endif
6684fba2e1fSBoyan Karatotev	endif
6695b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6705b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6715b18de09SZelalem Awekeendif
6725b18de09SZelalem Aweke
6735b18de09SZelalem Aweke################################################################################
67473c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
67573c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
67673c99d4eSJuan Castillo################################################################################
6772da8d8bfSJeenu Viswambharan
67873c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6790f21c547SJuan Castillo
68042d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
68142d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
68242d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
68342d4d3baSArvind Ram Prakash# BL2 in EL3
68442d4d3baSArvind Ram Prakash
68542d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
68642d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68742d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
688*c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
689*c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
69042d4d3baSArvind Ram Prakash	endif
69142d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
69242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
69342d4d3baSArvind Ram Prakashelse
69442d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
69542d4d3baSArvind Ram Prakashendif
69642d4d3baSArvind Ram Prakash
6978012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6988012cc5cSMasahiro Yamada
69926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
70026e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
70126e63c44SEtienne Carriereendif
70226e63c44SEtienne Carriere
7033bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7043bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7053bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7067b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7077b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7087b592418SSamuel Hollandendif
709*c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
710320920c1SMasahiro Yamada
711320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
712320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
713320920c1SMasahiro Yamadaelse
714320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
715320920c1SMasahiro Yamadaendif
716320920c1SMasahiro Yamada
717320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71842d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71969af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
720966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
72169af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
72269af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
723*c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
724*c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
725966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
726320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
727320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
728966660ecSChris Kay
729966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
730d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
731d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
732*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7333bd17c0fSSoby Mathew
734007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
735007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
736007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
737007433d8SBoyan Karatotev
7389cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73942d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7409cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
741d5e97a1dSMasahiro Yamadaelse
7429cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
743*c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
744007433d8SBoyan Karatotev
745007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7469cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7479cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7489cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
749007433d8SBoyan Karatotevelse
750007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
751d5e97a1dSMasahiro Yamadaendif
752d5e97a1dSMasahiro Yamada
75354035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
75454035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
75554035fc4SSandrine Bailleux# This can be overridden by the platform.
75673c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7574f6ad66aSAchin Gupta
758a4409008Sdp-arm################################################################################
759a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
760a4409008Sdp-arm################################################################################
761*c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
762*c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
763*c5e1da83SJayanth Dodderi Chidanand
764a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
765a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
766a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
767a4409008Sdp-arm
768a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
769a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
770a4409008Sdp-arm                endif
771a4409008Sdp-arm        $(info Including ${AARCH32_SP_MAKE})
772a4409008Sdp-arm        include ${AARCH32_SP_MAKE}
773a4409008Sdp-arm        endif
774*c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7754f6ad66aSAchin Gupta
77673c99d4eSJuan Castillo################################################################################
77777f1f7a1SVarun Wadekar# Include libc if not overridden
77877f1f7a1SVarun Wadekar################################################################################
77977f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
78077f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
78177f1f7a1SVarun Wadekarendif
78277f1f7a1SVarun Wadekar
78377f1f7a1SVarun Wadekar################################################################################
784*c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
785cf2c8a33SAntonio Nino Diaz################################################################################
786cf2c8a33SAntonio Nino Diaz
787*c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
788*c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
789*c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
790*c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
791*c5e1da83SJayanth Dodderi Chidanand        else
792*c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
793*c5e1da83SJayanth Dodderi Chidanand        endif
794*c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
795*c5e1da83SJayanth Dodderi Chidanand
796*c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
797*c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
798*c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
799*c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
800*c5e1da83SJayanth Dodderi Chidanand        endif
801*c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
802*c5e1da83SJayanth Dodderi Chidanand
803*c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
804*c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
805*c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
806*c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
807*c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
808*c5e1da83SJayanth Dodderi Chidanandendif
809*c5e1da83SJayanth Dodderi Chidanand
810*c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
811*c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
812*c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
813*c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
814*c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
815*c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
816*c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
817*c5e1da83SJayanth Dodderi Chidanand
818cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81968450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
82068450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
82168450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
822cf2c8a33SAntonio Nino Diaz	endif
82376580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
824*c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
825*c5e1da83SJayanth Dodderi Chidanand                build options.")
82676580f3dSQixiang Xu	endif
82776580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
828*c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
829*c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
83076580f3dSQixiang Xu	endif
831*c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
832cf2c8a33SAntonio Nino Diaz
833cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
834cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
835cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
836cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
837cf2c8a33SAntonio Nino Diaz	endif
83868450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83968450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
840*c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
841cf2c8a33SAntonio Nino Diaz	endif
842*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
843cf2c8a33SAntonio Nino Diaz
844d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
845d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
846d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
847d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
848d4593e47SJeenu Viswambharanendif
8491a0a3f06SYatharth Kochar
85042d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
85142d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
85242d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8537d173fc5SJiafei Panendif
8547d173fc5SJiafei Pan
8559202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85614c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
857*c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
858*c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8599202d519SManish Pandeyendif
860*c5e1da83SJayanth Dodderi Chidanand
8619202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8629202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8639202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8649202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8659202d519SManish Pandey	endif
86646cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8679202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
86814c6016aSJeenu Viswambharan	endif
869*c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
870*c5e1da83SJayanth Dodderi Chidanand
8719202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8721a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8736503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8746503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8751a7c1cfeSJeenu Viswambharan	endif
876*c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8771a7c1cfeSJeenu Viswambharan
878ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
879209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
880209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
881*c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
882*c5e1da83SJayanth Dodderi Chidanand                to be set.")
883209a60ccSSoby Mathew	endif
884*c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
885209a60ccSSoby Mathew
8862bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8872bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8882bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8892bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8902bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8912bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8922bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8932bf4f27fSManish V Badarkhe# Support hash calculation only
8942bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8952bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8962bf4f27fSManish V Badarkhe# Support authentication verification only
897c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
898c9c56f6eSManish V Badarkheelse
899c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
900*c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
901c9c56f6eSManish V Badarkhe
902cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
903cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
904700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
90584ef9cd8SManish V Badarkheendif
90684ef9cd8SManish V Badarkhe
907b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9089fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9099fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
910b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9119fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9129fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
91306715f85SAlexei Fedorov	endif
914*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9159fc59639SAlexei Fedorov
91606715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9179fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9189fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
919b86048c4SAntonio Nino Diaz	endif
920*c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9219fc59639SAlexei Fedorov
9229dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9239dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9249dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9259dd94382SJustin Chadwell	endif
926*c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9279dd94382SJustin Chadwell
928396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
929396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
930*c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
931396b339dSManish V Badarkhe
9326a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9336a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
934*c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9356a0da736SJayanth Dodderi Chidanand
93603d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
93703d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
938*c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
939*c5e1da83SJayanth Dodderi Chidanand                to be set")
94003d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
94103d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
94203d3c0d7SJayanth Dodderi Chidanand	endif
943*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
94445007acdSJayanth Dodderi Chidanand
94560e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
94660e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
947*c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
948*c5e1da83SJayanth Dodderi Chidanand                library v2")
94960e8f3cfSPetre-Ionut Tudor	endif
950*c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
95160e8f3cfSPetre-Ionut Tudor
9527cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9537cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
954*c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
955*c5e1da83SJayanth Dodderi Chidanand                to be set)
9567cda17bbSSumit Garg	endif
957*c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9587cda17bbSSumit Garg
959744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
960dc78e62dSjohpow01ifeq (${ARCH},aarch32)
961744ad974Sjohpow01
962744ad974Sjohpow01	# SME/SVE only supported on AArch64
96345007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
964dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
965dc78e62dSjohpow01	endif
96603d3c0d7SJayanth Dodderi Chidanand
967dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
968dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96924ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
970dc78e62dSjohpow01	endif
971744ad974Sjohpow01
972ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
973744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
974744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
975744ad974Sjohpow01	endif
976744ad974Sjohpow01
977ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
978ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
979ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
980ff86e0b4SJuan Pablo Conde	endif
981*c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
982dc78e62dSjohpow01
983dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
984dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
98545007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
986dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
987dc78e62dSjohpow01	endif
988dc78e62dSjohpow01endif
989dc78e62dSjohpow01
9900d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9910d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9920d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9930d122947SBoyan Karatotev	endif
994*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9950d122947SBoyan Karatotev
996dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
997dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
998dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
999dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
1000dc78e62dSjohpow01	endif
10010d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
10020d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
10030d122947SBoyan Karatotev	endif
1004*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
1005*c5e1da83SJayanth Dodderi Chidanand
1006dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1007dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1008dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1009dc78e62dSjohpow01	endif
1010*c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1011dc78e62dSjohpow01
1012dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1013dc78e62dSjohpow01# its own context management including FPU registers.
1014dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
101545007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1016dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1017dc78e62dSjohpow01	endif
101803d3c0d7SJayanth Dodderi Chidanand
1019dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1020dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1021dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1022dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1023dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1024dc78e62dSjohpow01	endif
1025*c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1026dc78e62dSjohpow01
102700e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
102800e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102900e28874SManish V Badarkheendif
103000e28874SManish V Badarkhe
1031274a69e7SChris Kayifeq (${ENABLE_RME},1)
1032274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1033274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1034274a69e7SChris Kay	endif
1035274a69e7SChris Kayendif
1036274a69e7SChris Kay
1037*c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1038*c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1039*c5e1da83SJayanth Dodderi Chidanand
1040*c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1041*c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1042*c5e1da83SJayanth Dodderi Chidanand
1043*c5e1da83SJayanth Dodderi Chidanand#SVE_VECTOR_LEN
1044*c5e1da83SJayanth Dodderi Chidanand$(eval $(call add_define,SVE_VECTOR_LEN))
1045*c5e1da83SJayanth Dodderi Chidanand
1046cf2c8a33SAntonio Nino Diaz################################################################################
104773c99d4eSJuan Castillo# Process platform overrideable behaviour
104873c99d4eSJuan Castillo################################################################################
10494f6ad66aSAchin Gupta
10505f24ce96SManish Pandeyifdef BL1_SOURCES
10515f24ce96SManish Pandey	NEED_BL1 := yes
1052*c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10535f24ce96SManish Pandey
10545f24ce96SManish Pandeyifdef BL2_SOURCES
10555f24ce96SManish Pandey	NEED_BL2 := yes
10565f24ce96SManish Pandey
1057bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1058bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1059cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1060cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1061cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10624c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1063cf2c8a33SAntonio Nino Diaz	else
106468450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1065cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1066cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1067cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1068cf2c8a33SAntonio Nino Diaz		else
1069cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1070cf2c8a33SAntonio Nino Diaz		endif
10714c117f6cSSandrine Bailleux	endif
1072*c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10736f971622SJuan Castillo
10745f24ce96SManish Pandeyifdef BL2U_SOURCES
10755f24ce96SManish Pandey	NEED_BL2U := yes
1076*c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10775f24ce96SManish Pandey
10784d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10794d045d0eSMasahiro Yamadaifdef SCP_BL2
10804d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1081*c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10824d045d0eSMasahiro Yamada
10835744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10845744e874SSoby Mathewifneq (${ARCH},aarch32)
10855744e874SSoby Mathew	ifdef BL31_SOURCES
1086*c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1087*c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10885744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10895744e874SSoby Mathew			NEED_BL31 := yes
10905744e874SSoby Mathew		endif
10915744e874SSoby Mathew	endif
1092*c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10935744e874SSoby Mathew
109473c99d4eSJuan Castillo# Process TBB related flags
10956f971622SJuan Castilloifneq (${GENERATE_COT},0)
109673c99d4eSJuan Castillo	# Common cert_create options
10976f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10986f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10990191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1100fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1101fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
11020191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1103fd34e7baSJuan Castillo		endif
11046f971622SJuan Castillo	endif
110573c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
110673c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
110773c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
110873c99d4eSJuan Castillo	endif
1109*c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11106f971622SJuan Castillo
11111c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11121c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1113*c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11141c75d5dfSMasahiro Yamada
11155f24ce96SManish Pandeyifdef FDT_SOURCES
11165f24ce96SManish Pandey	NEED_FDT := yes
1117*c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11185f24ce96SManish Pandey
111973c99d4eSJuan Castillo################################################################################
112046e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
112146e5e035SMichalis Pappas################################################################################
112246e5e035SMichalis Pappas
112346e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
112446e5e035SMichalis Pappas
112546e5e035SMichalis Pappas################################################################################
11268a86052dSSoby Mathew# Include BL specific makefiles
11278a86052dSSoby Mathew################################################################################
11285f24ce96SManish Pandey
11295f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11308a86052dSSoby Mathewinclude bl1/bl1.mk
11318a86052dSSoby Mathewendif
11328a86052dSSoby Mathew
11335f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11348a86052dSSoby Mathewinclude bl2/bl2.mk
11358a86052dSSoby Mathewendif
11368a86052dSSoby Mathew
11375f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11388a86052dSSoby Mathewinclude bl2u/bl2u.mk
11398a86052dSSoby Mathewendif
11408a86052dSSoby Mathew
11415744e874SSoby Mathewifeq (${NEED_BL31},yes)
11428a86052dSSoby Mathewinclude bl31/bl31.mk
11438a86052dSSoby Mathewendif
114403b397a8SNishanth Menon
114573c99d4eSJuan Castillo################################################################################
114673c99d4eSJuan Castillo# Build options checks
114773c99d4eSJuan Castillo################################################################################
114873c99d4eSJuan Castillo
1149*c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1150327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1151327131c4SLeonardo Sandoval    $(sort \
1152327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
115346789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1154327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1155327131c4SLeonardo Sandoval	CREATE_KEYS \
1156327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1157327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1158327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1159327131c4SLeonardo Sandoval	DEBUG \
11600063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1161327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1162327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11631fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1164742ca230SChris Kay	ENABLE_AMU_FCONF \
1165873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1166327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
116724077098SAndre Przywara	ENABLE_FEAT_SB \
1168327131c4SLeonardo Sandoval	ENABLE_PIE \
1169327131c4SLeonardo Sandoval	ENABLE_PMF \
1170327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1171327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1172dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11730c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1174327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1175327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1176327131c4SLeonardo Sandoval	GENERATE_COT \
1177327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
117846cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1179327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1180327131c4SLeonardo Sandoval	MEASURED_BOOT \
118100e28874SManish V Badarkhe	DRTM_SUPPORT \
1182327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1183327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1184327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11850ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1186327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1187327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
118864b4710bSWing Li	PSCI_OS_INIT_MODE \
1189327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1190327131c4SLeonardo Sandoval	SAVE_KEYS \
1191327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
119296a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1193327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1194327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1195327131c4SLeonardo Sandoval	SPM_MM \
11961d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1197327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1198327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1199327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1200327131c4SLeonardo Sandoval	USE_DEBUGFS \
1201327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1202327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1203327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1204327131c4SLeonardo Sandoval	USE_ROMLIB \
1205327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1206327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
120742d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1208327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1209327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1210327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1211327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1212327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1213327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
121400e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1215327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1216327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1217396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
121868120783SChris Kay	ENABLE_MPMM \
121968120783SChris Kay	ENABLE_MPMM_FCONF \
12206a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12210b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1222ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1223ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
122404c7303bSOkash Khawaja	CONDITIONAL_CMO \
12259202d519SManish Pandey	RAS_FFH_SUPPORT \
1226327131c4SLeonardo Sandoval)))
122773c99d4eSJuan Castillo
1228*c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1229327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1230327131c4SLeonardo Sandoval    $(sort \
1231327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1232327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1233327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12346a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12356a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12366a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12372bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
12381298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
123947c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12406a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12416a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1242d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12436a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12446a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12459202d519SManish Pandey	ENABLE_FEAT_RAS	\
12466a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12476a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12486a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12496a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12506a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12516a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1252ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12536a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1254d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1255062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1256062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1257062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1258062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1259688ab57bSMark Brown	ENABLE_FEAT_GCS \
12606a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12616a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12626a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12636437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1264603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
126545007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
126603d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12672b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12686a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1269327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12705357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12715357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1272781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1273781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1274bebcf27fSMark Brown	SVE_VECTOR_LEN \
12750ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1276327131c4SLeonardo Sandoval)))
1277c877b414SJeenu Viswambharan
1278aacff749SJustin Chadwellifdef KEY_SIZE
1279aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1280aacff749SJustin Chadwellendif
1281aacff749SJustin Chadwell
12821f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12831f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12841f461979SJustin Chadwellendif
12851f461979SJustin Chadwell
128673c99d4eSJuan Castillo################################################################################
128773c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
128873c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
128973c99d4eSJuan Castillo# platform to overwrite the default options
129073c99d4eSJuan Castillo################################################################################
129173c99d4eSJuan Castillo
1292327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1293327131c4SLeonardo Sandoval    $(sort \
1294327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1295327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1296327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
129746789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1298327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1299327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1300327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1301327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1302327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1303327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1304327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1305062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1306327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13070063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1308d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13091fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1310742ca230SChris Kay	ENABLE_AMU_FCONF \
1311873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1312327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1313327131c4SLeonardo Sandoval	ENABLE_BTI \
1314327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1315327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1316327131c4SLeonardo Sandoval	ENABLE_PIE \
1317327131c4SLeonardo Sandoval	ENABLE_PMF \
1318327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13195b18de09SZelalem Aweke	ENABLE_RME \
1320327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1321dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
132203d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1323dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
132490118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1325327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13260c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1327327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1328327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1329327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1330327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1331327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
133246cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1333327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1334327131c4SLeonardo Sandoval	LOG_LEVEL \
1335327131c4SLeonardo Sandoval	MEASURED_BOOT \
133600e28874SManish V Badarkhe	DRTM_SUPPORT \
1337327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1338327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1339327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13400ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1341327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1342327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
134364b4710bSWing Li	PSCI_OS_INIT_MODE \
13449202d519SManish Pandey	ENABLE_FEAT_RAS \
13459202d519SManish Pandey	RAS_FFH_SUPPORT \
1346327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1347327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
134896a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1349327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1350327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1351327131c4SLeonardo Sandoval	SPD_${SPD} \
1352327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1353327131c4SLeonardo Sandoval	SPM_MM \
13541d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1355327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1356327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1357c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13587dfb9911SJimmy Brisson	TRNG_SUPPORT \
1359ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1360ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1361327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1362327131c4SLeonardo Sandoval	USE_DEBUGFS \
1363327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1364327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1365327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1366327131c4SLeonardo Sandoval	USE_ROMLIB \
1367327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1368327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
136942d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
137042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1371327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1372327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1373327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1374327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
137500e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1376327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1377327131c4SLeonardo Sandoval	USE_SP804_TIMER \
137812cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1379ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13804e04478aSChris Kay	ENABLE_FEAT_SB \
13817d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13825357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13835357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1384396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1385744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1386813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1387d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13888fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1389cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
139068120783SChris Kay	ENABLE_MPMM \
139168120783SChris Kay	ENABLE_MPMM_FCONF \
1392f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1393f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13946a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13956a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13966a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13976a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13986a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1399d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1400062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1401062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1402062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1403062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1404688ab57bSMark Brown	ENABLE_FEAT_GCS \
14056a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1406781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1407781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
140804c7303bSOkash Khawaja	CONDITIONAL_CMO \
14090ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1410327131c4SLeonardo Sandoval)))
14112fae4b1eSJeenu Viswambharan
14121f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14131f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1414*c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14151f461979SJustin Chadwell
14164c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14174c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14184c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1419cf2c8a33SAntonio Nino Diazelse
142068450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
142168450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
142268450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
142368450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14244c117f6cSSandrine Bailleux	endif
1425*c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
142673c99d4eSJuan Castillo
1427209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1428209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1429209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1430209a60ccSSoby Mathewendif
1431209a60ccSSoby Mathew
1432c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1433c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1434c2ad38ceSVarun Wadekarendif
1435c2ad38ceSVarun Wadekar
1436ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1437ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1438c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1439ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1440ce2b1ec6SManish Pandey	FIP_DEPS += sp
144107c44475SManish Pandey	CRT_DEPS += sp
1442ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1443ce2b1ec6SManish Pandeyelse
1444c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1445c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1446c33ff198SOlivier Deprez	endif
1447*c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1448*c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1449ce2b1ec6SManish Pandey
145073c99d4eSJuan Castillo################################################################################
145173c99d4eSJuan Castillo# Build targets
145273c99d4eSJuan Castillo################################################################################
145373c99d4eSJuan Castillo
145490aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
145573c99d4eSJuan Castillo.SUFFIXES:
145673c99d4eSJuan Castillo
145773c99d4eSJuan Castilloall: msg_start
145873c99d4eSJuan Castillo
145973c99d4eSJuan Castillomsg_start:
146073c99d4eSJuan Castillo	@echo "Building ${PLAT}"
146173c99d4eSJuan Castillo
14627a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1463d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1464c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1465c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1466c2ad38ceSVarun Wadekarelse
1467bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14687a24cba5SSoby Mathewendif
1469*c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14707a24cba5SSoby Mathew
14715accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
147261f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14735fee0287SRoberto Vargas
147473c99d4eSJuan Castillo# Expand build macros for the different images
147573c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1476b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1477434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1478*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
147973c99d4eSJuan Castillo
148073c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1481*c5e1da83SJayanth Dodderi Chidanand
148242d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1483c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1484c9b31ae8SRoberto Vargasendif
1485c9b31ae8SRoberto Vargas
1486eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1487eb1acfb6SChris Kay
148833950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1489434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1490*c5e1da83SJayanth Dodderi Chidanand
1491*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
149273c99d4eSJuan Castillo
14934d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
149433950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1495*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14964d045d0eSMasahiro Yamada
149773c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
149873c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
149926d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
150026d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1501c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1502c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1503434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1504c6ba9b45SSumit Gargelse
150533950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1506434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1507*c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1508*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
150973c99d4eSJuan Castillo
151070d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1511c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
151270d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
151373c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
151426d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
151526d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15169cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15179cd15239SMasahiro Yamada
1518c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1519434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1520c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1521c6ba9b45SSumit Gargelse
1522434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
152333950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1524*c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1525*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
152673c99d4eSJuan Castillo
15275b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15285b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15295b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15305b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15315b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15325b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15335b18de09SZelalem Aweke
15345b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15355b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1536*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15375b18de09SZelalem Aweke
153873c99d4eSJuan Castillo# Add the BL33 image if required by the platform
153973c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
154033950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1541*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1542db6071c9SJuan Castillo
15439003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
154433950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1545434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1546*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15479003fa0bSYatharth Kochar
154803b397a8SNishanth Menon# Expand build macros for the different images
154903b397a8SNishanth Menonifeq (${NEED_FDT},yes)
155003b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1551*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
155203b397a8SNishanth Menon
1553ce2b1ec6SManish Pandey# Add Secure Partition packages
1554ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1555ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
15561e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1557822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1558ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1559ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1560ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1561*c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1562ce2b1ec6SManish Pandey
156336eaaf37SIan Spraylocate-checkpatch:
156436eaaf37SIan Sprayifndef CHECKPATCH
156566079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156636eaaf37SIan Sprayelse
156736eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
156866079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156936eaaf37SIan Sprayendif
1570*c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
157136eaaf37SIan Spray
15724f6ad66aSAchin Guptaclean:
15734f6ad66aSAchin Gupta	@echo "  CLEAN"
1574f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
157588a1cf1eSSami Mujawarifdef UNIX_MK
15762f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
157788a1cf1eSSami Mujawarelse
157888a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
157988a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
158088a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1581*c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15826f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
158390aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15845accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15854f6ad66aSAchin Gupta
1586eaaeece2SJames Morrisseyrealclean distclean:
1587eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1588f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1589f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
159088a1cf1eSSami Mujawarifdef UNIX_MK
15912f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
159288a1cf1eSSami Mujawarelse
159388a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
159488a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
159588a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1596*c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1597e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
159890aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
15995accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16004f6ad66aSAchin Gupta
160136eaaf37SIan Spraycheckcodebase:		locate-checkpatch
160236eaaf37SIan Spray	@echo "  CHECKING STYLE"
160336eaaf37SIan Spray	@if test -d .git ; then						\
16041ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16051a41e8c1SDan Handley		while read GIT_FILE ;					\
16061a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16071a41e8c1SDan Handley		done ;							\
160836eaaf37SIan Spray	else								\
16091a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16101a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16111a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
161261f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16131a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16141ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16151a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
161636eaaf37SIan Spray	fi
161736eaaf37SIan Spray
161836eaaf37SIan Spraycheckpatch:		locate-checkpatch
161936eaaf37SIan Spray	@echo "  CHECKING STYLE"
162002a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
162102a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
162202a76d5fSYann Gautier	fi
162351d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
162477a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
162577a0a7f1SYann Gautier	do								\
162651d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
162751d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
162802a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162902a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
163051d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
163102a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
163202a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
163351d28937SAntonio Nino Diaz	done
163436eaaf37SIan Spray
163573c99d4eSJuan Castillocerttool: ${CRTTOOL}
163673c99d4eSJuan Castillo
1637a9812206SPali Rohár${CRTTOOL}: FORCE
1638598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${CRTTOOLPATH} all
1639f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16406f971622SJuan Castillo	@echo "Built $@ successfully"
1641f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16426f971622SJuan Castillo
16436f971622SJuan Castilloifneq (${GENERATE_COT},0)
164473c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16456f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1646f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16476f971622SJuan Castillo	@echo "Built $@ successfully"
16486f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1649f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1650*c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
165127713fb4SSoby Mathew
165273c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16534727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1654819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1655819281eeSdp-arm	${Q}${FIPTOOL} info $@
1656f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16572f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1658f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1659f58ad36fSHarry Liebel
16600191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16610191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16620191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1663052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16640191262dSYatharth Kochar	@echo "Built $@ successfully"
16650191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1666052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1667*c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16680191262dSYatharth Kochar
16690191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16704727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1671819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1672819281eeSdp-arm	${Q}${FIPTOOL} info $@
1673052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16740191262dSYatharth Kochar	@echo "Built $@ successfully"
1675052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16760191262dSYatharth Kochar
167773c99d4eSJuan Castillofiptool: ${FIPTOOL}
167873c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16790191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
168073c99d4eSJuan Castillo
1681a9812206SPali Rohár${FIPTOOL}: FORCE
168288a1cf1eSSami Mujawarifdef UNIX_MK
1683598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
168488a1cf1eSSami Mujawarelse
168588a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
168688a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
168788a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1688*c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1689f58ad36fSHarry Liebel
1690a9812206SPali Rohárromlib.bin: libraries FORCE
1691bbb24f61SJohn Tsichritzis	${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
16925accce5bSRoberto Vargas
1693cfe83910SLouis Mayencourtmemmap: all
1694af5b49e9SHarrison Mutaiifdef UNIX_MK
1695af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1696af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1697af5b49e9SHarrison Mutaielse
1698af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1699af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1700af5b49e9SHarrison Mutaiendif
1701cfe83910SLouis Mayencourt
17026de32378SMadhukar Pappireddydoc:
17036de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
17046de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
17056de32378SMadhukar Pappireddy
170690aa901fSSumit Gargenctool: ${ENCTOOL}
170790aa901fSSumit Garg
1708a9812206SPali Rohár${ENCTOOL}: FORCE
1709598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
171090aa901fSSumit Garg	@${ECHO_BLANK_LINE}
171190aa901fSSumit Garg	@echo "Built $@ successfully"
171290aa901fSSumit Garg	@${ECHO_BLANK_LINE}
171390aa901fSSumit Garg
171435fab8c9SJoakim Bechcscope:
171535fab8c9SJoakim Bech	@echo "  CSCOPE"
171635fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
171735fab8c9SJoakim Bech	${Q}cscope -b -q -k
171835fab8c9SJoakim Bech
171972ee3314SRyan Harkinhelp:
17207c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
172172ee3314SRyan Harkin	@echo ""
172272ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
172308c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
172472ee3314SRyan Harkin	@echo ""
17257c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17267c23126cSJohn Tsichritzis	@echo ""
17271b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17281b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17291b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17301b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17311b578596SSandrine Bailleux	@echo ""
173272ee3314SRyan Harkin	@echo "Supported Targets:"
17331b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
173436eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17358aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17369003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1737d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17389d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17399d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
174073c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17411b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17420191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
174336eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
174436eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
174536eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
174672ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
174735fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
174872ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17496f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
175090aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1751f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1752ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
175326010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
175438c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1755cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17566de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
175772ee3314SRyan Harkin	@echo ""
17581b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
175972ee3314SRyan Harkin	@echo ""
176072ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
176172ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1762a9812206SPali Rohár
1763a9812206SPali Rohár.PHONY: FORCE
1764a9812206SPali RohárFORCE:;
1765