xref: /rk3399_ARM-atf/Makefile (revision c73686a11cea8f9d22d7df3c5480f8824cfeec09)
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
220d4089fb8SGovindraj 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)
227d4089fb8SGovindraj Raja		march-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
228fa6f774bSAlexei Fedorov	else
229d4089fb8SGovindraj 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))
275d4089fb8SGovindraj 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))),)
282d4089fb8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi $(march-directive)
283d4089fb8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi $(march-directive)
284c8a992fdSorigin		LD			:=	$(LINKER)
285c8a992fdSorigin	else
286d4089fb8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive) $(march-directive)
287d4089fb8SGovindraj 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))),)
299d4089fb8SGovindraj Raja	TF_CFLAGS_aarch32	=	$(march-directive)
300d4089fb8SGovindraj 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
311d4089fb8SGovindraj Raja	TF_CFLAGS_aarch32	=	$(march-directive)
312d4089fb8SGovindraj 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
352d4089fb8SGovindraj 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)
440d4089fb8SGovindraj 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		\
526*c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
527566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
5287f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
52975311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
5309d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
53161f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
532d7a6b0f8SRyan Harkin
53390ce8b87SBoyan Karatotev# Pointer Authentication sources
53490ce8b87SBoyan Karatotevifeq (${ENABLE_PAUTH}, 1)
53590ce8b87SBoyan Karatotev# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
53690ce8b87SBoyan Karatotev# Pauth support. As it's not secure, it must be reimplemented for real platforms
53790ce8b87SBoyan Karatotev	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
53890ce8b87SBoyan Karatotevendif
53990ce8b87SBoyan Karatotev
5408422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
5418422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
5428422a840SAntonio Nino Diazendif
5438422a840SAntonio Nino Diaz
5441f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
5451f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
5461f461979SJustin Chadwellendif
5471f461979SJustin Chadwell
54801d237cbSYann GautierINCLUDES		+=	-Iinclude				\
549f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
55009d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
55109d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
55209d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
55309d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
55409d40e0eSAntonio Nino Diaz
5559c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5569c6d1c50SAntonio Nino Diaz
55773c99d4eSJuan Castillo################################################################################
55873c99d4eSJuan Castillo# Generic definitions
55973c99d4eSJuan Castillo################################################################################
560231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
561231c1470SEvan Lloyd
56229214e95SGrant Likelyifeq (${BUILD_BASE},)
56373c99d4eSJuan Castillo     BUILD_BASE		:=	./build
56429214e95SGrant Likelyendif
56529214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
56673c99d4eSJuan Castillo
567231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
56873c99d4eSJuan Castillo
56973c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
57073c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
57173c99d4eSJuan Castillo
57273c99d4eSJuan Castillo################################################################################
57373c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
57473c99d4eSJuan Castillo################################################################################
57573c99d4eSJuan Castillo
57673c99d4eSJuan Castilloifneq (${SPD},none)
5779d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5789d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5799d29c227SSoby Mathew	endif
58028f39f02SMax Shvetsov
5814c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5824c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
583c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
584c5e1da83SJayanth Dodderi Chidanand                ignored.")
5854c117f6cSSandrine Bailleux	endif
58628f39f02SMax Shvetsov
587c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
588c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
589c3fb00d9SAchin Gupta		SPD_DIR := std_svc
59028f39f02SMax Shvetsov
591033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
592f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5931d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
5941d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5951d63ae4dSMarc Bonnici			endif
59628f39f02SMax Shvetsov		endif
597db1ef41aSOlivier Deprez
598db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
599db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
600db1ef41aSOlivier Deprez		endif
601ca932481SDavidson K
602ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
603ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
604ca932481SDavidson K		endif
60533993a37SBalint Dobszay
60633993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
60733993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
60833993a37SBalint Dobszay		endif
60946789a7cSBalint Dobszay
61046789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
61146789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
61246789a7cSBalint Dobszay		endif
613c3fb00d9SAchin Gupta	else
614c3fb00d9SAchin Gupta		# All other SPDs in spd directory
615c3fb00d9SAchin Gupta		SPD_DIR := spd
616c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
617c3fb00d9SAchin Gupta
61873c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
619c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
620c3fb00d9SAchin Gupta
62173c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
622c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
62373c99d4eSJuan Castillo	endif
62473c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
62573c99d4eSJuan Castillo        include ${SPD_MAKE}
62673c99d4eSJuan Castillo
62770d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
62870d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
62970d1fc53SJuan Castillo	# supports two mutually exclusive options:
63070d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
63170d1fc53SJuan Castillo	#   of source files to build BL32
63270d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
63370d1fc53SJuan Castillo	#   that will be included in the FIP
63470d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
63570d1fc53SJuan Castillo	# over the sources.
636c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
637e35c4045SJeenu Viswambharan
638f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
639f1910cc1SGovindraj Raja	ifeq (${SPD},none)
640f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
641c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
642c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
643f1910cc1SGovindraj Raja		endif
644f1910cc1SGovindraj Raja	endif
645f1910cc1SGovindraj Rajaendif
646f1910cc1SGovindraj Raja
64751faada7SDouglas Raillard################################################################################
6485b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6495b18de09SZelalem Aweke################################################################################
6505b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6515b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6525b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6535b18de09SZelalem Aweke	endif
6541d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6551d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6561d63ae4dSMarc Bonnici	endif
657c5e1da83SJayanth Dodderi Chidanand
6584fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6594fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6604fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6614fba2e1fSBoyan Karatotev		endif
6624fba2e1fSBoyan Karatotev	endif
6635b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6645b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6655b18de09SZelalem Awekeendif
6665b18de09SZelalem Aweke
6675b18de09SZelalem Aweke################################################################################
66873c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
66973c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
67073c99d4eSJuan Castillo################################################################################
6712da8d8bfSJeenu Viswambharan
67273c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6730f21c547SJuan Castillo
67442d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
67542d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
67642d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
67742d4d3baSArvind Ram Prakash# BL2 in EL3
67842d4d3baSArvind Ram Prakash
67942d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
68042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68142d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
682c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
683c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
68442d4d3baSArvind Ram Prakash	endif
68542d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
68642d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68742d4d3baSArvind Ram Prakashelse
68842d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
68942d4d3baSArvind Ram Prakashendif
69042d4d3baSArvind Ram Prakash
6918012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6928012cc5cSMasahiro Yamada
69326e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
69426e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
69526e63c44SEtienne Carriereendif
69626e63c44SEtienne Carriere
6973bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6983bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6993bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7007b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7017b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7027b592418SSamuel Hollandendif
703c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
704320920c1SMasahiro Yamada
705320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
706320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
707320920c1SMasahiro Yamadaelse
708320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
709320920c1SMasahiro Yamadaendif
710320920c1SMasahiro Yamada
711320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71242d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71369af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
714966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
71569af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
71669af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
717c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
718c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
719966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
720320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
721320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
722966660ecSChris Kay
723966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
724d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
725d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
726c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7273bd17c0fSSoby Mathew
728007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
729007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
730007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
731007433d8SBoyan Karatotev
7329cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73342d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7349cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
735d5e97a1dSMasahiro Yamadaelse
7369cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
737c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
738007433d8SBoyan Karatotev
739007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7409cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7419cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7429cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
743007433d8SBoyan Karatotevelse
744007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
745d5e97a1dSMasahiro Yamadaendif
746d5e97a1dSMasahiro Yamada
74754035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
74854035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
74954035fc4SSandrine Bailleux# This can be overridden by the platform.
75073c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7514f6ad66aSAchin Gupta
752a4409008Sdp-arm################################################################################
753a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
754a4409008Sdp-arm################################################################################
755c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
756c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
757c5e1da83SJayanth Dodderi Chidanand
758a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
759a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
760a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
761a4409008Sdp-arm
762a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
763a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
764a4409008Sdp-arm                endif
765a4409008Sdp-arm        $(info Including ${AARCH32_SP_MAKE})
766a4409008Sdp-arm        include ${AARCH32_SP_MAKE}
767a4409008Sdp-arm        endif
768c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7694f6ad66aSAchin Gupta
77073c99d4eSJuan Castillo################################################################################
77177f1f7a1SVarun Wadekar# Include libc if not overridden
77277f1f7a1SVarun Wadekar################################################################################
77377f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
77477f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
77577f1f7a1SVarun Wadekarendif
77677f1f7a1SVarun Wadekar
77777f1f7a1SVarun Wadekar################################################################################
778c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
779cf2c8a33SAntonio Nino Diaz################################################################################
780cf2c8a33SAntonio Nino Diaz
781c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
782c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
783c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
784c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
785c5e1da83SJayanth Dodderi Chidanand        else
786c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
787c5e1da83SJayanth Dodderi Chidanand        endif
788c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
789c5e1da83SJayanth Dodderi Chidanand
790c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
791c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
792c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
793c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
794c5e1da83SJayanth Dodderi Chidanand        endif
795c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
796c5e1da83SJayanth Dodderi Chidanand
797c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
798c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
799c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
800c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
801c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
802c5e1da83SJayanth Dodderi Chidanandendif
803c5e1da83SJayanth Dodderi Chidanand
804c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
805c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
806c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
807c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
808c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
809c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
810c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
811c5e1da83SJayanth Dodderi Chidanand
812cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81368450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
81468450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
81568450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
816cf2c8a33SAntonio Nino Diaz	endif
81776580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
818c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
819c5e1da83SJayanth Dodderi Chidanand                build options.")
82076580f3dSQixiang Xu	endif
82176580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
822c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
823c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
82476580f3dSQixiang Xu	endif
825c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
826cf2c8a33SAntonio Nino Diaz
827cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
828cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
829cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
830cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
831cf2c8a33SAntonio Nino Diaz	endif
83268450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83368450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
834c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
835cf2c8a33SAntonio Nino Diaz	endif
836c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
837cf2c8a33SAntonio Nino Diaz
838d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
839d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
840d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
841d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
842d4593e47SJeenu Viswambharanendif
8431a0a3f06SYatharth Kochar
84442d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
84542d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
84642d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8477d173fc5SJiafei Panendif
8487d173fc5SJiafei Pan
8499202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85014c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
851c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
852c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8539202d519SManish Pandeyendif
854c5e1da83SJayanth Dodderi Chidanand
8559202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8569202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8579202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8589202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8599202d519SManish Pandey	endif
86046cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8619202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
86214c6016aSJeenu Viswambharan	endif
863c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
864c5e1da83SJayanth Dodderi Chidanand
8659202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8661a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8676503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8686503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8691a7c1cfeSJeenu Viswambharan	endif
870c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8711a7c1cfeSJeenu Viswambharan
872ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
873209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
874209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
875c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
876c5e1da83SJayanth Dodderi Chidanand                to be set.")
877209a60ccSSoby Mathew	endif
878c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
879209a60ccSSoby Mathew
8802bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8812bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8822bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8832bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8842bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8852bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8862bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8872bf4f27fSManish V Badarkhe# Support hash calculation only
8882bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8892bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8902bf4f27fSManish V Badarkhe# Support authentication verification only
891c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
892c9c56f6eSManish V Badarkheelse
893c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
894c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
895c9c56f6eSManish V Badarkhe
896cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
897cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
898700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
89984ef9cd8SManish V Badarkheendif
90084ef9cd8SManish V Badarkhe
901b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9029fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9039fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
904b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9059fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9069fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
90706715f85SAlexei Fedorov	endif
908c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9099fc59639SAlexei Fedorov
91006715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9119fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9129fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
913b86048c4SAntonio Nino Diaz	endif
914c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9159fc59639SAlexei Fedorov
9169dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9179dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9189dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9199dd94382SJustin Chadwell	endif
920c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9219dd94382SJustin Chadwell
922396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
923396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
924c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
925396b339dSManish V Badarkhe
9266a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9276a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
928c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9296a0da736SJayanth Dodderi Chidanand
93003d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
93103d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
932c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
933c5e1da83SJayanth Dodderi Chidanand                to be set")
93403d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
93503d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
93603d3c0d7SJayanth Dodderi Chidanand	endif
937c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
93845007acdSJayanth Dodderi Chidanand
93960e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
94060e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
941c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
942c5e1da83SJayanth Dodderi Chidanand                library v2")
94360e8f3cfSPetre-Ionut Tudor	endif
944c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
94560e8f3cfSPetre-Ionut Tudor
9467cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9477cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
948c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
949c5e1da83SJayanth Dodderi Chidanand                to be set)
9507cda17bbSSumit Garg	endif
951c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9527cda17bbSSumit Garg
953744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
954dc78e62dSjohpow01ifeq (${ARCH},aarch32)
955744ad974Sjohpow01
956744ad974Sjohpow01	# SME/SVE only supported on AArch64
95745007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
958dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
959dc78e62dSjohpow01	endif
96003d3c0d7SJayanth Dodderi Chidanand
961dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
962dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96324ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
964dc78e62dSjohpow01	endif
965744ad974Sjohpow01
966ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
967744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
968744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
969744ad974Sjohpow01	endif
970744ad974Sjohpow01
971ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
972ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
973ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
974ff86e0b4SJuan Pablo Conde	endif
975c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
976dc78e62dSjohpow01
977dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
978dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
97945007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
980dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
981dc78e62dSjohpow01	endif
982dc78e62dSjohpow01endif
983dc78e62dSjohpow01
9840d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9850d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9860d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9870d122947SBoyan Karatotev	endif
988c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9890d122947SBoyan Karatotev
990dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
991dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
992dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
993dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
994dc78e62dSjohpow01	endif
9950d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9960d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9970d122947SBoyan Karatotev	endif
998c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
999c5e1da83SJayanth Dodderi Chidanand
1000dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1001dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1002dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1003dc78e62dSjohpow01	endif
1004c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1005dc78e62dSjohpow01
1006dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1007dc78e62dSjohpow01# its own context management including FPU registers.
1008dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
100945007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1010dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1011dc78e62dSjohpow01	endif
101203d3c0d7SJayanth Dodderi Chidanand
1013dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1014dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1015dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1016dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1017dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1018dc78e62dSjohpow01	endif
1019c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1020dc78e62dSjohpow01
102100e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
102200e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102300e28874SManish V Badarkheendif
102400e28874SManish V Badarkhe
1025274a69e7SChris Kayifeq (${ENABLE_RME},1)
1026274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1027274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1028274a69e7SChris Kay	endif
1029274a69e7SChris Kayendif
1030274a69e7SChris Kay
1031c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1032c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1033c5e1da83SJayanth Dodderi Chidanand
1034c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1035c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1036c5e1da83SJayanth Dodderi Chidanand
1037cf2c8a33SAntonio Nino Diaz################################################################################
103873c99d4eSJuan Castillo# Process platform overrideable behaviour
103973c99d4eSJuan Castillo################################################################################
10404f6ad66aSAchin Gupta
10415f24ce96SManish Pandeyifdef BL1_SOURCES
10425f24ce96SManish Pandey	NEED_BL1 := yes
1043c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10445f24ce96SManish Pandey
10455f24ce96SManish Pandeyifdef BL2_SOURCES
10465f24ce96SManish Pandey	NEED_BL2 := yes
10475f24ce96SManish Pandey
1048bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1049bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1050cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1051cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1052cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10534c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1054cf2c8a33SAntonio Nino Diaz	else
105568450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1056cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1057cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1058cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1059cf2c8a33SAntonio Nino Diaz		else
1060cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1061cf2c8a33SAntonio Nino Diaz		endif
10624c117f6cSSandrine Bailleux	endif
1063c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10646f971622SJuan Castillo
10655f24ce96SManish Pandeyifdef BL2U_SOURCES
10665f24ce96SManish Pandey	NEED_BL2U := yes
1067c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10685f24ce96SManish Pandey
10694d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10704d045d0eSMasahiro Yamadaifdef SCP_BL2
10714d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1072c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10734d045d0eSMasahiro Yamada
10745744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10755744e874SSoby Mathewifneq (${ARCH},aarch32)
10765744e874SSoby Mathew	ifdef BL31_SOURCES
1077c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1078c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10795744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10805744e874SSoby Mathew			NEED_BL31 := yes
10815744e874SSoby Mathew		endif
10825744e874SSoby Mathew	endif
1083c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10845744e874SSoby Mathew
108573c99d4eSJuan Castillo# Process TBB related flags
10866f971622SJuan Castilloifneq (${GENERATE_COT},0)
108773c99d4eSJuan Castillo	# Common cert_create options
10886f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10896f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10900191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1091fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1092fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10930191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1094fd34e7baSJuan Castillo		endif
10956f971622SJuan Castillo	endif
109673c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
109773c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
109873c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
109973c99d4eSJuan Castillo	endif
1100c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11016f971622SJuan Castillo
11021c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11031c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1104c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11051c75d5dfSMasahiro Yamada
11065f24ce96SManish Pandeyifdef FDT_SOURCES
11075f24ce96SManish Pandey	NEED_FDT := yes
1108c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11095f24ce96SManish Pandey
111073c99d4eSJuan Castillo################################################################################
111146e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
111246e5e035SMichalis Pappas################################################################################
111346e5e035SMichalis Pappas
111446e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
111546e5e035SMichalis Pappas
111646e5e035SMichalis Pappas################################################################################
11178a86052dSSoby Mathew# Include BL specific makefiles
11188a86052dSSoby Mathew################################################################################
11195f24ce96SManish Pandey
11205f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11218a86052dSSoby Mathewinclude bl1/bl1.mk
11228a86052dSSoby Mathewendif
11238a86052dSSoby Mathew
11245f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11258a86052dSSoby Mathewinclude bl2/bl2.mk
11268a86052dSSoby Mathewendif
11278a86052dSSoby Mathew
11285f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11298a86052dSSoby Mathewinclude bl2u/bl2u.mk
11308a86052dSSoby Mathewendif
11318a86052dSSoby Mathew
11325744e874SSoby Mathewifeq (${NEED_BL31},yes)
11338a86052dSSoby Mathewinclude bl31/bl31.mk
11348a86052dSSoby Mathewendif
113503b397a8SNishanth Menon
113673c99d4eSJuan Castillo################################################################################
113773c99d4eSJuan Castillo# Build options checks
113873c99d4eSJuan Castillo################################################################################
113973c99d4eSJuan Castillo
1140c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1141327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1142327131c4SLeonardo Sandoval    $(sort \
1143327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
114446789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1145327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1146327131c4SLeonardo Sandoval	CREATE_KEYS \
1147327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1148327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1149327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1150327131c4SLeonardo Sandoval	DEBUG \
11510063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1152327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1153327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11541fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1155742ca230SChris Kay	ENABLE_AMU_FCONF \
1156873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1157327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
115824077098SAndre Przywara	ENABLE_FEAT_SB \
1159327131c4SLeonardo Sandoval	ENABLE_PIE \
1160327131c4SLeonardo Sandoval	ENABLE_PMF \
1161327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1162327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1163dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11640c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1165327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1166327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1167327131c4SLeonardo Sandoval	GENERATE_COT \
1168327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
116946cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1170327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1171327131c4SLeonardo Sandoval	MEASURED_BOOT \
117200e28874SManish V Badarkhe	DRTM_SUPPORT \
1173327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1174327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1175327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11760ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1177327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1178327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
117964b4710bSWing Li	PSCI_OS_INIT_MODE \
1180327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1181327131c4SLeonardo Sandoval	SAVE_KEYS \
1182327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
118396a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1184327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1185327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1186327131c4SLeonardo Sandoval	SPM_MM \
11871d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1188327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1189327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1190327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1191327131c4SLeonardo Sandoval	USE_DEBUGFS \
1192327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1193327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1194327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1195327131c4SLeonardo Sandoval	USE_ROMLIB \
1196327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1197327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
119842d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1199327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1200327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1201327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1202327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1203327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1204327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
120500e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1206327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1207327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1208396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
120968120783SChris Kay	ENABLE_MPMM \
121068120783SChris Kay	ENABLE_MPMM_FCONF \
12116a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12120b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1213ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1214ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
121504c7303bSOkash Khawaja	CONDITIONAL_CMO \
12169202d519SManish Pandey	RAS_FFH_SUPPORT \
1217327131c4SLeonardo Sandoval)))
121873c99d4eSJuan Castillo
1219c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1220327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1221327131c4SLeonardo Sandoval    $(sort \
1222327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1223327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1224327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12256a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12266a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12276a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12282bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
12291298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
123047c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12316a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12326a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1233d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12346a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12356a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12369202d519SManish Pandey	ENABLE_FEAT_RAS	\
12376a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12386a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12396a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12406a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12416a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12426a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1243ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12446a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1245d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1246062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1247062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1248062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1249062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1250688ab57bSMark Brown	ENABLE_FEAT_GCS \
12516a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12526a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12536a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12546437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1255603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
125645007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
125703d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12582b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12596a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1260327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12615357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12625357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1263781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1264781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1265bebcf27fSMark Brown	SVE_VECTOR_LEN \
12660ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1267327131c4SLeonardo Sandoval)))
1268c877b414SJeenu Viswambharan
1269aacff749SJustin Chadwellifdef KEY_SIZE
1270aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1271aacff749SJustin Chadwellendif
1272aacff749SJustin Chadwell
12731f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12741f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12751f461979SJustin Chadwellendif
12761f461979SJustin Chadwell
127773c99d4eSJuan Castillo################################################################################
127873c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
127973c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
128073c99d4eSJuan Castillo# platform to overwrite the default options
128173c99d4eSJuan Castillo################################################################################
128273c99d4eSJuan Castillo
1283327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1284327131c4SLeonardo Sandoval    $(sort \
1285327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1286327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1287327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
128846789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1289327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1290327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1291327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1292327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1293327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1294327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1295327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1296062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1297327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
12980063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1299d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13001fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1301742ca230SChris Kay	ENABLE_AMU_FCONF \
1302873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1303327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1304327131c4SLeonardo Sandoval	ENABLE_BTI \
1305327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1306327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1307327131c4SLeonardo Sandoval	ENABLE_PIE \
1308327131c4SLeonardo Sandoval	ENABLE_PMF \
1309327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13105b18de09SZelalem Aweke	ENABLE_RME \
1311327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1312dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131303d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1314dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
131590118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1316327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13170c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1318327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1319327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1320327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1321327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1322327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132346cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1324327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1325327131c4SLeonardo Sandoval	LOG_LEVEL \
1326327131c4SLeonardo Sandoval	MEASURED_BOOT \
132700e28874SManish V Badarkhe	DRTM_SUPPORT \
1328327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1329327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1330327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13310ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1332327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1333327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
133464b4710bSWing Li	PSCI_OS_INIT_MODE \
13359202d519SManish Pandey	ENABLE_FEAT_RAS \
13369202d519SManish Pandey	RAS_FFH_SUPPORT \
1337327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1338327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
133996a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1340327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1341327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1342327131c4SLeonardo Sandoval	SPD_${SPD} \
1343327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1344327131c4SLeonardo Sandoval	SPM_MM \
13451d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1346327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1347327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1348c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13497dfb9911SJimmy Brisson	TRNG_SUPPORT \
1350ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1351ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1352327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1353327131c4SLeonardo Sandoval	USE_DEBUGFS \
1354327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1355327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1356327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1357327131c4SLeonardo Sandoval	USE_ROMLIB \
1358327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1359327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
136042d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
136142d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1362327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1363327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1364327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1365327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
136600e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1367327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1368327131c4SLeonardo Sandoval	USE_SP804_TIMER \
136912cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1370ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13714e04478aSChris Kay	ENABLE_FEAT_SB \
13727d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13735357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13745357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1375396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1376744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1377813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1378d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13798fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1380cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
138168120783SChris Kay	ENABLE_MPMM \
138268120783SChris Kay	ENABLE_MPMM_FCONF \
1383f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1384f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13856a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13866a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13876a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13886a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13896a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1390d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1391062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1392062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1393062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1394062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1395688ab57bSMark Brown	ENABLE_FEAT_GCS \
13966a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1397781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1398781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
139904c7303bSOkash Khawaja	CONDITIONAL_CMO \
14000ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1401a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1402327131c4SLeonardo Sandoval)))
14032fae4b1eSJeenu Viswambharan
14041f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14051f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1406c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14071f461979SJustin Chadwell
14084c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14094c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14104c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1411cf2c8a33SAntonio Nino Diazelse
141268450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
141368450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
141468450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
141568450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14164c117f6cSSandrine Bailleux	endif
1417c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
141873c99d4eSJuan Castillo
1419209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1420209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1421209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1422209a60ccSSoby Mathewendif
1423209a60ccSSoby Mathew
1424c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1425c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1426c2ad38ceSVarun Wadekarendif
1427c2ad38ceSVarun Wadekar
1428ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1429ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1430c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1431ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1432ce2b1ec6SManish Pandey	FIP_DEPS += sp
143307c44475SManish Pandey	CRT_DEPS += sp
1434ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1435ce2b1ec6SManish Pandeyelse
1436c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1437c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1438c33ff198SOlivier Deprez	endif
1439c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1440c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1441ce2b1ec6SManish Pandey
144273c99d4eSJuan Castillo################################################################################
144373c99d4eSJuan Castillo# Build targets
144473c99d4eSJuan Castillo################################################################################
144573c99d4eSJuan Castillo
144690aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
144773c99d4eSJuan Castillo.SUFFIXES:
144873c99d4eSJuan Castillo
144973c99d4eSJuan Castilloall: msg_start
145073c99d4eSJuan Castillo
145173c99d4eSJuan Castillomsg_start:
145273c99d4eSJuan Castillo	@echo "Building ${PLAT}"
145373c99d4eSJuan Castillo
14547a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1455d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1456c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1457c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1458c2ad38ceSVarun Wadekarelse
1459bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14607a24cba5SSoby Mathewendif
1461c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14627a24cba5SSoby Mathew
14635accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
146461f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14655fee0287SRoberto Vargas
146673c99d4eSJuan Castillo# Expand build macros for the different images
146773c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1468b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1469434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1470c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
147173c99d4eSJuan Castillo
147273c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1473c5e1da83SJayanth Dodderi Chidanand
147442d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1475c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1476c9b31ae8SRoberto Vargasendif
1477c9b31ae8SRoberto Vargas
1478eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1479eb1acfb6SChris Kay
148033950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1481434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1482c5e1da83SJayanth Dodderi Chidanand
1483c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
148473c99d4eSJuan Castillo
14854d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
148633950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1487c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14884d045d0eSMasahiro Yamada
148973c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
149073c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
149126d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
149226d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1493c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1494c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1495434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1496c6ba9b45SSumit Gargelse
149733950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1498434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1499c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1500c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
150173c99d4eSJuan Castillo
150270d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1503c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
150470d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
150573c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
150626d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
150726d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15089cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15099cd15239SMasahiro Yamada
1510c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1511434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1512c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1513c6ba9b45SSumit Gargelse
1514434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
151533950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1516c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1517c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
151873c99d4eSJuan Castillo
15195b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15205b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15215b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15225b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15235b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15245b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15255b18de09SZelalem Aweke
15265b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15275b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1528c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15295b18de09SZelalem Aweke
153073c99d4eSJuan Castillo# Add the BL33 image if required by the platform
153173c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
153233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1533c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1534db6071c9SJuan Castillo
15359003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
153633950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1537434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1538c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15399003fa0bSYatharth Kochar
154003b397a8SNishanth Menon# Expand build macros for the different images
154103b397a8SNishanth Menonifeq (${NEED_FDT},yes)
154203b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1543c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
154403b397a8SNishanth Menon
1545ce2b1ec6SManish Pandey# Add Secure Partition packages
1546ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1547ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
15481e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1549822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1550ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1551ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1552ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1553c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1554ce2b1ec6SManish Pandey
155536eaaf37SIan Spraylocate-checkpatch:
155636eaaf37SIan Sprayifndef CHECKPATCH
155766079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
155836eaaf37SIan Sprayelse
155936eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
156066079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156136eaaf37SIan Sprayendif
1562c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
156336eaaf37SIan Spray
15644f6ad66aSAchin Guptaclean:
15654f6ad66aSAchin Gupta	@echo "  CLEAN"
1566f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
156788a1cf1eSSami Mujawarifdef UNIX_MK
15682f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
156988a1cf1eSSami Mujawarelse
157088a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
157188a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
157288a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1573c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15746f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
157590aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15765accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15774f6ad66aSAchin Gupta
1578eaaeece2SJames Morrisseyrealclean distclean:
1579eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1580f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1581f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
158288a1cf1eSSami Mujawarifdef UNIX_MK
15832f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
158488a1cf1eSSami Mujawarelse
158588a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
158688a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
158788a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1588c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1589e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
159090aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
15915accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15924f6ad66aSAchin Gupta
159336eaaf37SIan Spraycheckcodebase:		locate-checkpatch
159436eaaf37SIan Spray	@echo "  CHECKING STYLE"
159536eaaf37SIan Spray	@if test -d .git ; then						\
15961ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
15971a41e8c1SDan Handley		while read GIT_FILE ;					\
15981a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
15991a41e8c1SDan Handley		done ;							\
160036eaaf37SIan Spray	else								\
16011a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16021a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16031a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
160461f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16051a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16061ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16071a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
160836eaaf37SIan Spray	fi
160936eaaf37SIan Spray
161036eaaf37SIan Spraycheckpatch:		locate-checkpatch
161136eaaf37SIan Spray	@echo "  CHECKING STYLE"
161202a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
161302a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
161402a76d5fSYann Gautier	fi
161551d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
161677a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
161777a0a7f1SYann Gautier	do								\
161851d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
161951d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
162002a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162102a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
162251d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
162302a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162402a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
162551d28937SAntonio Nino Diaz	done
162636eaaf37SIan Spray
162773c99d4eSJuan Castillocerttool: ${CRTTOOL}
162873c99d4eSJuan Castillo
1629a9812206SPali Rohár${CRTTOOL}: FORCE
1630598b166bSLionel 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
1631f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16326f971622SJuan Castillo	@echo "Built $@ successfully"
1633f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16346f971622SJuan Castillo
16356f971622SJuan Castilloifneq (${GENERATE_COT},0)
163673c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16376f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1638f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16396f971622SJuan Castillo	@echo "Built $@ successfully"
16406f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1641f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1642c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
164327713fb4SSoby Mathew
164473c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16454727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1646819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1647819281eeSdp-arm	${Q}${FIPTOOL} info $@
1648f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16492f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1650f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1651f58ad36fSHarry Liebel
16520191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16530191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16540191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1655052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16560191262dSYatharth Kochar	@echo "Built $@ successfully"
16570191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1658052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1659c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16600191262dSYatharth Kochar
16610191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16624727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1663819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1664819281eeSdp-arm	${Q}${FIPTOOL} info $@
1665052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16660191262dSYatharth Kochar	@echo "Built $@ successfully"
1667052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16680191262dSYatharth Kochar
166973c99d4eSJuan Castillofiptool: ${FIPTOOL}
167073c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16710191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
167273c99d4eSJuan Castillo
1673a9812206SPali Rohár${FIPTOOL}: FORCE
167488a1cf1eSSami Mujawarifdef UNIX_MK
1675598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
167688a1cf1eSSami Mujawarelse
167788a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
167888a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
167988a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1680c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1681f58ad36fSHarry Liebel
1682a9812206SPali Rohárromlib.bin: libraries FORCE
1683bbb24f61SJohn 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
16845accce5bSRoberto Vargas
1685cfe83910SLouis Mayencourtmemmap: all
1686af5b49e9SHarrison Mutaiifdef UNIX_MK
1687af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1688af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1689af5b49e9SHarrison Mutaielse
1690af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1691af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1692af5b49e9SHarrison Mutaiendif
1693cfe83910SLouis Mayencourt
16946de32378SMadhukar Pappireddydoc:
16956de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
16966de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
16976de32378SMadhukar Pappireddy
169890aa901fSSumit Gargenctool: ${ENCTOOL}
169990aa901fSSumit Garg
1700a9812206SPali Rohár${ENCTOOL}: FORCE
1701598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
170290aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170390aa901fSSumit Garg	@echo "Built $@ successfully"
170490aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170590aa901fSSumit Garg
170635fab8c9SJoakim Bechcscope:
170735fab8c9SJoakim Bech	@echo "  CSCOPE"
170835fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
170935fab8c9SJoakim Bech	${Q}cscope -b -q -k
171035fab8c9SJoakim Bech
171172ee3314SRyan Harkinhelp:
17127c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
171372ee3314SRyan Harkin	@echo ""
171472ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
171508c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
171672ee3314SRyan Harkin	@echo ""
17177c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17187c23126cSJohn Tsichritzis	@echo ""
17191b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17201b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17211b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17221b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17231b578596SSandrine Bailleux	@echo ""
172472ee3314SRyan Harkin	@echo "Supported Targets:"
17251b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
172636eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17278aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17289003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1729d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17309d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17319d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
173273c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17331b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17340191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
173536eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
173636eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
173736eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
173872ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
173935fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
174072ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17416f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
174290aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1743f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1744ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
174526010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
174638c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1747cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17486de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
174972ee3314SRyan Harkin	@echo ""
17501b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
175172ee3314SRyan Harkin	@echo ""
175272ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
175372ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1754a9812206SPali Rohár
1755a9812206SPali Rohár.PHONY: FORCE
1756a9812206SPali RohárFORCE:;
1757