xref: /rk3399_ARM-atf/Makefile (revision d4089fb8d885573a1bca437e036474bf188b54f2)
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
122c5e1da83SJayanth Dodderi Chidanand################################################################################
123c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
124c5e1da83SJayanth Dodderi Chidanand################################################################################
125c5e1da83SJayanth Dodderi Chidanand
126c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
127c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
128c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
129c5e1da83SJayanth Dodderi Chidanand
130c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
131c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
132c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
133c5e1da83SJayanth Dodderi Chidanand
134c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
135c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
136c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
137c5e1da83SJayanth Dodderi Chidanand
138c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
139c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
140c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
141c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
142c5e1da83SJayanth Dodderi Chidanand
143c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
144c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
145c5e1da83SJayanth Dodderi Chidanand
146c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
147c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
148c5e1da83SJayanth Dodderi Chidanand
149c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
150c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
151c5e1da83SJayanth Dodderi Chidanand
152c5e1da83SJayanth Dodderi Chidanand################################################################################
153c5e1da83SJayanth Dodderi Chidanand# Process BRANCH_PROTECTION value and set
154c5e1da83SJayanth Dodderi Chidanand# Pointer Authentication and Branch Target Identification flags
155c5e1da83SJayanth Dodderi Chidanand################################################################################
156c5e1da83SJayanth Dodderi Chidanandifeq (${BRANCH_PROTECTION},0)
157c5e1da83SJayanth Dodderi Chidanand	# Default value turns off all types of branch protection
158c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := none
159c5e1da83SJayanth Dodderi Chidanandelse ifneq (${ARCH},aarch64)
160c5e1da83SJayanth Dodderi Chidanand        $(error BRANCH_PROTECTION requires AArch64)
161c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},1)
162c5e1da83SJayanth Dodderi Chidanand	# Enables all types of branch protection features
163c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := standard
164c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
165c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
166c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},2)
167c5e1da83SJayanth Dodderi Chidanand	# Return address signing to its standard level
168c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret
169c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
170c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},3)
171c5e1da83SJayanth Dodderi Chidanand	# Extend the signing to include leaf functions
172c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret+leaf
173c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
174c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},4)
175c5e1da83SJayanth Dodderi Chidanand	# Turn on branch target identification mechanism
176c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := bti
177c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
178c5e1da83SJayanth Dodderi Chidanandelse
179c5e1da83SJayanth Dodderi Chidanand        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
180c5e1da83SJayanth Dodderi Chidanandendif #(BRANCH_PROTECTION)
181c5e1da83SJayanth Dodderi Chidanand
182c5e1da83SJayanth Dodderi Chidanand################################################################################
183c5e1da83SJayanth Dodderi Chidanand# RME dependent flags configuration
184c5e1da83SJayanth Dodderi Chidanand################################################################################
185c5e1da83SJayanth Dodderi Chidanand# FEAT_RME
186c5e1da83SJayanth Dodderi Chidanandifeq (${ENABLE_RME},1)
187c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support PIE
188c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_PIE},0)
189c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support PIE)
190c5e1da83SJayanth Dodderi Chidanand	endif
191c5e1da83SJayanth Dodderi Chidanand
192c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support BRBE
193c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_BRBE_FOR_NS},0)
194c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support BRBE.)
195c5e1da83SJayanth Dodderi Chidanand	endif
196c5e1da83SJayanth Dodderi Chidanand
197c5e1da83SJayanth Dodderi Chidanand	# RME requires AARCH64
198c5e1da83SJayanth Dodderi Chidanand	ifneq (${ARCH},aarch64)
199c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME requires AArch64)
200c5e1da83SJayanth Dodderi Chidanand	endif
201c5e1da83SJayanth Dodderi Chidanand
202c5e1da83SJayanth Dodderi Chidanand	# RME requires el2 context to be saved for now.
203c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_EL2_REGS := 1
204c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_AARCH32_REGS := 0
205c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MAJOR := 8
206c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MINOR := 5
207c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV = 1
208c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT = 1
209c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS := 1
210c5e1da83SJayanth Dodderi Chidanand
211c5e1da83SJayanth Dodderi Chidanand	# RME enables CSV2_2 extension by default.
212c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 = 1
213c5e1da83SJayanth Dodderi Chidanandendif #(FEAT_RME)
214c5e1da83SJayanth Dodderi Chidanand
215c5e1da83SJayanth Dodderi Chidanand################################################################################
216c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
217c5e1da83SJayanth Dodderi Chidanand################################################################################
21826e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
21926e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
220*d4089fb8SGovindraj Raja# Will set march-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)
227*d4089fb8SGovindraj Raja		march-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
228fa6f774bSAlexei Fedorov	else
229*d4089fb8SGovindraj Raja		march-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
230c5e1da83SJayanth Dodderi Chidanand	endif #(ARM_ARCH_MINOR)
231c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
232c5e1da83SJayanth Dodderi Chidanand
233c5e1da83SJayanth Dodderi Chidanand################################################################################
234c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
235c5e1da83SJayanth Dodderi Chidanand################################################################################
236c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
237c5e1da83SJayanth Dodderi Chidanand
238c5e1da83SJayanth Dodderi Chidanand####################################################
239c5e1da83SJayanth Dodderi Chidanand# Enable required options for Memory Stack Tagging.
240c5e1da83SJayanth Dodderi Chidanand####################################################
24126e63c44SEtienne Carriere
2427ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2437ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2444a565bd8SSami Mujawar	# Check if revision is greater than or equal to 8.5
2454a565bd8SSami Mujawar	ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2467ff088d1SManish V Badarkhe		mem_tag_arch_support	= 	yes
2477ff088d1SManish V Badarkhe	endif
248c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
2497ff088d1SManish V Badarkhe
250f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2517ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2527ff088d1SManish V Badarkhe	ifdef mem_tag_arch_support
253f1821790SAlexei Fedorov		# Check for armclang and clang compilers
2547ff088d1SManish V Badarkhe		ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
255f1821790SAlexei Fedorov		# Add "memtag" architecture feature modifier if not specified
256f1821790SAlexei Fedorov			ifeq ( ,$(findstring memtag,$(arch-features)))
257f1821790SAlexei Fedorov				arch-features	:=	$(arch-features)+memtag
258f1821790SAlexei Fedorov			endif	# memtag
2597ff088d1SManish V Badarkhe			ifeq ($(notdir $(CC)),armclang)
2607ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-mmemtag-stack
2617ff088d1SManish V Badarkhe			else ifeq ($(notdir $(CC)),clang)
2627ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-fsanitize=memtag
263f1821790SAlexei Fedorov			endif	# armclang
264c5e1da83SJayanth Dodderi Chidanand		endif
2657ff088d1SManish V Badarkhe	else
266c5e1da83SJayanth Dodderi Chidanand                $(error "Error: stack memory tagging is not supported for  \
267c5e1da83SJayanth Dodderi Chidanand                 architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
268c5e1da83SJayanth Dodderi Chidanand	endif #(mem_tag_arch_support)
269c5e1da83SJayanth Dodderi Chidanandendif #(SUPPORT_STACK_MEMTAG)
270f1821790SAlexei Fedorov
271f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
272f1821790SAlexei Fedorovifneq ($(arch-features), none)
273f1821790SAlexei Fedorov	# Strip "none+" from arch-features
274f1821790SAlexei Fedorov	arch-features	:=	$(subst none+,,$(arch-features))
275*d4089fb8SGovindraj Raja	march-directive	:=	$(march-directive)+$(arch-features)
276f1821790SAlexei Fedorov# Print features
277f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
278c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
2794e04478aSChris Kay
280c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
281fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
282*d4089fb8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi $(march-directive)
283*d4089fb8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi $(march-directive)
284c8a992fdSorigin		LD			:=	$(LINKER)
285c8a992fdSorigin	else
286*d4089fb8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive) $(march-directive)
287*d4089fb8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf $(march-directive)
288c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
289c8a992fdSorigin
290c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
291c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
292c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
293641f16e7SAmbroise Vincent	endif
294c8a992fdSorigin
295c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
296c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
297c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
298edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
299*d4089fb8SGovindraj Raja	TF_CFLAGS_aarch32	=	$(march-directive)
300*d4089fb8SGovindraj Raja	TF_CFLAGS_aarch64	=	$(march-directive)
301edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
302edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
303edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
304edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
305edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
306edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
307edbce9aaSzelalem-aweke		endif
308edbce9aaSzelalem-aweke	endif
309edbce9aaSzelalem-aweke	LD			=	$(LINKER)
310d5461857Sdp-armelse
311*d4089fb8SGovindraj Raja	TF_CFLAGS_aarch32	=	$(march-directive)
312*d4089fb8SGovindraj Raja	TF_CFLAGS_aarch64	=	$(march-directive)
3132adee763SRoberto Vargas	LD			=	$(LINKER)
314c5e1da83SJayanth Dodderi Chidanandendif #(clang)
315d5461857Sdp-arm
31632b209bfSAhmad Fatoum# Process Debug flag
31732b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
31832b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
31932b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
3204466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
3214466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
32232b209bfSAhmad Fatoum
32332b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
32432b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
32532b209bfSAhmad Fatoumelse
32632b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
32732b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
32832b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
329c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
33032b209bfSAhmad Fatoum
331f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
332f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
333f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
334f1de4c8fSPeiyuan Songendif
335dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
336f1de4c8fSPeiyuan Song
3378fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3388fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
3398fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3408fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
3418fd9d4d5SAntonio Nino Diazelse
3428fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
343c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
3448fd9d4d5SAntonio Nino Diaz
345a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
346d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3479d29c227SSoby Mathew
3489fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3499fc59639SAlexei Fedorov	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
350c5e1da83SJayanth Dodderi Chidanandendif #(BP_OPTION)
3519fc59639SAlexei Fedorov
352*d4089fb8SGovindraj RajaASFLAGS		+=	$(march-directive)
353b86048c4SAntonio Nino Diaz
354c5e1da83SJayanth Dodderi Chidanand##############################################################################
355c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
356c5e1da83SJayanth Dodderi Chidanand###############################################################################
3579ab81b5eSJustin Chadwell# General warnings
3589ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
359b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
360d75a9ecdSBoyan Karatotev				-Wredundant-decls
361d75a9ecdSBoyan Karatotev# stricter warnings
362d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
363d75a9ecdSBoyan Karatotev# too verbose for generic build
364d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
365d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
366d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
367d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
3689ab81b5eSJustin Chadwell
3699ab81b5eSJustin Chadwell# Additional warnings
370d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
371d75a9ecdSBoyan Karatotev# full -Wextra
372d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
373d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
374d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
375e7c645b5SYann Gautier
376d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
377d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
378d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
379d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
380d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
381d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
382d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
383d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
384d141e638SBoyan Karatotev# currently very involved and many platforms set this off
385d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
386e7c645b5SYann Gautier
387d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
388e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
389d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
390d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
391d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
392e7c645b5SYann GautierWARNING3 += -Wcast-qual
393e7c645b5SYann GautierWARNING3 += -Wconversion
394e7c645b5SYann GautierWARNING3 += -Wpacked
395e7c645b5SYann GautierWARNING3 += -Wpointer-arith
396e7c645b5SYann GautierWARNING3 += -Wswitch-default
397e7c645b5SYann Gautier
398d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
399d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
400d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
401d75a9ecdSBoyan Karatotevifdef W
402d75a9ecdSBoyan Karatotev	ifneq (${W},0)
403d75a9ecdSBoyan Karatotev		E	 ?= 0
404d75a9ecdSBoyan Karatotev	endif
405d75a9ecdSBoyan Karatotevendif
406d75a9ecdSBoyan Karatotev
407e7c645b5SYann Gautierifeq (${W},1)
4089ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
409e7c645b5SYann Gautierelse ifeq (${W},2)
4109ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
411e7c645b5SYann Gautierelse ifeq (${W},3)
4129ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
413c5e1da83SJayanth Dodderi Chidanandendif #(W)
414e7c645b5SYann Gautier
4159ab81b5eSJustin Chadwell# Compiler specific warnings
41600296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
41793c690ebSJustin Chadwell# not using clang
418d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
419d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
420d7b4cd41SJustin Chadwell				-Wlogical-op
421dea23e24SGovindraj Raja
422dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
423dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
424dea23e24SGovindraj Raja
42593c690ebSJustin Chadwellelse
42693c690ebSJustin Chadwell# using clang
427d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
428d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
429c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
43000296576SAmbroise Vincent
4316336b07aSYann Gautierifneq (${E},0)
4326336b07aSYann Gautier	ERRORS := -Werror
433c5e1da83SJayanth Dodderi Chidanandendif #(E)
4346336b07aSYann Gautier
435c5e1da83SJayanth Dodderi Chidanand################################################################################
436c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
437c5e1da83SJayanth Dodderi Chidanand################################################################################
438ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
4399ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
440*d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
441d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
44259de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
443ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
444ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
445ebd6efaeSSamuel Holland				-Os -std=gnu99
44673c99d4eSJuan Castillo
4471f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4481f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
449c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
450c5e1da83SJayanth Dodderi Chidanand
4511f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4521f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
4531f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
454c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
4551f461979SJustin Chadwell
456f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
457f7ec31dbSdavid cunado
4581f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
4591f49db5fSMarco Felsch
460641f16e7SAmbroise Vincent# LD = armlink
461c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
462c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
463c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
464edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
465641f16e7SAmbroise Vincent
466641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
467edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
468edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
469edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
470edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
471ac98b82aSChris Kay
472ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
473ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
474ac98b82aSChris Kay
475edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
476edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
477edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
478edbce9aaSzelalem-aweke		endif
479c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
480c5e1da83SJayanth Dodderi Chidanand
481edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
482edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
483edbce9aaSzelalem-aweke	ifneq (${ERRATA_A53_843419},1)
484edbce9aaSzelalem-aweke		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
485edbce9aaSzelalem-aweke	endif
486edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
487edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
488641f16e7SAmbroise Vincent
489641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
490c2ad38ceSVarun Wadekarelse
4911f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
4921f49db5fSMarco Felsch# are not loaded by a elf loader.
4931f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
494ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
495c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
496ac98b82aSChris Kay
497ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
498ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
499ac98b82aSChris Kay
500641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
501ebac6922SYabin Cui# therefore don't add those in that case.
502ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
503ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
504641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
505ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
506edbce9aaSzelalem-aweke	endif
507c5e1da83SJayanth Dodderi Chidanand
508c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
50973c99d4eSJuan Castillo
51003b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
511a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
512a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
51303b397a8SNishanth Menon
51473c99d4eSJuan Castillo################################################################################
51573c99d4eSJuan Castillo# Common sources and include directories
51673c99d4eSJuan Castillo################################################################################
5176a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
518d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
51973c99d4eSJuan Castillo
52073c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
5217f56e9a3SSoby Mathew				common/tf_log.c				\
5229d29c227SSoby Mathew				common/${ARCH}/debug.S			\
52391b48c9fSJulius Werner				drivers/console/multi_console.c		\
5249d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
5259d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
526566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
5277f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
52875311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
5299d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
53061f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
531d7a6b0f8SRyan Harkin
53290ce8b87SBoyan Karatotev# Pointer Authentication sources
53390ce8b87SBoyan Karatotevifeq (${ENABLE_PAUTH}, 1)
53490ce8b87SBoyan Karatotev# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
53590ce8b87SBoyan Karatotev# Pauth support. As it's not secure, it must be reimplemented for real platforms
53690ce8b87SBoyan Karatotev	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
53790ce8b87SBoyan Karatotevendif
53890ce8b87SBoyan Karatotev
5398422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
5408422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
5418422a840SAntonio Nino Diazendif
5428422a840SAntonio Nino Diaz
5431f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
5441f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
5451f461979SJustin Chadwellendif
5461f461979SJustin Chadwell
54701d237cbSYann GautierINCLUDES		+=	-Iinclude				\
548f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
54909d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
55009d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
55109d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
55209d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
55309d40e0eSAntonio Nino Diaz
5549c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5559c6d1c50SAntonio Nino Diaz
55673c99d4eSJuan Castillo################################################################################
55773c99d4eSJuan Castillo# Generic definitions
55873c99d4eSJuan Castillo################################################################################
559231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
560231c1470SEvan Lloyd
56129214e95SGrant Likelyifeq (${BUILD_BASE},)
56273c99d4eSJuan Castillo     BUILD_BASE		:=	./build
56329214e95SGrant Likelyendif
56429214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
56573c99d4eSJuan Castillo
566231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
56773c99d4eSJuan Castillo
56873c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
56973c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
57073c99d4eSJuan Castillo
57173c99d4eSJuan Castillo################################################################################
57273c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
57373c99d4eSJuan Castillo################################################################################
57473c99d4eSJuan Castillo
57573c99d4eSJuan Castilloifneq (${SPD},none)
5769d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5779d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5789d29c227SSoby Mathew	endif
57928f39f02SMax Shvetsov
5804c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5814c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
582c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
583c5e1da83SJayanth Dodderi Chidanand                ignored.")
5844c117f6cSSandrine Bailleux	endif
58528f39f02SMax Shvetsov
586c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
587c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
588c3fb00d9SAchin Gupta		SPD_DIR := std_svc
58928f39f02SMax Shvetsov
590033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
591f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5921d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
5931d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5941d63ae4dSMarc Bonnici			endif
59528f39f02SMax Shvetsov		endif
596db1ef41aSOlivier Deprez
597db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
598db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
599db1ef41aSOlivier Deprez		endif
600ca932481SDavidson K
601ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
602ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
603ca932481SDavidson K		endif
60433993a37SBalint Dobszay
60533993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
60633993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
60733993a37SBalint Dobszay		endif
60846789a7cSBalint Dobszay
60946789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
61046789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
61146789a7cSBalint Dobszay		endif
612c3fb00d9SAchin Gupta	else
613c3fb00d9SAchin Gupta		# All other SPDs in spd directory
614c3fb00d9SAchin Gupta		SPD_DIR := spd
615c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
616c3fb00d9SAchin Gupta
61773c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
618c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
619c3fb00d9SAchin Gupta
62073c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
621c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
62273c99d4eSJuan Castillo	endif
62373c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
62473c99d4eSJuan Castillo        include ${SPD_MAKE}
62573c99d4eSJuan Castillo
62670d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
62770d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
62870d1fc53SJuan Castillo	# supports two mutually exclusive options:
62970d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
63070d1fc53SJuan Castillo	#   of source files to build BL32
63170d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
63270d1fc53SJuan Castillo	#   that will be included in the FIP
63370d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
63470d1fc53SJuan Castillo	# over the sources.
635c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
636e35c4045SJeenu Viswambharan
637f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
638f1910cc1SGovindraj Raja	ifeq (${SPD},none)
639f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
640c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
641c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
642f1910cc1SGovindraj Raja		endif
643f1910cc1SGovindraj Raja	endif
644f1910cc1SGovindraj Rajaendif
645f1910cc1SGovindraj Raja
64651faada7SDouglas Raillard################################################################################
6475b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6485b18de09SZelalem Aweke################################################################################
6495b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6505b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6515b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6525b18de09SZelalem Aweke	endif
6531d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6541d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6551d63ae4dSMarc Bonnici	endif
656c5e1da83SJayanth Dodderi Chidanand
6574fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6584fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6594fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6604fba2e1fSBoyan Karatotev		endif
6614fba2e1fSBoyan Karatotev	endif
6625b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6635b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6645b18de09SZelalem Awekeendif
6655b18de09SZelalem Aweke
6665b18de09SZelalem Aweke################################################################################
66773c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
66873c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
66973c99d4eSJuan Castillo################################################################################
6702da8d8bfSJeenu Viswambharan
67173c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6720f21c547SJuan Castillo
67342d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
67442d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
67542d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
67642d4d3baSArvind Ram Prakash# BL2 in EL3
67742d4d3baSArvind Ram Prakash
67842d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
67942d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68042d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
681c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
682c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
68342d4d3baSArvind Ram Prakash	endif
68442d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
68542d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68642d4d3baSArvind Ram Prakashelse
68742d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
68842d4d3baSArvind Ram Prakashendif
68942d4d3baSArvind Ram Prakash
6908012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6918012cc5cSMasahiro Yamada
69226e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
69326e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
69426e63c44SEtienne Carriereendif
69526e63c44SEtienne Carriere
6963bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6973bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6983bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6997b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7007b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7017b592418SSamuel Hollandendif
702c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
703320920c1SMasahiro Yamada
704320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
705320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
706320920c1SMasahiro Yamadaelse
707320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
708320920c1SMasahiro Yamadaendif
709320920c1SMasahiro Yamada
710320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71142d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71269af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
713966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
71469af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
71569af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
716c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
717c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
718966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
719320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
720320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
721966660ecSChris Kay
722966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
723d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
724d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
725c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7263bd17c0fSSoby Mathew
727007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
728007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
729007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
730007433d8SBoyan Karatotev
7319cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73242d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7339cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
734d5e97a1dSMasahiro Yamadaelse
7359cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
736c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
737007433d8SBoyan Karatotev
738007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7399cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7409cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7419cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
742007433d8SBoyan Karatotevelse
743007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
744d5e97a1dSMasahiro Yamadaendif
745d5e97a1dSMasahiro Yamada
74654035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
74754035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
74854035fc4SSandrine Bailleux# This can be overridden by the platform.
74973c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7504f6ad66aSAchin Gupta
751a4409008Sdp-arm################################################################################
752a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
753a4409008Sdp-arm################################################################################
754c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
755c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
756c5e1da83SJayanth Dodderi Chidanand
757a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
758a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
759a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
760a4409008Sdp-arm
761a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
762a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
763a4409008Sdp-arm                endif
764a4409008Sdp-arm        $(info Including ${AARCH32_SP_MAKE})
765a4409008Sdp-arm        include ${AARCH32_SP_MAKE}
766a4409008Sdp-arm        endif
767c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7684f6ad66aSAchin Gupta
76973c99d4eSJuan Castillo################################################################################
77077f1f7a1SVarun Wadekar# Include libc if not overridden
77177f1f7a1SVarun Wadekar################################################################################
77277f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
77377f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
77477f1f7a1SVarun Wadekarendif
77577f1f7a1SVarun Wadekar
77677f1f7a1SVarun Wadekar################################################################################
777c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
778cf2c8a33SAntonio Nino Diaz################################################################################
779cf2c8a33SAntonio Nino Diaz
780c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
781c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
782c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
783c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
784c5e1da83SJayanth Dodderi Chidanand        else
785c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
786c5e1da83SJayanth Dodderi Chidanand        endif
787c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
788c5e1da83SJayanth Dodderi Chidanand
789c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
790c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
791c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
792c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
793c5e1da83SJayanth Dodderi Chidanand        endif
794c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
795c5e1da83SJayanth Dodderi Chidanand
796c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
797c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
798c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
799c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
800c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
801c5e1da83SJayanth Dodderi Chidanandendif
802c5e1da83SJayanth Dodderi Chidanand
803c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
804c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
805c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
806c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
807c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
808c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
809c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
810c5e1da83SJayanth Dodderi Chidanand
811cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81268450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
81368450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
81468450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
815cf2c8a33SAntonio Nino Diaz	endif
81676580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
817c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
818c5e1da83SJayanth Dodderi Chidanand                build options.")
81976580f3dSQixiang Xu	endif
82076580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
821c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
822c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
82376580f3dSQixiang Xu	endif
824c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
825cf2c8a33SAntonio Nino Diaz
826cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
827cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
828cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
829cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
830cf2c8a33SAntonio Nino Diaz	endif
83168450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83268450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
833c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
834cf2c8a33SAntonio Nino Diaz	endif
835c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
836cf2c8a33SAntonio Nino Diaz
837d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
838d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
839d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
840d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
841d4593e47SJeenu Viswambharanendif
8421a0a3f06SYatharth Kochar
84342d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
84442d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
84542d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8467d173fc5SJiafei Panendif
8477d173fc5SJiafei Pan
8489202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
84914c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
850c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
851c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8529202d519SManish Pandeyendif
853c5e1da83SJayanth Dodderi Chidanand
8549202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8559202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8569202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8579202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8589202d519SManish Pandey	endif
85946cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8609202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
86114c6016aSJeenu Viswambharan	endif
862c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
863c5e1da83SJayanth Dodderi Chidanand
8649202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8651a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8666503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8676503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8681a7c1cfeSJeenu Viswambharan	endif
869c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8701a7c1cfeSJeenu Viswambharan
871ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
872209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
873209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
874c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
875c5e1da83SJayanth Dodderi Chidanand                to be set.")
876209a60ccSSoby Mathew	endif
877c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
878209a60ccSSoby Mathew
8792bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8802bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8812bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8822bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8832bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8842bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8852bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8862bf4f27fSManish V Badarkhe# Support hash calculation only
8872bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8882bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8892bf4f27fSManish V Badarkhe# Support authentication verification only
890c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
891c9c56f6eSManish V Badarkheelse
892c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
893c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
894c9c56f6eSManish V Badarkhe
895cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
896cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
897700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
89884ef9cd8SManish V Badarkheendif
89984ef9cd8SManish V Badarkhe
900b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9019fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9029fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
903b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9049fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9059fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
90606715f85SAlexei Fedorov	endif
907c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9089fc59639SAlexei Fedorov
90906715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9109fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9119fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
912b86048c4SAntonio Nino Diaz	endif
913c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9149fc59639SAlexei Fedorov
9159dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9169dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9179dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9189dd94382SJustin Chadwell	endif
919c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9209dd94382SJustin Chadwell
921396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
922396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
923c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
924396b339dSManish V Badarkhe
9256a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9266a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
927c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9286a0da736SJayanth Dodderi Chidanand
92903d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
93003d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
931c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
932c5e1da83SJayanth Dodderi Chidanand                to be set")
93303d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
93403d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
93503d3c0d7SJayanth Dodderi Chidanand	endif
936c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
93745007acdSJayanth Dodderi Chidanand
93860e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
93960e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
940c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
941c5e1da83SJayanth Dodderi Chidanand                library v2")
94260e8f3cfSPetre-Ionut Tudor	endif
943c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
94460e8f3cfSPetre-Ionut Tudor
9457cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9467cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
947c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
948c5e1da83SJayanth Dodderi Chidanand                to be set)
9497cda17bbSSumit Garg	endif
950c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9517cda17bbSSumit Garg
952744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
953dc78e62dSjohpow01ifeq (${ARCH},aarch32)
954744ad974Sjohpow01
955744ad974Sjohpow01	# SME/SVE only supported on AArch64
95645007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
957dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
958dc78e62dSjohpow01	endif
95903d3c0d7SJayanth Dodderi Chidanand
960dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
961dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96224ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
963dc78e62dSjohpow01	endif
964744ad974Sjohpow01
965ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
966744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
967744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
968744ad974Sjohpow01	endif
969744ad974Sjohpow01
970ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
971ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
972ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
973ff86e0b4SJuan Pablo Conde	endif
974c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
975dc78e62dSjohpow01
976dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
977dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
97845007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
979dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
980dc78e62dSjohpow01	endif
981dc78e62dSjohpow01endif
982dc78e62dSjohpow01
9830d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9840d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9850d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9860d122947SBoyan Karatotev	endif
987c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9880d122947SBoyan Karatotev
989dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
990dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
991dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
992dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
993dc78e62dSjohpow01	endif
9940d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9950d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9960d122947SBoyan Karatotev	endif
997c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
998c5e1da83SJayanth Dodderi Chidanand
999dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1000dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1001dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1002dc78e62dSjohpow01	endif
1003c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1004dc78e62dSjohpow01
1005dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1006dc78e62dSjohpow01# its own context management including FPU registers.
1007dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
100845007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1009dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1010dc78e62dSjohpow01	endif
101103d3c0d7SJayanth Dodderi Chidanand
1012dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1013dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1014dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1015dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1016dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1017dc78e62dSjohpow01	endif
1018c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1019dc78e62dSjohpow01
102000e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
102100e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102200e28874SManish V Badarkheendif
102300e28874SManish V Badarkhe
1024274a69e7SChris Kayifeq (${ENABLE_RME},1)
1025274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1026274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1027274a69e7SChris Kay	endif
1028274a69e7SChris Kayendif
1029274a69e7SChris Kay
1030c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1031c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1032c5e1da83SJayanth Dodderi Chidanand
1033c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1034c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1035c5e1da83SJayanth Dodderi Chidanand
1036cf2c8a33SAntonio Nino Diaz################################################################################
103773c99d4eSJuan Castillo# Process platform overrideable behaviour
103873c99d4eSJuan Castillo################################################################################
10394f6ad66aSAchin Gupta
10405f24ce96SManish Pandeyifdef BL1_SOURCES
10415f24ce96SManish Pandey	NEED_BL1 := yes
1042c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10435f24ce96SManish Pandey
10445f24ce96SManish Pandeyifdef BL2_SOURCES
10455f24ce96SManish Pandey	NEED_BL2 := yes
10465f24ce96SManish Pandey
1047bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1048bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1049cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1050cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1051cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10524c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1053cf2c8a33SAntonio Nino Diaz	else
105468450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1055cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1056cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1057cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1058cf2c8a33SAntonio Nino Diaz		else
1059cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1060cf2c8a33SAntonio Nino Diaz		endif
10614c117f6cSSandrine Bailleux	endif
1062c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10636f971622SJuan Castillo
10645f24ce96SManish Pandeyifdef BL2U_SOURCES
10655f24ce96SManish Pandey	NEED_BL2U := yes
1066c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10675f24ce96SManish Pandey
10684d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10694d045d0eSMasahiro Yamadaifdef SCP_BL2
10704d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1071c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10724d045d0eSMasahiro Yamada
10735744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10745744e874SSoby Mathewifneq (${ARCH},aarch32)
10755744e874SSoby Mathew	ifdef BL31_SOURCES
1076c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1077c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10785744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10795744e874SSoby Mathew			NEED_BL31 := yes
10805744e874SSoby Mathew		endif
10815744e874SSoby Mathew	endif
1082c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10835744e874SSoby Mathew
108473c99d4eSJuan Castillo# Process TBB related flags
10856f971622SJuan Castilloifneq (${GENERATE_COT},0)
108673c99d4eSJuan Castillo	# Common cert_create options
10876f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10886f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10890191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1090fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1091fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10920191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1093fd34e7baSJuan Castillo		endif
10946f971622SJuan Castillo	endif
109573c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
109673c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
109773c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
109873c99d4eSJuan Castillo	endif
1099c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11006f971622SJuan Castillo
11011c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11021c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1103c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11041c75d5dfSMasahiro Yamada
11055f24ce96SManish Pandeyifdef FDT_SOURCES
11065f24ce96SManish Pandey	NEED_FDT := yes
1107c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11085f24ce96SManish Pandey
110973c99d4eSJuan Castillo################################################################################
111046e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
111146e5e035SMichalis Pappas################################################################################
111246e5e035SMichalis Pappas
111346e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
111446e5e035SMichalis Pappas
111546e5e035SMichalis Pappas################################################################################
11168a86052dSSoby Mathew# Include BL specific makefiles
11178a86052dSSoby Mathew################################################################################
11185f24ce96SManish Pandey
11195f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11208a86052dSSoby Mathewinclude bl1/bl1.mk
11218a86052dSSoby Mathewendif
11228a86052dSSoby Mathew
11235f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11248a86052dSSoby Mathewinclude bl2/bl2.mk
11258a86052dSSoby Mathewendif
11268a86052dSSoby Mathew
11275f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11288a86052dSSoby Mathewinclude bl2u/bl2u.mk
11298a86052dSSoby Mathewendif
11308a86052dSSoby Mathew
11315744e874SSoby Mathewifeq (${NEED_BL31},yes)
11328a86052dSSoby Mathewinclude bl31/bl31.mk
11338a86052dSSoby Mathewendif
113403b397a8SNishanth Menon
113573c99d4eSJuan Castillo################################################################################
113673c99d4eSJuan Castillo# Build options checks
113773c99d4eSJuan Castillo################################################################################
113873c99d4eSJuan Castillo
1139c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1140327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1141327131c4SLeonardo Sandoval    $(sort \
1142327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
114346789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1144327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1145327131c4SLeonardo Sandoval	CREATE_KEYS \
1146327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1147327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1148327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1149327131c4SLeonardo Sandoval	DEBUG \
11500063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1151327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1152327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11531fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1154742ca230SChris Kay	ENABLE_AMU_FCONF \
1155873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1156327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
115724077098SAndre Przywara	ENABLE_FEAT_SB \
1158327131c4SLeonardo Sandoval	ENABLE_PIE \
1159327131c4SLeonardo Sandoval	ENABLE_PMF \
1160327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1161327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1162dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11630c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1164327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1165327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1166327131c4SLeonardo Sandoval	GENERATE_COT \
1167327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
116846cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1169327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1170327131c4SLeonardo Sandoval	MEASURED_BOOT \
117100e28874SManish V Badarkhe	DRTM_SUPPORT \
1172327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1173327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1174327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11750ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1176327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1177327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
117864b4710bSWing Li	PSCI_OS_INIT_MODE \
1179327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1180327131c4SLeonardo Sandoval	SAVE_KEYS \
1181327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
118296a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1183327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1184327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1185327131c4SLeonardo Sandoval	SPM_MM \
11861d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1187327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1188327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1189327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1190327131c4SLeonardo Sandoval	USE_DEBUGFS \
1191327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1192327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1193327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1194327131c4SLeonardo Sandoval	USE_ROMLIB \
1195327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1196327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
119742d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1198327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1199327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1200327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1201327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1202327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1203327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
120400e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1205327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1206327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1207396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
120868120783SChris Kay	ENABLE_MPMM \
120968120783SChris Kay	ENABLE_MPMM_FCONF \
12106a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12110b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1212ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1213ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
121404c7303bSOkash Khawaja	CONDITIONAL_CMO \
12159202d519SManish Pandey	RAS_FFH_SUPPORT \
1216327131c4SLeonardo Sandoval)))
121773c99d4eSJuan Castillo
1218c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1219327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1220327131c4SLeonardo Sandoval    $(sort \
1221327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1222327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1223327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12246a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12256a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12266a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12272bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
12281298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
122947c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12306a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12316a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1232d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12336a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12346a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12359202d519SManish Pandey	ENABLE_FEAT_RAS	\
12366a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12376a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12386a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12396a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12406a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12416a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1242ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12436a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1244d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1245062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1246062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1247062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1248062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1249688ab57bSMark Brown	ENABLE_FEAT_GCS \
12506a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12516a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12526a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12536437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1254603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
125545007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
125603d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12572b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12586a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1259327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12605357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12615357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1262781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1263781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1264bebcf27fSMark Brown	SVE_VECTOR_LEN \
12650ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1266327131c4SLeonardo Sandoval)))
1267c877b414SJeenu Viswambharan
1268aacff749SJustin Chadwellifdef KEY_SIZE
1269aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1270aacff749SJustin Chadwellendif
1271aacff749SJustin Chadwell
12721f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12731f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12741f461979SJustin Chadwellendif
12751f461979SJustin Chadwell
127673c99d4eSJuan Castillo################################################################################
127773c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
127873c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
127973c99d4eSJuan Castillo# platform to overwrite the default options
128073c99d4eSJuan Castillo################################################################################
128173c99d4eSJuan Castillo
1282327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1283327131c4SLeonardo Sandoval    $(sort \
1284327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1285327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1286327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
128746789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1288327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1289327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1290327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1291327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1292327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1293327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1294327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1295062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1296327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
12970063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1298d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12991fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1300742ca230SChris Kay	ENABLE_AMU_FCONF \
1301873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1302327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1303327131c4SLeonardo Sandoval	ENABLE_BTI \
1304327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1305327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1306327131c4SLeonardo Sandoval	ENABLE_PIE \
1307327131c4SLeonardo Sandoval	ENABLE_PMF \
1308327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13095b18de09SZelalem Aweke	ENABLE_RME \
1310327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1311dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131203d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1313dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
131490118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1315327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13160c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1317327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1318327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1319327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1320327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1321327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132246cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1323327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1324327131c4SLeonardo Sandoval	LOG_LEVEL \
1325327131c4SLeonardo Sandoval	MEASURED_BOOT \
132600e28874SManish V Badarkhe	DRTM_SUPPORT \
1327327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1328327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1329327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13300ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1331327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1332327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
133364b4710bSWing Li	PSCI_OS_INIT_MODE \
13349202d519SManish Pandey	ENABLE_FEAT_RAS \
13359202d519SManish Pandey	RAS_FFH_SUPPORT \
1336327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1337327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
133896a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1339327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1340327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1341327131c4SLeonardo Sandoval	SPD_${SPD} \
1342327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1343327131c4SLeonardo Sandoval	SPM_MM \
13441d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1345327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1346327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1347c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13487dfb9911SJimmy Brisson	TRNG_SUPPORT \
1349ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1350ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1351327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1352327131c4SLeonardo Sandoval	USE_DEBUGFS \
1353327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1354327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1355327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1356327131c4SLeonardo Sandoval	USE_ROMLIB \
1357327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1358327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
135942d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
136042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1361327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1362327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1363327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1364327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
136500e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1366327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1367327131c4SLeonardo Sandoval	USE_SP804_TIMER \
136812cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1369ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13704e04478aSChris Kay	ENABLE_FEAT_SB \
13717d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13725357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13735357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1374396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1375744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1376813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1377d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13788fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1379cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
138068120783SChris Kay	ENABLE_MPMM \
138168120783SChris Kay	ENABLE_MPMM_FCONF \
1382f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1383f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13846a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13856a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13866a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13876a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13886a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1389d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1390062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1391062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1392062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1393062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1394688ab57bSMark Brown	ENABLE_FEAT_GCS \
13956a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1396781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1397781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
139804c7303bSOkash Khawaja	CONDITIONAL_CMO \
13990ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1400a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1401327131c4SLeonardo Sandoval)))
14022fae4b1eSJeenu Viswambharan
14031f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14041f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1405c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14061f461979SJustin Chadwell
14074c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14084c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14094c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1410cf2c8a33SAntonio Nino Diazelse
141168450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
141268450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
141368450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
141468450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14154c117f6cSSandrine Bailleux	endif
1416c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
141773c99d4eSJuan Castillo
1418209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1419209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1420209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1421209a60ccSSoby Mathewendif
1422209a60ccSSoby Mathew
1423c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1424c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1425c2ad38ceSVarun Wadekarendif
1426c2ad38ceSVarun Wadekar
1427ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1428ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1429c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1430ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1431ce2b1ec6SManish Pandey	FIP_DEPS += sp
143207c44475SManish Pandey	CRT_DEPS += sp
1433ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1434ce2b1ec6SManish Pandeyelse
1435c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1436c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1437c33ff198SOlivier Deprez	endif
1438c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1439c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1440ce2b1ec6SManish Pandey
144173c99d4eSJuan Castillo################################################################################
144273c99d4eSJuan Castillo# Build targets
144373c99d4eSJuan Castillo################################################################################
144473c99d4eSJuan Castillo
144590aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
144673c99d4eSJuan Castillo.SUFFIXES:
144773c99d4eSJuan Castillo
144873c99d4eSJuan Castilloall: msg_start
144973c99d4eSJuan Castillo
145073c99d4eSJuan Castillomsg_start:
145173c99d4eSJuan Castillo	@echo "Building ${PLAT}"
145273c99d4eSJuan Castillo
14537a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1454d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1455c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1456c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1457c2ad38ceSVarun Wadekarelse
1458bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14597a24cba5SSoby Mathewendif
1460c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14617a24cba5SSoby Mathew
14625accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
146361f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14645fee0287SRoberto Vargas
146573c99d4eSJuan Castillo# Expand build macros for the different images
146673c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1467b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1468434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1469c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
147073c99d4eSJuan Castillo
147173c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1472c5e1da83SJayanth Dodderi Chidanand
147342d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1474c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1475c9b31ae8SRoberto Vargasendif
1476c9b31ae8SRoberto Vargas
1477eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1478eb1acfb6SChris Kay
147933950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1480434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1481c5e1da83SJayanth Dodderi Chidanand
1482c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
148373c99d4eSJuan Castillo
14844d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
148533950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1486c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14874d045d0eSMasahiro Yamada
148873c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
148973c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
149026d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
149126d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1492c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1493c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1494434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1495c6ba9b45SSumit Gargelse
149633950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1497434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1498c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1499c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
150073c99d4eSJuan Castillo
150170d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1502c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
150370d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
150473c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
150526d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
150626d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15079cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15089cd15239SMasahiro Yamada
1509c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1510434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1511c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1512c6ba9b45SSumit Gargelse
1513434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
151433950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1515c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1516c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
151773c99d4eSJuan Castillo
15185b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15195b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15205b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15215b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15225b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15235b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15245b18de09SZelalem Aweke
15255b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15265b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1527c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15285b18de09SZelalem Aweke
152973c99d4eSJuan Castillo# Add the BL33 image if required by the platform
153073c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
153133950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1532c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1533db6071c9SJuan Castillo
15349003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
153533950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1536434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1537c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15389003fa0bSYatharth Kochar
153903b397a8SNishanth Menon# Expand build macros for the different images
154003b397a8SNishanth Menonifeq (${NEED_FDT},yes)
154103b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1542c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
154303b397a8SNishanth Menon
1544ce2b1ec6SManish Pandey# Add Secure Partition packages
1545ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1546ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
15471e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1548822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1549ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1550ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1551ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1552c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1553ce2b1ec6SManish Pandey
155436eaaf37SIan Spraylocate-checkpatch:
155536eaaf37SIan Sprayifndef CHECKPATCH
155666079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
155736eaaf37SIan Sprayelse
155836eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
155966079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156036eaaf37SIan Sprayendif
1561c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
156236eaaf37SIan Spray
15634f6ad66aSAchin Guptaclean:
15644f6ad66aSAchin Gupta	@echo "  CLEAN"
1565f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
156688a1cf1eSSami Mujawarifdef UNIX_MK
15672f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
156888a1cf1eSSami Mujawarelse
156988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
157088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
157188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1572c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15736f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
157490aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15755accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15764f6ad66aSAchin Gupta
1577eaaeece2SJames Morrisseyrealclean distclean:
1578eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1579f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1580f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
158188a1cf1eSSami Mujawarifdef UNIX_MK
15822f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
158388a1cf1eSSami Mujawarelse
158488a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
158588a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
158688a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1587c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1588e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
158990aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
15905accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15914f6ad66aSAchin Gupta
159236eaaf37SIan Spraycheckcodebase:		locate-checkpatch
159336eaaf37SIan Spray	@echo "  CHECKING STYLE"
159436eaaf37SIan Spray	@if test -d .git ; then						\
15951ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
15961a41e8c1SDan Handley		while read GIT_FILE ;					\
15971a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
15981a41e8c1SDan Handley		done ;							\
159936eaaf37SIan Spray	else								\
16001a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16011a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16021a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
160361f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16041a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16051ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16061a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
160736eaaf37SIan Spray	fi
160836eaaf37SIan Spray
160936eaaf37SIan Spraycheckpatch:		locate-checkpatch
161036eaaf37SIan Spray	@echo "  CHECKING STYLE"
161102a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
161202a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
161302a76d5fSYann Gautier	fi
161451d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
161577a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
161677a0a7f1SYann Gautier	do								\
161751d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
161851d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
161902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162002a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
162151d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
162202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162302a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
162451d28937SAntonio Nino Diaz	done
162536eaaf37SIan Spray
162673c99d4eSJuan Castillocerttool: ${CRTTOOL}
162773c99d4eSJuan Castillo
1628a9812206SPali Rohár${CRTTOOL}: FORCE
1629598b166bSLionel 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
1630f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16316f971622SJuan Castillo	@echo "Built $@ successfully"
1632f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16336f971622SJuan Castillo
16346f971622SJuan Castilloifneq (${GENERATE_COT},0)
163573c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16366f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1637f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16386f971622SJuan Castillo	@echo "Built $@ successfully"
16396f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1640f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1641c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
164227713fb4SSoby Mathew
164373c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16444727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1645819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1646819281eeSdp-arm	${Q}${FIPTOOL} info $@
1647f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16482f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1649f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1650f58ad36fSHarry Liebel
16510191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16520191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16530191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1654052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16550191262dSYatharth Kochar	@echo "Built $@ successfully"
16560191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1657052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1658c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16590191262dSYatharth Kochar
16600191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16614727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1662819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1663819281eeSdp-arm	${Q}${FIPTOOL} info $@
1664052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16650191262dSYatharth Kochar	@echo "Built $@ successfully"
1666052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16670191262dSYatharth Kochar
166873c99d4eSJuan Castillofiptool: ${FIPTOOL}
166973c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16700191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
167173c99d4eSJuan Castillo
1672a9812206SPali Rohár${FIPTOOL}: FORCE
167388a1cf1eSSami Mujawarifdef UNIX_MK
1674598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
167588a1cf1eSSami Mujawarelse
167688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
167788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
167888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1679c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1680f58ad36fSHarry Liebel
1681a9812206SPali Rohárromlib.bin: libraries FORCE
1682bbb24f61SJohn 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
16835accce5bSRoberto Vargas
1684cfe83910SLouis Mayencourtmemmap: all
1685af5b49e9SHarrison Mutaiifdef UNIX_MK
1686af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1687af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1688af5b49e9SHarrison Mutaielse
1689af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1690af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1691af5b49e9SHarrison Mutaiendif
1692cfe83910SLouis Mayencourt
16936de32378SMadhukar Pappireddydoc:
16946de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
16956de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
16966de32378SMadhukar Pappireddy
169790aa901fSSumit Gargenctool: ${ENCTOOL}
169890aa901fSSumit Garg
1699a9812206SPali Rohár${ENCTOOL}: FORCE
1700598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
170190aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170290aa901fSSumit Garg	@echo "Built $@ successfully"
170390aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170490aa901fSSumit Garg
170535fab8c9SJoakim Bechcscope:
170635fab8c9SJoakim Bech	@echo "  CSCOPE"
170735fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
170835fab8c9SJoakim Bech	${Q}cscope -b -q -k
170935fab8c9SJoakim Bech
171072ee3314SRyan Harkinhelp:
17117c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
171272ee3314SRyan Harkin	@echo ""
171372ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
171408c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
171572ee3314SRyan Harkin	@echo ""
17167c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17177c23126cSJohn Tsichritzis	@echo ""
17181b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17191b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17201b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17211b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17221b578596SSandrine Bailleux	@echo ""
172372ee3314SRyan Harkin	@echo "Supported Targets:"
17241b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
172536eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17268aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17279003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1728d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17299d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17309d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
173173c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17321b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17330191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
173436eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
173536eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
173636eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
173772ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
173835fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
173972ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17406f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
174190aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1742f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1743ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
174426010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
174538c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1746cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17476de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
174872ee3314SRyan Harkin	@echo ""
17491b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
175072ee3314SRyan Harkin	@echo ""
175172ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
175272ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1753a9812206SPali Rohár
1754a9812206SPali Rohár.PHONY: FORCE
1755a9812206SPali RohárFORCE:;
1756