xref: /rk3399_ARM-atf/Makefile (revision 055ebeca1b642ae69885a95e3c102f95d567a11e)
14f6ad66aSAchin Gupta#
201cf14ddSMaksims Svecovs# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta#
482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta#
64f6ad66aSAchin Gupta
7e35c4045SJeenu Viswambharan#
8aaa3e722SJuan Castillo# Trusted Firmware Version
9aaa3e722SJuan Castillo#
101a0f1121SSoby MathewVERSION_MAJOR			:= 2
11b78ad00eSJuan Pablo CondeVERSION_MINOR			:= 9
12*055ebecaSYann GautierVERSION_PATCH			:= 0
13*055ebecaSYann 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_ARM_DIRS_TO_CHECK	:=	$(sort $(filter-out                     \
454501843fSGilad Ben-Yossef					include/drivers/arm/cryptocell,	\
464501843fSGilad Ben-Yossef					$(wildcard include/drivers/arm/*)))
474501843fSGilad Ben-YossefINC_ARM_DIRS_TO_CHECK	+=	include/drivers/arm/cryptocell/*.h
484501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
494501843fSGilad Ben-Yossef					include/drivers/arm,		\
504501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
51f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
521a41e8c1SDan Handley					include/lib/libfdt		\
5361f72a34SRoberto Vargas					include/lib/libc,		\
54f0b489c1SDan Handley					$(wildcard include/lib/*)))
55f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
564501843fSGilad Ben-Yossef					include/lib			\
574501843fSGilad Ben-Yossef					include/drivers,		\
58f0b489c1SDan Handley					$(wildcard include/*)))
59f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
60d801fbb0Sdp-arm					lib/compiler-rt			\
6155cdcf75SAntonio Nino Diaz					lib/libfdt%			\
6261f72a34SRoberto Vargas					lib/libc,			\
63a194255dSDaniel Boulby					lib/zlib			\
64f0b489c1SDan Handley					$(wildcard lib/*)))
65f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
66f0b489c1SDan Handley					lib				\
67f0b489c1SDan Handley					include				\
68f0b489c1SDan Handley					docs				\
691ef35512SPaul Beesley					%.rst,				\
70f0b489c1SDan Handley					$(wildcard *)))
71f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
72f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
73f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
744501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
754501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
764501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
7736eaaf37SIan Spray
7873c99d4eSJuan Castillo################################################################################
7973c99d4eSJuan Castillo# Process build options
8073c99d4eSJuan Castillo################################################################################
8173c99d4eSJuan Castillo
8273c99d4eSJuan Castillo# Verbose flag
83e35c4045SJeenu Viswambharanifeq (${V},0)
84b169f6a9SEvan Lloyd	Q:=@
85ee1ba6d4SAndre Przywara	ECHO:=@echo
8636eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
874f6ad66aSAchin Guptaelse
88b169f6a9SEvan Lloyd	Q:=
89b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
904f6ad66aSAchin Guptaendif
91ee1ba6d4SAndre Przywara
92ee1ba6d4SAndre Przywaraifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
93ee1ba6d4SAndre Przywara	Q:=@
94b5a0f4bdSAntonio Nino Diaz	ECHO:=$(ECHO_QUIET)
95ee1ba6d4SAndre Przywaraendif
96ee1ba6d4SAndre Przywara
97ee1ba6d4SAndre Przywaraexport Q ECHO
982f2cef46SJeenu Viswambharan
9973c99d4eSJuan Castillo################################################################################
10073c99d4eSJuan Castillo# Toolchain
10173c99d4eSJuan Castillo################################################################################
10273c99d4eSJuan Castillo
10372610c41Sdp-armHOSTCC			:=	gcc
10472610c41Sdp-armexport HOSTCC
10572610c41Sdp-arm
10673c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
10773c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
10873c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
10973c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1102adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
11173c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
11273c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
11373c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
11473c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
11538c14d88SSoby MathewDTC			:=	dtc
11673c99d4eSJuan Castillo
117b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
118b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1192adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1202adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
121b25a577fSJulius Wernerendif
122b25a577fSJulius Werner
123c5e1da83SJayanth Dodderi Chidanand################################################################################
124c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
125c5e1da83SJayanth Dodderi Chidanand################################################################################
126c5e1da83SJayanth Dodderi Chidanand
127c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
128c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
129c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
130c5e1da83SJayanth Dodderi Chidanand
131c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
132c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
133c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
134c5e1da83SJayanth Dodderi Chidanand
135c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
136c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
137c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
138c5e1da83SJayanth Dodderi Chidanand
139c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
140c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
141c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
142c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
14320629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
144c5e1da83SJayanth Dodderi Chidanand
145c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
146c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
147c5e1da83SJayanth Dodderi Chidanand
148c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
149c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
150c5e1da83SJayanth Dodderi Chidanand
151c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
152c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
153c5e1da83SJayanth Dodderi Chidanand
154c5e1da83SJayanth Dodderi Chidanand################################################################################
155c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
156c5e1da83SJayanth Dodderi Chidanand################################################################################
15726e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
15826e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
159d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
16026e63c44SEtienne Carriereelse
16126e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
162c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
163c5e1da83SJayanth Dodderi Chidanand
164c5e1da83SJayanth Dodderi Chidanand################################################################################
165c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
166c5e1da83SJayanth Dodderi Chidanand################################################################################
167c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
168c5e1da83SJayanth Dodderi Chidanand
169f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
170f1821790SAlexei Fedorovifneq ($(arch-features), none)
171f1821790SAlexei Fedorov	# Strip "none+" from arch-features
172f1821790SAlexei Fedorov	arch-features	:=	$(subst none+,,$(arch-features))
173d4089fb8SGovindraj Raja	march-directive	:=	$(march-directive)+$(arch-features)
174f1821790SAlexei Fedorov# Print features
175f1821790SAlexei Fedorov        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
176c5e1da83SJayanth Dodderi Chidanandendif #(arch-features)
1774e04478aSChris Kay
178c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
179fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
1807794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
1817794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
182c8a992fdSorigin		LD			:=	$(LINKER)
183c8a992fdSorigin	else
1847794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
1857794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
186c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
187c8a992fdSorigin
188c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
189c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
190c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
191641f16e7SAmbroise Vincent	endif
192c8a992fdSorigin
193c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
194c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
195c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
196edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
197edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
198edbce9aaSzelalem-aweke		# Enable LTO only for aarch64
199edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
200edbce9aaSzelalem-aweke			LTO_CFLAGS	=	-flto
201edbce9aaSzelalem-aweke			# Use gcc as a wrapper for the ld, recommended for LTO
202edbce9aaSzelalem-aweke			LINKER		:=	${CROSS_COMPILE}gcc
203edbce9aaSzelalem-aweke		endif
204edbce9aaSzelalem-aweke	endif
205edbce9aaSzelalem-aweke	LD			=	$(LINKER)
206d5461857Sdp-armelse
2072adee763SRoberto Vargas	LD			=	$(LINKER)
208c5e1da83SJayanth Dodderi Chidanandendif #(clang)
209d5461857Sdp-arm
21032b209bfSAhmad Fatoum# Process Debug flag
21132b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
21232b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
21332b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
2144466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
2154466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
21632b209bfSAhmad Fatoum
21732b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
21832b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
21932b209bfSAhmad Fatoumelse
22032b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
22132b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
22232b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
223c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
22432b209bfSAhmad Fatoum
225f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
226f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
227f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
228f1de4c8fSPeiyuan Songendif
229dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
230f1de4c8fSPeiyuan Song
2318fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
2328fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
2338fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
2348fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
2358fd9d4d5SAntonio Nino Diazelse
2368fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
237c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
2388fd9d4d5SAntonio Nino Diaz
239a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
240d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
2419d29c227SSoby Mathew
242d4089fb8SGovindraj RajaASFLAGS		+=	$(march-directive)
243b86048c4SAntonio Nino Diaz
244c5e1da83SJayanth Dodderi Chidanand##############################################################################
245c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
246c5e1da83SJayanth Dodderi Chidanand###############################################################################
2479ab81b5eSJustin Chadwell# General warnings
2489ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
249b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
250d75a9ecdSBoyan Karatotev				-Wredundant-decls
251d75a9ecdSBoyan Karatotev# stricter warnings
252d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
253d75a9ecdSBoyan Karatotev# too verbose for generic build
254d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
255d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
256d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
257d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
2589ab81b5eSJustin Chadwell
2599ab81b5eSJustin Chadwell# Additional warnings
260d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
261d75a9ecdSBoyan Karatotev# full -Wextra
262d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
263d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
264d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
265e7c645b5SYann Gautier
266d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
267d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
268d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
269d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
270d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
271d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
272d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
273d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
274d141e638SBoyan Karatotev# currently very involved and many platforms set this off
275d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
276e7c645b5SYann Gautier
277d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
278e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
279d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
280d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
281d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
282e7c645b5SYann GautierWARNING3 += -Wcast-qual
283e7c645b5SYann GautierWARNING3 += -Wconversion
284e7c645b5SYann GautierWARNING3 += -Wpacked
285e7c645b5SYann GautierWARNING3 += -Wpointer-arith
286e7c645b5SYann GautierWARNING3 += -Wswitch-default
287e7c645b5SYann Gautier
288d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
289d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
290d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
291d75a9ecdSBoyan Karatotevifdef W
292d75a9ecdSBoyan Karatotev	ifneq (${W},0)
293d75a9ecdSBoyan Karatotev		E	 ?= 0
294d75a9ecdSBoyan Karatotev	endif
295d75a9ecdSBoyan Karatotevendif
296d75a9ecdSBoyan Karatotev
297e7c645b5SYann Gautierifeq (${W},1)
2989ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
299e7c645b5SYann Gautierelse ifeq (${W},2)
3009ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
301e7c645b5SYann Gautierelse ifeq (${W},3)
3029ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
303c5e1da83SJayanth Dodderi Chidanandendif #(W)
304e7c645b5SYann Gautier
3059ab81b5eSJustin Chadwell# Compiler specific warnings
30600296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
30793c690ebSJustin Chadwell# not using clang
308d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
309d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
310d7b4cd41SJustin Chadwell				-Wlogical-op
311dea23e24SGovindraj Raja
312dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
313dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
314dea23e24SGovindraj Raja
31593c690ebSJustin Chadwellelse
31693c690ebSJustin Chadwell# using clang
317d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
318d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
319c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
32000296576SAmbroise Vincent
3216336b07aSYann Gautierifneq (${E},0)
3226336b07aSYann Gautier	ERRORS := -Werror
323c5e1da83SJayanth Dodderi Chidanandendif #(E)
3246336b07aSYann Gautier
325c5e1da83SJayanth Dodderi Chidanand################################################################################
326c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
327c5e1da83SJayanth Dodderi Chidanand################################################################################
328ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3299ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
330d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
331d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
33259de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
333ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
334ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
335ebd6efaeSSamuel Holland				-Os -std=gnu99
33673c99d4eSJuan Castillo
3371f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3381f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
339c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
340c5e1da83SJayanth Dodderi Chidanand
3411f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
3421f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
3431f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
344c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
3451f461979SJustin Chadwell
346f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
347f7ec31dbSdavid cunado
3481f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
3491f49db5fSMarco Felsch
350641f16e7SAmbroise Vincent# LD = armlink
351c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
352c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
353c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
354edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
355641f16e7SAmbroise Vincent
356641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
357edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
358edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
359edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
360edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
361ac98b82aSChris Kay
362ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
363ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
364ac98b82aSChris Kay
365edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
366edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
367edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
368edbce9aaSzelalem-aweke		endif
369c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
370c5e1da83SJayanth Dodderi Chidanand
371edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
372edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
373edbce9aaSzelalem-aweke	ifneq (${ERRATA_A53_843419},1)
374edbce9aaSzelalem-aweke		TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
375edbce9aaSzelalem-aweke	endif
376edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
377edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
378641f16e7SAmbroise Vincent
379641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
380c2ad38ceSVarun Wadekarelse
3811f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
3821f49db5fSMarco Felsch# are not loaded by a elf loader.
3831f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
384ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
385c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
386ac98b82aSChris Kay
387ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
388ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
389ac98b82aSChris Kay
390641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
391ebac6922SYabin Cui# therefore don't add those in that case.
392ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
393ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
394641f16e7SAmbroise Vincent	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
395ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
396edbce9aaSzelalem-aweke	endif
397c5e1da83SJayanth Dodderi Chidanand
398c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
39973c99d4eSJuan Castillo
40003b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
401a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
402a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
40303b397a8SNishanth Menon
40473c99d4eSJuan Castillo################################################################################
405f5211420SGovindraj Raja# Setup ARCH_MAJOR/MINOR before parsing arch_features.
406f5211420SGovindraj Raja################################################################################
407f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
408f5211420SGovindraj Raja	ARM_ARCH_MAJOR := 8
409f5211420SGovindraj Raja	ARM_ARCH_MINOR := 6
410f5211420SGovindraj Rajaendif
411f5211420SGovindraj Raja
412f5211420SGovindraj Raja################################################################################
41373c99d4eSJuan Castillo# Common sources and include directories
41473c99d4eSJuan Castillo################################################################################
4156a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
416d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
41773c99d4eSJuan Castillo
41873c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4197f56e9a3SSoby Mathew				common/tf_log.c				\
4209d29c227SSoby Mathew				common/${ARCH}/debug.S			\
42191b48c9fSJulius Werner				drivers/console/multi_console.c		\
4229d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4239d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
424c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
425566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4267f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
42775311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4289d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
42961f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
430d7a6b0f8SRyan Harkin
4318422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4328422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4338422a840SAntonio Nino Diazendif
4348422a840SAntonio Nino Diaz
4351f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4361f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
4371f461979SJustin Chadwellendif
4381f461979SJustin Chadwell
43901d237cbSYann GautierINCLUDES		+=	-Iinclude				\
440f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
44109d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
44209d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
44309d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
44409d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
44509d40e0eSAntonio Nino Diaz
4469c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4479c6d1c50SAntonio Nino Diaz
44873c99d4eSJuan Castillo################################################################################
449f5211420SGovindraj Raja# Process BRANCH_PROTECTION value and set
450f5211420SGovindraj Raja# Pointer Authentication and Branch Target Identification flags
451f5211420SGovindraj Raja################################################################################
452f5211420SGovindraj Rajaifeq (${BRANCH_PROTECTION},0)
453f5211420SGovindraj Raja	# Default value turns off all types of branch protection
454f5211420SGovindraj Raja	BP_OPTION := none
455f5211420SGovindraj Rajaelse ifneq (${ARCH},aarch64)
456f5211420SGovindraj Raja        $(error BRANCH_PROTECTION requires AArch64)
457f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},1)
458f5211420SGovindraj Raja	# Enables all types of branch protection features
459f5211420SGovindraj Raja	BP_OPTION := standard
460f5211420SGovindraj Raja	ENABLE_BTI := 1
461f5211420SGovindraj Raja	ENABLE_PAUTH := 1
462f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},2)
463f5211420SGovindraj Raja	# Return address signing to its standard level
464f5211420SGovindraj Raja	BP_OPTION := pac-ret
465f5211420SGovindraj Raja	ENABLE_PAUTH := 1
466f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},3)
467f5211420SGovindraj Raja	# Extend the signing to include leaf functions
468f5211420SGovindraj Raja	BP_OPTION := pac-ret+leaf
469f5211420SGovindraj Raja	ENABLE_PAUTH := 1
470f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},4)
471f5211420SGovindraj Raja	# Turn on branch target identification mechanism
472f5211420SGovindraj Raja	BP_OPTION := bti
473f5211420SGovindraj Raja	ENABLE_BTI := 1
474f5211420SGovindraj Rajaelse
475f5211420SGovindraj Raja        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
476f5211420SGovindraj Rajaendif #(BRANCH_PROTECTION)
477f5211420SGovindraj Raja
478f5211420SGovindraj Rajaifeq ($(ENABLE_PAUTH),1)
479f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
480f5211420SGovindraj Rajaendif
481f5211420SGovindraj Rajaifneq (${BP_OPTION},none)
482f5211420SGovindraj Raja	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
483f5211420SGovindraj Rajaendif #(BP_OPTION)
484f5211420SGovindraj Raja
485f5211420SGovindraj Raja# Pointer Authentication sources
486f5211420SGovindraj Rajaifeq (${ENABLE_PAUTH}, 1)
487f5211420SGovindraj Raja# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
488f5211420SGovindraj Raja# Pauth support. As it's not secure, it must be reimplemented for real platforms
489f5211420SGovindraj Raja	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
490f5211420SGovindraj Rajaendif
491f5211420SGovindraj Raja
492f5211420SGovindraj Raja####################################################
493f5211420SGovindraj Raja# Enable required options for Memory Stack Tagging.
494f5211420SGovindraj Raja####################################################
495f5211420SGovindraj Raja
496f5211420SGovindraj Raja# Currently, these options are enabled only for clang and armclang compiler.
497f5211420SGovindraj Rajaifeq (${SUPPORT_STACK_MEMTAG},yes)
498f5211420SGovindraj Raja    ifdef mem_tag_arch_support
499f5211420SGovindraj Raja        # Check for armclang and clang compilers
500f5211420SGovindraj Raja        ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
501f5211420SGovindraj Raja        # Add "memtag" architecture feature modifier if not specified
502f5211420SGovindraj Raja            ifeq ( ,$(findstring memtag,$(arch-features)))
503f5211420SGovindraj Raja                arch-features	:=	$(arch-features)+memtag
504f5211420SGovindraj Raja            endif	# memtag
505f5211420SGovindraj Raja            ifeq ($(notdir $(CC)),armclang)
506f5211420SGovindraj Raja                TF_CFLAGS	+=	-mmemtag-stack
507f5211420SGovindraj Raja            else ifeq ($(notdir $(CC)),clang)
508f5211420SGovindraj Raja                TF_CFLAGS	+=	-fsanitize=memtag
509f5211420SGovindraj Raja            endif	# armclang
510f5211420SGovindraj Raja        endif
511f5211420SGovindraj Raja    else
512f5211420SGovindraj Raja        $(error "Error: stack memory tagging is not supported for  \
513f5211420SGovindraj Raja        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
514f5211420SGovindraj Raja	endif #(mem_tag_arch_support)
515f5211420SGovindraj Rajaendif #(SUPPORT_STACK_MEMTAG)
516f5211420SGovindraj Raja
517f5211420SGovindraj Raja################################################################################
518f5211420SGovindraj Raja# RME dependent flags configuration, Enable optional features for RME.
519f5211420SGovindraj Raja################################################################################
520f5211420SGovindraj Raja# FEAT_RME
521f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
522f5211420SGovindraj Raja	# RME doesn't support PIE
523f5211420SGovindraj Raja	ifneq (${ENABLE_PIE},0)
524f5211420SGovindraj Raja                $(error ENABLE_RME does not support PIE)
525f5211420SGovindraj Raja	endif
526f5211420SGovindraj Raja
527f5211420SGovindraj Raja	# RME doesn't support BRBE
528f5211420SGovindraj Raja	ifneq (${ENABLE_BRBE_FOR_NS},0)
529f5211420SGovindraj Raja                $(error ENABLE_RME does not support BRBE.)
530f5211420SGovindraj Raja	endif
531f5211420SGovindraj Raja
532f5211420SGovindraj Raja	# RME requires AARCH64
533f5211420SGovindraj Raja	ifneq (${ARCH},aarch64)
534f5211420SGovindraj Raja                $(error ENABLE_RME requires AArch64)
535f5211420SGovindraj Raja	endif
536f5211420SGovindraj Raja
537f5211420SGovindraj Raja	# RME requires el2 context to be saved for now.
538f5211420SGovindraj Raja	CTX_INCLUDE_EL2_REGS := 1
539f5211420SGovindraj Raja	CTX_INCLUDE_AARCH32_REGS := 0
540f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
541f5211420SGovindraj Raja
542f5211420SGovindraj Raja	# RME enables CSV2_2 extension by default.
543f5211420SGovindraj Raja	ENABLE_FEAT_CSV2_2 = 1
544f5211420SGovindraj Rajaendif #(FEAT_RME)
545f5211420SGovindraj Raja
546f5211420SGovindraj Raja################################################################################
54773c99d4eSJuan Castillo# Generic definitions
54873c99d4eSJuan Castillo################################################################################
549231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
550231c1470SEvan Lloyd
55129214e95SGrant Likelyifeq (${BUILD_BASE},)
55273c99d4eSJuan Castillo     BUILD_BASE		:=	./build
55329214e95SGrant Likelyendif
55429214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
55573c99d4eSJuan Castillo
556231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
55773c99d4eSJuan Castillo
55873c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
55973c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
56073c99d4eSJuan Castillo
56173c99d4eSJuan Castillo################################################################################
56273c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
56373c99d4eSJuan Castillo################################################################################
56473c99d4eSJuan Castillo
56573c99d4eSJuan Castilloifneq (${SPD},none)
5669d29c227SSoby Mathew	ifeq (${ARCH},aarch32)
5679d29c227SSoby Mathew                $(error "Error: SPD is incompatible with AArch32.")
5689d29c227SSoby Mathew	endif
56928f39f02SMax Shvetsov
5704c117f6cSSandrine Bailleux	ifdef EL3_PAYLOAD_BASE
5714c117f6cSSandrine Bailleux                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
572c5e1da83SJayanth Dodderi Chidanand                $(warning "The SPD and its BL32 companion will be present but \
573c5e1da83SJayanth Dodderi Chidanand                ignored.")
5744c117f6cSSandrine Bailleux	endif
57528f39f02SMax Shvetsov
576c3fb00d9SAchin Gupta	ifeq (${SPD},spmd)
577c3fb00d9SAchin Gupta	# SPMD is located in std_svc directory
578c3fb00d9SAchin Gupta		SPD_DIR := std_svc
57928f39f02SMax Shvetsov
580033039f8SMax Shvetsov		ifeq ($(SPMD_SPM_AT_SEL2),1)
581f1910cc1SGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
5821d63ae4dSMarc Bonnici			ifeq ($(SPMC_AT_EL3),1)
5831d63ae4dSMarc Bonnici                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5841d63ae4dSMarc Bonnici			endif
58528f39f02SMax Shvetsov		endif
586db1ef41aSOlivier Deprez
587db1ef41aSOlivier Deprez		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
588db1ef41aSOlivier Deprez			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
589db1ef41aSOlivier Deprez		endif
590ca932481SDavidson K
591ca932481SDavidson K		ifeq ($(TS_SP_FW_CONFIG),1)
592ca932481SDavidson K		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
593ca932481SDavidson K		endif
59433993a37SBalint Dobszay
59533993a37SBalint Dobszay		ifneq ($(ARM_BL2_SP_LIST_DTS),)
59633993a37SBalint Dobszay		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
59733993a37SBalint Dobszay		endif
59846789a7cSBalint Dobszay
59946789a7cSBalint Dobszay		ifneq ($(SP_LAYOUT_FILE),)
60046789a7cSBalint Dobszay		BL2_ENABLE_SP_LOAD := 1
60146789a7cSBalint Dobszay		endif
602c3fb00d9SAchin Gupta	else
603c3fb00d9SAchin Gupta		# All other SPDs in spd directory
604c3fb00d9SAchin Gupta		SPD_DIR := spd
605c5e1da83SJayanth Dodderi Chidanand	endif #(SPD)
606c3fb00d9SAchin Gupta
60773c99d4eSJuan Castillo	# We expect to locate an spd.mk under the specified SPD directory
608c3fb00d9SAchin Gupta	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
609c3fb00d9SAchin Gupta
61073c99d4eSJuan Castillo	ifeq (${SPD_MAKE},)
611c3fb00d9SAchin Gupta                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
61273c99d4eSJuan Castillo	endif
61373c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
61473c99d4eSJuan Castillo        include ${SPD_MAKE}
61573c99d4eSJuan Castillo
61670d1fc53SJuan Castillo	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
61770d1fc53SJuan Castillo	# Makefile would set NEED_BL32 to "yes". In this case, the build system
61870d1fc53SJuan Castillo	# supports two mutually exclusive options:
61970d1fc53SJuan Castillo	# * BL32 is built from source: then BL32_SOURCES must contain the list
62070d1fc53SJuan Castillo	#   of source files to build BL32
62170d1fc53SJuan Castillo	# * BL32 is a prebuilt binary: then BL32 must point to the image file
62270d1fc53SJuan Castillo	#   that will be included in the FIP
62370d1fc53SJuan Castillo	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
62470d1fc53SJuan Castillo	# over the sources.
625c5e1da83SJayanth Dodderi Chidanandendif #(SPD=none)
626e35c4045SJeenu Viswambharan
627890b5088SRaghu Krishnamurthyifeq (${ENABLE_SPMD_LP}, 1)
628890b5088SRaghu Krishnamurthyifneq (${SPD},spmd)
629890b5088SRaghu Krishnamurthy        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
630890b5088SRaghu Krishnamurthyendif
631890b5088SRaghu Krishnamurthyifeq ($(SPMC_AT_EL3),1)
632890b5088SRaghu Krishnamurthy        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
633890b5088SRaghu Krishnamurthyendif
634890b5088SRaghu Krishnamurthyendif
635890b5088SRaghu Krishnamurthy
636f1910cc1SGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
637f1910cc1SGovindraj Raja	ifeq (${SPD},none)
638f1910cc1SGovindraj Raja		ifeq (${ENABLE_RME},0)
639c5e1da83SJayanth Dodderi Chidanand                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
640c5e1da83SJayanth Dodderi Chidanand                        or RME is enabled)
641f1910cc1SGovindraj Raja		endif
642f1910cc1SGovindraj Raja	endif
643f1910cc1SGovindraj Rajaendif
644f1910cc1SGovindraj Raja
64551faada7SDouglas Raillard################################################################################
6465b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6475b18de09SZelalem Aweke################################################################################
6485b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6495b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6505b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6515b18de09SZelalem Aweke	endif
6521d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6531d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6541d63ae4dSMarc Bonnici	endif
655c5e1da83SJayanth Dodderi Chidanand
6564fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6574fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6584fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6594fba2e1fSBoyan Karatotev		endif
6604fba2e1fSBoyan Karatotev	endif
6615b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6625b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6635b18de09SZelalem Awekeendif
6645b18de09SZelalem Aweke
6655b18de09SZelalem Aweke################################################################################
66673c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
66773c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
66873c99d4eSJuan Castillo################################################################################
6692da8d8bfSJeenu Viswambharan
67073c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6710f21c547SJuan Castillo
6727794d6c8SGovindraj Raja################################################################################
6737794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6747794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6757794d6c8SGovindraj Raja################################################################################
6767794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6777794d6c8SGovindraj Raja
6787794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6797794d6c8SGovindraj Raja
68042d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
68142d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
68242d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
68342d4d3baSArvind Ram Prakash# BL2 in EL3
68442d4d3baSArvind Ram Prakash
68542d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
68642d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68742d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
688c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
689c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
69042d4d3baSArvind Ram Prakash	endif
69142d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
69242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
69342d4d3baSArvind Ram Prakashelse
69442d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
69542d4d3baSArvind Ram Prakashendif
69642d4d3baSArvind Ram Prakash
6978012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6988012cc5cSMasahiro Yamada
69926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
70026e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
70126e63c44SEtienne Carriereendif
70226e63c44SEtienne Carriere
7033bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7043bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7053bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7067b592418SSamuel Hollandifneq ($(findstring gcc,$(notdir $(LD))),)
7077b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7087b592418SSamuel Hollandendif
709c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
710320920c1SMasahiro Yamada
711320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
712320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
713320920c1SMasahiro Yamadaelse
714320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
715320920c1SMasahiro Yamadaendif
716320920c1SMasahiro Yamada
717320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
71842d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
71969af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
720966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
72169af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
72269af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
723c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
724c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
725966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
726320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
727320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
728966660ecSChris Kay
729966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
730d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
731d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
732c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7333bd17c0fSSoby Mathew
734007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
735007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
736007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
737007433d8SBoyan Karatotev
7389cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
73942d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7409cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
741d5e97a1dSMasahiro Yamadaelse
7429cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
743c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
744007433d8SBoyan Karatotev
745007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7469cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7479cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7489cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
749007433d8SBoyan Karatotevelse
750007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
751d5e97a1dSMasahiro Yamadaendif
752d5e97a1dSMasahiro Yamada
75354035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
75454035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
75554035fc4SSandrine Bailleux# This can be overridden by the platform.
75673c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7574f6ad66aSAchin Gupta
758a4409008Sdp-arm################################################################################
759a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
760a4409008Sdp-arm################################################################################
761c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
762c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
763c5e1da83SJayanth Dodderi Chidanand
764a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
765a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
766a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
767a4409008Sdp-arm
768a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
769a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
770a4409008Sdp-arm                endif
771a4409008Sdp-arm                $(info Including ${AARCH32_SP_MAKE})
772a4409008Sdp-arm                include ${AARCH32_SP_MAKE}
773a4409008Sdp-arm        endif
774c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7754f6ad66aSAchin Gupta
77673c99d4eSJuan Castillo################################################################################
77777f1f7a1SVarun Wadekar# Include libc if not overridden
77877f1f7a1SVarun Wadekar################################################################################
77977f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
78077f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
78177f1f7a1SVarun Wadekarendif
78277f1f7a1SVarun Wadekar
78377f1f7a1SVarun Wadekar################################################################################
784c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
785cf2c8a33SAntonio Nino Diaz################################################################################
786cf2c8a33SAntonio Nino Diaz
787c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
788c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
789c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
790c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
791c5e1da83SJayanth Dodderi Chidanand        else
792c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
793c5e1da83SJayanth Dodderi Chidanand        endif
794c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
795c5e1da83SJayanth Dodderi Chidanand
796c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
797c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
798c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
799c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
800c5e1da83SJayanth Dodderi Chidanand        endif
801c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
802c5e1da83SJayanth Dodderi Chidanand
803c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
804c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
805c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
806c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
807c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
808c5e1da83SJayanth Dodderi Chidanandendif
809c5e1da83SJayanth Dodderi Chidanand
810c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
811c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
812c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
813c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
814c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
815c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
816c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
817c5e1da83SJayanth Dodderi Chidanand
818cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
81968450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
82068450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
82168450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
822cf2c8a33SAntonio Nino Diaz	endif
82376580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
824c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
825c5e1da83SJayanth Dodderi Chidanand                build options.")
82676580f3dSQixiang Xu	endif
82776580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
828c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
829c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
83076580f3dSQixiang Xu	endif
831c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
832cf2c8a33SAntonio Nino Diaz
833cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
834cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
835cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
836cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
837cf2c8a33SAntonio Nino Diaz	endif
83868450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
83968450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
840c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
841cf2c8a33SAntonio Nino Diaz	endif
842c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
843cf2c8a33SAntonio Nino Diaz
844d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
845d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
846d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
847d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
848d4593e47SJeenu Viswambharanendif
8491a0a3f06SYatharth Kochar
85042d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
85142d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
85242d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8537d173fc5SJiafei Panendif
8547d173fc5SJiafei Pan
8559202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85614c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
857c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
858c5e1da83SJayanth Dodderi Chidanand        and RAS_FFH_SUPPORT instead")
8599202d519SManish Pandeyendif
860c5e1da83SJayanth Dodderi Chidanand
8619202d519SManish Pandey# RAS firmware first handling requires that EAs are handled in EL3 first
8629202d519SManish Pandeyifeq ($(RAS_FFH_SUPPORT),1)
8639202d519SManish Pandey	ifneq ($(ENABLE_FEAT_RAS),1)
8649202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
8659202d519SManish Pandey	endif
86646cc41d5SManish Pandey	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
8679202d519SManish Pandey                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
86814c6016aSJeenu Viswambharan	endif
869c5e1da83SJayanth Dodderi Chidanandendif #(RAS_FFH_SUPPORT)
870c5e1da83SJayanth Dodderi Chidanand
8719202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8721a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8736503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8746503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8751a7c1cfeSJeenu Viswambharan	endif
876c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8771a7c1cfeSJeenu Viswambharan
878ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
879209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
880209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
881c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
882c5e1da83SJayanth Dodderi Chidanand                to be set.")
883209a60ccSSoby Mathew	endif
884c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
885209a60ccSSoby Mathew
8862bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8872bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8882bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8892bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8902bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8912bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8922bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8932bf4f27fSManish V Badarkhe# Support hash calculation only
8942bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8952bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8962bf4f27fSManish V Badarkhe# Support authentication verification only
897c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
898c9c56f6eSManish V Badarkheelse
899c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
900c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
901c9c56f6eSManish V Badarkhe
902cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
903cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
904700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
90584ef9cd8SManish V Badarkheendif
90684ef9cd8SManish V Badarkhe
907b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9089fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9099fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
910b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9119fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9129fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
91306715f85SAlexei Fedorov	endif
914c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9159fc59639SAlexei Fedorov
91606715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9179fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9189fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
919b86048c4SAntonio Nino Diaz	endif
920c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9219fc59639SAlexei Fedorov
9229dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
9239dd94382SJustin Chadwell	ifneq (${ARCH},aarch64)
9249dd94382SJustin Chadwell                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
9259dd94382SJustin Chadwell	endif
926c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_MTE_REGS)
9279dd94382SJustin Chadwell
928396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
929396b339dSManish V Badarkhe        $(info PSA_FWU_SUPPORT is an experimental feature)
930c5e1da83SJayanth Dodderi Chidanandendif #(PSA_FWU_SUPPORT)
931396b339dSManish V Badarkhe
9326a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9336a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
934c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9356a0da736SJayanth Dodderi Chidanand
93603d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
93703d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
938c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
939c5e1da83SJayanth Dodderi Chidanand                to be set")
94003d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
94103d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
94203d3c0d7SJayanth Dodderi Chidanand	endif
943c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
94445007acdSJayanth Dodderi Chidanand
94560e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
94660e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
947c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
948c5e1da83SJayanth Dodderi Chidanand                library v2")
94960e8f3cfSPetre-Ionut Tudor	endif
950c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
95160e8f3cfSPetre-Ionut Tudor
9527cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9537cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
954c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
955c5e1da83SJayanth Dodderi Chidanand                to be set)
9567cda17bbSSumit Garg	endif
957c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9587cda17bbSSumit Garg
959744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
960dc78e62dSjohpow01ifeq (${ARCH},aarch32)
961744ad974Sjohpow01
962744ad974Sjohpow01	# SME/SVE only supported on AArch64
96345007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
964dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
965dc78e62dSjohpow01	endif
96603d3c0d7SJayanth Dodderi Chidanand
967dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
968dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
96924ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
970dc78e62dSjohpow01	endif
971744ad974Sjohpow01
972ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
973744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
974744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
975744ad974Sjohpow01	endif
976744ad974Sjohpow01
977ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
978ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
979ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
980ff86e0b4SJuan Pablo Conde	endif
981c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
982dc78e62dSjohpow01
9830d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9840d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9850d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9860d122947SBoyan Karatotev	endif
987c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9880d122947SBoyan Karatotev
989dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
990dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
991dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
992dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
993dc78e62dSjohpow01	endif
9940d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9950d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9960d122947SBoyan Karatotev	endif
997c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
998c5e1da83SJayanth Dodderi Chidanand
999dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
1000dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},0)
1001dc78e62dSjohpow01                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1002dc78e62dSjohpow01	endif
1003c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SVE_FOR_SWD)
1004dc78e62dSjohpow01
1005dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1006dc78e62dSjohpow01# its own context management including FPU registers.
1007dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
100845007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
1009dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1010dc78e62dSjohpow01	endif
101103d3c0d7SJayanth Dodderi Chidanand
1012dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
1013dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
1014dc78e62dSjohpow01                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1015dc78e62dSjohpow01                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1016dc78e62dSjohpow01		override ENABLE_SVE_FOR_NS	:= 0
1017dc78e62dSjohpow01	endif
1018c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1019dc78e62dSjohpow01
102000e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
102100e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
102200e28874SManish V Badarkheendif
102300e28874SManish V Badarkhe
10243ba2c151SRaymond Maoifeq (${TRANSFER_LIST},1)
10253ba2c151SRaymond Mao        $(info TRANSFER_LIST is an experimental feature)
10263ba2c151SRaymond Maoendif
10273ba2c151SRaymond Mao
1028274a69e7SChris Kayifeq (${ENABLE_RME},1)
1029274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1030274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1031274a69e7SChris Kay	endif
1032274a69e7SChris Kayendif
1033274a69e7SChris Kay
1034c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_RNG is supported
1035c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1036c5e1da83SJayanth Dodderi Chidanand
1037c5e1da83SJayanth Dodderi Chidanand# Determine if FEAT_SB is supported
1038c5e1da83SJayanth Dodderi ChidanandENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1039c5e1da83SJayanth Dodderi Chidanand
1040cf2c8a33SAntonio Nino Diaz################################################################################
104173c99d4eSJuan Castillo# Process platform overrideable behaviour
104273c99d4eSJuan Castillo################################################################################
10434f6ad66aSAchin Gupta
10445f24ce96SManish Pandeyifdef BL1_SOURCES
10455f24ce96SManish Pandey	NEED_BL1 := yes
1046c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10475f24ce96SManish Pandey
10485f24ce96SManish Pandeyifdef BL2_SOURCES
10495f24ce96SManish Pandey	NEED_BL2 := yes
10505f24ce96SManish Pandey
1051bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1052bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1053cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1054cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1055cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10564c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1057cf2c8a33SAntonio Nino Diaz	else
105868450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1059cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1060cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1061cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1062cf2c8a33SAntonio Nino Diaz		else
1063cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1064cf2c8a33SAntonio Nino Diaz		endif
10654c117f6cSSandrine Bailleux	endif
1066c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10676f971622SJuan Castillo
10685f24ce96SManish Pandeyifdef BL2U_SOURCES
10695f24ce96SManish Pandey	NEED_BL2U := yes
1070c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10715f24ce96SManish Pandey
10724d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10734d045d0eSMasahiro Yamadaifdef SCP_BL2
10744d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1075c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10764d045d0eSMasahiro Yamada
10775744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10785744e874SSoby Mathewifneq (${ARCH},aarch32)
10795744e874SSoby Mathew	ifdef BL31_SOURCES
1080c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1081c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10825744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10835744e874SSoby Mathew			NEED_BL31 := yes
10845744e874SSoby Mathew		endif
10855744e874SSoby Mathew	endif
1086c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10875744e874SSoby Mathew
108873c99d4eSJuan Castillo# Process TBB related flags
10896f971622SJuan Castilloifneq (${GENERATE_COT},0)
109073c99d4eSJuan Castillo	# Common cert_create options
10916f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
10926f971622SJuan Castillo                $(eval CRT_ARGS += -n)
10930191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1094fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1095fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
10960191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1097fd34e7baSJuan Castillo		endif
10986f971622SJuan Castillo	endif
109973c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
110073c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
110173c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
110273c99d4eSJuan Castillo	endif
1103c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11046f971622SJuan Castillo
11051c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11061c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1107c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11081c75d5dfSMasahiro Yamada
11095f24ce96SManish Pandeyifdef FDT_SOURCES
11105f24ce96SManish Pandey	NEED_FDT := yes
1111c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11125f24ce96SManish Pandey
111373c99d4eSJuan Castillo################################################################################
111446e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
111546e5e035SMichalis Pappas################################################################################
111646e5e035SMichalis Pappas
111746e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
111846e5e035SMichalis Pappas
111946e5e035SMichalis Pappas################################################################################
11208a86052dSSoby Mathew# Include BL specific makefiles
11218a86052dSSoby Mathew################################################################################
11225f24ce96SManish Pandey
11235f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11248a86052dSSoby Mathewinclude bl1/bl1.mk
11258a86052dSSoby Mathewendif
11268a86052dSSoby Mathew
11275f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11288a86052dSSoby Mathewinclude bl2/bl2.mk
11298a86052dSSoby Mathewendif
11308a86052dSSoby Mathew
11315f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11328a86052dSSoby Mathewinclude bl2u/bl2u.mk
11338a86052dSSoby Mathewendif
11348a86052dSSoby Mathew
11355744e874SSoby Mathewifeq (${NEED_BL31},yes)
11368a86052dSSoby Mathewinclude bl31/bl31.mk
11378a86052dSSoby Mathewendif
113803b397a8SNishanth Menon
113973c99d4eSJuan Castillo################################################################################
114073c99d4eSJuan Castillo# Build options checks
114173c99d4eSJuan Castillo################################################################################
114273c99d4eSJuan Castillo
1143c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1144327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1145327131c4SLeonardo Sandoval    $(sort \
1146327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
114746789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1148327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1149327131c4SLeonardo Sandoval	CREATE_KEYS \
1150327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1151327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1152327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1153327131c4SLeonardo Sandoval	DEBUG \
1154327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1155327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11561fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1157742ca230SChris Kay	ENABLE_AMU_FCONF \
1158873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1159327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
116024077098SAndre Przywara	ENABLE_FEAT_SB \
1161327131c4SLeonardo Sandoval	ENABLE_PIE \
1162327131c4SLeonardo Sandoval	ENABLE_PMF \
1163327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1164327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1165dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11660c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1167327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1168327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1169327131c4SLeonardo Sandoval	GENERATE_COT \
1170327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
117146cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1172327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1173327131c4SLeonardo Sandoval	MEASURED_BOOT \
117400e28874SManish V Badarkhe	DRTM_SUPPORT \
1175327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1176327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1177327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
11780ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1179327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1180327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
118164b4710bSWing Li	PSCI_OS_INIT_MODE \
1182327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1183327131c4SLeonardo Sandoval	SAVE_KEYS \
1184327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
118596a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1186327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1187327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1188327131c4SLeonardo Sandoval	SPM_MM \
11891d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1190327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1191890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
11923ba2c151SRaymond Mao	TRANSFER_LIST \
1193327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1194327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1195327131c4SLeonardo Sandoval	USE_DEBUGFS \
1196327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1197327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1198327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1199327131c4SLeonardo Sandoval	USE_ROMLIB \
1200327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1201327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
120242d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1203327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1204327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1205327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1206327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1207327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1208327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
120900e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1210327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1211327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1212396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
121368120783SChris Kay	ENABLE_MPMM \
121468120783SChris Kay	ENABLE_MPMM_FCONF \
12156a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12160b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1217ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1218ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
121904c7303bSOkash Khawaja	CONDITIONAL_CMO \
12209202d519SManish Pandey	RAS_FFH_SUPPORT \
1221327131c4SLeonardo Sandoval)))
122273c99d4eSJuan Castillo
1223c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1224327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1225327131c4SLeonardo Sandoval    $(sort \
1226327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1227327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1228327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12296a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12306a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_MTE_REGS \
12316a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12322bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
123383a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12341298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
123547c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12366a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12376a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1238d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12396a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12406a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
12419202d519SManish Pandey	ENABLE_FEAT_RAS	\
12426a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12436a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12446a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
12456a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12466a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12476a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1248ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12496a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1250d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1251062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1252062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1253062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1254062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1255688ab57bSMark Brown	ENABLE_FEAT_GCS \
12566a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
12574d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
12586a0da736SJayanth Dodderi Chidanand	ENABLE_MPAM_FOR_LOWER_ELS \
12596a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12606437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1261603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
126245007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
126303d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12642b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12656a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1266327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12675357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12685357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1269781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1270781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1271bebcf27fSMark Brown	SVE_VECTOR_LEN \
12720ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1273327131c4SLeonardo Sandoval)))
1274c877b414SJeenu Viswambharan
1275aacff749SJustin Chadwellifdef KEY_SIZE
1276aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1277aacff749SJustin Chadwellendif
1278aacff749SJustin Chadwell
12791f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
12801f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
12811f461979SJustin Chadwellendif
12821f461979SJustin Chadwell
128373c99d4eSJuan Castillo################################################################################
128473c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
128573c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
128673c99d4eSJuan Castillo# platform to overwrite the default options
128773c99d4eSJuan Castillo################################################################################
128873c99d4eSJuan Castillo
1289327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1290327131c4SLeonardo Sandoval    $(sort \
1291327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1292327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1293327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
129446789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1295327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1296327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1297327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
1298327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
1299327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1300327131c4SLeonardo Sandoval	CTX_INCLUDE_MTE_REGS \
1301327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1302062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1303327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13040063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1305d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13061fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1307742ca230SChris Kay	ENABLE_AMU_FCONF \
1308873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1309327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1310327131c4SLeonardo Sandoval	ENABLE_BTI \
1311327131c4SLeonardo Sandoval	ENABLE_MPAM_FOR_LOWER_ELS \
1312327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1313327131c4SLeonardo Sandoval	ENABLE_PIE \
1314327131c4SLeonardo Sandoval	ENABLE_PMF \
1315327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13165b18de09SZelalem Aweke	ENABLE_RME \
1317327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1318dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
131903d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1320dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
132190118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1322327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13230c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1324327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1325327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1326327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1327327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1328327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
132946cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1330327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1331327131c4SLeonardo Sandoval	LOG_LEVEL \
1332327131c4SLeonardo Sandoval	MEASURED_BOOT \
133300e28874SManish V Badarkhe	DRTM_SUPPORT \
1334327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1335327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1336327131c4SLeonardo Sandoval	PLAT_${PLAT} \
13370ce2072dSTamas Ban	PLAT_RSS_NOT_SUPPORTED \
1338327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1339327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
134064b4710bSWing Li	PSCI_OS_INIT_MODE \
13419202d519SManish Pandey	ENABLE_FEAT_RAS \
13429202d519SManish Pandey	RAS_FFH_SUPPORT \
1343327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1344327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
134596a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1346327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1347327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1348327131c4SLeonardo Sandoval	SPD_${SPD} \
1349327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1350327131c4SLeonardo Sandoval	SPM_MM \
13511d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1352327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
13533ba2c151SRaymond Mao	TRANSFER_LIST \
1354327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1355c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13567dfb9911SJimmy Brisson	TRNG_SUPPORT \
1357ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1358ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1359327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1360327131c4SLeonardo Sandoval	USE_DEBUGFS \
1361327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1362327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1363327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1364327131c4SLeonardo Sandoval	USE_ROMLIB \
1365327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1366327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
136742d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
136842d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1369327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1370327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1371327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1372327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
137300e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1374327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1375327131c4SLeonardo Sandoval	USE_SP804_TIMER \
137612cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1377ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
13784e04478aSChris Kay	ENABLE_FEAT_SB \
13797d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
13805357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
13815357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1382396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
1383744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1384813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1385d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
13868fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1387cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
138868120783SChris Kay	ENABLE_MPMM \
138968120783SChris Kay	ENABLE_MPMM_FCONF \
1390f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
1391f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
13926a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
13936a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
13946a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
13956a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
13966a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1397d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1398062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1399062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1400062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1401062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1402688ab57bSMark Brown	ENABLE_FEAT_GCS \
14034d0b6632SMaksims Svecovs	ENABLE_FEAT_MTE_PERM \
14046a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1405781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1406781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
140704c7303bSOkash Khawaja	CONDITIONAL_CMO \
14080ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1409a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1410890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
1411327131c4SLeonardo Sandoval)))
14122fae4b1eSJeenu Viswambharan
14131f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14141f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1415c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14161f461979SJustin Chadwell
14174c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14184c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14194c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1420cf2c8a33SAntonio Nino Diazelse
142168450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
142268450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
142368450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
142468450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14254c117f6cSSandrine Bailleux	endif
1426c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
142773c99d4eSJuan Castillo
1428209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1429209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1430209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1431209a60ccSSoby Mathewendif
1432209a60ccSSoby Mathew
1433c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1434c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1435c2ad38ceSVarun Wadekarendif
1436c2ad38ceSVarun Wadekar
1437ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1438ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1439c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1440ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1441ce2b1ec6SManish Pandey	FIP_DEPS += sp
144207c44475SManish Pandey	CRT_DEPS += sp
1443ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1444ce2b1ec6SManish Pandeyelse
1445c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1446c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1447c33ff198SOlivier Deprez	endif
1448c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1449c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1450ce2b1ec6SManish Pandey
145173c99d4eSJuan Castillo################################################################################
145273c99d4eSJuan Castillo# Build targets
145373c99d4eSJuan Castillo################################################################################
145473c99d4eSJuan Castillo
145590aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
145673c99d4eSJuan Castillo.SUFFIXES:
145773c99d4eSJuan Castillo
145873c99d4eSJuan Castilloall: msg_start
145973c99d4eSJuan Castillo
146073c99d4eSJuan Castillomsg_start:
146173c99d4eSJuan Castillo	@echo "Building ${PLAT}"
146273c99d4eSJuan Castillo
14637a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1464d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1465c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1466c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1467c2ad38ceSVarun Wadekarelse
1468bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
14697a24cba5SSoby Mathewendif
1470c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
14717a24cba5SSoby Mathew
14725accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
147361f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
14745fee0287SRoberto Vargas
147573c99d4eSJuan Castillo# Expand build macros for the different images
147673c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1477b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1478434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1479c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
148073c99d4eSJuan Castillo
148173c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1482c5e1da83SJayanth Dodderi Chidanand
148342d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1484c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1485c9b31ae8SRoberto Vargasendif
1486c9b31ae8SRoberto Vargas
1487eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1488eb1acfb6SChris Kay
148933950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1490434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1491c5e1da83SJayanth Dodderi Chidanand
1492c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
149373c99d4eSJuan Castillo
14944d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
149533950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1496c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
14974d045d0eSMasahiro Yamada
149873c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
149973c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
150026d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
150126d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1502c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1503c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1504434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1505c6ba9b45SSumit Gargelse
150633950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1507434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1508c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1509c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
151073c99d4eSJuan Castillo
151170d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1512c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
151370d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
151473c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
151526d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
151626d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15179cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15189cd15239SMasahiro Yamada
1519c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1520434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1521c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1522c6ba9b45SSumit Gargelse
1523434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
152433950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1525c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1526c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
152773c99d4eSJuan Castillo
15285b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15295b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15305b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15315b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15325b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15335b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15345b18de09SZelalem Aweke
15355b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15365b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1537c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15385b18de09SZelalem Aweke
153973c99d4eSJuan Castillo# Add the BL33 image if required by the platform
154073c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
154133950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1542c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1543db6071c9SJuan Castillo
15449003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
154533950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1546434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1547c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15489003fa0bSYatharth Kochar
154903b397a8SNishanth Menon# Expand build macros for the different images
155003b397a8SNishanth Menonifeq (${NEED_FDT},yes)
155103b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1552c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
155303b397a8SNishanth Menon
1554ce2b1ec6SManish Pandey# Add Secure Partition packages
1555ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1556ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk : ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
155720629b31SKarl Meakin	${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1558822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1559ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1560ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1561ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1562c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1563ce2b1ec6SManish Pandey
156436eaaf37SIan Spraylocate-checkpatch:
156536eaaf37SIan Sprayifndef CHECKPATCH
156666079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
156736eaaf37SIan Sprayelse
156836eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
156966079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
157036eaaf37SIan Sprayendif
1571c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
157236eaaf37SIan Spray
15734f6ad66aSAchin Guptaclean:
15744f6ad66aSAchin Gupta	@echo "  CLEAN"
1575f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
157688a1cf1eSSami Mujawarifdef UNIX_MK
15772f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
157888a1cf1eSSami Mujawarelse
157988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
158088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
158188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1582c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
15836f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
158490aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
15855accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
15864f6ad66aSAchin Gupta
1587eaaeece2SJames Morrisseyrealclean distclean:
1588eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1589f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1590f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
159188a1cf1eSSami Mujawarifdef UNIX_MK
15922f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
159388a1cf1eSSami Mujawarelse
159488a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
159588a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
159688a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1597c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1598e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
159990aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
16005accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16014f6ad66aSAchin Gupta
160236eaaf37SIan Spraycheckcodebase:		locate-checkpatch
160336eaaf37SIan Spray	@echo "  CHECKING STYLE"
160436eaaf37SIan Spray	@if test -d .git ; then						\
16051ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16061a41e8c1SDan Handley		while read GIT_FILE ;					\
16071a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16081a41e8c1SDan Handley		done ;							\
160936eaaf37SIan Spray	else								\
16101a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16111a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16121a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
161361f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16141a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16151ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16161a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
161736eaaf37SIan Spray	fi
161836eaaf37SIan Spray
161936eaaf37SIan Spraycheckpatch:		locate-checkpatch
162036eaaf37SIan Spray	@echo "  CHECKING STYLE"
162102a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
162202a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
162302a76d5fSYann Gautier	fi
162451d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
162577a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
162677a0a7f1SYann Gautier	do								\
162751d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
162851d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
162902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
163002a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
163151d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
163202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
163302a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
163451d28937SAntonio Nino Diaz	done
163536eaaf37SIan Spray
163673c99d4eSJuan Castillocerttool: ${CRTTOOL}
163773c99d4eSJuan Castillo
1638a9812206SPali Rohár${CRTTOOL}: FORCE
1639598b166bSLionel 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
1640f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16416f971622SJuan Castillo	@echo "Built $@ successfully"
1642f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16436f971622SJuan Castillo
16446f971622SJuan Castilloifneq (${GENERATE_COT},0)
164573c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16466f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1647f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16486f971622SJuan Castillo	@echo "Built $@ successfully"
16496f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1650f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1651c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
165227713fb4SSoby Mathew
165373c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
16544727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1655819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1656819281eeSdp-arm	${Q}${FIPTOOL} info $@
1657f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
16582f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1659f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1660f58ad36fSHarry Liebel
16610191262dSYatharth Kocharifneq (${GENERATE_COT},0)
16620191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
16630191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1664052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16650191262dSYatharth Kochar	@echo "Built $@ successfully"
16660191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1667052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
1668c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
16690191262dSYatharth Kochar
16700191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
16714727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1672819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1673819281eeSdp-arm	${Q}${FIPTOOL} info $@
1674052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16750191262dSYatharth Kochar	@echo "Built $@ successfully"
1676052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
16770191262dSYatharth Kochar
167873c99d4eSJuan Castillofiptool: ${FIPTOOL}
167973c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
16800191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
168173c99d4eSJuan Castillo
1682a9812206SPali Rohár${FIPTOOL}: FORCE
168388a1cf1eSSami Mujawarifdef UNIX_MK
1684598b166bSLionel Debieve	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
168588a1cf1eSSami Mujawarelse
168688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
168788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
168888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1689c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1690f58ad36fSHarry Liebel
1691a9812206SPali Rohárromlib.bin: libraries FORCE
1692bbb24f61SJohn 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
16935accce5bSRoberto Vargas
1694cfe83910SLouis Mayencourtmemmap: all
1695af5b49e9SHarrison Mutaiifdef UNIX_MK
1696af5b49e9SHarrison Mutai	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1697af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1698af5b49e9SHarrison Mutaielse
1699af5b49e9SHarrison Mutai	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1700af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1701af5b49e9SHarrison Mutaiendif
1702cfe83910SLouis Mayencourt
17036de32378SMadhukar Pappireddydoc:
17046de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
17056de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
17066de32378SMadhukar Pappireddy
170790aa901fSSumit Gargenctool: ${ENCTOOL}
170890aa901fSSumit Garg
1709a9812206SPali Rohár${ENCTOOL}: FORCE
1710598b166bSLionel Debieve	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
171190aa901fSSumit Garg	@${ECHO_BLANK_LINE}
171290aa901fSSumit Garg	@echo "Built $@ successfully"
171390aa901fSSumit Garg	@${ECHO_BLANK_LINE}
171490aa901fSSumit Garg
171535fab8c9SJoakim Bechcscope:
171635fab8c9SJoakim Bech	@echo "  CSCOPE"
171735fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
171835fab8c9SJoakim Bech	${Q}cscope -b -q -k
171935fab8c9SJoakim Bech
172072ee3314SRyan Harkinhelp:
17217c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
172272ee3314SRyan Harkin	@echo ""
172372ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
172408c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
172572ee3314SRyan Harkin	@echo ""
17267c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
17277c23126cSJohn Tsichritzis	@echo ""
17281b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
17291b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
17301b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
17311b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
17321b578596SSandrine Bailleux	@echo ""
173372ee3314SRyan Harkin	@echo "Supported Targets:"
17341b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
173536eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
17368aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
17379003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1738d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
17399d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17409d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
174173c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17421b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
17430191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
174436eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
174536eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
174636eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
174772ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
174835fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
174972ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
17506f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
175190aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1752f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1753ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
175426010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
175538c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1756cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
17576de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
175872ee3314SRyan Harkin	@echo ""
17591b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
176072ee3314SRyan Harkin	@echo ""
176172ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
176272ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1763a9812206SPali Rohár
1764a9812206SPali Rohár.PHONY: FORCE
1765a9812206SPali RohárFORCE:;
1766