xref: /rk3399_ARM-atf/Makefile (revision 20629b3153bccdda32116ed5c4861e61fa1fba95)
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
142*20629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
143c5e1da83SJayanth Dodderi Chidanand
144c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
145c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
146c5e1da83SJayanth Dodderi Chidanand
147c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
148c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
149c5e1da83SJayanth Dodderi Chidanand
150c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
151c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
152c5e1da83SJayanth Dodderi Chidanand
153c5e1da83SJayanth Dodderi Chidanand################################################################################
154c5e1da83SJayanth Dodderi Chidanand# Process BRANCH_PROTECTION value and set
155c5e1da83SJayanth Dodderi Chidanand# Pointer Authentication and Branch Target Identification flags
156c5e1da83SJayanth Dodderi Chidanand################################################################################
157c5e1da83SJayanth Dodderi Chidanandifeq (${BRANCH_PROTECTION},0)
158c5e1da83SJayanth Dodderi Chidanand	# Default value turns off all types of branch protection
159c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := none
160c5e1da83SJayanth Dodderi Chidanandelse ifneq (${ARCH},aarch64)
161c5e1da83SJayanth Dodderi Chidanand        $(error BRANCH_PROTECTION requires AArch64)
162c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},1)
163c5e1da83SJayanth Dodderi Chidanand	# Enables all types of branch protection features
164c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := standard
165c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
166c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
167c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},2)
168c5e1da83SJayanth Dodderi Chidanand	# Return address signing to its standard level
169c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret
170c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
171c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},3)
172c5e1da83SJayanth Dodderi Chidanand	# Extend the signing to include leaf functions
173c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := pac-ret+leaf
174c5e1da83SJayanth Dodderi Chidanand	ENABLE_PAUTH := 1
175c5e1da83SJayanth Dodderi Chidanandelse ifeq (${BRANCH_PROTECTION},4)
176c5e1da83SJayanth Dodderi Chidanand	# Turn on branch target identification mechanism
177c5e1da83SJayanth Dodderi Chidanand	BP_OPTION := bti
178c5e1da83SJayanth Dodderi Chidanand	ENABLE_BTI := 1
179c5e1da83SJayanth Dodderi Chidanandelse
180c5e1da83SJayanth Dodderi Chidanand        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
181c5e1da83SJayanth Dodderi Chidanandendif #(BRANCH_PROTECTION)
182c5e1da83SJayanth Dodderi Chidanand
183c5e1da83SJayanth Dodderi Chidanand################################################################################
184c5e1da83SJayanth Dodderi Chidanand# RME dependent flags configuration
185c5e1da83SJayanth Dodderi Chidanand################################################################################
186c5e1da83SJayanth Dodderi Chidanand# FEAT_RME
187c5e1da83SJayanth Dodderi Chidanandifeq (${ENABLE_RME},1)
188c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support PIE
189c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_PIE},0)
190c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support PIE)
191c5e1da83SJayanth Dodderi Chidanand	endif
192c5e1da83SJayanth Dodderi Chidanand
193c5e1da83SJayanth Dodderi Chidanand	# RME doesn't support BRBE
194c5e1da83SJayanth Dodderi Chidanand	ifneq (${ENABLE_BRBE_FOR_NS},0)
195c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME does not support BRBE.)
196c5e1da83SJayanth Dodderi Chidanand	endif
197c5e1da83SJayanth Dodderi Chidanand
198c5e1da83SJayanth Dodderi Chidanand	# RME requires AARCH64
199c5e1da83SJayanth Dodderi Chidanand	ifneq (${ARCH},aarch64)
200c5e1da83SJayanth Dodderi Chidanand                $(error ENABLE_RME requires AArch64)
201c5e1da83SJayanth Dodderi Chidanand	endif
202c5e1da83SJayanth Dodderi Chidanand
203c5e1da83SJayanth Dodderi Chidanand	# RME requires el2 context to be saved for now.
204c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_EL2_REGS := 1
205c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_AARCH32_REGS := 0
206c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MAJOR := 8
207c5e1da83SJayanth Dodderi Chidanand	ARM_ARCH_MINOR := 5
208c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV = 1
209c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT = 1
210c5e1da83SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS := 1
211c5e1da83SJayanth Dodderi Chidanand
212c5e1da83SJayanth Dodderi Chidanand	# RME enables CSV2_2 extension by default.
213c5e1da83SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 = 1
214c5e1da83SJayanth Dodderi Chidanandendif #(FEAT_RME)
215c5e1da83SJayanth Dodderi Chidanand
216c5e1da83SJayanth Dodderi Chidanand################################################################################
217c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
218c5e1da83SJayanth Dodderi Chidanand################################################################################
21926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
22026e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
221d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
22226e63c44SEtienne Carriereelse
22326e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
224c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
225c5e1da83SJayanth Dodderi Chidanand
226c5e1da83SJayanth Dodderi Chidanand################################################################################
227c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
228c5e1da83SJayanth Dodderi Chidanand################################################################################
229c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
230c5e1da83SJayanth Dodderi Chidanand
231c5e1da83SJayanth Dodderi Chidanand####################################################
232c5e1da83SJayanth Dodderi Chidanand# Enable required options for Memory Stack Tagging.
233c5e1da83SJayanth Dodderi Chidanand####################################################
23426e63c44SEtienne Carriere
2357ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2367ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2374a565bd8SSami Mujawar	# Check if revision is greater than or equal to 8.5
2384a565bd8SSami Mujawar	ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2397ff088d1SManish V Badarkhe		mem_tag_arch_support	= 	yes
2407ff088d1SManish V Badarkhe	endif
241c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
2427ff088d1SManish V Badarkhe
243f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2447ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2457ff088d1SManish V Badarkhe	ifdef mem_tag_arch_support
246f1821790SAlexei Fedorov		# Check for armclang and clang compilers
2477ff088d1SManish V Badarkhe		ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
248f1821790SAlexei Fedorov		# Add "memtag" architecture feature modifier if not specified
249f1821790SAlexei Fedorov			ifeq ( ,$(findstring memtag,$(arch-features)))
250f1821790SAlexei Fedorov				arch-features	:=	$(arch-features)+memtag
251f1821790SAlexei Fedorov			endif	# memtag
2527ff088d1SManish V Badarkhe			ifeq ($(notdir $(CC)),armclang)
2537ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-mmemtag-stack
2547ff088d1SManish V Badarkhe			else ifeq ($(notdir $(CC)),clang)
2557ff088d1SManish V Badarkhe				TF_CFLAGS	+=	-fsanitize=memtag
256f1821790SAlexei Fedorov			endif	# armclang
257c5e1da83SJayanth Dodderi Chidanand		endif
2587ff088d1SManish V Badarkhe	else
259c5e1da83SJayanth Dodderi Chidanand                $(error "Error: stack memory tagging is not supported for  \
260c5e1da83SJayanth Dodderi Chidanand                 architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
261c5e1da83SJayanth Dodderi Chidanand	endif #(mem_tag_arch_support)
262c5e1da83SJayanth Dodderi Chidanandendif #(SUPPORT_STACK_MEMTAG)
263f1821790SAlexei Fedorov
264f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
265f1821790SAlexei Fedorovifneq ($(arch-features), none)
266f1821790SAlexei Fedorov	# Strip "none+" from arch-features
267f1821790SAlexei Fedorov	arch-features	:=	$(subst none+,,$(arch-features))
268d4089fb8SGovindraj Raja	march-directive	:=	$(march-directive)+$(arch-features)
269f1821790SAlexei Fedorov# Print features
270f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
271c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
2724e04478aSChris Kay
273c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
274fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
2757794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
2767794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
277c8a992fdSorigin		LD			:=	$(LINKER)
278c8a992fdSorigin	else
2797794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
2807794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
281c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
282c8a992fdSorigin
283c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
284c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
285c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
286641f16e7SAmbroise Vincent	endif
287c8a992fdSorigin
288c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
289c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
290c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
291edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
292edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
293edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
294edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
295edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
296edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
297edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
298edbce9aaSzelalem-aweke		endif
299edbce9aaSzelalem-aweke	endif
300edbce9aaSzelalem-aweke	LD			=	$(LINKER)
301d5461857Sdp-armelse
3022adee763SRoberto Vargas	LD			=	$(LINKER)
303c5e1da83SJayanth Dodderi Chidanandendif #(clang)
304d5461857Sdp-arm
30532b209bfSAhmad Fatoum# Process Debug flag
30632b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
30732b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
30832b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
3094466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
3104466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
31132b209bfSAhmad Fatoum
31232b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
31332b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
31432b209bfSAhmad Fatoumelse
31532b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
31632b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
31732b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
318c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
31932b209bfSAhmad Fatoum
320f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
321f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
322f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
323f1de4c8fSPeiyuan Songendif
324dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
325f1de4c8fSPeiyuan Song
3268fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3278fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
3288fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3298fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
3308fd9d4d5SAntonio Nino Diazelse
3318fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
332c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
3338fd9d4d5SAntonio Nino Diaz
334a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
335d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3369d29c227SSoby Mathew
3379fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3389fc59639SAlexei Fedorov	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
339c5e1da83SJayanth Dodderi Chidanandendif #(BP_OPTION)
3409fc59639SAlexei Fedorov
341d4089fb8SGovindraj RajaASFLAGS		+=	$(march-directive)
342b86048c4SAntonio Nino Diaz
343c5e1da83SJayanth Dodderi Chidanand##############################################################################
344c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
345c5e1da83SJayanth Dodderi Chidanand###############################################################################
3469ab81b5eSJustin Chadwell# General warnings
3479ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
348b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
349d75a9ecdSBoyan Karatotev				-Wredundant-decls
350d75a9ecdSBoyan Karatotev# stricter warnings
351d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
352d75a9ecdSBoyan Karatotev# too verbose for generic build
353d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
354d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
355d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
356d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
3579ab81b5eSJustin Chadwell
3589ab81b5eSJustin Chadwell# Additional warnings
359d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
360d75a9ecdSBoyan Karatotev# full -Wextra
361d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
362d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
363d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
364e7c645b5SYann Gautier
365d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
366d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
367d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
368d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
369d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
370d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
371d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
372d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
373d141e638SBoyan Karatotev# currently very involved and many platforms set this off
374d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
375e7c645b5SYann Gautier
376d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
377e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
378d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
379d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
380d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
381e7c645b5SYann GautierWARNING3 += -Wcast-qual
382e7c645b5SYann GautierWARNING3 += -Wconversion
383e7c645b5SYann GautierWARNING3 += -Wpacked
384e7c645b5SYann GautierWARNING3 += -Wpointer-arith
385e7c645b5SYann GautierWARNING3 += -Wswitch-default
386e7c645b5SYann Gautier
387d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
388d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
389d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
390d75a9ecdSBoyan Karatotevifdef W
391d75a9ecdSBoyan Karatotev	ifneq (${W},0)
392d75a9ecdSBoyan Karatotev		E	 ?= 0
393d75a9ecdSBoyan Karatotev	endif
394d75a9ecdSBoyan Karatotevendif
395d75a9ecdSBoyan Karatotev
396e7c645b5SYann Gautierifeq (${W},1)
3979ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
398e7c645b5SYann Gautierelse ifeq (${W},2)
3999ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
400e7c645b5SYann Gautierelse ifeq (${W},3)
4019ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
402c5e1da83SJayanth Dodderi Chidanandendif #(W)
403e7c645b5SYann Gautier
4049ab81b5eSJustin Chadwell# Compiler specific warnings
40500296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
40693c690ebSJustin Chadwell# not using clang
407d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
408d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
409d7b4cd41SJustin Chadwell				-Wlogical-op
410dea23e24SGovindraj Raja
411dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
412dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
413dea23e24SGovindraj Raja
41493c690ebSJustin Chadwellelse
41593c690ebSJustin Chadwell# using clang
416d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
417d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
418c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
41900296576SAmbroise Vincent
4206336b07aSYann Gautierifneq (${E},0)
4216336b07aSYann Gautier	ERRORS := -Werror
422c5e1da83SJayanth Dodderi Chidanandendif #(E)
4236336b07aSYann Gautier
424c5e1da83SJayanth Dodderi Chidanand################################################################################
425c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
426c5e1da83SJayanth Dodderi Chidanand################################################################################
427ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
4289ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
429d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
430d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
43159de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
432ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
433ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
434ebd6efaeSSamuel Holland				-Os -std=gnu99
43573c99d4eSJuan Castillo
4361f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4371f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
438c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
439c5e1da83SJayanth Dodderi Chidanand
4401f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4411f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
4421f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
443c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
4441f461979SJustin Chadwell
445f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
446f7ec31dbSdavid cunado
4471f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
4481f49db5fSMarco Felsch
449641f16e7SAmbroise Vincent# LD = armlink
450c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
451c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
452c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
453edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
454641f16e7SAmbroise Vincent
455641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
456edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
457edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
458edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
459edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
460ac98b82aSChris Kay
461ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
462ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
463ac98b82aSChris Kay
464edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
465edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
466edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
467edbce9aaSzelalem-aweke		endif
468c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
469c5e1da83SJayanth Dodderi Chidanand
470edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
471edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
472edbce9aaSzelalem-aweke	ifneq (${ERRATA_A53_843419},1)
473edbce9aaSzelalem-aweke		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
474edbce9aaSzelalem-aweke	endif
475edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
476edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
477641f16e7SAmbroise Vincent
478641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
479c2ad38ceSVarun Wadekarelse
4801f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
4811f49db5fSMarco Felsch# are not loaded by a elf loader.
4821f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
483ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
484c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
485ac98b82aSChris Kay
486ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
487ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
488ac98b82aSChris Kay
489641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
490ebac6922SYabin Cui# therefore don't add those in that case.
491ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
492ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
493641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
494ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
495edbce9aaSzelalem-aweke	endif
496c5e1da83SJayanth Dodderi Chidanand
497c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
49873c99d4eSJuan Castillo
49903b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
500a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
501a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
50203b397a8SNishanth Menon
50373c99d4eSJuan Castillo################################################################################
50473c99d4eSJuan Castillo# Common sources and include directories
50573c99d4eSJuan Castillo################################################################################
5066a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
507d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
50873c99d4eSJuan Castillo
50973c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
5107f56e9a3SSoby Mathew				common/tf_log.c				\
5119d29c227SSoby Mathew				common/${ARCH}/debug.S			\
51291b48c9fSJulius Werner				drivers/console/multi_console.c		\
5139d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
5149d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
515c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
516566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
5177f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
51875311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
5199d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
52061f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
521d7a6b0f8SRyan Harkin
52290ce8b87SBoyan Karatotev# Pointer Authentication sources
52390ce8b87SBoyan Karatotevifeq (${ENABLE_PAUTH}, 1)
52490ce8b87SBoyan Karatotev# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
52590ce8b87SBoyan Karatotev# Pauth support. As it's not secure, it must be reimplemented for real platforms
52690ce8b87SBoyan Karatotev	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
52790ce8b87SBoyan Karatotevendif
52890ce8b87SBoyan Karatotev
5298422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
5308422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
5318422a840SAntonio Nino Diazendif
5328422a840SAntonio Nino Diaz
5331f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
5341f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
5351f461979SJustin Chadwellendif
5361f461979SJustin Chadwell
53701d237cbSYann GautierINCLUDES		+=	-Iinclude				\
538f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
53909d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
54009d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
54109d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
54209d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
54309d40e0eSAntonio Nino Diaz
5449c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5459c6d1c50SAntonio Nino Diaz
54673c99d4eSJuan Castillo################################################################################
54773c99d4eSJuan Castillo# Generic definitions
54873c99d4eSJuan Castillo################################################################################
549231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
550231c1470SEvan Lloyd
55129214e95SGrant Likelyifeq (${BUILD_BASE},)
55273c99d4eSJuan Castillo     BUILD_BASE		:=	./build
55329214e95SGrant Likelyendif
55429214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
55573c99d4eSJuan Castillo
556231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
55773c99d4eSJuan Castillo
55873c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
55973c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
56073c99d4eSJuan Castillo
56173c99d4eSJuan Castillo################################################################################
56273c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
56373c99d4eSJuan Castillo################################################################################
56473c99d4eSJuan Castillo
56573c99d4eSJuan Castilloifneq (${SPD},none)
5669d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5679d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5689d29c227SSoby Mathew	endif
56928f39f02SMax Shvetsov
5704c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5714c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
572c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
573c5e1da83SJayanth Dodderi Chidanand                ignored.")
5744c117f6cSSandrine Bailleux	endif
57528f39f02SMax Shvetsov
576c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
577c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
578c3fb00d9SAchin Gupta		SPD_DIR := std_svc
57928f39f02SMax Shvetsov
580033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
581f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5821d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
5831d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5841d63ae4dSMarc Bonnici			endif
58528f39f02SMax Shvetsov		endif
586db1ef41aSOlivier Deprez
587db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
588db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
589db1ef41aSOlivier Deprez		endif
590ca932481SDavidson K
591ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
592ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
593ca932481SDavidson K		endif
59433993a37SBalint Dobszay
59533993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
59633993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
59733993a37SBalint Dobszay		endif
59846789a7cSBalint Dobszay
59946789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
60046789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
60146789a7cSBalint Dobszay		endif
602c3fb00d9SAchin Gupta	else
603c3fb00d9SAchin Gupta		# All other SPDs in spd directory
604c3fb00d9SAchin Gupta		SPD_DIR := spd
605c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
606c3fb00d9SAchin Gupta
60773c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
608c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
609c3fb00d9SAchin Gupta
61073c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
611c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
61273c99d4eSJuan Castillo	endif
61373c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
61473c99d4eSJuan Castillo        include ${SPD_MAKE}
61573c99d4eSJuan Castillo
61670d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
61770d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
61870d1fc53SJuan Castillo	# supports two mutually exclusive options:
61970d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
62070d1fc53SJuan Castillo	#   of source files to build BL32
62170d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
62270d1fc53SJuan Castillo	#   that will be included in the FIP
62370d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
62470d1fc53SJuan Castillo	# over the sources.
625c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
626e35c4045SJeenu Viswambharan
627f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
628f1910cc1SGovindraj Raja	ifeq (${SPD},none)
629f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
630c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
631c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
632f1910cc1SGovindraj Raja		endif
633f1910cc1SGovindraj Raja	endif
634f1910cc1SGovindraj Rajaendif
635f1910cc1SGovindraj Raja
63651faada7SDouglas Raillard################################################################################
6375b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6385b18de09SZelalem Aweke################################################################################
6395b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6405b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6415b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6425b18de09SZelalem Aweke	endif
6431d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6441d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6451d63ae4dSMarc Bonnici	endif
646c5e1da83SJayanth Dodderi Chidanand
6474fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6484fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6494fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6504fba2e1fSBoyan Karatotev		endif
6514fba2e1fSBoyan Karatotev	endif
6525b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6535b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6545b18de09SZelalem Awekeendif
6555b18de09SZelalem Aweke
6565b18de09SZelalem Aweke################################################################################
65773c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
65873c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
65973c99d4eSJuan Castillo################################################################################
6602da8d8bfSJeenu Viswambharan
66173c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6620f21c547SJuan Castillo
6637794d6c8SGovindraj Raja################################################################################
6647794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6657794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6667794d6c8SGovindraj Raja################################################################################
6677794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6687794d6c8SGovindraj Raja
6697794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6707794d6c8SGovindraj Raja
67142d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
67242d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
67342d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
67442d4d3baSArvind Ram Prakash# BL2 in EL3
67542d4d3baSArvind Ram Prakash
67642d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
67742d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
67842d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
679c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
680c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
68142d4d3baSArvind Ram Prakash	endif
68242d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
68342d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68442d4d3baSArvind Ram Prakashelse
68542d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
68642d4d3baSArvind Ram Prakashendif
68742d4d3baSArvind Ram Prakash
6888012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6898012cc5cSMasahiro Yamada
69026e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
69126e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
69226e63c44SEtienne Carriereendif
69326e63c44SEtienne Carriere
6943bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6953bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6963bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6977b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
6987b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
6997b592418SSamuel Hollandendif
700c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
701320920c1SMasahiro Yamada
702320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
703320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
704320920c1SMasahiro Yamadaelse
705320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
706320920c1SMasahiro Yamadaendif
707320920c1SMasahiro Yamada
708320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
70942d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71069af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
711966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
71269af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
71369af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
714c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
715c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
716966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
717320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
718320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
719966660ecSChris Kay
720966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
721d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
722d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
723c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7243bd17c0fSSoby Mathew
725007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
726007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
727007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
728007433d8SBoyan Karatotev
7299cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73042d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7319cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
732d5e97a1dSMasahiro Yamadaelse
7339cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
734c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
735007433d8SBoyan Karatotev
736007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7379cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7389cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7399cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
740007433d8SBoyan Karatotevelse
741007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
742d5e97a1dSMasahiro Yamadaendif
743d5e97a1dSMasahiro Yamada
74454035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
74554035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
74654035fc4SSandrine Bailleux# This can be overridden by the platform.
74773c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7484f6ad66aSAchin Gupta
749a4409008Sdp-arm################################################################################
750a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
751a4409008Sdp-arm################################################################################
752c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
753c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
754c5e1da83SJayanth Dodderi Chidanand
755a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
756a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
757a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
758a4409008Sdp-arm
759a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
760a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
761a4409008Sdp-arm                endif
762a4409008Sdp-arm        $(info Including ${AARCH32_SP_MAKE})
763a4409008Sdp-arm        include ${AARCH32_SP_MAKE}
764a4409008Sdp-arm        endif
765c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7664f6ad66aSAchin Gupta
76773c99d4eSJuan Castillo################################################################################
76877f1f7a1SVarun Wadekar# Include libc if not overridden
76977f1f7a1SVarun Wadekar################################################################################
77077f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
77177f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
77277f1f7a1SVarun Wadekarendif
77377f1f7a1SVarun Wadekar
77477f1f7a1SVarun Wadekar################################################################################
775c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
776cf2c8a33SAntonio Nino Diaz################################################################################
777cf2c8a33SAntonio Nino Diaz
778c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
779c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
780c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
781c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
782c5e1da83SJayanth Dodderi Chidanand        else
783c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
784c5e1da83SJayanth Dodderi Chidanand        endif
785c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
786c5e1da83SJayanth Dodderi Chidanand
787c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
788c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
789c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
790c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
791c5e1da83SJayanth Dodderi Chidanand        endif
792c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
793c5e1da83SJayanth Dodderi Chidanand
794c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
795c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
796c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
797c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
798c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
799c5e1da83SJayanth Dodderi Chidanandendif
800c5e1da83SJayanth Dodderi Chidanand
801c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
802c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
803c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
804c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
805c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
806c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
807c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
808c5e1da83SJayanth Dodderi Chidanand
809cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81068450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
81168450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
81268450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
813cf2c8a33SAntonio Nino Diaz	endif
81476580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
815c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
816c5e1da83SJayanth Dodderi Chidanand                build options.")
81776580f3dSQixiang Xu	endif
81876580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
819c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
820c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
82176580f3dSQixiang Xu	endif
822c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
823cf2c8a33SAntonio Nino Diaz
824cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
825cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
826cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
827cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
828cf2c8a33SAntonio Nino Diaz	endif
82968450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83068450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
831c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
832cf2c8a33SAntonio Nino Diaz	endif
833c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
834cf2c8a33SAntonio Nino Diaz
835d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
836d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
837d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
838d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
839d4593e47SJeenu Viswambharanendif
8401a0a3f06SYatharth Kochar
84142d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
84242d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
84342d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8447d173fc5SJiafei Panendif
8457d173fc5SJiafei Pan
8469202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
84714c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
848c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
849c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8509202d519SManish Pandeyendif
851c5e1da83SJayanth Dodderi Chidanand
8529202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8539202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8549202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8559202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8569202d519SManish Pandey	endif
85746cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8589202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
85914c6016aSJeenu Viswambharan	endif
860c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
861c5e1da83SJayanth Dodderi Chidanand
8629202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8631a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8646503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8656503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8661a7c1cfeSJeenu Viswambharan	endif
867c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8681a7c1cfeSJeenu Viswambharan
869ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
870209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
871209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
872c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
873c5e1da83SJayanth Dodderi Chidanand                to be set.")
874209a60ccSSoby Mathew	endif
875c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
876209a60ccSSoby Mathew
8772bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8782bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8792bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8802bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8812bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8822bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8832bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8842bf4f27fSManish V Badarkhe# Support hash calculation only
8852bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8862bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8872bf4f27fSManish V Badarkhe# Support authentication verification only
888c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
889c9c56f6eSManish V Badarkheelse
890c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
891c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
892c9c56f6eSManish V Badarkhe
893cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
894cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
895700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
89684ef9cd8SManish V Badarkheendif
89784ef9cd8SManish V Badarkhe
898b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
8999fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9009fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
901b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9029fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9039fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
90406715f85SAlexei Fedorov	endif
905c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9069fc59639SAlexei Fedorov
90706715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9089fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9099fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
910b86048c4SAntonio Nino Diaz	endif
911c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9129fc59639SAlexei Fedorov
9139dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9149dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9159dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9169dd94382SJustin Chadwell	endif
917c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9189dd94382SJustin Chadwell
919396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
920396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
921c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
922396b339dSManish V Badarkhe
9236a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9246a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
925c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9266a0da736SJayanth Dodderi Chidanand
92703d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
92803d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
929c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
930c5e1da83SJayanth Dodderi Chidanand                to be set")
93103d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
93203d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
93303d3c0d7SJayanth Dodderi Chidanand	endif
934c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
93545007acdSJayanth Dodderi Chidanand
93660e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
93760e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
938c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
939c5e1da83SJayanth Dodderi Chidanand                library v2")
94060e8f3cfSPetre-Ionut Tudor	endif
941c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
94260e8f3cfSPetre-Ionut Tudor
9437cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9447cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
945c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
946c5e1da83SJayanth Dodderi Chidanand                to be set)
9477cda17bbSSumit Garg	endif
948c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9497cda17bbSSumit Garg
950744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
951dc78e62dSjohpow01ifeq (${ARCH},aarch32)
952744ad974Sjohpow01
953744ad974Sjohpow01	# SME/SVE only supported on AArch64
95445007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
955dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
956dc78e62dSjohpow01	endif
95703d3c0d7SJayanth Dodderi Chidanand
958dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
959dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96024ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
961dc78e62dSjohpow01	endif
962744ad974Sjohpow01
963ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
964744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
965744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
966744ad974Sjohpow01	endif
967744ad974Sjohpow01
968ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
969ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
970ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
971ff86e0b4SJuan Pablo Conde	endif
972c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
973dc78e62dSjohpow01
974dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
975dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
97645007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
977dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
978dc78e62dSjohpow01	endif
979dc78e62dSjohpow01endif
980dc78e62dSjohpow01
9810d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9820d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9830d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9840d122947SBoyan Karatotev	endif
985c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9860d122947SBoyan Karatotev
987dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
988dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
989dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
990dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
991dc78e62dSjohpow01	endif
9920d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9930d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9940d122947SBoyan Karatotev	endif
995c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
996c5e1da83SJayanth Dodderi Chidanand
997dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
998dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
999dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1000dc78e62dSjohpow01	endif
1001c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1002dc78e62dSjohpow01
1003dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1004dc78e62dSjohpow01# its own context management including FPU registers.
1005dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
100645007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1007dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1008dc78e62dSjohpow01	endif
100903d3c0d7SJayanth Dodderi Chidanand
1010dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1011dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1012dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1013dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1014dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1015dc78e62dSjohpow01	endif
1016c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1017dc78e62dSjohpow01
101800e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
101900e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102000e28874SManish V Badarkheendif
102100e28874SManish V Badarkhe
1022274a69e7SChris Kayifeq (${ENABLE_RME},1)
1023274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1024274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1025274a69e7SChris Kay	endif
1026274a69e7SChris Kayendif
1027274a69e7SChris Kay
1028c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1029c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1030c5e1da83SJayanth Dodderi Chidanand
1031c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1032c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1033c5e1da83SJayanth Dodderi Chidanand
1034cf2c8a33SAntonio Nino Diaz################################################################################
103573c99d4eSJuan Castillo# Process platform overrideable behaviour
103673c99d4eSJuan Castillo################################################################################
10374f6ad66aSAchin Gupta
10385f24ce96SManish Pandeyifdef BL1_SOURCES
10395f24ce96SManish Pandey	NEED_BL1 := yes
1040c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10415f24ce96SManish Pandey
10425f24ce96SManish Pandeyifdef BL2_SOURCES
10435f24ce96SManish Pandey	NEED_BL2 := yes
10445f24ce96SManish Pandey
1045bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1046bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1047cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1048cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1049cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10504c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1051cf2c8a33SAntonio Nino Diaz	else
105268450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1053cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1054cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1055cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1056cf2c8a33SAntonio Nino Diaz		else
1057cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1058cf2c8a33SAntonio Nino Diaz		endif
10594c117f6cSSandrine Bailleux	endif
1060c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10616f971622SJuan Castillo
10625f24ce96SManish Pandeyifdef BL2U_SOURCES
10635f24ce96SManish Pandey	NEED_BL2U := yes
1064c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10655f24ce96SManish Pandey
10664d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10674d045d0eSMasahiro Yamadaifdef SCP_BL2
10684d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1069c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10704d045d0eSMasahiro Yamada
10715744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10725744e874SSoby Mathewifneq (${ARCH},aarch32)
10735744e874SSoby Mathew	ifdef BL31_SOURCES
1074c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1075c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10765744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10775744e874SSoby Mathew			NEED_BL31 := yes
10785744e874SSoby Mathew		endif
10795744e874SSoby Mathew	endif
1080c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10815744e874SSoby Mathew
108273c99d4eSJuan Castillo# Process TBB related flags
10836f971622SJuan Castilloifneq (${GENERATE_COT},0)
108473c99d4eSJuan Castillo	# Common cert_create options
10856f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10866f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10870191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1088fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1089fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10900191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1091fd34e7baSJuan Castillo		endif
10926f971622SJuan Castillo	endif
109373c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
109473c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
109573c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
109673c99d4eSJuan Castillo	endif
1097c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
10986f971622SJuan Castillo
10991c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11001c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1101c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11021c75d5dfSMasahiro Yamada
11035f24ce96SManish Pandeyifdef FDT_SOURCES
11045f24ce96SManish Pandey	NEED_FDT := yes
1105c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11065f24ce96SManish Pandey
110773c99d4eSJuan Castillo################################################################################
110846e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
110946e5e035SMichalis Pappas################################################################################
111046e5e035SMichalis Pappas
111146e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
111246e5e035SMichalis Pappas
111346e5e035SMichalis Pappas################################################################################
11148a86052dSSoby Mathew# Include BL specific makefiles
11158a86052dSSoby Mathew################################################################################
11165f24ce96SManish Pandey
11175f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11188a86052dSSoby Mathewinclude bl1/bl1.mk
11198a86052dSSoby Mathewendif
11208a86052dSSoby Mathew
11215f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11228a86052dSSoby Mathewinclude bl2/bl2.mk
11238a86052dSSoby Mathewendif
11248a86052dSSoby Mathew
11255f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11268a86052dSSoby Mathewinclude bl2u/bl2u.mk
11278a86052dSSoby Mathewendif
11288a86052dSSoby Mathew
11295744e874SSoby Mathewifeq (${NEED_BL31},yes)
11308a86052dSSoby Mathewinclude bl31/bl31.mk
11318a86052dSSoby Mathewendif
113203b397a8SNishanth Menon
113373c99d4eSJuan Castillo################################################################################
113473c99d4eSJuan Castillo# Build options checks
113573c99d4eSJuan Castillo################################################################################
113673c99d4eSJuan Castillo
1137c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1138327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1139327131c4SLeonardo Sandoval    $(sort \
1140327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
114146789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1142327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1143327131c4SLeonardo Sandoval	CREATE_KEYS \
1144327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1145327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1146327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1147327131c4SLeonardo Sandoval	DEBUG \
1148327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1149327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11501fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1151742ca230SChris Kay	ENABLE_AMU_FCONF \
1152873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1153327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
115424077098SAndre Przywara	ENABLE_FEAT_SB \
1155327131c4SLeonardo Sandoval	ENABLE_PIE \
1156327131c4SLeonardo Sandoval	ENABLE_PMF \
1157327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1158327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1159dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11600c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1161327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1162327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1163327131c4SLeonardo Sandoval	GENERATE_COT \
1164327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
116546cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1166327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1167327131c4SLeonardo Sandoval	MEASURED_BOOT \
116800e28874SManish V Badarkhe	DRTM_SUPPORT \
1169327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1170327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1171327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11720ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1173327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1174327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
117564b4710bSWing Li	PSCI_OS_INIT_MODE \
1176327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1177327131c4SLeonardo Sandoval	SAVE_KEYS \
1178327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
117996a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1180327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1181327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1182327131c4SLeonardo Sandoval	SPM_MM \
11831d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1184327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1185327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1186327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1187327131c4SLeonardo Sandoval	USE_DEBUGFS \
1188327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1189327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1190327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1191327131c4SLeonardo Sandoval	USE_ROMLIB \
1192327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1193327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
119442d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1195327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1196327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1197327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1198327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1199327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1200327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
120100e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1202327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1203327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1204396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
120568120783SChris Kay	ENABLE_MPMM \
120668120783SChris Kay	ENABLE_MPMM_FCONF \
12076a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12080b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1209ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1210ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
121104c7303bSOkash Khawaja	CONDITIONAL_CMO \
12129202d519SManish Pandey	RAS_FFH_SUPPORT \
1213327131c4SLeonardo Sandoval)))
121473c99d4eSJuan Castillo
1215c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1216327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1217327131c4SLeonardo Sandoval    $(sort \
1218327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1219327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1220327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12216a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12226a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12236a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12242bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
122583a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12261298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
122747c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12286a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12296a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1230d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12316a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12326a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12339202d519SManish Pandey	ENABLE_FEAT_RAS	\
12346a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12356a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12366a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12376a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12386a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12396a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1240ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12416a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1242d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1243062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1244062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1245062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1246062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1247688ab57bSMark Brown	ENABLE_FEAT_GCS \
12486a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12494d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
12506a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12516a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12526437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1253603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
125445007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
125503d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12562b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12576a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1258327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12595357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12605357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1261781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1262781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1263bebcf27fSMark Brown	SVE_VECTOR_LEN \
12640ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1265327131c4SLeonardo Sandoval)))
1266c877b414SJeenu Viswambharan
1267aacff749SJustin Chadwellifdef KEY_SIZE
1268aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1269aacff749SJustin Chadwellendif
1270aacff749SJustin Chadwell
12711f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12721f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12731f461979SJustin Chadwellendif
12741f461979SJustin Chadwell
127573c99d4eSJuan Castillo################################################################################
127673c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
127773c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
127873c99d4eSJuan Castillo# platform to overwrite the default options
127973c99d4eSJuan Castillo################################################################################
128073c99d4eSJuan Castillo
1281327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1282327131c4SLeonardo Sandoval    $(sort \
1283327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1284327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1285327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
128646789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1287327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1288327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1289327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1290327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1291327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1292327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1293327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1294062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1295327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
12960063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1297d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12981fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1299742ca230SChris Kay	ENABLE_AMU_FCONF \
1300873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1301327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1302327131c4SLeonardo Sandoval	ENABLE_BTI \
1303327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1304327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1305327131c4SLeonardo Sandoval	ENABLE_PIE \
1306327131c4SLeonardo Sandoval	ENABLE_PMF \
1307327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13085b18de09SZelalem Aweke	ENABLE_RME \
1309327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1310dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131103d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1312dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
131390118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1314327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13150c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1316327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1317327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1318327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1319327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1320327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132146cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1322327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1323327131c4SLeonardo Sandoval	LOG_LEVEL \
1324327131c4SLeonardo Sandoval	MEASURED_BOOT \
132500e28874SManish V Badarkhe	DRTM_SUPPORT \
1326327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1327327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1328327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13290ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1330327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1331327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
133264b4710bSWing Li	PSCI_OS_INIT_MODE \
13339202d519SManish Pandey	ENABLE_FEAT_RAS \
13349202d519SManish Pandey	RAS_FFH_SUPPORT \
1335327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1336327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
133796a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1338327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1339327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1340327131c4SLeonardo Sandoval	SPD_${SPD} \
1341327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1342327131c4SLeonardo Sandoval	SPM_MM \
13431d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1344327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1345327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1346c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13477dfb9911SJimmy Brisson	TRNG_SUPPORT \
1348ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1349ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1350327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1351327131c4SLeonardo Sandoval	USE_DEBUGFS \
1352327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1353327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1354327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1355327131c4SLeonardo Sandoval	USE_ROMLIB \
1356327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1357327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
135842d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
135942d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1360327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1361327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1362327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1363327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
136400e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1365327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1366327131c4SLeonardo Sandoval	USE_SP804_TIMER \
136712cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1368ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13694e04478aSChris Kay	ENABLE_FEAT_SB \
13707d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13715357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13725357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1373396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1374744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1375813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1376d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13778fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1378cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
137968120783SChris Kay	ENABLE_MPMM \
138068120783SChris Kay	ENABLE_MPMM_FCONF \
1381f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1382f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13836a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13846a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13856a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13866a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13876a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1388d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1389062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1390062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1391062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1392062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1393688ab57bSMark Brown	ENABLE_FEAT_GCS \
13944d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
13956a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1396781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1397781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
139804c7303bSOkash Khawaja	CONDITIONAL_CMO \
13990ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1400a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1401327131c4SLeonardo Sandoval)))
14022fae4b1eSJeenu Viswambharan
14031f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14041f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1405c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14061f461979SJustin Chadwell
14074c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14084c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14094c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1410cf2c8a33SAntonio Nino Diazelse
141168450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
141268450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
141368450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
141468450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14154c117f6cSSandrine Bailleux	endif
1416c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
141773c99d4eSJuan Castillo
1418209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1419209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1420209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1421209a60ccSSoby Mathewendif
1422209a60ccSSoby Mathew
1423c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1424c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1425c2ad38ceSVarun Wadekarendif
1426c2ad38ceSVarun Wadekar
1427ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1428ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1429c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1430ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1431ce2b1ec6SManish Pandey	FIP_DEPS += sp
143207c44475SManish Pandey	CRT_DEPS += sp
1433ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1434ce2b1ec6SManish Pandeyelse
1435c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1436c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1437c33ff198SOlivier Deprez	endif
1438c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1439c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1440ce2b1ec6SManish Pandey
144173c99d4eSJuan Castillo################################################################################
144273c99d4eSJuan Castillo# Build targets
144373c99d4eSJuan Castillo################################################################################
144473c99d4eSJuan Castillo
144590aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
144673c99d4eSJuan Castillo.SUFFIXES:
144773c99d4eSJuan Castillo
144873c99d4eSJuan Castilloall: msg_start
144973c99d4eSJuan Castillo
145073c99d4eSJuan Castillomsg_start:
145173c99d4eSJuan Castillo	@echo "Building ${PLAT}"
145273c99d4eSJuan Castillo
14537a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1454d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1455c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1456c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1457c2ad38ceSVarun Wadekarelse
1458bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14597a24cba5SSoby Mathewendif
1460c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14617a24cba5SSoby Mathew
14625accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
146361f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14645fee0287SRoberto Vargas
146573c99d4eSJuan Castillo# Expand build macros for the different images
146673c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1467b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1468434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1469c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
147073c99d4eSJuan Castillo
147173c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1472c5e1da83SJayanth Dodderi Chidanand
147342d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1474c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1475c9b31ae8SRoberto Vargasendif
1476c9b31ae8SRoberto Vargas
1477eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1478eb1acfb6SChris Kay
147933950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1480434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1481c5e1da83SJayanth Dodderi Chidanand
1482c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
148373c99d4eSJuan Castillo
14844d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
148533950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1486c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14874d045d0eSMasahiro Yamada
148873c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
148973c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
149026d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
149126d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1492c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1493c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1494434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1495c6ba9b45SSumit Gargelse
149633950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1497434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1498c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1499c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
150073c99d4eSJuan Castillo
150170d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1502c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
150370d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
150473c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
150526d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
150626d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15079cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15089cd15239SMasahiro Yamada
1509c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1510434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1511c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1512c6ba9b45SSumit Gargelse
1513434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
151433950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1515c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1516c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
151773c99d4eSJuan Castillo
15185b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15195b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15205b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15215b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15225b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15235b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15245b18de09SZelalem Aweke
15255b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15265b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1527c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15285b18de09SZelalem Aweke
152973c99d4eSJuan Castillo# Add the BL33 image if required by the platform
153073c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
153133950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1532c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1533db6071c9SJuan Castillo
15349003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
153533950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1536434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1537c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15389003fa0bSYatharth Kochar
153903b397a8SNishanth Menon# Expand build macros for the different images
154003b397a8SNishanth Menonifeq (${NEED_FDT},yes)
154103b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1542c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
154303b397a8SNishanth Menon
1544ce2b1ec6SManish Pandey# Add Secure Partition packages
1545ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1546ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk : ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1547*20629b31SKarl Meakin	${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1548822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1549ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1550ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1551ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1552c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1553ce2b1ec6SManish Pandey
155436eaaf37SIan Spraylocate-checkpatch:
155536eaaf37SIan Sprayifndef CHECKPATCH
155666079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
155736eaaf37SIan Sprayelse
155836eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
155966079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156036eaaf37SIan Sprayendif
1561c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
156236eaaf37SIan Spray
15634f6ad66aSAchin Guptaclean:
15644f6ad66aSAchin Gupta	@echo "  CLEAN"
1565f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
156688a1cf1eSSami Mujawarifdef UNIX_MK
15672f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
156888a1cf1eSSami Mujawarelse
156988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
157088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
157188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1572c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15736f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
157490aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15755accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15764f6ad66aSAchin Gupta
1577eaaeece2SJames Morrisseyrealclean distclean:
1578eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1579f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1580f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
158188a1cf1eSSami Mujawarifdef UNIX_MK
15822f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
158388a1cf1eSSami Mujawarelse
158488a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
158588a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
158688a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1587c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1588e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
158990aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
15905accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15914f6ad66aSAchin Gupta
159236eaaf37SIan Spraycheckcodebase:		locate-checkpatch
159336eaaf37SIan Spray	@echo "  CHECKING STYLE"
159436eaaf37SIan Spray	@if test -d .git ; then						\
15951ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
15961a41e8c1SDan Handley		while read GIT_FILE ;					\
15971a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
15981a41e8c1SDan Handley		done ;							\
159936eaaf37SIan Spray	else								\
16001a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16011a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16021a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
160361f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16041a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16051ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16061a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
160736eaaf37SIan Spray	fi
160836eaaf37SIan Spray
160936eaaf37SIan Spraycheckpatch:		locate-checkpatch
161036eaaf37SIan Spray	@echo "  CHECKING STYLE"
161102a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
161202a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
161302a76d5fSYann Gautier	fi
161451d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
161577a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
161677a0a7f1SYann Gautier	do								\
161751d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
161851d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
161902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162002a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
162151d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
162202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
162302a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
162451d28937SAntonio Nino Diaz	done
162536eaaf37SIan Spray
162673c99d4eSJuan Castillocerttool: ${CRTTOOL}
162773c99d4eSJuan Castillo
1628a9812206SPali Rohár${CRTTOOL}: FORCE
1629598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${CRTTOOLPATH} all
1630f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16316f971622SJuan Castillo	@echo "Built $@ successfully"
1632f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16336f971622SJuan Castillo
16346f971622SJuan Castilloifneq (${GENERATE_COT},0)
163573c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16366f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1637f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16386f971622SJuan Castillo	@echo "Built $@ successfully"
16396f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1640f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1641c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
164227713fb4SSoby Mathew
164373c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16444727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1645819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1646819281eeSdp-arm	${Q}${FIPTOOL} info $@
1647f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16482f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1649f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1650f58ad36fSHarry Liebel
16510191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16520191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16530191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1654052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16550191262dSYatharth Kochar	@echo "Built $@ successfully"
16560191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1657052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1658c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16590191262dSYatharth Kochar
16600191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16614727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1662819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1663819281eeSdp-arm	${Q}${FIPTOOL} info $@
1664052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16650191262dSYatharth Kochar	@echo "Built $@ successfully"
1666052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16670191262dSYatharth Kochar
166873c99d4eSJuan Castillofiptool: ${FIPTOOL}
166973c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16700191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
167173c99d4eSJuan Castillo
1672a9812206SPali Rohár${FIPTOOL}: FORCE
167388a1cf1eSSami Mujawarifdef UNIX_MK
1674598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
167588a1cf1eSSami Mujawarelse
167688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
167788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
167888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1679c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1680f58ad36fSHarry Liebel
1681a9812206SPali Rohárromlib.bin: libraries FORCE
1682bbb24f61SJohn Tsichritzis	${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
16835accce5bSRoberto Vargas
1684cfe83910SLouis Mayencourtmemmap: all
1685af5b49e9SHarrison Mutaiifdef UNIX_MK
1686af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1687af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1688af5b49e9SHarrison Mutaielse
1689af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1690af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1691af5b49e9SHarrison Mutaiendif
1692cfe83910SLouis Mayencourt
16936de32378SMadhukar Pappireddydoc:
16946de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
16956de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
16966de32378SMadhukar Pappireddy
169790aa901fSSumit Gargenctool: ${ENCTOOL}
169890aa901fSSumit Garg
1699a9812206SPali Rohár${ENCTOOL}: FORCE
1700598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
170190aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170290aa901fSSumit Garg	@echo "Built $@ successfully"
170390aa901fSSumit Garg	@${ECHO_BLANK_LINE}
170490aa901fSSumit Garg
170535fab8c9SJoakim Bechcscope:
170635fab8c9SJoakim Bech	@echo "  CSCOPE"
170735fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
170835fab8c9SJoakim Bech	${Q}cscope -b -q -k
170935fab8c9SJoakim Bech
171072ee3314SRyan Harkinhelp:
17117c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
171272ee3314SRyan Harkin	@echo ""
171372ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
171408c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
171572ee3314SRyan Harkin	@echo ""
17167c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17177c23126cSJohn Tsichritzis	@echo ""
17181b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17191b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17201b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17211b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17221b578596SSandrine Bailleux	@echo ""
172372ee3314SRyan Harkin	@echo "Supported Targets:"
17241b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
172536eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17268aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17279003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1728d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17299d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17309d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
173173c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17321b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17330191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
173436eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
173536eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
173636eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
173772ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
173835fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
173972ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17406f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
174190aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1742f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1743ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
174426010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
174538c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1746cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17476de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
174872ee3314SRyan Harkin	@echo ""
17491b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
175072ee3314SRyan Harkin	@echo ""
175172ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
175272ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1753a9812206SPali Rohár
1754a9812206SPali Rohár.PHONY: FORCE
1755a9812206SPali RohárFORCE:;
1756