xref: /rk3399_ARM-atf/Makefile (revision a8cf6faeae17b01906810ffeacfadea04d6cd121)
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
22026e63c44SEtienne Carriere# Will set march32-directive from platform configuration
22126e63c44SEtienne Carriereelse
22226e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
223fa6f774bSAlexei Fedorov
224f1821790SAlexei Fedorov# Set the compiler's target architecture profile based on
225f1821790SAlexei Fedorov# ARM_ARCH_MAJOR ARM_ARCH_MINOR options
226fa6f774bSAlexei Fedorov	ifeq (${ARM_ARCH_MINOR},0)
227f1821790SAlexei Fedorov		march32-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
228f1821790SAlexei Fedorov		march64-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
229fa6f774bSAlexei Fedorov	else
230f1821790SAlexei Fedorov		march32-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
231f1821790SAlexei Fedorov		march64-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
232c5e1da83SJayanth Dodderi Chidanand	endif #(ARM_ARCH_MINOR)
233c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
234c5e1da83SJayanth Dodderi Chidanand
235c5e1da83SJayanth Dodderi Chidanand################################################################################
236c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
237c5e1da83SJayanth Dodderi Chidanand################################################################################
238c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
239c5e1da83SJayanth Dodderi Chidanand
240c5e1da83SJayanth Dodderi Chidanand####################################################
241c5e1da83SJayanth Dodderi Chidanand# Enable required options for Memory Stack Tagging.
242c5e1da83SJayanth Dodderi Chidanand####################################################
24326e63c44SEtienne Carriere
2447ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2457ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2464a565bd8SSami Mujawar	# Check if revision is greater than or equal to 8.5
2474a565bd8SSami Mujawar	ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2487ff088d1SManish V Badarkhe		mem_tag_arch_support	= 	yes
2497ff088d1SManish V Badarkhe	endif
250c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
2517ff088d1SManish V Badarkhe
252f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2537ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2547ff088d1SManish V Badarkhe	ifdef mem_tag_arch_support
255f1821790SAlexei Fedorov		# Check for armclang and clang compilers
2567ff088d1SManish V Badarkhe		ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
257f1821790SAlexei Fedorov		# Add "memtag" architecture feature modifier if not specified
258f1821790SAlexei Fedorov			ifeq ( ,$(findstring memtag,$(arch-features)))
259f1821790SAlexei Fedorov				arch-features	:=	$(arch-features)+memtag
260f1821790SAlexei Fedorov			endif	# memtag
2617ff088d1SManish V Badarkhe			ifeq ($(notdir $(CC)),armclang)
2627ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-mmemtag-stack
2637ff088d1SManish V Badarkhe			else ifeq ($(notdir $(CC)),clang)
2647ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-fsanitize=memtag
265f1821790SAlexei Fedorov			endif	# armclang
266c5e1da83SJayanth Dodderi Chidanand		endif
2677ff088d1SManish V Badarkhe	else
268c5e1da83SJayanth Dodderi Chidanand                $(error "Error: stack memory tagging is not supported for  \
269c5e1da83SJayanth Dodderi Chidanand                 architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
270c5e1da83SJayanth Dodderi Chidanand	endif #(mem_tag_arch_support)
271c5e1da83SJayanth Dodderi Chidanandendif #(SUPPORT_STACK_MEMTAG)
272f1821790SAlexei Fedorov
273f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
274f1821790SAlexei Fedorovifneq ($(arch-features), none)
275f1821790SAlexei Fedorov	# Strip "none+" from arch-features
276f1821790SAlexei Fedorov	arch-features		:=	$(subst none+,,$(arch-features))
277f1821790SAlexei Fedorov	ifeq ($(ARCH), aarch32)
278f1821790SAlexei Fedorov		march32-directive	:=	$(march32-directive)+$(arch-features)
279f1821790SAlexei Fedorov	else
280f1821790SAlexei Fedorov		march64-directive	:=	$(march64-directive)+$(arch-features)
2817ff088d1SManish V Badarkhe	endif
282f1821790SAlexei Fedorov# Print features
283f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
284c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
2854e04478aSChris Kay
286c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
287fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
288c8a992fdSorigin		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi $(march32-directive)
289c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi $(march64-directive)
290c8a992fdSorigin		LD			:=	$(LINKER)
291c8a992fdSorigin	else
29294eb1277SArvind Ram Prakash		TF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
293c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-elf $(march64-directive)
294c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
295c8a992fdSorigin
296c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
297c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
298c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
299641f16e7SAmbroise Vincent	endif
300c8a992fdSorigin
301c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
302c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
303c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
304edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
305edbce9aaSzelalem-aweke	TF_CFLAGS_aarch32	=	$(march32-directive)
306edbce9aaSzelalem-aweke	TF_CFLAGS_aarch64	=	$(march64-directive)
307edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
308edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
309edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
310edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
311edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
312edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
313edbce9aaSzelalem-aweke		endif
314edbce9aaSzelalem-aweke	endif
315edbce9aaSzelalem-aweke	LD			=	$(LINKER)
316d5461857Sdp-armelse
31726e63c44SEtienne Carriere	TF_CFLAGS_aarch32	=	$(march32-directive)
318fa6f774bSAlexei Fedorov	TF_CFLAGS_aarch64	=	$(march64-directive)
3192adee763SRoberto Vargas	LD			=	$(LINKER)
320c5e1da83SJayanth Dodderi Chidanandendif #(clang)
321d5461857Sdp-arm
32232b209bfSAhmad Fatoum# Process Debug flag
32332b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
32432b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
32532b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
3264466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
3274466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
32832b209bfSAhmad Fatoum
32932b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
33032b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
33132b209bfSAhmad Fatoumelse
33232b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
33332b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
33432b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
335c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
33632b209bfSAhmad Fatoum
337f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
338f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
339f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
340f1de4c8fSPeiyuan Songendif
341dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
342f1de4c8fSPeiyuan Song
3438fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3448fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
3458fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3468fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
3478fd9d4d5SAntonio Nino Diazelse
3488fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
349c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
3508fd9d4d5SAntonio Nino Diaz
351a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
352d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3539d29c227SSoby Mathew
3549fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3559fc59639SAlexei Fedorov	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
356c5e1da83SJayanth Dodderi Chidanandendif #(BP_OPTION)
3579fc59639SAlexei Fedorov
35826e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
359fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
360b86048c4SAntonio Nino Diaz
361c5e1da83SJayanth Dodderi Chidanand##############################################################################
362c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
363c5e1da83SJayanth Dodderi Chidanand###############################################################################
3649ab81b5eSJustin Chadwell# General warnings
3659ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
366b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
367d75a9ecdSBoyan Karatotev				-Wredundant-decls
368d75a9ecdSBoyan Karatotev# stricter warnings
369d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
370d75a9ecdSBoyan Karatotev# too verbose for generic build
371d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
372d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
373d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
374d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
3759ab81b5eSJustin Chadwell
3769ab81b5eSJustin Chadwell# Additional warnings
377d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
378d75a9ecdSBoyan Karatotev# full -Wextra
379d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
380d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
381d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
382e7c645b5SYann Gautier
383d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
384d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
385d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
386d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
387d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
388d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
389d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
390d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
391d141e638SBoyan Karatotev# currently very involved and many platforms set this off
392d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
393e7c645b5SYann Gautier
394d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
395e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
396d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
397d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
398d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
399e7c645b5SYann GautierWARNING3 += -Wcast-qual
400e7c645b5SYann GautierWARNING3 += -Wconversion
401e7c645b5SYann GautierWARNING3 += -Wpacked
402e7c645b5SYann GautierWARNING3 += -Wpointer-arith
403e7c645b5SYann GautierWARNING3 += -Wswitch-default
404e7c645b5SYann Gautier
405d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
406d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
407d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
408d75a9ecdSBoyan Karatotevifdef W
409d75a9ecdSBoyan Karatotev	ifneq (${W},0)
410d75a9ecdSBoyan Karatotev		E	 ?= 0
411d75a9ecdSBoyan Karatotev	endif
412d75a9ecdSBoyan Karatotevendif
413d75a9ecdSBoyan Karatotev
414e7c645b5SYann Gautierifeq (${W},1)
4159ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
416e7c645b5SYann Gautierelse ifeq (${W},2)
4179ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
418e7c645b5SYann Gautierelse ifeq (${W},3)
4199ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
420c5e1da83SJayanth Dodderi Chidanandendif #(W)
421e7c645b5SYann Gautier
4229ab81b5eSJustin Chadwell# Compiler specific warnings
42300296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
42493c690ebSJustin Chadwell# not using clang
425d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
426d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
427d7b4cd41SJustin Chadwell				-Wlogical-op
428dea23e24SGovindraj Raja
429dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
430dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
431dea23e24SGovindraj Raja
43293c690ebSJustin Chadwellelse
43393c690ebSJustin Chadwell# using clang
434d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
435d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
436c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
43700296576SAmbroise Vincent
4386336b07aSYann Gautierifneq (${E},0)
4396336b07aSYann Gautier	ERRORS := -Werror
440c5e1da83SJayanth Dodderi Chidanandendif #(E)
4416336b07aSYann Gautier
442c5e1da83SJayanth Dodderi Chidanand################################################################################
443c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
444c5e1da83SJayanth Dodderi Chidanand################################################################################
445ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
4469ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
44759de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
448d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
44959de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
450ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
451ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
452ebd6efaeSSamuel Holland				-Os -std=gnu99
45373c99d4eSJuan Castillo
4541f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4551f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
456c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
457c5e1da83SJayanth Dodderi Chidanand
4581f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4591f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
4601f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
461c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
4621f461979SJustin Chadwell
463f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
464f7ec31dbSdavid cunado
4651f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
4661f49db5fSMarco Felsch
467641f16e7SAmbroise Vincent# LD = armlink
468c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
469c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
470c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
471edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
472641f16e7SAmbroise Vincent
473641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
474edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
475edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
476edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
477edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
478ac98b82aSChris Kay
479ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
480ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
481ac98b82aSChris Kay
482edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
483edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
484edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
485edbce9aaSzelalem-aweke		endif
486c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
487c5e1da83SJayanth Dodderi Chidanand
488edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
489edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
490edbce9aaSzelalem-aweke	ifneq (${ERRATA_A53_843419},1)
491edbce9aaSzelalem-aweke		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
492edbce9aaSzelalem-aweke	endif
493edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
494edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
495641f16e7SAmbroise Vincent
496641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
497c2ad38ceSVarun Wadekarelse
4981f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
4991f49db5fSMarco Felsch# are not loaded by a elf loader.
5001f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
501ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
502c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
503ac98b82aSChris Kay
504ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
505ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
506ac98b82aSChris Kay
507641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
508ebac6922SYabin Cui# therefore don't add those in that case.
509ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
510ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
511641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
512ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
513edbce9aaSzelalem-aweke	endif
514c5e1da83SJayanth Dodderi Chidanand
515c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
51673c99d4eSJuan Castillo
51703b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
518a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
519a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
52003b397a8SNishanth Menon
52173c99d4eSJuan Castillo################################################################################
52273c99d4eSJuan Castillo# Common sources and include directories
52373c99d4eSJuan Castillo################################################################################
5246a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
525d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
52673c99d4eSJuan Castillo
52773c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
5287f56e9a3SSoby Mathew				common/tf_log.c				\
5299d29c227SSoby Mathew				common/${ARCH}/debug.S			\
53091b48c9fSJulius Werner				drivers/console/multi_console.c		\
5319d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
5329d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
533566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
5347f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
53575311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
5369d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
53761f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
538d7a6b0f8SRyan Harkin
53990ce8b87SBoyan Karatotev# Pointer Authentication sources
54090ce8b87SBoyan Karatotevifeq (${ENABLE_PAUTH}, 1)
54190ce8b87SBoyan Karatotev# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
54290ce8b87SBoyan Karatotev# Pauth support. As it's not secure, it must be reimplemented for real platforms
54390ce8b87SBoyan Karatotev	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
54490ce8b87SBoyan Karatotevendif
54590ce8b87SBoyan Karatotev
5468422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
5478422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
5488422a840SAntonio Nino Diazendif
5498422a840SAntonio Nino Diaz
5501f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
5511f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
5521f461979SJustin Chadwellendif
5531f461979SJustin Chadwell
55401d237cbSYann GautierINCLUDES		+=	-Iinclude				\
555f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
55609d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
55709d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
55809d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
55909d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
56009d40e0eSAntonio Nino Diaz
5619c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5629c6d1c50SAntonio Nino Diaz
56373c99d4eSJuan Castillo################################################################################
56473c99d4eSJuan Castillo# Generic definitions
56573c99d4eSJuan Castillo################################################################################
566231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
567231c1470SEvan Lloyd
56829214e95SGrant Likelyifeq (${BUILD_BASE},)
56973c99d4eSJuan Castillo     BUILD_BASE		:=	./build
57029214e95SGrant Likelyendif
57129214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
57273c99d4eSJuan Castillo
573231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
57473c99d4eSJuan Castillo
57573c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
57673c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
57773c99d4eSJuan Castillo
57873c99d4eSJuan Castillo################################################################################
57973c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
58073c99d4eSJuan Castillo################################################################################
58173c99d4eSJuan Castillo
58273c99d4eSJuan Castilloifneq (${SPD},none)
5839d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5849d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5859d29c227SSoby Mathew	endif
58628f39f02SMax Shvetsov
5874c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5884c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
589c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
590c5e1da83SJayanth Dodderi Chidanand                ignored.")
5914c117f6cSSandrine Bailleux	endif
59228f39f02SMax Shvetsov
593c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
594c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
595c3fb00d9SAchin Gupta		SPD_DIR := std_svc
59628f39f02SMax Shvetsov
597033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
598f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5991d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
6001d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
6011d63ae4dSMarc Bonnici			endif
60228f39f02SMax Shvetsov		endif
603db1ef41aSOlivier Deprez
604db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
605db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
606db1ef41aSOlivier Deprez		endif
607ca932481SDavidson K
608ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
609ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
610ca932481SDavidson K		endif
61133993a37SBalint Dobszay
61233993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
61333993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
61433993a37SBalint Dobszay		endif
61546789a7cSBalint Dobszay
61646789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
61746789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
61846789a7cSBalint Dobszay		endif
619c3fb00d9SAchin Gupta	else
620c3fb00d9SAchin Gupta		# All other SPDs in spd directory
621c3fb00d9SAchin Gupta		SPD_DIR := spd
622c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
623c3fb00d9SAchin Gupta
62473c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
625c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
626c3fb00d9SAchin Gupta
62773c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
628c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
62973c99d4eSJuan Castillo	endif
63073c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
63173c99d4eSJuan Castillo        include ${SPD_MAKE}
63273c99d4eSJuan Castillo
63370d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
63470d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
63570d1fc53SJuan Castillo	# supports two mutually exclusive options:
63670d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
63770d1fc53SJuan Castillo	#   of source files to build BL32
63870d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
63970d1fc53SJuan Castillo	#   that will be included in the FIP
64070d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
64170d1fc53SJuan Castillo	# over the sources.
642c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
643e35c4045SJeenu Viswambharan
644f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
645f1910cc1SGovindraj Raja	ifeq (${SPD},none)
646f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
647c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
648c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
649f1910cc1SGovindraj Raja		endif
650f1910cc1SGovindraj Raja	endif
651f1910cc1SGovindraj Rajaendif
652f1910cc1SGovindraj Raja
65351faada7SDouglas Raillard################################################################################
6545b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6555b18de09SZelalem Aweke################################################################################
6565b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6575b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6585b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6595b18de09SZelalem Aweke	endif
6601d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6611d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6621d63ae4dSMarc Bonnici	endif
663c5e1da83SJayanth Dodderi Chidanand
6644fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6654fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6664fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6674fba2e1fSBoyan Karatotev		endif
6684fba2e1fSBoyan Karatotev	endif
6695b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6705b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6715b18de09SZelalem Awekeendif
6725b18de09SZelalem Aweke
6735b18de09SZelalem Aweke################################################################################
67473c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
67573c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
67673c99d4eSJuan Castillo################################################################################
6772da8d8bfSJeenu Viswambharan
67873c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6790f21c547SJuan Castillo
68042d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
68142d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
68242d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
68342d4d3baSArvind Ram Prakash# BL2 in EL3
68442d4d3baSArvind Ram Prakash
68542d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
68642d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68742d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
688c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
689c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
69042d4d3baSArvind Ram Prakash	endif
69142d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
69242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
69342d4d3baSArvind Ram Prakashelse
69442d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
69542d4d3baSArvind Ram Prakashendif
69642d4d3baSArvind Ram Prakash
6978012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6988012cc5cSMasahiro Yamada
69926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
70026e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
70126e63c44SEtienne Carriereendif
70226e63c44SEtienne Carriere
7033bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7043bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7053bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7067b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7077b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7087b592418SSamuel Hollandendif
709c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
710320920c1SMasahiro Yamada
711320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
712320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
713320920c1SMasahiro Yamadaelse
714320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
715320920c1SMasahiro Yamadaendif
716320920c1SMasahiro Yamada
717320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71842d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71969af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
720966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
72169af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
72269af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
723c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
724c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
725966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
726320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
727320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
728966660ecSChris Kay
729966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
730d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
731d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
732c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7333bd17c0fSSoby Mathew
734007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
735007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
736007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
737007433d8SBoyan Karatotev
7389cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73942d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7409cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
741d5e97a1dSMasahiro Yamadaelse
7429cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
743c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
744007433d8SBoyan Karatotev
745007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7469cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7479cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7489cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
749007433d8SBoyan Karatotevelse
750007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
751d5e97a1dSMasahiro Yamadaendif
752d5e97a1dSMasahiro Yamada
75354035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
75454035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
75554035fc4SSandrine Bailleux# This can be overridden by the platform.
75673c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7574f6ad66aSAchin Gupta
758a4409008Sdp-arm################################################################################
759a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
760a4409008Sdp-arm################################################################################
761c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
762c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
763c5e1da83SJayanth Dodderi Chidanand
764a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
765a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
766a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
767a4409008Sdp-arm
768a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
769a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
770a4409008Sdp-arm                endif
771a4409008Sdp-arm        $(info Including ${AARCH32_SP_MAKE})
772a4409008Sdp-arm        include ${AARCH32_SP_MAKE}
773a4409008Sdp-arm        endif
774c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7754f6ad66aSAchin Gupta
77673c99d4eSJuan Castillo################################################################################
77777f1f7a1SVarun Wadekar# Include libc if not overridden
77877f1f7a1SVarun Wadekar################################################################################
77977f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
78077f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
78177f1f7a1SVarun Wadekarendif
78277f1f7a1SVarun Wadekar
78377f1f7a1SVarun Wadekar################################################################################
784c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
785cf2c8a33SAntonio Nino Diaz################################################################################
786cf2c8a33SAntonio Nino Diaz
787c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
788c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
789c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
790c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
791c5e1da83SJayanth Dodderi Chidanand        else
792c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
793c5e1da83SJayanth Dodderi Chidanand        endif
794c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
795c5e1da83SJayanth Dodderi Chidanand
796c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
797c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
798c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
799c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
800c5e1da83SJayanth Dodderi Chidanand        endif
801c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
802c5e1da83SJayanth Dodderi Chidanand
803c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
804c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
805c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
806c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
807c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
808c5e1da83SJayanth Dodderi Chidanandendif
809c5e1da83SJayanth Dodderi Chidanand
810c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
811c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
812c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
813c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
814c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
815c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
816c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
817c5e1da83SJayanth Dodderi Chidanand
818cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81968450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
82068450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
82168450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
822cf2c8a33SAntonio Nino Diaz	endif
82376580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
824c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
825c5e1da83SJayanth Dodderi Chidanand                build options.")
82676580f3dSQixiang Xu	endif
82776580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
828c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
829c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
83076580f3dSQixiang Xu	endif
831c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
832cf2c8a33SAntonio Nino Diaz
833cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
834cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
835cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
836cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
837cf2c8a33SAntonio Nino Diaz	endif
83868450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83968450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
840c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
841cf2c8a33SAntonio Nino Diaz	endif
842c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
843cf2c8a33SAntonio Nino Diaz
844d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
845d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
846d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
847d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
848d4593e47SJeenu Viswambharanendif
8491a0a3f06SYatharth Kochar
85042d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
85142d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
85242d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8537d173fc5SJiafei Panendif
8547d173fc5SJiafei Pan
8559202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85614c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
857c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
858c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8599202d519SManish Pandeyendif
860c5e1da83SJayanth Dodderi Chidanand
8619202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8629202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8639202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8649202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8659202d519SManish Pandey	endif
86646cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8679202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
86814c6016aSJeenu Viswambharan	endif
869c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
870c5e1da83SJayanth Dodderi Chidanand
8719202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8721a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8736503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8746503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8751a7c1cfeSJeenu Viswambharan	endif
876c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8771a7c1cfeSJeenu Viswambharan
878ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
879209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
880209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
881c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
882c5e1da83SJayanth Dodderi Chidanand                to be set.")
883209a60ccSSoby Mathew	endif
884c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
885209a60ccSSoby Mathew
8862bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8872bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8882bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8892bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8902bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8912bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8922bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8932bf4f27fSManish V Badarkhe# Support hash calculation only
8942bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8952bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8962bf4f27fSManish V Badarkhe# Support authentication verification only
897c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
898c9c56f6eSManish V Badarkheelse
899c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
900c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
901c9c56f6eSManish V Badarkhe
902cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
903cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
904700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
90584ef9cd8SManish V Badarkheendif
90684ef9cd8SManish V Badarkhe
907b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9089fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9099fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
910b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9119fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9129fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
91306715f85SAlexei Fedorov	endif
914c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9159fc59639SAlexei Fedorov
91606715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9179fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9189fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
919b86048c4SAntonio Nino Diaz	endif
920c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9219fc59639SAlexei Fedorov
9229dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9239dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9249dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9259dd94382SJustin Chadwell	endif
926c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9279dd94382SJustin Chadwell
928396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
929396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
930c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
931396b339dSManish V Badarkhe
9326a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9336a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
934c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9356a0da736SJayanth Dodderi Chidanand
93603d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
93703d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
938c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
939c5e1da83SJayanth Dodderi Chidanand                to be set")
94003d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
94103d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
94203d3c0d7SJayanth Dodderi Chidanand	endif
943c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
94445007acdSJayanth Dodderi Chidanand
94560e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
94660e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
947c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
948c5e1da83SJayanth Dodderi Chidanand                library v2")
94960e8f3cfSPetre-Ionut Tudor	endif
950c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
95160e8f3cfSPetre-Ionut Tudor
9527cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9537cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
954c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
955c5e1da83SJayanth Dodderi Chidanand                to be set)
9567cda17bbSSumit Garg	endif
957c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9587cda17bbSSumit Garg
959744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
960dc78e62dSjohpow01ifeq (${ARCH},aarch32)
961744ad974Sjohpow01
962744ad974Sjohpow01	# SME/SVE only supported on AArch64
96345007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
964dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
965dc78e62dSjohpow01	endif
96603d3c0d7SJayanth Dodderi Chidanand
967dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
968dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96924ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
970dc78e62dSjohpow01	endif
971744ad974Sjohpow01
972ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
973744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
974744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
975744ad974Sjohpow01	endif
976744ad974Sjohpow01
977ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
978ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
979ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
980ff86e0b4SJuan Pablo Conde	endif
981c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
982dc78e62dSjohpow01
983dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
984dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
98545007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
986dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
987dc78e62dSjohpow01	endif
988dc78e62dSjohpow01endif
989dc78e62dSjohpow01
9900d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9910d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9920d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9930d122947SBoyan Karatotev	endif
994c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9950d122947SBoyan Karatotev
996dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
997dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
998dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
999dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
1000dc78e62dSjohpow01	endif
10010d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
10020d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
10030d122947SBoyan Karatotev	endif
1004c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
1005c5e1da83SJayanth Dodderi Chidanand
1006dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1007dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1008dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1009dc78e62dSjohpow01	endif
1010c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1011dc78e62dSjohpow01
1012dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1013dc78e62dSjohpow01# its own context management including FPU registers.
1014dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
101545007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1016dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1017dc78e62dSjohpow01	endif
101803d3c0d7SJayanth Dodderi Chidanand
1019dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1020dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1021dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1022dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1023dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1024dc78e62dSjohpow01	endif
1025c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1026dc78e62dSjohpow01
102700e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
102800e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102900e28874SManish V Badarkheendif
103000e28874SManish V Badarkhe
1031274a69e7SChris Kayifeq (${ENABLE_RME},1)
1032274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1033274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1034274a69e7SChris Kay	endif
1035274a69e7SChris Kayendif
1036274a69e7SChris Kay
1037c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1038c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1039c5e1da83SJayanth Dodderi Chidanand
1040c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1041c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1042c5e1da83SJayanth Dodderi Chidanand
1043cf2c8a33SAntonio Nino Diaz################################################################################
104473c99d4eSJuan Castillo# Process platform overrideable behaviour
104573c99d4eSJuan Castillo################################################################################
10464f6ad66aSAchin Gupta
10475f24ce96SManish Pandeyifdef BL1_SOURCES
10485f24ce96SManish Pandey	NEED_BL1 := yes
1049c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10505f24ce96SManish Pandey
10515f24ce96SManish Pandeyifdef BL2_SOURCES
10525f24ce96SManish Pandey	NEED_BL2 := yes
10535f24ce96SManish Pandey
1054bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1055bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1056cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1057cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1058cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10594c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1060cf2c8a33SAntonio Nino Diaz	else
106168450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1062cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1063cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1064cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1065cf2c8a33SAntonio Nino Diaz		else
1066cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1067cf2c8a33SAntonio Nino Diaz		endif
10684c117f6cSSandrine Bailleux	endif
1069c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10706f971622SJuan Castillo
10715f24ce96SManish Pandeyifdef BL2U_SOURCES
10725f24ce96SManish Pandey	NEED_BL2U := yes
1073c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10745f24ce96SManish Pandey
10754d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10764d045d0eSMasahiro Yamadaifdef SCP_BL2
10774d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1078c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10794d045d0eSMasahiro Yamada
10805744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10815744e874SSoby Mathewifneq (${ARCH},aarch32)
10825744e874SSoby Mathew	ifdef BL31_SOURCES
1083c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1084c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10855744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10865744e874SSoby Mathew			NEED_BL31 := yes
10875744e874SSoby Mathew		endif
10885744e874SSoby Mathew	endif
1089c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10905744e874SSoby Mathew
109173c99d4eSJuan Castillo# Process TBB related flags
10926f971622SJuan Castilloifneq (${GENERATE_COT},0)
109373c99d4eSJuan Castillo	# Common cert_create options
10946f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10956f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10960191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1097fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1098fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10990191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1100fd34e7baSJuan Castillo		endif
11016f971622SJuan Castillo	endif
110273c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
110373c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
110473c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
110573c99d4eSJuan Castillo	endif
1106c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11076f971622SJuan Castillo
11081c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11091c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1110c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11111c75d5dfSMasahiro Yamada
11125f24ce96SManish Pandeyifdef FDT_SOURCES
11135f24ce96SManish Pandey	NEED_FDT := yes
1114c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11155f24ce96SManish Pandey
111673c99d4eSJuan Castillo################################################################################
111746e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
111846e5e035SMichalis Pappas################################################################################
111946e5e035SMichalis Pappas
112046e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
112146e5e035SMichalis Pappas
112246e5e035SMichalis Pappas################################################################################
11238a86052dSSoby Mathew# Include BL specific makefiles
11248a86052dSSoby Mathew################################################################################
11255f24ce96SManish Pandey
11265f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11278a86052dSSoby Mathewinclude bl1/bl1.mk
11288a86052dSSoby Mathewendif
11298a86052dSSoby Mathew
11305f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11318a86052dSSoby Mathewinclude bl2/bl2.mk
11328a86052dSSoby Mathewendif
11338a86052dSSoby Mathew
11345f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11358a86052dSSoby Mathewinclude bl2u/bl2u.mk
11368a86052dSSoby Mathewendif
11378a86052dSSoby Mathew
11385744e874SSoby Mathewifeq (${NEED_BL31},yes)
11398a86052dSSoby Mathewinclude bl31/bl31.mk
11408a86052dSSoby Mathewendif
114103b397a8SNishanth Menon
114273c99d4eSJuan Castillo################################################################################
114373c99d4eSJuan Castillo# Build options checks
114473c99d4eSJuan Castillo################################################################################
114573c99d4eSJuan Castillo
1146c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1147327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1148327131c4SLeonardo Sandoval    $(sort \
1149327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
115046789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1151327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1152327131c4SLeonardo Sandoval	CREATE_KEYS \
1153327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1154327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1155327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1156327131c4SLeonardo Sandoval	DEBUG \
11570063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1158327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1159327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11601fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1161742ca230SChris Kay	ENABLE_AMU_FCONF \
1162873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1163327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
116424077098SAndre Przywara	ENABLE_FEAT_SB \
1165327131c4SLeonardo Sandoval	ENABLE_PIE \
1166327131c4SLeonardo Sandoval	ENABLE_PMF \
1167327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1168327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1169dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11700c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1171327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1172327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1173327131c4SLeonardo Sandoval	GENERATE_COT \
1174327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
117546cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1176327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1177327131c4SLeonardo Sandoval	MEASURED_BOOT \
117800e28874SManish V Badarkhe	DRTM_SUPPORT \
1179327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1180327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1181327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11820ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1183327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1184327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
118564b4710bSWing Li	PSCI_OS_INIT_MODE \
1186327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1187327131c4SLeonardo Sandoval	SAVE_KEYS \
1188327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
118996a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1190327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1191327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1192327131c4SLeonardo Sandoval	SPM_MM \
11931d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1194327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1195327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1196327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1197327131c4SLeonardo Sandoval	USE_DEBUGFS \
1198327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1199327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1200327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1201327131c4SLeonardo Sandoval	USE_ROMLIB \
1202327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1203327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
120442d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1205327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1206327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1207327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1208327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1209327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1210327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
121100e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1212327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1213327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1214396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
121568120783SChris Kay	ENABLE_MPMM \
121668120783SChris Kay	ENABLE_MPMM_FCONF \
12176a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12180b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1219ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1220ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
122104c7303bSOkash Khawaja	CONDITIONAL_CMO \
12229202d519SManish Pandey	RAS_FFH_SUPPORT \
1223327131c4SLeonardo Sandoval)))
122473c99d4eSJuan Castillo
1225c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1226327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1227327131c4SLeonardo Sandoval    $(sort \
1228327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1229327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1230327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12316a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12326a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12336a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12342bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
12351298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
123647c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12376a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12386a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1239d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12406a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12416a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12429202d519SManish Pandey	ENABLE_FEAT_RAS	\
12436a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12446a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12456a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12466a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12476a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12486a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1249ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12506a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1251d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1252062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1253062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1254062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1255062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1256688ab57bSMark Brown	ENABLE_FEAT_GCS \
12576a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12586a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12596a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12606437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1261603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
126245007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
126303d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12642b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12656a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1266327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12675357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12685357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1269781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1270781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1271bebcf27fSMark Brown	SVE_VECTOR_LEN \
12720ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1273327131c4SLeonardo Sandoval)))
1274c877b414SJeenu Viswambharan
1275aacff749SJustin Chadwellifdef KEY_SIZE
1276aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1277aacff749SJustin Chadwellendif
1278aacff749SJustin Chadwell
12791f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12801f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12811f461979SJustin Chadwellendif
12821f461979SJustin Chadwell
128373c99d4eSJuan Castillo################################################################################
128473c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
128573c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
128673c99d4eSJuan Castillo# platform to overwrite the default options
128773c99d4eSJuan Castillo################################################################################
128873c99d4eSJuan Castillo
1289327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1290327131c4SLeonardo Sandoval    $(sort \
1291327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1292327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1293327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
129446789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1295327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1296327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1297327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1298327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1299327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1300327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1301327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1302062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1303327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13040063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1305d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13061fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1307742ca230SChris Kay	ENABLE_AMU_FCONF \
1308873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1309327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1310327131c4SLeonardo Sandoval	ENABLE_BTI \
1311327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1312327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1313327131c4SLeonardo Sandoval	ENABLE_PIE \
1314327131c4SLeonardo Sandoval	ENABLE_PMF \
1315327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13165b18de09SZelalem Aweke	ENABLE_RME \
1317327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1318dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131903d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1320dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
132190118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1322327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13230c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1324327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1325327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1326327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1327327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1328327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132946cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1330327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1331327131c4SLeonardo Sandoval	LOG_LEVEL \
1332327131c4SLeonardo Sandoval	MEASURED_BOOT \
133300e28874SManish V Badarkhe	DRTM_SUPPORT \
1334327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1335327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1336327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13370ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1338327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1339327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
134064b4710bSWing Li	PSCI_OS_INIT_MODE \
13419202d519SManish Pandey	ENABLE_FEAT_RAS \
13429202d519SManish Pandey	RAS_FFH_SUPPORT \
1343327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1344327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
134596a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1346327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1347327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1348327131c4SLeonardo Sandoval	SPD_${SPD} \
1349327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1350327131c4SLeonardo Sandoval	SPM_MM \
13511d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1352327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1353327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1354c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13557dfb9911SJimmy Brisson	TRNG_SUPPORT \
1356ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1357ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1358327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1359327131c4SLeonardo Sandoval	USE_DEBUGFS \
1360327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1361327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1362327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1363327131c4SLeonardo Sandoval	USE_ROMLIB \
1364327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1365327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
136642d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
136742d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1368327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1369327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1370327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1371327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
137200e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1373327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1374327131c4SLeonardo Sandoval	USE_SP804_TIMER \
137512cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1376ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13774e04478aSChris Kay	ENABLE_FEAT_SB \
13787d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13795357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13805357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1381396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1382744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1383813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1384d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13858fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1386cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
138768120783SChris Kay	ENABLE_MPMM \
138868120783SChris Kay	ENABLE_MPMM_FCONF \
1389f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1390f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13916a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13926a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13936a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13946a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13956a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1396d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1397062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1398062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1399062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1400062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1401688ab57bSMark Brown	ENABLE_FEAT_GCS \
14026a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1403781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1404781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
140504c7303bSOkash Khawaja	CONDITIONAL_CMO \
14060ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1407*a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1408327131c4SLeonardo Sandoval)))
14092fae4b1eSJeenu Viswambharan
14101f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14111f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1412c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14131f461979SJustin Chadwell
14144c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14154c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14164c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1417cf2c8a33SAntonio Nino Diazelse
141868450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
141968450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
142068450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
142168450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14224c117f6cSSandrine Bailleux	endif
1423c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
142473c99d4eSJuan Castillo
1425209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1426209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1427209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1428209a60ccSSoby Mathewendif
1429209a60ccSSoby Mathew
1430c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1431c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1432c2ad38ceSVarun Wadekarendif
1433c2ad38ceSVarun Wadekar
1434ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1435ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1436c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1437ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1438ce2b1ec6SManish Pandey	FIP_DEPS += sp
143907c44475SManish Pandey	CRT_DEPS += sp
1440ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1441ce2b1ec6SManish Pandeyelse
1442c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1443c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1444c33ff198SOlivier Deprez	endif
1445c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1446c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1447ce2b1ec6SManish Pandey
144873c99d4eSJuan Castillo################################################################################
144973c99d4eSJuan Castillo# Build targets
145073c99d4eSJuan Castillo################################################################################
145173c99d4eSJuan Castillo
145290aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
145373c99d4eSJuan Castillo.SUFFIXES:
145473c99d4eSJuan Castillo
145573c99d4eSJuan Castilloall: msg_start
145673c99d4eSJuan Castillo
145773c99d4eSJuan Castillomsg_start:
145873c99d4eSJuan Castillo	@echo "Building ${PLAT}"
145973c99d4eSJuan Castillo
14607a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1461d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1462c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1463c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1464c2ad38ceSVarun Wadekarelse
1465bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14667a24cba5SSoby Mathewendif
1467c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14687a24cba5SSoby Mathew
14695accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
147061f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14715fee0287SRoberto Vargas
147273c99d4eSJuan Castillo# Expand build macros for the different images
147373c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1474b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1475434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1476c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
147773c99d4eSJuan Castillo
147873c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1479c5e1da83SJayanth Dodderi Chidanand
148042d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1481c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1482c9b31ae8SRoberto Vargasendif
1483c9b31ae8SRoberto Vargas
1484eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1485eb1acfb6SChris Kay
148633950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1487434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1488c5e1da83SJayanth Dodderi Chidanand
1489c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
149073c99d4eSJuan Castillo
14914d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
149233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1493c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14944d045d0eSMasahiro Yamada
149573c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
149673c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
149726d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
149826d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1499c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1500c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1501434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1502c6ba9b45SSumit Gargelse
150333950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1504434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1505c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1506c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
150773c99d4eSJuan Castillo
150870d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1509c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
151070d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
151173c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
151226d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
151326d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15149cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15159cd15239SMasahiro Yamada
1516c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1517434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1518c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1519c6ba9b45SSumit Gargelse
1520434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
152133950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1522c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1523c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
152473c99d4eSJuan Castillo
15255b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15265b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15275b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15285b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15295b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15305b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15315b18de09SZelalem Aweke
15325b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15335b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1534c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15355b18de09SZelalem Aweke
153673c99d4eSJuan Castillo# Add the BL33 image if required by the platform
153773c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
153833950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1539c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1540db6071c9SJuan Castillo
15419003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
154233950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1543434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1544c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15459003fa0bSYatharth Kochar
154603b397a8SNishanth Menon# Expand build macros for the different images
154703b397a8SNishanth Menonifeq (${NEED_FDT},yes)
154803b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1549c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
155003b397a8SNishanth Menon
1551ce2b1ec6SManish Pandey# Add Secure Partition packages
1552ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1553ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
15541e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1555822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1556ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1557ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1558ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1559c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1560ce2b1ec6SManish Pandey
156136eaaf37SIan Spraylocate-checkpatch:
156236eaaf37SIan Sprayifndef CHECKPATCH
156366079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156436eaaf37SIan Sprayelse
156536eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
156666079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156736eaaf37SIan Sprayendif
1568c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
156936eaaf37SIan Spray
15704f6ad66aSAchin Guptaclean:
15714f6ad66aSAchin Gupta	@echo "  CLEAN"
1572f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
157388a1cf1eSSami Mujawarifdef UNIX_MK
15742f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
157588a1cf1eSSami Mujawarelse
157688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
157788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
157888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1579c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15806f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
158190aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15825accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15834f6ad66aSAchin Gupta
1584eaaeece2SJames Morrisseyrealclean distclean:
1585eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1586f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1587f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
158888a1cf1eSSami Mujawarifdef UNIX_MK
15892f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
159088a1cf1eSSami Mujawarelse
159188a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
159288a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
159388a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1594c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1595e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
159690aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
15975accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15984f6ad66aSAchin Gupta
159936eaaf37SIan Spraycheckcodebase:		locate-checkpatch
160036eaaf37SIan Spray	@echo "  CHECKING STYLE"
160136eaaf37SIan Spray	@if test -d .git ; then						\
16021ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16031a41e8c1SDan Handley		while read GIT_FILE ;					\
16041a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16051a41e8c1SDan Handley		done ;							\
160636eaaf37SIan Spray	else								\
16071a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16081a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16091a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
161061f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16111a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16121ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16131a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
161436eaaf37SIan Spray	fi
161536eaaf37SIan Spray
161636eaaf37SIan Spraycheckpatch:		locate-checkpatch
161736eaaf37SIan Spray	@echo "  CHECKING STYLE"
161802a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
161902a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
162002a76d5fSYann Gautier	fi
162151d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
162277a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
162377a0a7f1SYann Gautier	do								\
162451d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
162551d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
162602a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162702a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
162851d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
162902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
163002a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
163151d28937SAntonio Nino Diaz	done
163236eaaf37SIan Spray
163373c99d4eSJuan Castillocerttool: ${CRTTOOL}
163473c99d4eSJuan Castillo
1635a9812206SPali Rohár${CRTTOOL}: FORCE
1636598b166bSLionel 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
1637f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16386f971622SJuan Castillo	@echo "Built $@ successfully"
1639f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16406f971622SJuan Castillo
16416f971622SJuan Castilloifneq (${GENERATE_COT},0)
164273c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16436f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1644f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16456f971622SJuan Castillo	@echo "Built $@ successfully"
16466f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1647f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1648c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
164927713fb4SSoby Mathew
165073c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16514727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1652819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1653819281eeSdp-arm	${Q}${FIPTOOL} info $@
1654f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16552f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1656f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1657f58ad36fSHarry Liebel
16580191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16590191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16600191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1661052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16620191262dSYatharth Kochar	@echo "Built $@ successfully"
16630191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1664052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1665c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16660191262dSYatharth Kochar
16670191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16684727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1669819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1670819281eeSdp-arm	${Q}${FIPTOOL} info $@
1671052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16720191262dSYatharth Kochar	@echo "Built $@ successfully"
1673052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16740191262dSYatharth Kochar
167573c99d4eSJuan Castillofiptool: ${FIPTOOL}
167673c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16770191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
167873c99d4eSJuan Castillo
1679a9812206SPali Rohár${FIPTOOL}: FORCE
168088a1cf1eSSami Mujawarifdef UNIX_MK
1681598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
168288a1cf1eSSami Mujawarelse
168388a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
168488a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
168588a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1686c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1687f58ad36fSHarry Liebel
1688a9812206SPali Rohárromlib.bin: libraries FORCE
1689bbb24f61SJohn 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
16905accce5bSRoberto Vargas
1691cfe83910SLouis Mayencourtmemmap: all
1692af5b49e9SHarrison Mutaiifdef UNIX_MK
1693af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1694af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1695af5b49e9SHarrison Mutaielse
1696af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1697af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1698af5b49e9SHarrison Mutaiendif
1699cfe83910SLouis Mayencourt
17006de32378SMadhukar Pappireddydoc:
17016de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
17026de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
17036de32378SMadhukar Pappireddy
170490aa901fSSumit Gargenctool: ${ENCTOOL}
170590aa901fSSumit Garg
1706a9812206SPali Rohár${ENCTOOL}: FORCE
1707598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
170890aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170990aa901fSSumit Garg	@echo "Built $@ successfully"
171090aa901fSSumit Garg	@${ECHO_BLANK_LINE}
171190aa901fSSumit Garg
171235fab8c9SJoakim Bechcscope:
171335fab8c9SJoakim Bech	@echo "  CSCOPE"
171435fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
171535fab8c9SJoakim Bech	${Q}cscope -b -q -k
171635fab8c9SJoakim Bech
171772ee3314SRyan Harkinhelp:
17187c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
171972ee3314SRyan Harkin	@echo ""
172072ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
172108c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
172272ee3314SRyan Harkin	@echo ""
17237c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17247c23126cSJohn Tsichritzis	@echo ""
17251b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17261b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17271b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17281b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17291b578596SSandrine Bailleux	@echo ""
173072ee3314SRyan Harkin	@echo "Supported Targets:"
17311b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
173236eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17338aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17349003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1735d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17369d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17379d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
173873c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17391b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17400191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
174136eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
174236eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
174336eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
174472ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
174535fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
174672ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17476f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
174890aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1749f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1750ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
175126010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
175238c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1753cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17546de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
175572ee3314SRyan Harkin	@echo ""
17561b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
175772ee3314SRyan Harkin	@echo ""
175872ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
175972ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1760a9812206SPali Rohár
1761a9812206SPali Rohár.PHONY: FORCE
1762a9812206SPali RohárFORCE:;
1763