xref: /rk3399_ARM-atf/Makefile (revision 781cb31439f9b02e2f0befc4bee651ff5f945cf7)
14f6ad66aSAchin Gupta#
2*781cb314SChris Kay# Copyright (c) 2013-2024, 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
1198735809SManish V BadarkheVERSION_MINOR			:= 10
123e56c69fSYann GautierVERSION_PATCH			:= 0	# Only used for LTS releases
13055ebecaSYann GautierVERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
14aaa3e722SJuan Castillo
1588154678SJuan Castillo# Default goal is build all images
1688154678SJuan Castillo.DEFAULT_GOAL			:= all
1788154678SJuan Castillo
1872fc70edSDouglas Raillard# Avoid any implicit propagation of command line variable definitions to
1972fc70edSDouglas Raillard# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
2072fc70edSDouglas Raillard# usage. Other command line options like "-s" are still propagated as usual.
2172fc70edSDouglas RaillardMAKEOVERRIDES =
2272fc70edSDouglas Raillard
23231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := make_helpers/
24231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
25e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
2673c99d4eSJuan Castillo
2773c99d4eSJuan Castillo################################################################################
282fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
2973c99d4eSJuan Castillo################################################################################
30e35c4045SJeenu Viswambharan
312fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
32872be88aSdp-arm
33cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
34cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
352fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
362fae4b1eSJeenu ViswambharanPLAT				:= ${DEFAULT_PLAT}
3773c99d4eSJuan Castillo
3873c99d4eSJuan Castillo################################################################################
3973c99d4eSJuan Castillo# Checkpatch script options
4073c99d4eSJuan Castillo################################################################################
4173c99d4eSJuan Castillo
42f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
43f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
444501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
454501843fSGilad Ben-Yossef					include/drivers/arm,		\
464501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
47f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
481a41e8c1SDan Handley					include/lib/libfdt		\
4961f72a34SRoberto Vargas					include/lib/libc,		\
50f0b489c1SDan Handley					$(wildcard include/lib/*)))
51f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
524501843fSGilad Ben-Yossef					include/lib			\
534501843fSGilad Ben-Yossef					include/drivers,		\
54f0b489c1SDan Handley					$(wildcard include/*)))
55f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
56d801fbb0Sdp-arm					lib/compiler-rt			\
5755cdcf75SAntonio Nino Diaz					lib/libfdt%			\
5861f72a34SRoberto Vargas					lib/libc,			\
59a194255dSDaniel Boulby					lib/zlib			\
60f0b489c1SDan Handley					$(wildcard lib/*)))
61f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
62f0b489c1SDan Handley					lib				\
63f0b489c1SDan Handley					include				\
64f0b489c1SDan Handley					docs				\
651ef35512SPaul Beesley					%.rst,				\
66f0b489c1SDan Handley					$(wildcard *)))
67f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
68f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
69f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
704501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
714501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
724501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
7336eaaf37SIan Spray
7473c99d4eSJuan Castillo################################################################################
7573c99d4eSJuan Castillo# Process build options
7673c99d4eSJuan Castillo################################################################################
7773c99d4eSJuan Castillo
7873c99d4eSJuan Castillo# Verbose flag
79e35c4045SJeenu Viswambharanifeq (${V},0)
80b169f6a9SEvan Lloyd	Q:=@
81ee1ba6d4SAndre Przywara	ECHO:=@echo
8236eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
834f6ad66aSAchin Guptaelse
84b169f6a9SEvan Lloyd	Q:=
85b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
864f6ad66aSAchin Guptaendif
87ee1ba6d4SAndre Przywara
88ee1ba6d4SAndre Przywaraifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
89ee1ba6d4SAndre Przywara	Q:=@
90b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
91ee1ba6d4SAndre Przywaraendif
92ee1ba6d4SAndre Przywara
93ee1ba6d4SAndre Przywaraexport Q ECHO
942f2cef46SJeenu Viswambharan
9573c99d4eSJuan Castillo################################################################################
9673c99d4eSJuan Castillo# Toolchain
9773c99d4eSJuan Castillo################################################################################
9873c99d4eSJuan Castillo
9972610c41Sdp-armHOSTCC			:=	gcc
10072610c41Sdp-armexport HOSTCC
10172610c41Sdp-arm
10273c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
103*781cb314SChris KayCPP			:=	${CROSS_COMPILE}gcc -E
10473c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
10573c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1062adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
10773c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
10873c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
10973c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
11038c14d88SSoby MathewDTC			:=	dtc
11173c99d4eSJuan Castillo
112b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
113b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1142adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1152adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
116b25a577fSJulius Wernerendif
117b25a577fSJulius Werner
118c5e1da83SJayanth Dodderi Chidanand################################################################################
119c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
120c5e1da83SJayanth Dodderi Chidanand################################################################################
121c5e1da83SJayanth Dodderi Chidanand
122c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
123c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
124c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
125c5e1da83SJayanth Dodderi Chidanand
126c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
127c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
128c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
129c5e1da83SJayanth Dodderi Chidanand
130c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
131c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
132c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
133c5e1da83SJayanth Dodderi Chidanand
134c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
135c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
136c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
137c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
13820629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
139c5e1da83SJayanth Dodderi Chidanand
140c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
141c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
142c5e1da83SJayanth Dodderi Chidanand
143c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
144c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
145c5e1da83SJayanth Dodderi Chidanand
146c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
147c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
148c5e1da83SJayanth Dodderi Chidanand
149c5e1da83SJayanth Dodderi Chidanand################################################################################
150c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
151c5e1da83SJayanth Dodderi Chidanand################################################################################
15226e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
15326e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
154d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
15526e63c44SEtienne Carriereelse
15626e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
157c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
158c5e1da83SJayanth Dodderi Chidanand
159c5e1da83SJayanth Dodderi Chidanand################################################################################
160c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
161c5e1da83SJayanth Dodderi Chidanand################################################################################
162c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
163c5e1da83SJayanth Dodderi Chidanand
164f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
165f1821790SAlexei Fedorovifneq ($(arch-features), none)
166f1821790SAlexei Fedorov	# Strip "none+" from arch-features
167f1821790SAlexei Fedorov	arch-features	:=	$(subst none+,,$(arch-features))
168d4089fb8SGovindraj Raja	march-directive	:=	$(march-directive)+$(arch-features)
169f1821790SAlexei Fedorov# Print features
170f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
171c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
1724e04478aSChris Kay
173c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
174fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
1757794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
1767794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
177c8a992fdSorigin		LD			:=	$(LINKER)
178c8a992fdSorigin	else
1797794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
1807794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
181c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
182c8a992fdSorigin
183c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
184c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
185c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
186641f16e7SAmbroise Vincent	endif
187c8a992fdSorigin
188c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
189c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
190edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
191edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
192edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
193edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
194edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
195edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
196edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
197edbce9aaSzelalem-aweke		endif
198edbce9aaSzelalem-aweke	endif
199edbce9aaSzelalem-aweke	LD			=	$(LINKER)
200d5461857Sdp-armelse
2012adee763SRoberto Vargas	LD			=	$(LINKER)
202c5e1da83SJayanth Dodderi Chidanandendif #(clang)
203d5461857Sdp-arm
20432b209bfSAhmad Fatoum# Process Debug flag
20532b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
20632b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
20732b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
2084466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
2094466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
21032b209bfSAhmad Fatoum
21132b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
21232b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
21332b209bfSAhmad Fatoumelse
21432b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
21532b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
21632b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
217c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
21832b209bfSAhmad Fatoum
219f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
220f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
221f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
222f1de4c8fSPeiyuan Songendif
223dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
224f1de4c8fSPeiyuan Song
2258fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
2268fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
2278fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
2288fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
2298fd9d4d5SAntonio Nino Diazelse
2308fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
231c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
2328fd9d4d5SAntonio Nino Diaz
233a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
234d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
2359d29c227SSoby Mathew
236d4089fb8SGovindraj RajaASFLAGS		+=	$(march-directive)
237b86048c4SAntonio Nino Diaz
238c5e1da83SJayanth Dodderi Chidanand##############################################################################
239c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
240c5e1da83SJayanth Dodderi Chidanand###############################################################################
2419ab81b5eSJustin Chadwell# General warnings
2429ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
243b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
244d75a9ecdSBoyan Karatotev				-Wredundant-decls
245d75a9ecdSBoyan Karatotev# stricter warnings
246d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
247d75a9ecdSBoyan Karatotev# too verbose for generic build
248d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
249d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
250d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
251d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
2529ab81b5eSJustin Chadwell
2539ab81b5eSJustin Chadwell# Additional warnings
254d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
255d75a9ecdSBoyan Karatotev# full -Wextra
256d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
257d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
258d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
259e7c645b5SYann Gautier
260d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
261d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
262d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
263d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
264d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
265d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
266d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
267d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
268d141e638SBoyan Karatotev# currently very involved and many platforms set this off
269d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
270e7c645b5SYann Gautier
271d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
272e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
273d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
274d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
275d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
276e7c645b5SYann GautierWARNING3 += -Wcast-qual
277e7c645b5SYann GautierWARNING3 += -Wconversion
278e7c645b5SYann GautierWARNING3 += -Wpacked
279e7c645b5SYann GautierWARNING3 += -Wpointer-arith
280e7c645b5SYann GautierWARNING3 += -Wswitch-default
281e7c645b5SYann Gautier
282d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
283d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
284d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
285d75a9ecdSBoyan Karatotevifdef W
286d75a9ecdSBoyan Karatotev	ifneq (${W},0)
287d75a9ecdSBoyan Karatotev		E	 ?= 0
288d75a9ecdSBoyan Karatotev	endif
289d75a9ecdSBoyan Karatotevendif
290d75a9ecdSBoyan Karatotev
291e7c645b5SYann Gautierifeq (${W},1)
2929ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
293e7c645b5SYann Gautierelse ifeq (${W},2)
2949ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
295e7c645b5SYann Gautierelse ifeq (${W},3)
2969ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
297c5e1da83SJayanth Dodderi Chidanandendif #(W)
298e7c645b5SYann Gautier
2999ab81b5eSJustin Chadwell# Compiler specific warnings
30000296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
30193c690ebSJustin Chadwell# not using clang
302d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
303d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
304d7b4cd41SJustin Chadwell				-Wlogical-op
305dea23e24SGovindraj Raja
306dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
307dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
308dea23e24SGovindraj Raja
309538516f5SBipin Raviifeq ($(HARDEN_SLS), 1)
310538516f5SBipin Ravi        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
311538516f5SBipin Raviendif
312538516f5SBipin Ravi
31393c690ebSJustin Chadwellelse
31493c690ebSJustin Chadwell# using clang
315d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
316d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
317c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
31800296576SAmbroise Vincent
3196336b07aSYann Gautierifneq (${E},0)
3206336b07aSYann Gautier	ERRORS := -Werror
321c5e1da83SJayanth Dodderi Chidanandendif #(E)
3226336b07aSYann Gautier
323c5e1da83SJayanth Dodderi Chidanand################################################################################
324c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
325c5e1da83SJayanth Dodderi Chidanand################################################################################
326ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3279ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
328d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
329d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
33059de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
331ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
332ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
333ebd6efaeSSamuel Holland				-Os -std=gnu99
33473c99d4eSJuan Castillo
3351f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3361f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
337c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
338c5e1da83SJayanth Dodderi Chidanand
3391f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
3401f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
3411f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
342c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
3431f461979SJustin Chadwell
344f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
345f7ec31dbSdavid cunado
3461f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
3471f49db5fSMarco Felsch
348641f16e7SAmbroise Vincent# LD = armlink
349c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
350c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
351c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
352edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
353641f16e7SAmbroise Vincent
354641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
355edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
356edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
357edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
358edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
359ac98b82aSChris Kay
360ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
361ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
362304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	-Wl,--build-id=none
363ac98b82aSChris Kay
364edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
365edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
366edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
367edbce9aaSzelalem-aweke		endif
368c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
369c5e1da83SJayanth Dodderi Chidanand
370edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
371edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
372cfe6767fSYann Gautier	ifeq (${ARCH},aarch64)
373edbce9aaSzelalem-aweke		ifneq (${ERRATA_A53_843419},1)
374edbce9aaSzelalem-aweke			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
375edbce9aaSzelalem-aweke		endif
376cfe6767fSYann Gautier	endif
377edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
378edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
379641f16e7SAmbroise Vincent
380641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
381c2ad38ceSVarun Wadekarelse
3821f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
3831f49db5fSMarco Felsch# are not loaded by a elf loader.
3841f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
385ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
386c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
387ac98b82aSChris Kay
388ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
389ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
390304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	--build-id=none
391ac98b82aSChris Kay
392641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
393ebac6922SYabin Cui# therefore don't add those in that case.
394ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
395ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
396641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
397ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
398edbce9aaSzelalem-aweke	endif
399c5e1da83SJayanth Dodderi Chidanand
400c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
40173c99d4eSJuan Castillo
40273c99d4eSJuan Castillo################################################################################
403f5211420SGovindraj Raja# Setup ARCH_MAJOR/MINOR before parsing arch_features.
404f5211420SGovindraj Raja################################################################################
405f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
406f5211420SGovindraj Raja	ARM_ARCH_MAJOR := 8
407f5211420SGovindraj Raja	ARM_ARCH_MINOR := 6
408f5211420SGovindraj Rajaendif
409f5211420SGovindraj Raja
410f5211420SGovindraj Raja################################################################################
41173c99d4eSJuan Castillo# Common sources and include directories
41273c99d4eSJuan Castillo################################################################################
413d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
41473c99d4eSJuan Castillo
41573c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4167f56e9a3SSoby Mathew				common/tf_log.c				\
4179d29c227SSoby Mathew				common/${ARCH}/debug.S			\
41891b48c9fSJulius Werner				drivers/console/multi_console.c		\
4199d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4209d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
421c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
422566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4237f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
42475311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4259d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
42661f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
427d7a6b0f8SRyan Harkin
4288422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4298422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4308422a840SAntonio Nino Diazendif
4318422a840SAntonio Nino Diaz
4321f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4331f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
4341f461979SJustin Chadwellendif
4351f461979SJustin Chadwell
43601d237cbSYann GautierINCLUDES		+=	-Iinclude				\
437f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
43809d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
43909d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
44009d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
44109d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
44209d40e0eSAntonio Nino Diaz
443e03dcc8fSNishant SharmaDTC_FLAGS		+=	-I dts -O dtb
444e03dcc8fSNishant SharmaDTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
445e03dcc8fSNishant Sharma				-x assembler-with-cpp $(DEFINES)
446e03dcc8fSNishant Sharma
4479c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4489c6d1c50SAntonio Nino Diaz
44973c99d4eSJuan Castillo################################################################################
4503547270fSGovindraj Raja# Generic definitions
4513547270fSGovindraj Raja################################################################################
4523547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
4533547270fSGovindraj Raja
4543547270fSGovindraj Rajaifeq (${BUILD_BASE},)
4553547270fSGovindraj Raja     BUILD_BASE		:=	./build
4563547270fSGovindraj Rajaendif
4573547270fSGovindraj RajaBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
4583547270fSGovindraj Raja
4593547270fSGovindraj RajaSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
4603547270fSGovindraj Raja
4613547270fSGovindraj Raja# Platforms providing their own TBB makefile may override this value
4623547270fSGovindraj RajaINCLUDE_TBBR_MK		:=	1
4633547270fSGovindraj Raja
4643547270fSGovindraj Raja################################################################################
4653547270fSGovindraj Raja# Include SPD Makefile if one has been specified
4663547270fSGovindraj Raja################################################################################
4673547270fSGovindraj Raja
4683547270fSGovindraj Rajaifneq (${SPD},none)
4693547270fSGovindraj Raja	ifeq (${ARCH},aarch32)
4703547270fSGovindraj Raja                $(error "Error: SPD is incompatible with AArch32.")
4713547270fSGovindraj Raja	endif
4723547270fSGovindraj Raja
4733547270fSGovindraj Raja	ifdef EL3_PAYLOAD_BASE
4743547270fSGovindraj Raja                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
4753547270fSGovindraj Raja                $(warning "The SPD and its BL32 companion will be present but \
4763547270fSGovindraj Raja                ignored.")
4773547270fSGovindraj Raja	endif
4783547270fSGovindraj Raja
4793547270fSGovindraj Raja	ifeq (${SPD},spmd)
4803547270fSGovindraj Raja	# SPMD is located in std_svc directory
4813547270fSGovindraj Raja		SPD_DIR := std_svc
4823547270fSGovindraj Raja
4833547270fSGovindraj Raja		ifeq ($(SPMD_SPM_AT_SEL2),1)
4843547270fSGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
4853547270fSGovindraj Raja			ifeq ($(SPMC_AT_EL3),1)
4863547270fSGovindraj Raja                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
4873547270fSGovindraj Raja			endif
4883547270fSGovindraj Raja		endif
4893547270fSGovindraj Raja
4903547270fSGovindraj Raja		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
4913547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
4923547270fSGovindraj Raja		endif
4933547270fSGovindraj Raja
4943547270fSGovindraj Raja		ifeq ($(TS_SP_FW_CONFIG),1)
4953547270fSGovindraj Raja		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
4963547270fSGovindraj Raja		endif
4973547270fSGovindraj Raja
4983547270fSGovindraj Raja		ifneq ($(ARM_BL2_SP_LIST_DTS),)
4993547270fSGovindraj Raja		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
5003547270fSGovindraj Raja		endif
5013547270fSGovindraj Raja
5023547270fSGovindraj Raja		ifneq ($(SP_LAYOUT_FILE),)
5033547270fSGovindraj Raja		BL2_ENABLE_SP_LOAD := 1
5043547270fSGovindraj Raja		endif
505c189adbdSGovindraj Raja
506c189adbdSGovindraj Raja		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
507c189adbdSGovindraj Raja			ifneq ($(SPMC_AT_EL3),1)
508c189adbdSGovindraj Raja			$(error SEL0 SP cannot be enabled without SPMC at EL3)
509c189adbdSGovindraj Raja			endif
510c189adbdSGovindraj Raja		endif
5113547270fSGovindraj Raja	else
5123547270fSGovindraj Raja		# All other SPDs in spd directory
5133547270fSGovindraj Raja		SPD_DIR := spd
5143547270fSGovindraj Raja	endif #(SPD)
5153547270fSGovindraj Raja
5163547270fSGovindraj Raja	# We expect to locate an spd.mk under the specified SPD directory
5173547270fSGovindraj Raja	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
5183547270fSGovindraj Raja
5193547270fSGovindraj Raja	ifeq (${SPD_MAKE},)
5203547270fSGovindraj Raja                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
5213547270fSGovindraj Raja	endif
5223547270fSGovindraj Raja        $(info Including ${SPD_MAKE})
5233547270fSGovindraj Raja        include ${SPD_MAKE}
5243547270fSGovindraj Raja
5253547270fSGovindraj Raja	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
5263547270fSGovindraj Raja	# Makefile would set NEED_BL32 to "yes". In this case, the build system
5273547270fSGovindraj Raja	# supports two mutually exclusive options:
5283547270fSGovindraj Raja	# * BL32 is built from source: then BL32_SOURCES must contain the list
5293547270fSGovindraj Raja	#   of source files to build BL32
5303547270fSGovindraj Raja	# * BL32 is a prebuilt binary: then BL32 must point to the image file
5313547270fSGovindraj Raja	#   that will be included in the FIP
5323547270fSGovindraj Raja	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
5333547270fSGovindraj Raja	# over the sources.
5343547270fSGovindraj Rajaendif #(SPD=none)
5353547270fSGovindraj Raja
5363547270fSGovindraj Rajaifeq (${ENABLE_SPMD_LP}, 1)
5373547270fSGovindraj Rajaifneq (${SPD},spmd)
5383547270fSGovindraj Raja        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
5393547270fSGovindraj Rajaendif
5403547270fSGovindraj Rajaifeq ($(SPMC_AT_EL3),1)
5413547270fSGovindraj Raja        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
5423547270fSGovindraj Rajaendif
5433547270fSGovindraj Rajaendif
5443547270fSGovindraj Raja
5453547270fSGovindraj Raja################################################################################
546f5211420SGovindraj Raja# Process BRANCH_PROTECTION value and set
547f5211420SGovindraj Raja# Pointer Authentication and Branch Target Identification flags
548f5211420SGovindraj Raja################################################################################
549f5211420SGovindraj Rajaifeq (${BRANCH_PROTECTION},0)
550f5211420SGovindraj Raja	# Default value turns off all types of branch protection
551f5211420SGovindraj Raja	BP_OPTION := none
552f5211420SGovindraj Rajaelse ifneq (${ARCH},aarch64)
553f5211420SGovindraj Raja        $(error BRANCH_PROTECTION requires AArch64)
554f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},1)
555f5211420SGovindraj Raja	# Enables all types of branch protection features
556f5211420SGovindraj Raja	BP_OPTION := standard
557f5211420SGovindraj Raja	ENABLE_BTI := 1
558f5211420SGovindraj Raja	ENABLE_PAUTH := 1
559f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},2)
560f5211420SGovindraj Raja	# Return address signing to its standard level
561f5211420SGovindraj Raja	BP_OPTION := pac-ret
562f5211420SGovindraj Raja	ENABLE_PAUTH := 1
563f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},3)
564f5211420SGovindraj Raja	# Extend the signing to include leaf functions
565f5211420SGovindraj Raja	BP_OPTION := pac-ret+leaf
566f5211420SGovindraj Raja	ENABLE_PAUTH := 1
567f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},4)
568f5211420SGovindraj Raja	# Turn on branch target identification mechanism
569f5211420SGovindraj Raja	BP_OPTION := bti
570f5211420SGovindraj Raja	ENABLE_BTI := 1
571f5211420SGovindraj Rajaelse
572f5211420SGovindraj Raja        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
573f5211420SGovindraj Rajaendif #(BRANCH_PROTECTION)
574f5211420SGovindraj Raja
575f5211420SGovindraj Rajaifeq ($(ENABLE_PAUTH),1)
576f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
577f5211420SGovindraj Rajaendif
578f5211420SGovindraj Rajaifneq (${BP_OPTION},none)
579f5211420SGovindraj Raja	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
580f5211420SGovindraj Rajaendif #(BP_OPTION)
581f5211420SGovindraj Raja
582f5211420SGovindraj Raja# Pointer Authentication sources
583f5211420SGovindraj Rajaifeq (${ENABLE_PAUTH}, 1)
584f5211420SGovindraj Raja# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
585f5211420SGovindraj Raja# Pauth support. As it's not secure, it must be reimplemented for real platforms
586f5211420SGovindraj Raja	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
587f5211420SGovindraj Rajaendif
588f5211420SGovindraj Raja
5893547270fSGovindraj Raja################################################################################
5903547270fSGovindraj Raja# Include the platform specific Makefile after the SPD Makefile (the platform
5913547270fSGovindraj Raja# makefile may use all previous definitions in this file)
5923547270fSGovindraj Raja################################################################################
5933547270fSGovindraj Rajainclude ${PLAT_MAKEFILE_FULL}
5943547270fSGovindraj Raja
5953547270fSGovindraj Raja################################################################################
5963547270fSGovindraj Raja# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
5973547270fSGovindraj Raja# platform.
5983547270fSGovindraj Raja################################################################################
5993547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
6003547270fSGovindraj Raja
601f5211420SGovindraj Raja####################################################
602f5211420SGovindraj Raja# Enable required options for Memory Stack Tagging.
603f5211420SGovindraj Raja####################################################
604f5211420SGovindraj Raja
605f5211420SGovindraj Raja# Currently, these options are enabled only for clang and armclang compiler.
606f5211420SGovindraj Rajaifeq (${SUPPORT_STACK_MEMTAG},yes)
607f5211420SGovindraj Raja    ifdef mem_tag_arch_support
608f5211420SGovindraj Raja        # Check for armclang and clang compilers
609f5211420SGovindraj Raja        ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
610f5211420SGovindraj Raja        # Add "memtag" architecture feature modifier if not specified
611f5211420SGovindraj Raja            ifeq ( ,$(findstring memtag,$(arch-features)))
612f5211420SGovindraj Raja                arch-features	:=	$(arch-features)+memtag
613f5211420SGovindraj Raja            endif	# memtag
614f5211420SGovindraj Raja            ifeq ($(notdir $(CC)),armclang)
615f5211420SGovindraj Raja                TF_CFLAGS	+=	-mmemtag-stack
616f5211420SGovindraj Raja            else ifeq ($(notdir $(CC)),clang)
617f5211420SGovindraj Raja                TF_CFLAGS	+=	-fsanitize=memtag
618f5211420SGovindraj Raja            endif	# armclang
619f5211420SGovindraj Raja        endif
620f5211420SGovindraj Raja    else
621f5211420SGovindraj Raja        $(error "Error: stack memory tagging is not supported for  \
622f5211420SGovindraj Raja        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
623f5211420SGovindraj Raja	endif #(mem_tag_arch_support)
624f5211420SGovindraj Rajaendif #(SUPPORT_STACK_MEMTAG)
625f5211420SGovindraj Raja
626f5211420SGovindraj Raja################################################################################
627f5211420SGovindraj Raja# RME dependent flags configuration, Enable optional features for RME.
628f5211420SGovindraj Raja################################################################################
629f5211420SGovindraj Raja# FEAT_RME
630f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
631d638029fSGovindraj Raja	# RME doesn't support BRBE
632d638029fSGovindraj Raja	ENABLE_BRBE_FOR_NS := 0
633d638029fSGovindraj Raja
634f5211420SGovindraj Raja	# RME doesn't support PIE
635f5211420SGovindraj Raja	ifneq (${ENABLE_PIE},0)
636f5211420SGovindraj Raja                $(error ENABLE_RME does not support PIE)
637f5211420SGovindraj Raja	endif
638f5211420SGovindraj Raja
639f5211420SGovindraj Raja	# RME doesn't support BRBE
640f5211420SGovindraj Raja	ifneq (${ENABLE_BRBE_FOR_NS},0)
641f5211420SGovindraj Raja                $(error ENABLE_RME does not support BRBE.)
642f5211420SGovindraj Raja	endif
643f5211420SGovindraj Raja
644f5211420SGovindraj Raja	# RME requires AARCH64
645f5211420SGovindraj Raja	ifneq (${ARCH},aarch64)
646f5211420SGovindraj Raja                $(error ENABLE_RME requires AArch64)
647f5211420SGovindraj Raja	endif
648f5211420SGovindraj Raja
649f5211420SGovindraj Raja	# RME requires el2 context to be saved for now.
650f5211420SGovindraj Raja	CTX_INCLUDE_EL2_REGS := 1
651f5211420SGovindraj Raja	CTX_INCLUDE_AARCH32_REGS := 0
652f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
653f5211420SGovindraj Raja
654f5211420SGovindraj Raja	# RME enables CSV2_2 extension by default.
655f5211420SGovindraj Raja	ENABLE_FEAT_CSV2_2 = 1
656f5211420SGovindraj Rajaendif #(FEAT_RME)
657f5211420SGovindraj Raja
658f5211420SGovindraj Raja################################################################################
6595b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6605b18de09SZelalem Aweke################################################################################
6615b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6625b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6635b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6645b18de09SZelalem Aweke	endif
6651d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6661d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6671d63ae4dSMarc Bonnici	endif
668c5e1da83SJayanth Dodderi Chidanand
6694fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6704fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6714fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6724fba2e1fSBoyan Karatotev		endif
6734fba2e1fSBoyan Karatotev	endif
6745b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6755b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6765b18de09SZelalem Awekeendif
6775b18de09SZelalem Aweke
6783547270fSGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
6793547270fSGovindraj Raja	ifeq (${SPD},none)
6803547270fSGovindraj Raja		ifeq (${ENABLE_RME},0)
6813547270fSGovindraj Raja                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
6823547270fSGovindraj Raja                        or RME is enabled)
6833547270fSGovindraj Raja		endif
6843547270fSGovindraj Raja	endif
6853547270fSGovindraj Rajaendif
6860f21c547SJuan Castillo
6877794d6c8SGovindraj Raja################################################################################
6887794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6897794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6907794d6c8SGovindraj Raja################################################################################
6917794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6927794d6c8SGovindraj Raja
6937794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6947794d6c8SGovindraj Raja
69542d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
69642d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
69742d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
69842d4d3baSArvind Ram Prakash# BL2 in EL3
69942d4d3baSArvind Ram Prakash
70042d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
70142d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
70242d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
703c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
704c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
70542d4d3baSArvind Ram Prakash	endif
70642d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
70742d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
70842d4d3baSArvind Ram Prakashelse
70942d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
71042d4d3baSArvind Ram Prakashendif
71142d4d3baSArvind Ram Prakash
712f87e54f7SManish Pandey# This internal flag is set to 1 when Firmware First handling of External aborts
713f87e54f7SManish Pandey# is required by lowe ELs. Currently only NS requires this support.
714f87e54f7SManish Pandeyifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
715f87e54f7SManish Pandey	FFH_SUPPORT := 1
716f87e54f7SManish Pandeyelse
717f87e54f7SManish Pandey	FFH_SUPPORT := 0
718f87e54f7SManish Pandeyendif
719f87e54f7SManish Pandey
7208012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
7218012cc5cSMasahiro Yamada
72226e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
72326e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
72426e63c44SEtienne Carriereendif
72526e63c44SEtienne Carriere
7263bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7273bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7283bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7297b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7307b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7317b592418SSamuel Hollandendif
732c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
733320920c1SMasahiro Yamada
734320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
735320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
736320920c1SMasahiro Yamadaelse
737320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
738320920c1SMasahiro Yamadaendif
739320920c1SMasahiro Yamada
740320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
74142d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
74269af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
743966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
74469af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
74569af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
746c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
747c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
748966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
749320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
750320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
751966660ecSChris Kay
752966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
753d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
754d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
755c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7563bd17c0fSSoby Mathew
757007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
758007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
759007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
760007433d8SBoyan Karatotev
7619cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
76242d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7639cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
764d5e97a1dSMasahiro Yamadaelse
7659cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
766c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
767007433d8SBoyan Karatotev
768007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7699cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7709cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7719cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
772007433d8SBoyan Karatotevelse
773007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
774d5e97a1dSMasahiro Yamadaendif
775d5e97a1dSMasahiro Yamada
77654035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
77754035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
77854035fc4SSandrine Bailleux# This can be overridden by the platform.
77973c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7804f6ad66aSAchin Gupta
781a4409008Sdp-arm################################################################################
782a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
783a4409008Sdp-arm################################################################################
784c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
785c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
786c5e1da83SJayanth Dodderi Chidanand
787a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
788a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
789a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
790a4409008Sdp-arm
791a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
792a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
793a4409008Sdp-arm                endif
794a4409008Sdp-arm                $(info Including ${AARCH32_SP_MAKE})
795a4409008Sdp-arm                include ${AARCH32_SP_MAKE}
796a4409008Sdp-arm        endif
797c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7984f6ad66aSAchin Gupta
79973c99d4eSJuan Castillo################################################################################
80077f1f7a1SVarun Wadekar# Include libc if not overridden
80177f1f7a1SVarun Wadekar################################################################################
80277f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
80377f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
80477f1f7a1SVarun Wadekarendif
80577f1f7a1SVarun Wadekar
80677f1f7a1SVarun Wadekar################################################################################
807c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
808cf2c8a33SAntonio Nino Diaz################################################################################
809cf2c8a33SAntonio Nino Diaz
810c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
811c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
812c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
813c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
814c5e1da83SJayanth Dodderi Chidanand        else
815c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
816c5e1da83SJayanth Dodderi Chidanand        endif
817c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
818c5e1da83SJayanth Dodderi Chidanand
819c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
820c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
821c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
822c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
823c5e1da83SJayanth Dodderi Chidanand        endif
824c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
825c5e1da83SJayanth Dodderi Chidanand
826c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
827c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
828c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
829c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
830c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
831c5e1da83SJayanth Dodderi Chidanandendif
832c5e1da83SJayanth Dodderi Chidanand
833c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
834c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
835c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
836c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
837c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
838c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
839c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
840c5e1da83SJayanth Dodderi Chidanand
841cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
84268450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
84368450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
84468450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
845cf2c8a33SAntonio Nino Diaz	endif
84676580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
847c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
848c5e1da83SJayanth Dodderi Chidanand                build options.")
84976580f3dSQixiang Xu	endif
85076580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
851c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
852c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
85376580f3dSQixiang Xu	endif
854c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
855cf2c8a33SAntonio Nino Diaz
856cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
857cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
858cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
859cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
860cf2c8a33SAntonio Nino Diaz	endif
86168450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
86268450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
863c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
864cf2c8a33SAntonio Nino Diaz	endif
865c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
866cf2c8a33SAntonio Nino Diaz
867d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
868d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
869d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
870d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
871d4593e47SJeenu Viswambharanendif
8721a0a3f06SYatharth Kochar
87342d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
87442d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
87542d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8767d173fc5SJiafei Panendif
8777d173fc5SJiafei Pan
8789202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
87914c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
880c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
881f87e54f7SManish Pandey        and HANDLE_EA_EL3_FIRST_NS instead")
8829202d519SManish Pandeyendif
883c5e1da83SJayanth Dodderi Chidanand
884c5e1da83SJayanth Dodderi Chidanand
8859202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8861a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8876503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8886503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8891a7c1cfeSJeenu Viswambharan	endif
890c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8911a7c1cfeSJeenu Viswambharan
892ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
893209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
894209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
895c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
896c5e1da83SJayanth Dodderi Chidanand                to be set.")
897209a60ccSSoby Mathew	endif
898c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
899209a60ccSSoby Mathew
9002bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
9012bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
9022bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
9032bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
9042bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
9052bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
9062bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
9072bf4f27fSManish V Badarkhe# Support hash calculation only
9082bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
9092bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
9102bf4f27fSManish V Badarkhe# Support authentication verification only
911c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
912c9c56f6eSManish V Badarkheelse
913c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
914c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
915c9c56f6eSManish V Badarkhe
916cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
917cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
918700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
91984ef9cd8SManish V Badarkheendif
92084ef9cd8SManish V Badarkhe
921b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9229fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9239fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
924b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9259fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9269fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
92706715f85SAlexei Fedorov	endif
928c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9299fc59639SAlexei Fedorov
93006715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9319fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9329fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
933b86048c4SAntonio Nino Diaz	endif
934c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9359fc59639SAlexei Fedorov
9369dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9379dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9389dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9399dd94382SJustin Chadwell	endif
940c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9419dd94382SJustin Chadwell
942396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
943396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
944c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
945396b339dSManish V Badarkhe
9466a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9476a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
948c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9496a0da736SJayanth Dodderi Chidanand
95003d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
95103d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
952c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
953c5e1da83SJayanth Dodderi Chidanand                to be set")
95403d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
95503d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
95603d3c0d7SJayanth Dodderi Chidanand	endif
957c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
95845007acdSJayanth Dodderi Chidanand
95960e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
96060e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
961c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
962c5e1da83SJayanth Dodderi Chidanand                library v2")
96360e8f3cfSPetre-Ionut Tudor	endif
964c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
96560e8f3cfSPetre-Ionut Tudor
9667cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9677cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
968c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
969c5e1da83SJayanth Dodderi Chidanand                to be set)
9707cda17bbSSumit Garg	endif
971c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9727cda17bbSSumit Garg
973744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
974dc78e62dSjohpow01ifeq (${ARCH},aarch32)
975744ad974Sjohpow01
976744ad974Sjohpow01	# SME/SVE only supported on AArch64
97745007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
978dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
979dc78e62dSjohpow01	endif
98003d3c0d7SJayanth Dodderi Chidanand
981dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
982dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
98324ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
984dc78e62dSjohpow01	endif
985744ad974Sjohpow01
986ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
987744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
988744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
989744ad974Sjohpow01	endif
990744ad974Sjohpow01
991ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
992ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
993ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
994ff86e0b4SJuan Pablo Conde	endif
995c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
996dc78e62dSjohpow01
9970d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9980d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9990d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
10000d122947SBoyan Karatotev	endif
1001c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
10020d122947SBoyan Karatotev
1003dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
1004dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
1005dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
1006dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
1007dc78e62dSjohpow01	endif
10080d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
10090d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
10100d122947SBoyan Karatotev	endif
1011c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
1012c5e1da83SJayanth Dodderi Chidanand
1013dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1014dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1015dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1016dc78e62dSjohpow01	endif
1017c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1018dc78e62dSjohpow01
1019dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1020dc78e62dSjohpow01# its own context management including FPU registers.
1021dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
102245007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1023dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1024dc78e62dSjohpow01	endif
102503d3c0d7SJayanth Dodderi Chidanand
1026dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1027dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1028dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1029dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1030dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1031dc78e62dSjohpow01	endif
1032c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1033dc78e62dSjohpow01
103400e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
103500e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
103600e28874SManish V Badarkheendif
103700e28874SManish V Badarkhe
10383ba2c151SRaymond Maoifeq (${TRANSFER_LIST},1)
10393ba2c151SRaymond Mao        $(info TRANSFER_LIST is an experimental feature)
10403ba2c151SRaymond Maoendif
10413ba2c151SRaymond Mao
1042274a69e7SChris Kayifeq (${ENABLE_RME},1)
1043274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1044274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1045274a69e7SChris Kay	endif
1046274a69e7SChris Kayendif
1047274a69e7SChris Kay
1048c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1049c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1050c5e1da83SJayanth Dodderi Chidanand
1051c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1052c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1053c5e1da83SJayanth Dodderi Chidanand
10545782b890SManish V Badarkheifeq ($(PSA_CRYPTO),1)
10555782b890SManish V Badarkhe        $(info PSA_CRYPTO is an experimental feature)
10565782b890SManish V Badarkheendif
10575782b890SManish V Badarkhe
1058cf2c8a33SAntonio Nino Diaz################################################################################
105973c99d4eSJuan Castillo# Process platform overrideable behaviour
106073c99d4eSJuan Castillo################################################################################
10614f6ad66aSAchin Gupta
10625f24ce96SManish Pandeyifdef BL1_SOURCES
10635f24ce96SManish Pandey	NEED_BL1 := yes
1064c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10655f24ce96SManish Pandey
10665f24ce96SManish Pandeyifdef BL2_SOURCES
10675f24ce96SManish Pandey	NEED_BL2 := yes
10685f24ce96SManish Pandey
1069bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1070bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1071cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1072cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1073cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10744c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1075cf2c8a33SAntonio Nino Diaz	else
107668450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1077cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1078cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1079cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1080cf2c8a33SAntonio Nino Diaz		else
1081cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1082cf2c8a33SAntonio Nino Diaz		endif
10834c117f6cSSandrine Bailleux	endif
1084c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10856f971622SJuan Castillo
10865f24ce96SManish Pandeyifdef BL2U_SOURCES
10875f24ce96SManish Pandey	NEED_BL2U := yes
1088c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10895f24ce96SManish Pandey
10904d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10914d045d0eSMasahiro Yamadaifdef SCP_BL2
10924d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1093c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10944d045d0eSMasahiro Yamada
10955744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10965744e874SSoby Mathewifneq (${ARCH},aarch32)
10975744e874SSoby Mathew	ifdef BL31_SOURCES
1098c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1099c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
11005744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
11015744e874SSoby Mathew			NEED_BL31 := yes
11025744e874SSoby Mathew		endif
11035744e874SSoby Mathew	endif
1104c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
11055744e874SSoby Mathew
110673c99d4eSJuan Castillo# Process TBB related flags
11076f971622SJuan Castilloifneq (${GENERATE_COT},0)
110873c99d4eSJuan Castillo	# Common cert_create options
11096f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
11106f971622SJuan Castillo                $(eval CRT_ARGS += -n)
11110191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1112fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1113fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
11140191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1115fd34e7baSJuan Castillo		endif
11166f971622SJuan Castillo	endif
111773c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
111873c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
111973c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
112073c99d4eSJuan Castillo	endif
1121c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11226f971622SJuan Castillo
11231c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11241c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1125c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11261c75d5dfSMasahiro Yamada
11275f24ce96SManish Pandeyifdef FDT_SOURCES
11285f24ce96SManish Pandey	NEED_FDT := yes
1129c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11305f24ce96SManish Pandey
113173c99d4eSJuan Castillo################################################################################
113246e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
113346e5e035SMichalis Pappas################################################################################
113446e5e035SMichalis Pappas
113546e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
113646e5e035SMichalis Pappas
113746e5e035SMichalis Pappas################################################################################
11388a86052dSSoby Mathew# Include BL specific makefiles
11398a86052dSSoby Mathew################################################################################
11405f24ce96SManish Pandey
11415f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11428a86052dSSoby Mathewinclude bl1/bl1.mk
11438a86052dSSoby Mathewendif
11448a86052dSSoby Mathew
11455f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11468a86052dSSoby Mathewinclude bl2/bl2.mk
11478a86052dSSoby Mathewendif
11488a86052dSSoby Mathew
11495f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11508a86052dSSoby Mathewinclude bl2u/bl2u.mk
11518a86052dSSoby Mathewendif
11528a86052dSSoby Mathew
11535744e874SSoby Mathewifeq (${NEED_BL31},yes)
11548a86052dSSoby Mathewinclude bl31/bl31.mk
11558a86052dSSoby Mathewendif
115603b397a8SNishanth Menon
115773c99d4eSJuan Castillo################################################################################
115873c99d4eSJuan Castillo# Build options checks
115973c99d4eSJuan Castillo################################################################################
116073c99d4eSJuan Castillo
1161c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1162327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1163327131c4SLeonardo Sandoval    $(sort \
1164327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
116546789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1166327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1167327131c4SLeonardo Sandoval	CREATE_KEYS \
1168327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1169327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1170327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
11719acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1172327131c4SLeonardo Sandoval	DEBUG \
1173327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1174327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11751fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1176742ca230SChris Kay	ENABLE_AMU_FCONF \
1177873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1178327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
117924077098SAndre Przywara	ENABLE_FEAT_SB \
1180327131c4SLeonardo Sandoval	ENABLE_PIE \
1181327131c4SLeonardo Sandoval	ENABLE_PMF \
1182327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1183327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1184dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11850c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1186970a4a8dSManish Pandey	ENABLE_FEAT_RAS	\
1187f87e54f7SManish Pandey	FFH_SUPPORT	\
1188327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1189327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1190327131c4SLeonardo Sandoval	GENERATE_COT \
1191327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
119246cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1193538516f5SBipin Ravi	HARDEN_SLS \
1194327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1195327131c4SLeonardo Sandoval	MEASURED_BOOT \
119600e28874SManish V Badarkhe	DRTM_SUPPORT \
1197327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1198327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1199327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1200327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1201327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
120264b4710bSWing Li	PSCI_OS_INIT_MODE \
1203327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1204327131c4SLeonardo Sandoval	SAVE_KEYS \
1205327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
120696a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1207327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1208327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1209327131c4SLeonardo Sandoval	SPM_MM \
12101d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1211801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1212327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1213890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
12143ba2c151SRaymond Mao	TRANSFER_LIST \
1215327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1216327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1217327131c4SLeonardo Sandoval	USE_DEBUGFS \
1218327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1219327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1220327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1221327131c4SLeonardo Sandoval	USE_ROMLIB \
1222327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1223327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
122442d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1225327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1226327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1227327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1228327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1229327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1230327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
123100e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1232327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1233327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1234396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
123568120783SChris Kay	ENABLE_MPMM \
123668120783SChris Kay	ENABLE_MPMM_FCONF \
12376a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12380b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1239ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1240ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
124104c7303bSOkash Khawaja	CONDITIONAL_CMO \
12425782b890SManish V Badarkhe	PSA_CRYPTO	\
124385bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1244183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1245bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1246327131c4SLeonardo Sandoval)))
124773c99d4eSJuan Castillo
1248c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1249327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1250327131c4SLeonardo Sandoval    $(sort \
1251327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1252327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1253327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12546a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12556a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12566a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12572bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
125883a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12591298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
126047c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12616a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12626a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1263d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12646a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12656a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12666a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12676a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12686a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12696a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12706a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12716a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1272ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12736a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1274d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1275062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1276062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1277062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1278062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1279688ab57bSMark Brown	ENABLE_FEAT_GCS \
12806a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12814d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
1282edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
12836a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12846437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1285603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
128645007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
128703d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12882b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12896a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1290327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12915357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12925357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1293781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1294781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1295bebcf27fSMark Brown	SVE_VECTOR_LEN \
12960ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1297327131c4SLeonardo Sandoval)))
1298c877b414SJeenu Viswambharan
1299aacff749SJustin Chadwellifdef KEY_SIZE
1300aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1301aacff749SJustin Chadwellendif
1302aacff749SJustin Chadwell
13031f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
13041f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
13051f461979SJustin Chadwellendif
13061f461979SJustin Chadwell
130773c99d4eSJuan Castillo################################################################################
130873c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
130973c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
131073c99d4eSJuan Castillo# platform to overwrite the default options
131173c99d4eSJuan Castillo################################################################################
131273c99d4eSJuan Castillo
1313327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1314327131c4SLeonardo Sandoval    $(sort \
1315327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1316327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1317327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
131846789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1319327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1320327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1321327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1322327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
13239acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1324327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1325327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1326327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1327062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1328327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13290063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1330d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13311fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1332742ca230SChris Kay	ENABLE_AMU_FCONF \
1333873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1334327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1335327131c4SLeonardo Sandoval	ENABLE_BTI \
1336edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
1337327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1338327131c4SLeonardo Sandoval	ENABLE_PIE \
1339327131c4SLeonardo Sandoval	ENABLE_PMF \
1340327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13415b18de09SZelalem Aweke	ENABLE_RME \
1342327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1343dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
134403d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1345dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
134690118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1347327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13480c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1349970a4a8dSManish Pandey	ENABLE_FEAT_RAS \
1350f87e54f7SManish Pandey	FFH_SUPPORT \
1351327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1352327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1353327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1354327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1355327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
135646cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1357327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1358327131c4SLeonardo Sandoval	LOG_LEVEL \
1359327131c4SLeonardo Sandoval	MEASURED_BOOT \
136000e28874SManish V Badarkhe	DRTM_SUPPORT \
1361327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1362327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1363327131c4SLeonardo Sandoval	PLAT_${PLAT} \
1364327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1365327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
136664b4710bSWing Li	PSCI_OS_INIT_MODE \
1367327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1368327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
136996a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1370327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1371327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1372327131c4SLeonardo Sandoval	SPD_${SPD} \
1373327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1374327131c4SLeonardo Sandoval	SPM_MM \
13751d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1376801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1377327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
13783ba2c151SRaymond Mao	TRANSFER_LIST \
1379327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1380c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13817dfb9911SJimmy Brisson	TRNG_SUPPORT \
1382ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1383ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1384327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1385327131c4SLeonardo Sandoval	USE_DEBUGFS \
1386327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1387327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1388327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1389327131c4SLeonardo Sandoval	USE_ROMLIB \
1390327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1391327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
139242d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
139342d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1394327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1395327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1396327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1397327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
139800e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1399327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1400327131c4SLeonardo Sandoval	USE_SP804_TIMER \
140112cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1402ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
14034e04478aSChris Kay	ENABLE_FEAT_SB \
14047d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
14055357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
14065357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1407396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1408744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1409813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1410d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
14118fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1412cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
141368120783SChris Kay	ENABLE_MPMM \
141468120783SChris Kay	ENABLE_MPMM_FCONF \
1415f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1416f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
14176a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
14186a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
14196a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
14206a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
14216a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1422d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1423062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1424062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1425062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1426062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1427688ab57bSMark Brown	ENABLE_FEAT_GCS \
14284d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
14296a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1430781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1431781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
143204c7303bSOkash Khawaja	CONDITIONAL_CMO \
14330ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1434a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1435890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
14365782b890SManish V Badarkhe	PSA_CRYPTO	\
143785bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1438183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1439bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1440327131c4SLeonardo Sandoval)))
14412fae4b1eSJeenu Viswambharan
1442bfef8b90SJuan Pablo Condeifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1443bfef8b90SJuan Pablo Condeifeq (${DEBUG}, 0)
1444bfef8b90SJuan Pablo Conde        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1445bfef8b90SJuan Pablo Conde        override PLATFORM_REPORT_CTX_MEM_USE := 0
1446bfef8b90SJuan Pablo Condeendif
1447bfef8b90SJuan Pablo Condeendif
1448bfef8b90SJuan Pablo Conde
14491f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14501f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1451c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14521f461979SJustin Chadwell
14534c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14544c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14554c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1456cf2c8a33SAntonio Nino Diazelse
145768450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
145868450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
145968450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
146068450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14614c117f6cSSandrine Bailleux	endif
1462c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
146373c99d4eSJuan Castillo
1464209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1465209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1466209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1467209a60ccSSoby Mathewendif
1468209a60ccSSoby Mathew
1469c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1470c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1471c2ad38ceSVarun Wadekarendif
1472c2ad38ceSVarun Wadekar
1473ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1474ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1475c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1476ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1477ce2b1ec6SManish Pandey	FIP_DEPS += sp
147807c44475SManish Pandey	CRT_DEPS += sp
1479ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1480ce2b1ec6SManish Pandeyelse
1481c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1482c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1483c33ff198SOlivier Deprez	endif
1484c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1485c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1486ce2b1ec6SManish Pandey
148773c99d4eSJuan Castillo################################################################################
148873c99d4eSJuan Castillo# Build targets
148973c99d4eSJuan Castillo################################################################################
149073c99d4eSJuan Castillo
149190aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
149273c99d4eSJuan Castillo.SUFFIXES:
149373c99d4eSJuan Castillo
149473c99d4eSJuan Castilloall: msg_start
149573c99d4eSJuan Castillo
149673c99d4eSJuan Castillomsg_start:
149773c99d4eSJuan Castillo	@echo "Building ${PLAT}"
149873c99d4eSJuan Castillo
14997a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1500d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1501c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1502c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1503c2ad38ceSVarun Wadekarelse
1504bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
15057a24cba5SSoby Mathewendif
1506c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
15077a24cba5SSoby Mathew
15085accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
150961f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
15105fee0287SRoberto Vargas
151173c99d4eSJuan Castillo# Expand build macros for the different images
151273c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1513b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1514434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1515c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
151673c99d4eSJuan Castillo
151773c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1518c5e1da83SJayanth Dodderi Chidanand
151942d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1520c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1521c9b31ae8SRoberto Vargasendif
1522c9b31ae8SRoberto Vargas
1523eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1524eb1acfb6SChris Kay
152533950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1526434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1527c5e1da83SJayanth Dodderi Chidanand
1528c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
152973c99d4eSJuan Castillo
15304d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
153133950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1532c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
15334d045d0eSMasahiro Yamada
153473c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
153573c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
153626d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
153726d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1538c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1539c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1540434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1541c6ba9b45SSumit Gargelse
154233950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1543434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1544c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1545c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
154673c99d4eSJuan Castillo
154770d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1548c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
154970d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
155073c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
155126d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
155226d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15539cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15549cd15239SMasahiro Yamada
1555c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1556434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1557c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1558c6ba9b45SSumit Gargelse
1559434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
156033950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1561c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1562c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
156373c99d4eSJuan Castillo
15645b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15655b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15665b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15675b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15685b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15695b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15705b18de09SZelalem Aweke
15715b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15725b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1573c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15745b18de09SZelalem Aweke
157573c99d4eSJuan Castillo# Add the BL33 image if required by the platform
157673c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
157733950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1578c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1579db6071c9SJuan Castillo
15809003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
158133950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1582434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1583c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15849003fa0bSYatharth Kochar
158503b397a8SNishanth Menon# Expand build macros for the different images
158603b397a8SNishanth Menonifeq (${NEED_FDT},yes)
158703b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1588c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
158903b397a8SNishanth Menon
1590ce2b1ec6SManish Pandey# Add Secure Partition packages
1591ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1592ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk : ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
159320629b31SKarl Meakin	${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1594822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1595ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1596ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1597ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1598c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1599ce2b1ec6SManish Pandey
160036eaaf37SIan Spraylocate-checkpatch:
160136eaaf37SIan Sprayifndef CHECKPATCH
160266079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
160336eaaf37SIan Sprayelse
160436eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
160566079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
160636eaaf37SIan Sprayendif
1607c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
160836eaaf37SIan Spray
16094f6ad66aSAchin Guptaclean:
16104f6ad66aSAchin Gupta	@echo "  CLEAN"
1611f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
161288a1cf1eSSami Mujawarifdef UNIX_MK
16132f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
161488a1cf1eSSami Mujawarelse
161588a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
161688a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
161788a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1618c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16196f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
162090aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
16215accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16224f6ad66aSAchin Gupta
1623eaaeece2SJames Morrisseyrealclean distclean:
1624eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1625f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1626f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
162788a1cf1eSSami Mujawarifdef UNIX_MK
16282f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
162988a1cf1eSSami Mujawarelse
163088a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
163188a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
163288a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1633c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1634e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
163590aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
16365accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16374f6ad66aSAchin Gupta
163836eaaf37SIan Spraycheckcodebase:		locate-checkpatch
163936eaaf37SIan Spray	@echo "  CHECKING STYLE"
164036eaaf37SIan Spray	@if test -d .git ; then						\
16411ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16421a41e8c1SDan Handley		while read GIT_FILE ;					\
16431a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16441a41e8c1SDan Handley		done ;							\
164536eaaf37SIan Spray	else								\
16461a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16471a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16481a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
164961f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16501a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16511ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16521a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
165336eaaf37SIan Spray	fi
165436eaaf37SIan Spray
165536eaaf37SIan Spraycheckpatch:		locate-checkpatch
165636eaaf37SIan Spray	@echo "  CHECKING STYLE"
165702a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
165802a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
165902a76d5fSYann Gautier	fi
166051d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
166177a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
166277a0a7f1SYann Gautier	do								\
166351d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
166451d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
166502a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
166602a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
166751d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
166802a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
166902a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
167051d28937SAntonio Nino Diaz	done
167136eaaf37SIan Spray
167273c99d4eSJuan Castillocerttool: ${CRTTOOL}
167373c99d4eSJuan Castillo
1674a9812206SPali Rohár${CRTTOOL}: FORCE
1675598b166bSLionel 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
1676f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16776f971622SJuan Castillo	@echo "Built $@ successfully"
1678f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16796f971622SJuan Castillo
16806f971622SJuan Castilloifneq (${GENERATE_COT},0)
168173c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16826f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1683f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16846f971622SJuan Castillo	@echo "Built $@ successfully"
16856f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1686f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1687c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
168827713fb4SSoby Mathew
168973c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16904727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1691819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1692819281eeSdp-arm	${Q}${FIPTOOL} info $@
1693f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16942f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1695f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1696f58ad36fSHarry Liebel
16970191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16980191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16990191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1700052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
17010191262dSYatharth Kochar	@echo "Built $@ successfully"
17020191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1703052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1704c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
17050191262dSYatharth Kochar
17060191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
17074727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1708819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1709819281eeSdp-arm	${Q}${FIPTOOL} info $@
1710052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
17110191262dSYatharth Kochar	@echo "Built $@ successfully"
1712052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
17130191262dSYatharth Kochar
171473c99d4eSJuan Castillofiptool: ${FIPTOOL}
171573c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
17160191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
171773c99d4eSJuan Castillo
1718a9812206SPali Rohár${FIPTOOL}: FORCE
171988a1cf1eSSami Mujawarifdef UNIX_MK
1720598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
172188a1cf1eSSami Mujawarelse
172288a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
172388a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
172488a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1725c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1726f58ad36fSHarry Liebel
1727a9812206SPali Rohárromlib.bin: libraries FORCE
1728bbb24f61SJohn 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
17295accce5bSRoberto Vargas
1730cfe83910SLouis Mayencourtmemmap: all
1731af5b49e9SHarrison Mutaiifdef UNIX_MK
1732af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1733af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1734af5b49e9SHarrison Mutaielse
1735af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1736af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1737af5b49e9SHarrison Mutaiendif
1738cfe83910SLouis Mayencourt
17396de32378SMadhukar Pappireddydoc:
17406de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
17416de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
17426de32378SMadhukar Pappireddy
174390aa901fSSumit Gargenctool: ${ENCTOOL}
174490aa901fSSumit Garg
1745a9812206SPali Rohár${ENCTOOL}: FORCE
1746598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
174790aa901fSSumit Garg	@${ECHO_BLANK_LINE}
174890aa901fSSumit Garg	@echo "Built $@ successfully"
174990aa901fSSumit Garg	@${ECHO_BLANK_LINE}
175090aa901fSSumit Garg
175135fab8c9SJoakim Bechcscope:
175235fab8c9SJoakim Bech	@echo "  CSCOPE"
175335fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
175435fab8c9SJoakim Bech	${Q}cscope -b -q -k
175535fab8c9SJoakim Bech
175672ee3314SRyan Harkinhelp:
17577c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
175872ee3314SRyan Harkin	@echo ""
175972ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
176008c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
176172ee3314SRyan Harkin	@echo ""
17627c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17637c23126cSJohn Tsichritzis	@echo ""
17641b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17651b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17661b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17671b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17681b578596SSandrine Bailleux	@echo ""
176972ee3314SRyan Harkin	@echo "Supported Targets:"
17701b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
177136eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17728aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17739003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1774d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17759d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17769d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
177773c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17781b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17790191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
178036eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
178136eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
178236eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
178372ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
178435fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
178572ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17866f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
178790aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1788f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1789ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
179026010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
179138c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1792cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17936de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
179472ee3314SRyan Harkin	@echo ""
17951b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
179672ee3314SRyan Harkin	@echo ""
179772ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
179872ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1799a9812206SPali Rohár
1800a9812206SPali Rohár.PHONY: FORCE
1801a9812206SPali RohárFORCE:;
1802