xref: /rk3399_ARM-atf/Makefile (revision 1b2fb6adb53de652d3fe69984731a62da122e0da)
14f6ad66aSAchin Gupta#
20a33adc0SGovindraj Raja# Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta#
482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta#
64f6ad66aSAchin Gupta
7e35c4045SJeenu Viswambharan#
8aaa3e722SJuan Castillo# Trusted Firmware Version
9aaa3e722SJuan Castillo#
101a0f1121SSoby MathewVERSION_MAJOR			:= 2
11669e2b15SManish V BadarkheVERSION_MINOR			:= 11
12c25d1ccfSYann Gautier# VERSION_PATCH is only used for LTS releases
13c25d1ccfSYann GautierVERSION_PATCH			:= 0
14055ebecaSYann GautierVERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15aaa3e722SJuan Castillo
1688154678SJuan Castillo# Default goal is build all images
1788154678SJuan Castillo.DEFAULT_GOAL			:= all
1888154678SJuan Castillo
1972fc70edSDouglas Raillard# Avoid any implicit propagation of command line variable definitions to
2072fc70edSDouglas Raillard# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
2172fc70edSDouglas Raillard# usage. Other command line options like "-s" are still propagated as usual.
2272fc70edSDouglas RaillardMAKEOVERRIDES =
2372fc70edSDouglas Raillard
24231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := make_helpers/
25231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
27f4dd18c2SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}build-rules.mk
287c4e1eeaSChris Kayinclude ${MAKE_HELPERS_DIRECTORY}common.mk
2973c99d4eSJuan Castillo
3073c99d4eSJuan Castillo################################################################################
312fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
3273c99d4eSJuan Castillo################################################################################
33e35c4045SJeenu Viswambharan
342fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
35*1b2fb6adSAndrey Skvortsovinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36*1b2fb6adSAndrey Skvortsov
37*1b2fb6adSAndrey Skvortsov# To be able to set platform specific defaults
38*1b2fb6adSAndrey Skvortsovifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39*1b2fb6adSAndrey Skvortsovinclude ${PLAT_DEFAULTS_MAKEFILE_FULL}
40*1b2fb6adSAndrey Skvortsovendif
41872be88aSdp-arm
42cc277de8SChris Kay################################################################################
43cc277de8SChris Kay# Configure the toolchains used to build TF-A and its tools
44cc277de8SChris Kay################################################################################
45cc277de8SChris Kay
46291e7182SChris Kay#
47291e7182SChris Kay# The clean and check targets do not behave correctly if the user's environment
48291e7182SChris Kay# does not appropriately configure a toolchain. While we try to find a permanent
49291e7182SChris Kay# solution to this, do not try to detect any toolchains if we are building
50291e7182SChris Kay# exclusively with targets which do not use any toolchain tools.
51291e7182SChris Kay#
52291e7182SChris Kay
53291e7182SChris Kayifeq ($(filter-out check% %clean doc %tool,$(or $(MAKECMDGOALS),all)),)
54291e7182SChris Kay        toolchains :=
55291e7182SChris Kayendif
56291e7182SChris Kay
57cc277de8SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}toolchain.mk
58cc277de8SChris Kay
59cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
60cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
612fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
6273c99d4eSJuan Castillo
6373c99d4eSJuan Castillo################################################################################
6473c99d4eSJuan Castillo# Checkpatch script options
6573c99d4eSJuan Castillo################################################################################
6673c99d4eSJuan Castillo
67f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
68f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
694501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
704501843fSGilad Ben-Yossef					include/drivers/arm,		\
714501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
72f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
731a41e8c1SDan Handley					include/lib/libfdt		\
7461f72a34SRoberto Vargas					include/lib/libc,		\
75f0b489c1SDan Handley					$(wildcard include/lib/*)))
76f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
774501843fSGilad Ben-Yossef					include/lib			\
784501843fSGilad Ben-Yossef					include/drivers,		\
79f0b489c1SDan Handley					$(wildcard include/*)))
80f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
81d801fbb0Sdp-arm					lib/compiler-rt			\
8255cdcf75SAntonio Nino Diaz					lib/libfdt%			\
8361f72a34SRoberto Vargas					lib/libc,			\
84a194255dSDaniel Boulby					lib/zlib			\
85f0b489c1SDan Handley					$(wildcard lib/*)))
86f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
87f0b489c1SDan Handley					lib				\
88f0b489c1SDan Handley					include				\
89f0b489c1SDan Handley					docs				\
901ef35512SPaul Beesley					%.rst,				\
91f0b489c1SDan Handley					$(wildcard *)))
92f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
93f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
94f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
954501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
964501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
974501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
9836eaaf37SIan Spray
9973c99d4eSJuan Castillo################################################################################
10073c99d4eSJuan Castillo# Process build options
10173c99d4eSJuan Castillo################################################################################
10273c99d4eSJuan Castillo
1037c4e1eeaSChris Kayifeq ($(verbose),)
10436eaaf37SIan Spray	CHECKCODE_ARGS	+=	--no-summary --terse
1054f6ad66aSAchin Guptaendif
106ee1ba6d4SAndre Przywara
10773c99d4eSJuan Castillo################################################################################
108c5e1da83SJayanth Dodderi Chidanand# Auxiliary tools (fiptool, cert_create, etc)
109c5e1da83SJayanth Dodderi Chidanand################################################################################
110c5e1da83SJayanth Dodderi Chidanand
111c5e1da83SJayanth Dodderi Chidanand# Variables for use with Certificate Generation Tool
112c5e1da83SJayanth Dodderi ChidanandCRTTOOLPATH		?=	tools/cert_create
113c5e1da83SJayanth Dodderi ChidanandCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
114c5e1da83SJayanth Dodderi Chidanand
115c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Encryption Tool
116c5e1da83SJayanth Dodderi ChidanandENCTOOLPATH		?=	tools/encrypt_fw
117c5e1da83SJayanth Dodderi ChidanandENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
118c5e1da83SJayanth Dodderi Chidanand
119c5e1da83SJayanth Dodderi Chidanand# Variables for use with Firmware Image Package
120c5e1da83SJayanth Dodderi ChidanandFIPTOOLPATH		?=	tools/fiptool
121c5e1da83SJayanth Dodderi ChidanandFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
122c5e1da83SJayanth Dodderi Chidanand
123c5e1da83SJayanth Dodderi Chidanand# Variables for use with sptool
124c5e1da83SJayanth Dodderi ChidanandSPTOOLPATH		?=	tools/sptool
125c5e1da83SJayanth Dodderi ChidanandSPTOOL			?=	${SPTOOLPATH}/sptool.py
126c5e1da83SJayanth Dodderi ChidanandSP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
12720629b31SKarl MeakinSP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
128c5e1da83SJayanth Dodderi Chidanand
129c5e1da83SJayanth Dodderi Chidanand# Variables for use with ROMLIB
130c5e1da83SJayanth Dodderi ChidanandROMLIBPATH		?=	lib/romlib
131c5e1da83SJayanth Dodderi Chidanand
132c5e1da83SJayanth Dodderi Chidanand# Variable for use with Python
133c5e1da83SJayanth Dodderi ChidanandPYTHON			?=	python3
134c5e1da83SJayanth Dodderi Chidanand
135c5e1da83SJayanth Dodderi Chidanand# Variables for use with documentation build using Sphinx tool
136c5e1da83SJayanth Dodderi ChidanandDOCS_PATH		?=	docs
137c5e1da83SJayanth Dodderi Chidanand
138c5e1da83SJayanth Dodderi Chidanand################################################################################
139c5e1da83SJayanth Dodderi Chidanand# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
140c5e1da83SJayanth Dodderi Chidanand################################################################################
14126e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
14226e63c44SEtienne Carriere	target32-directive	= 	-target arm-none-eabi
143d4089fb8SGovindraj Raja# Will set march-directive from platform configuration
14426e63c44SEtienne Carriereelse
14526e63c44SEtienne Carriere	target32-directive	= 	-target armv8a-none-eabi
146c5e1da83SJayanth Dodderi Chidanandendif #(ARM_ARCH_MAJOR)
147c5e1da83SJayanth Dodderi Chidanand
148c5e1da83SJayanth Dodderi Chidanand################################################################################
149c5e1da83SJayanth Dodderi Chidanand# Get Architecture Feature Modifiers
150c5e1da83SJayanth Dodderi Chidanand################################################################################
151c5e1da83SJayanth Dodderi Chidanandarch-features		=	${ARM_ARCH_FEATURE}
152c5e1da83SJayanth Dodderi Chidanand
1538620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1548620bd0bSChris Kay	ifeq ($($(ARCH)-cc-id),arm-clang)
1557794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
1567794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
157c8a992fdSorigin	else
1587794d6c8SGovindraj Raja		TF_CFLAGS_aarch32	=	$(target32-directive)
1597794d6c8SGovindraj Raja		TF_CFLAGS_aarch64	:=	-target aarch64-elf
160641f16e7SAmbroise Vincent	endif
161c8a992fdSorigin
1628620bd0bSChris Kayelse ifeq ($($(ARCH)-cc-id),gnu-gcc)
163edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
164edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
165fa402f38SChris Kay		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
166edbce9aaSzelalem-aweke	endif
167c5e1da83SJayanth Dodderi Chidanandendif #(clang)
168d5461857Sdp-arm
16932b209bfSAhmad Fatoum# Process Debug flag
17032b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
17132b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
17232b209bfSAhmad Fatoum	BUILD_TYPE	:=	debug
1734466cf82SDaniel Boulby	TF_CFLAGS	+=	-g -gdwarf-4
1744466cf82SDaniel Boulby	ASFLAGS		+=	-g -Wa,-gdwarf-4
17532b209bfSAhmad Fatoum
17632b209bfSAhmad Fatoum	# Use LOG_LEVEL_INFO by default for debug builds
17732b209bfSAhmad Fatoum	LOG_LEVEL	:=	40
17832b209bfSAhmad Fatoumelse
17932b209bfSAhmad Fatoum	BUILD_TYPE	:=	release
18032b209bfSAhmad Fatoum	# Use LOG_LEVEL_NOTICE by default for release builds
18132b209bfSAhmad Fatoum	LOG_LEVEL	:=	20
182c5e1da83SJayanth Dodderi Chidanandendif #(Debug)
18332b209bfSAhmad Fatoum
184f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
185f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
186f1de4c8fSPeiyuan Song	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
187f1de4c8fSPeiyuan Songendif
188dddf4283Slaurenw-armVERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
189f1de4c8fSPeiyuan Song
1908fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
1918fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-marm
1928fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
1938fd9d4d5SAntonio Nino Diaz	TF_CFLAGS_aarch32	+=	-mthumb
1948fd9d4d5SAntonio Nino Diazelse
1958fd9d4d5SAntonio Nino Diaz        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
196c5e1da83SJayanth Dodderi Chidanandendif #(AARCH32_INSTRUCTION_SET)
1978fd9d4d5SAntonio Nino Diaz
198a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
199d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
2009d29c227SSoby Mathew
201c5e1da83SJayanth Dodderi Chidanand##############################################################################
202c5e1da83SJayanth Dodderi Chidanand# WARNINGS Configuration
203c5e1da83SJayanth Dodderi Chidanand###############################################################################
2049ab81b5eSJustin Chadwell# General warnings
2059ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
206b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
207d75a9ecdSBoyan Karatotev				-Wredundant-decls
208d75a9ecdSBoyan Karatotev# stricter warnings
209d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wextra -Wno-trigraphs
210d75a9ecdSBoyan Karatotev# too verbose for generic build
211d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-missing-field-initializers \
212d75a9ecdSBoyan Karatotev				-Wno-type-limits -Wno-sign-compare \
213d75a9ecdSBoyan Karatotev# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
214d75a9ecdSBoyan KaratotevWARNINGS		+=	-Wno-unused-parameter
2159ab81b5eSJustin Chadwell
2169ab81b5eSJustin Chadwell# Additional warnings
217d75a9ecdSBoyan Karatotev# Level 1 - infrequent warnings we should have none of
218d75a9ecdSBoyan Karatotev# full -Wextra
219d75a9ecdSBoyan KaratotevWARNING1 += -Wsign-compare
220d75a9ecdSBoyan KaratotevWARNING1 += -Wtype-limits
221d75a9ecdSBoyan KaratotevWARNING1 += -Wmissing-field-initializers
222e7c645b5SYann Gautier
223d75a9ecdSBoyan Karatotev# Level 2 - problematic warnings that we want
224d75a9ecdSBoyan Karatotev# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
225d75a9ecdSBoyan Karatotev# TODO: disable just for them and move into default build
226d75a9ecdSBoyan KaratotevWARNING2 += -Wold-style-definition
227d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-prototypes
228d75a9ecdSBoyan KaratotevWARNING2 += -Wmissing-format-attribute
229d75a9ecdSBoyan Karatotev# TF-A aims to comply with this eventually. Effort too large at present
230d75a9ecdSBoyan KaratotevWARNING2 += -Wundef
231d141e638SBoyan Karatotev# currently very involved and many platforms set this off
232d141e638SBoyan KaratotevWARNING2 += -Wunused-const-variable=2
233e7c645b5SYann Gautier
234d75a9ecdSBoyan Karatotev# Level 3 - very pedantic, frequently ignored
235e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
236d75a9ecdSBoyan KaratotevWARNING3 += -Waggregate-return
237d75a9ecdSBoyan KaratotevWARNING3 += -Wnested-externs
238d75a9ecdSBoyan KaratotevWARNING3 += -Wcast-align
239e7c645b5SYann GautierWARNING3 += -Wcast-qual
240e7c645b5SYann GautierWARNING3 += -Wconversion
241e7c645b5SYann GautierWARNING3 += -Wpacked
242e7c645b5SYann GautierWARNING3 += -Wpointer-arith
243e7c645b5SYann GautierWARNING3 += -Wswitch-default
244e7c645b5SYann Gautier
245d75a9ecdSBoyan Karatotev# Setting W is quite verbose and most warnings will be pre-existing issues
246d75a9ecdSBoyan Karatotev# outside of the contributor's control. Don't fail the build on them so warnings
247d75a9ecdSBoyan Karatotev# can be seen and hopefully addressed
248d75a9ecdSBoyan Karatotevifdef W
249d75a9ecdSBoyan Karatotev	ifneq (${W},0)
250d75a9ecdSBoyan Karatotev		E	 ?= 0
251d75a9ecdSBoyan Karatotev	endif
252d75a9ecdSBoyan Karatotevendif
253d75a9ecdSBoyan Karatotev
254e7c645b5SYann Gautierifeq (${W},1)
2559ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1)
256e7c645b5SYann Gautierelse ifeq (${W},2)
2579ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2)
258e7c645b5SYann Gautierelse ifeq (${W},3)
2599ab81b5eSJustin Chadwell	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
260c5e1da83SJayanth Dodderi Chidanandendif #(W)
261e7c645b5SYann Gautier
2629ab81b5eSJustin Chadwell# Compiler specific warnings
2638620bd0bSChris Kayifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
26493c690ebSJustin Chadwell# not using clang
265d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
266d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
267d7b4cd41SJustin Chadwell				-Wlogical-op
268dea23e24SGovindraj Raja
269dea23e24SGovindraj Raja# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
270dea23e24SGovindraj RajaTF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
271dea23e24SGovindraj Raja
272538516f5SBipin Raviifeq ($(HARDEN_SLS), 1)
273538516f5SBipin Ravi        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
274538516f5SBipin Raviendif
275538516f5SBipin Ravi
27693c690ebSJustin Chadwellelse
27793c690ebSJustin Chadwell# using clang
278d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
279d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
280c5e1da83SJayanth Dodderi Chidanandendif #(Clang Warning)
28100296576SAmbroise Vincent
2826336b07aSYann Gautierifneq (${E},0)
2836336b07aSYann Gautier	ERRORS := -Werror
284c5e1da83SJayanth Dodderi Chidanandendif #(E)
2856336b07aSYann Gautier
286c5e1da83SJayanth Dodderi Chidanand################################################################################
287c5e1da83SJayanth Dodderi Chidanand# Compiler and Linker Directives
288c5e1da83SJayanth Dodderi Chidanand################################################################################
289ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
2909ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
291d4089fb8SGovindraj RajaASFLAGS			+=	$(CPPFLAGS)                 			\
292d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
29359de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
294ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
295ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
296ebd6efaeSSamuel Holland				-Os -std=gnu99
29773c99d4eSJuan Castillo
2981f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
2991f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
300c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},on)
301c5e1da83SJayanth Dodderi Chidanand
3021f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
3031f461979SJustin Chadwell	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
3041f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
305c5e1da83SJayanth Dodderi Chidanandendif #(${SANITIZE_UB},trap)
3061f461979SJustin Chadwell
307291e7182SChris KayGCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
308f7ec31dbSdavid cunado
3091f49db5fSMarco FelschTF_LDFLAGS		+=	-z noexecstack
3101f49db5fSMarco Felsch
311641f16e7SAmbroise Vincent# LD = armlink
3128620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
313c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
314c2ad38ceSVarun Wadekar	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
315edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
316641f16e7SAmbroise Vincent
317641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
3188620bd0bSChris Kayelse ifeq ($($(ARCH)-ld-id),gnu-gcc)
319edbce9aaSzelalem-aweke	# Pass ld options with Wl or Xlinker switches
32086e489c1SChris Kay	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
321edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
322edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	-Wl,--gc-sections
323ac98b82aSChris Kay
324ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
325ac98b82aSChris Kay	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
326304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	-Wl,--build-id=none
327ac98b82aSChris Kay
328edbce9aaSzelalem-aweke	ifeq ($(ENABLE_LTO),1)
329edbce9aaSzelalem-aweke		ifeq (${ARCH},aarch64)
330edbce9aaSzelalem-aweke			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
33131f80efeSAndrey Skvortsov			TF_LDFLAGS      +=	-flto-partition=one
332edbce9aaSzelalem-aweke		endif
333c5e1da83SJayanth Dodderi Chidanand	endif #(ENABLE_LTO)
334c5e1da83SJayanth Dodderi Chidanand
335edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
336edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
337cfe6767fSYann Gautier	ifeq (${ARCH},aarch64)
338edbce9aaSzelalem-aweke		ifneq (${ERRATA_A53_843419},1)
339edbce9aaSzelalem-aweke			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
340edbce9aaSzelalem-aweke		endif
341cfe6767fSYann Gautier	endif
342edbce9aaSzelalem-aweke	TF_LDFLAGS		+= 	-nostdlib
343edbce9aaSzelalem-aweke	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
344641f16e7SAmbroise Vincent
345641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
346c2ad38ceSVarun Wadekarelse
3471f49db5fSMarco Felsch# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
3481f49db5fSMarco Felsch# are not loaded by a elf loader.
3491f49db5fSMarco Felsch	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
350ebac6922SYabin Cui	TF_LDFLAGS		+=	-O1
351c2b8806fSDouglas Raillard	TF_LDFLAGS		+=	--gc-sections
352ac98b82aSChris Kay
353ac98b82aSChris Kay	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
354ac98b82aSChris Kay	TF_LDFLAGS		+=	-z max-page-size=4096
355304ad94bSAndrey Skvortsov	TF_LDFLAGS		+=	--build-id=none
356ac98b82aSChris Kay
357641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
358ebac6922SYabin Cui# therefore don't add those in that case.
359ebac6922SYabin Cui# ld.lld reports section type mismatch warnings,
360ebac6922SYabin Cui# therefore don't add --fatal-warnings to it.
3618620bd0bSChris Kay	ifneq ($($(ARCH)-ld-id),llvm-lld)
362ebac6922SYabin Cui		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
363edbce9aaSzelalem-aweke	endif
364c5e1da83SJayanth Dodderi Chidanand
365c5e1da83SJayanth Dodderi Chidanandendif #(LD = armlink)
36673c99d4eSJuan Castillo
36773c99d4eSJuan Castillo################################################################################
368f5211420SGovindraj Raja# Setup ARCH_MAJOR/MINOR before parsing arch_features.
369f5211420SGovindraj Raja################################################################################
370f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
3717d5fc98fSAlexeiFedorov	ARM_ARCH_MAJOR := 9
3727d5fc98fSAlexeiFedorov	ARM_ARCH_MINOR := 2
373f5211420SGovindraj Rajaendif
374f5211420SGovindraj Raja
375f5211420SGovindraj Raja################################################################################
37673c99d4eSJuan Castillo# Common sources and include directories
37773c99d4eSJuan Castillo################################################################################
378d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
37973c99d4eSJuan Castillo
380758ccb80SChris Kay# Allow overriding the timestamp, for example for reproducible builds, or to
381758ccb80SChris Kay# synchronize timestamps across multiple projects.
382758ccb80SChris Kay# This must be set to a C string (including quotes where applicable).
383758ccb80SChris KayBUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
384758ccb80SChris Kay
385758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
386758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
387758ccb80SChris KayDEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
388758ccb80SChris Kay
38973c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
3907f56e9a3SSoby Mathew				common/tf_log.c				\
3919d29c227SSoby Mathew				common/${ARCH}/debug.S			\
39291b48c9fSJulius Werner				drivers/console/multi_console.c		\
3939d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
3949d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
395c73686a1SBoyan Karatotev				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
396566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
3977f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
39875311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
3999d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
40061f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
401d7a6b0f8SRyan Harkin
4028620bd0bSChris Kayifeq ($($(ARCH)-cc-id),arm-clang)
4038422a840SAntonio Nino Diaz	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4048422a840SAntonio Nino Diazendif
4058422a840SAntonio Nino Diaz
4061f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4071f461979SJustin Chadwell	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
4081f461979SJustin Chadwellendif
4091f461979SJustin Chadwell
41001d237cbSYann GautierINCLUDES		+=	-Iinclude				\
411f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
41209d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
41309d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
41409d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
41509d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
41609d40e0eSAntonio Nino Diaz
417e03dcc8fSNishant SharmaDTC_FLAGS		+=	-I dts -O dtb
418e03dcc8fSNishant SharmaDTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
419e03dcc8fSNishant Sharma				-x assembler-with-cpp $(DEFINES)
420e03dcc8fSNishant Sharma
4219c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4229c6d1c50SAntonio Nino Diaz
42373c99d4eSJuan Castillo################################################################################
4243547270fSGovindraj Raja# Generic definitions
4253547270fSGovindraj Raja################################################################################
4263547270fSGovindraj Raja
4273547270fSGovindraj Rajaifeq (${BUILD_BASE},)
4283547270fSGovindraj Raja     BUILD_BASE		:=	./build
4293547270fSGovindraj Rajaendif
4303547270fSGovindraj RajaBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
4313547270fSGovindraj Raja
4323547270fSGovindraj RajaSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
4333547270fSGovindraj Raja
4343547270fSGovindraj Raja# Platforms providing their own TBB makefile may override this value
4353547270fSGovindraj RajaINCLUDE_TBBR_MK		:=	1
4363547270fSGovindraj Raja
4373547270fSGovindraj Raja################################################################################
4383547270fSGovindraj Raja# Include SPD Makefile if one has been specified
4393547270fSGovindraj Raja################################################################################
4403547270fSGovindraj Raja
4413547270fSGovindraj Rajaifneq (${SPD},none)
4423547270fSGovindraj Raja	ifeq (${ARCH},aarch32)
4433547270fSGovindraj Raja                $(error "Error: SPD is incompatible with AArch32.")
4443547270fSGovindraj Raja	endif
4453547270fSGovindraj Raja
4463547270fSGovindraj Raja	ifdef EL3_PAYLOAD_BASE
4473547270fSGovindraj Raja                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
4483547270fSGovindraj Raja                $(warning "The SPD and its BL32 companion will be present but \
4493547270fSGovindraj Raja                ignored.")
4503547270fSGovindraj Raja	endif
4513547270fSGovindraj Raja
4523547270fSGovindraj Raja	ifeq (${SPD},spmd)
4533547270fSGovindraj Raja	# SPMD is located in std_svc directory
4543547270fSGovindraj Raja		SPD_DIR := std_svc
4553547270fSGovindraj Raja
4563547270fSGovindraj Raja		ifeq ($(SPMD_SPM_AT_SEL2),1)
4573547270fSGovindraj Raja			CTX_INCLUDE_EL2_REGS := 1
4583547270fSGovindraj Raja			ifeq ($(SPMC_AT_EL3),1)
4593547270fSGovindraj Raja                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
4603547270fSGovindraj Raja			endif
46159bdcc58SMadhukar Pappireddy			ifeq ($(CTX_INCLUDE_SVE_REGS),1)
46259bdcc58SMadhukar Pappireddy                                $(error SVE context management not needed with Hafnium SPMC.)
46359bdcc58SMadhukar Pappireddy			endif
4643547270fSGovindraj Raja		endif
4653547270fSGovindraj Raja
4663547270fSGovindraj Raja		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
4673547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
4683547270fSGovindraj Raja		endif
4693547270fSGovindraj Raja
4700686a01bSArunachalam Ganapathy		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
4710686a01bSArunachalam Ganapathy			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
4720686a01bSArunachalam Ganapathy		endif
4730686a01bSArunachalam Ganapathy
4743547270fSGovindraj Raja		ifeq ($(TS_SP_FW_CONFIG),1)
4753547270fSGovindraj Raja			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
4763547270fSGovindraj Raja		endif
4773547270fSGovindraj Raja
4783547270fSGovindraj Raja		ifneq ($(ARM_BL2_SP_LIST_DTS),)
4793547270fSGovindraj Raja		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
4803547270fSGovindraj Raja		endif
4813547270fSGovindraj Raja
4823547270fSGovindraj Raja		ifneq ($(SP_LAYOUT_FILE),)
4833547270fSGovindraj Raja		BL2_ENABLE_SP_LOAD := 1
4843547270fSGovindraj Raja		endif
485c189adbdSGovindraj Raja
486c189adbdSGovindraj Raja		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
487c189adbdSGovindraj Raja			ifneq ($(SPMC_AT_EL3),1)
488c189adbdSGovindraj Raja			$(error SEL0 SP cannot be enabled without SPMC at EL3)
489c189adbdSGovindraj Raja			endif
490c189adbdSGovindraj Raja		endif
4913547270fSGovindraj Raja	else
4923547270fSGovindraj Raja		# All other SPDs in spd directory
4933547270fSGovindraj Raja		SPD_DIR := spd
4943547270fSGovindraj Raja	endif #(SPD)
4953547270fSGovindraj Raja
4963547270fSGovindraj Raja	# We expect to locate an spd.mk under the specified SPD directory
4973547270fSGovindraj Raja	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
4983547270fSGovindraj Raja
4993547270fSGovindraj Raja	ifeq (${SPD_MAKE},)
5003547270fSGovindraj Raja                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
5013547270fSGovindraj Raja	endif
5023547270fSGovindraj Raja        $(info Including ${SPD_MAKE})
5033547270fSGovindraj Raja        include ${SPD_MAKE}
5043547270fSGovindraj Raja
5053547270fSGovindraj Raja	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
5063547270fSGovindraj Raja	# Makefile would set NEED_BL32 to "yes". In this case, the build system
5073547270fSGovindraj Raja	# supports two mutually exclusive options:
5083547270fSGovindraj Raja	# * BL32 is built from source: then BL32_SOURCES must contain the list
5093547270fSGovindraj Raja	#   of source files to build BL32
5103547270fSGovindraj Raja	# * BL32 is a prebuilt binary: then BL32 must point to the image file
5113547270fSGovindraj Raja	#   that will be included in the FIP
5123547270fSGovindraj Raja	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
5133547270fSGovindraj Raja	# over the sources.
5143547270fSGovindraj Rajaendif #(SPD=none)
5153547270fSGovindraj Raja
5163547270fSGovindraj Rajaifeq (${ENABLE_SPMD_LP}, 1)
5173547270fSGovindraj Rajaifneq (${SPD},spmd)
5183547270fSGovindraj Raja        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
5193547270fSGovindraj Rajaendif
5203547270fSGovindraj Rajaifeq ($(SPMC_AT_EL3),1)
5213547270fSGovindraj Raja        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
5223547270fSGovindraj Rajaendif
5233547270fSGovindraj Rajaendif
5243547270fSGovindraj Raja
5253547270fSGovindraj Raja################################################################################
526f5211420SGovindraj Raja# Process BRANCH_PROTECTION value and set
527f5211420SGovindraj Raja# Pointer Authentication and Branch Target Identification flags
528f5211420SGovindraj Raja################################################################################
529f5211420SGovindraj Rajaifeq (${BRANCH_PROTECTION},0)
530f5211420SGovindraj Raja	# Default value turns off all types of branch protection
531f5211420SGovindraj Raja	BP_OPTION := none
532f5211420SGovindraj Rajaelse ifneq (${ARCH},aarch64)
533f5211420SGovindraj Raja        $(error BRANCH_PROTECTION requires AArch64)
534f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},1)
535f5211420SGovindraj Raja	# Enables all types of branch protection features
536f5211420SGovindraj Raja	BP_OPTION := standard
537f5211420SGovindraj Raja	ENABLE_BTI := 1
538f5211420SGovindraj Raja	ENABLE_PAUTH := 1
539f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},2)
540f5211420SGovindraj Raja	# Return address signing to its standard level
541f5211420SGovindraj Raja	BP_OPTION := pac-ret
542f5211420SGovindraj Raja	ENABLE_PAUTH := 1
543f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},3)
544f5211420SGovindraj Raja	# Extend the signing to include leaf functions
545f5211420SGovindraj Raja	BP_OPTION := pac-ret+leaf
546f5211420SGovindraj Raja	ENABLE_PAUTH := 1
547f5211420SGovindraj Rajaelse ifeq (${BRANCH_PROTECTION},4)
548f5211420SGovindraj Raja	# Turn on branch target identification mechanism
549f5211420SGovindraj Raja	BP_OPTION := bti
550f5211420SGovindraj Raja	ENABLE_BTI := 1
551f5211420SGovindraj Rajaelse
552f5211420SGovindraj Raja        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
553f5211420SGovindraj Rajaendif #(BRANCH_PROTECTION)
554f5211420SGovindraj Raja
555f5211420SGovindraj Rajaifeq ($(ENABLE_PAUTH),1)
556f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
557f5211420SGovindraj Rajaendif
558f5211420SGovindraj Rajaifneq (${BP_OPTION},none)
559f5211420SGovindraj Raja	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
560f5211420SGovindraj Rajaendif #(BP_OPTION)
561f5211420SGovindraj Raja
562f5211420SGovindraj Raja# Pointer Authentication sources
563f5211420SGovindraj Rajaifeq (${ENABLE_PAUTH}, 1)
564f5211420SGovindraj Raja# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
565f5211420SGovindraj Raja# Pauth support. As it's not secure, it must be reimplemented for real platforms
566f5211420SGovindraj Raja	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
567f5211420SGovindraj Rajaendif
568f5211420SGovindraj Raja
5693547270fSGovindraj Raja################################################################################
5703547270fSGovindraj Raja# Include the platform specific Makefile after the SPD Makefile (the platform
5713547270fSGovindraj Raja# makefile may use all previous definitions in this file)
5723547270fSGovindraj Raja################################################################################
5733547270fSGovindraj Rajainclude ${PLAT_MAKEFILE_FULL}
5743547270fSGovindraj Raja
5753547270fSGovindraj Raja################################################################################
5763547270fSGovindraj Raja# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
5773547270fSGovindraj Raja# platform.
5783547270fSGovindraj Raja################################################################################
5793547270fSGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
5803547270fSGovindraj Raja
581f5211420SGovindraj Raja####################################################
582f5211420SGovindraj Raja# Enable required options for Memory Stack Tagging.
583f5211420SGovindraj Raja####################################################
584f5211420SGovindraj Raja
585f5211420SGovindraj Raja# Currently, these options are enabled only for clang and armclang compiler.
586f5211420SGovindraj Rajaifeq (${SUPPORT_STACK_MEMTAG},yes)
587f5211420SGovindraj Raja    ifdef mem_tag_arch_support
588f5211420SGovindraj Raja        # Check for armclang and clang compilers
5898620bd0bSChris Kay        ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
590f5211420SGovindraj Raja        # Add "memtag" architecture feature modifier if not specified
591f5211420SGovindraj Raja            ifeq ( ,$(findstring memtag,$(arch-features)))
592f5211420SGovindraj Raja                arch-features	:=	$(arch-features)+memtag
593f5211420SGovindraj Raja            endif	# memtag
5948620bd0bSChris Kay            ifeq ($($(ARCH)-cc-id),arm-clang)
595f5211420SGovindraj Raja                TF_CFLAGS	+=	-mmemtag-stack
5968620bd0bSChris Kay            else ifeq ($($(ARCH)-cc-id),llvm-clang)
597f5211420SGovindraj Raja                TF_CFLAGS	+=	-fsanitize=memtag
598f5211420SGovindraj Raja            endif	# armclang
599f5211420SGovindraj Raja        endif
600f5211420SGovindraj Raja    else
601f5211420SGovindraj Raja        $(error "Error: stack memory tagging is not supported for  \
602f5211420SGovindraj Raja        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
603f5211420SGovindraj Raja	endif #(mem_tag_arch_support)
604f5211420SGovindraj Rajaendif #(SUPPORT_STACK_MEMTAG)
605f5211420SGovindraj Raja
606f5211420SGovindraj Raja################################################################################
607f5211420SGovindraj Raja# RME dependent flags configuration, Enable optional features for RME.
608f5211420SGovindraj Raja################################################################################
609f5211420SGovindraj Raja# FEAT_RME
610f5211420SGovindraj Rajaifeq (${ENABLE_RME},1)
611d638029fSGovindraj Raja	# RME doesn't support BRBE
612d638029fSGovindraj Raja	ENABLE_BRBE_FOR_NS := 0
613d638029fSGovindraj Raja
614f5211420SGovindraj Raja	# RME doesn't support PIE
615f5211420SGovindraj Raja	ifneq (${ENABLE_PIE},0)
616f5211420SGovindraj Raja                $(error ENABLE_RME does not support PIE)
617f5211420SGovindraj Raja	endif
618f5211420SGovindraj Raja
619f5211420SGovindraj Raja	# RME doesn't support BRBE
620f5211420SGovindraj Raja	ifneq (${ENABLE_BRBE_FOR_NS},0)
621f5211420SGovindraj Raja                $(error ENABLE_RME does not support BRBE.)
622f5211420SGovindraj Raja	endif
623f5211420SGovindraj Raja
624f5211420SGovindraj Raja	# RME requires AARCH64
625f5211420SGovindraj Raja	ifneq (${ARCH},aarch64)
626f5211420SGovindraj Raja                $(error ENABLE_RME requires AArch64)
627f5211420SGovindraj Raja	endif
628f5211420SGovindraj Raja
629f5211420SGovindraj Raja	# RME requires el2 context to be saved for now.
630f5211420SGovindraj Raja	CTX_INCLUDE_EL2_REGS := 1
631f5211420SGovindraj Raja	CTX_INCLUDE_AARCH32_REGS := 0
632f5211420SGovindraj Raja	CTX_INCLUDE_PAUTH_REGS := 1
633f5211420SGovindraj Raja
634f5211420SGovindraj Raja	# RME enables CSV2_2 extension by default.
635f5211420SGovindraj Raja	ENABLE_FEAT_CSV2_2 = 1
636f5211420SGovindraj Rajaendif #(FEAT_RME)
637f5211420SGovindraj Raja
638f5211420SGovindraj Raja################################################################################
6395b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
6405b18de09SZelalem Aweke################################################################################
6415b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
6425b18de09SZelalem Aweke	ifneq (${ARCH},aarch64)
6435b18de09SZelalem Aweke                $(error ENABLE_RME requires AArch64)
6445b18de09SZelalem Aweke	endif
6451d63ae4dSMarc Bonnici	ifeq ($(SPMC_AT_EL3),1)
6461d63ae4dSMarc Bonnici                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
6471d63ae4dSMarc Bonnici	endif
648c5e1da83SJayanth Dodderi Chidanand
6494fba2e1fSBoyan Karatotev	ifneq (${SPD}, none)
6504fba2e1fSBoyan Karatotev		ifneq (${SPD}, spmd)
6514fba2e1fSBoyan Karatotev                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
6524fba2e1fSBoyan Karatotev		endif
6534fba2e1fSBoyan Karatotev	endif
6545b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
6555b18de09SZelalem Aweke$(warning "RME is an experimental feature")
6565b18de09SZelalem Awekeendif
6575b18de09SZelalem Aweke
6583547270fSGovindraj Rajaifeq (${CTX_INCLUDE_EL2_REGS}, 1)
6593547270fSGovindraj Raja	ifeq (${SPD},none)
6603547270fSGovindraj Raja		ifeq (${ENABLE_RME},0)
6613547270fSGovindraj Raja                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
6623547270fSGovindraj Raja                        or RME is enabled)
6633547270fSGovindraj Raja		endif
6643547270fSGovindraj Raja	endif
6653547270fSGovindraj Rajaendif
6660f21c547SJuan Castillo
6677794d6c8SGovindraj Raja################################################################################
6687794d6c8SGovindraj Raja# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
6697794d6c8SGovindraj Raja# up with appropriate march values for compiler.
6707794d6c8SGovindraj Raja################################################################################
6717794d6c8SGovindraj Rajainclude ${MAKE_HELPERS_DIRECTORY}march.mk
6727794d6c8SGovindraj Raja
6737794d6c8SGovindraj RajaTF_CFLAGS   +=	$(march-directive)
6747275ac2aSGovindraj RajaASFLAGS		+=	$(march-directive)
6757794d6c8SGovindraj Raja
67642d4d3baSArvind Ram Prakash# This internal flag is common option which is set to 1 for scenarios
67742d4d3baSArvind Ram Prakash# when the BL2 is running in EL3 level. This occurs in two scenarios -
67842d4d3baSArvind Ram Prakash# 4 world system running BL2 at EL3 and two world system without BL1 running
67942d4d3baSArvind Ram Prakash# BL2 in EL3
68042d4d3baSArvind Ram Prakash
68142d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2},1)
68242d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68342d4d3baSArvind Ram Prakash	ifeq (${ENABLE_RME},1)
684c5e1da83SJayanth Dodderi Chidanand                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
685c5e1da83SJayanth Dodderi Chidanand                supported at the moment.)
68642d4d3baSArvind Ram Prakash	endif
68742d4d3baSArvind Ram Prakashelse ifeq (${ENABLE_RME},1)
68842d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	1
68942d4d3baSArvind Ram Prakashelse
69042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	:=	0
69142d4d3baSArvind Ram Prakashendif
69242d4d3baSArvind Ram Prakash
693f87e54f7SManish Pandey# This internal flag is set to 1 when Firmware First handling of External aborts
694f87e54f7SManish Pandey# is required by lowe ELs. Currently only NS requires this support.
695f87e54f7SManish Pandeyifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
696f87e54f7SManish Pandey	FFH_SUPPORT := 1
697f87e54f7SManish Pandeyelse
698f87e54f7SManish Pandey	FFH_SUPPORT := 0
699f87e54f7SManish Pandeyendif
700f87e54f7SManish Pandey
70126e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
70226e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
70326e63c44SEtienne Carriereendif
70426e63c44SEtienne Carriere
7053bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
7063bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
7073bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
7088620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
7097b592418SSamuel Holland	TF_LDFLAGS	+=	-no-pie
7107b592418SSamuel Hollandendif
711c5e1da83SJayanth Dodderi Chidanandendif #(PIE_FOUND)
712320920c1SMasahiro Yamada
7138620bd0bSChris Kayifeq ($($(ARCH)-ld-id),gnu-gcc)
714320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
715320920c1SMasahiro Yamadaelse
716320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
717320920c1SMasahiro Yamadaendif
718320920c1SMasahiro Yamada
719320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
72042d4d3baSArvind Ram Prakash	ifeq ($(RESET_TO_BL2),1)
72169af7fcfSMasahiro Yamada		ifneq ($(BL2_IN_XIP_MEM),1)
722966660ecSChris Kay			BL2_CPPFLAGS	+=	-fpie
72369af7fcfSMasahiro Yamada			BL2_CFLAGS	+=	-fpie
72469af7fcfSMasahiro Yamada			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
725c5e1da83SJayanth Dodderi Chidanand		endif #(BL2_IN_XIP_MEM)
726c5e1da83SJayanth Dodderi Chidanand	endif #(RESET_TO_BL2)
727966660ecSChris Kay	BL31_CPPFLAGS	+=	-fpie
728320920c1SMasahiro Yamada	BL31_CFLAGS 	+=	-fpie
729320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
730966660ecSChris Kay
731966660ecSChris Kay	BL32_CPPFLAGS	+=	-fpie
732d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
733d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
734c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PIE)
7353bd17c0fSSoby Mathew
736007433d8SBoyan KaratotevBL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
737007433d8SBoyan KaratotevBL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
738007433d8SBoyan KaratotevBL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
739007433d8SBoyan Karatotev
7409cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
74142d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2),1)
7429cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL3
743d5e97a1dSMasahiro Yamadaelse
7449cefb4b1SMasahiro Yamada	BL2_CPPFLAGS += -DIMAGE_AT_EL1
745c5e1da83SJayanth Dodderi Chidanandendif #(RESET_TO_BL2)
746007433d8SBoyan Karatotev
747007433d8SBoyan Karatotevifeq (${ARCH},aarch64)
7489cefb4b1SMasahiro Yamada	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
7499cefb4b1SMasahiro Yamada	BL31_CPPFLAGS += -DIMAGE_AT_EL3
7509cefb4b1SMasahiro Yamada	BL32_CPPFLAGS += -DIMAGE_AT_EL1
751007433d8SBoyan Karatotevelse
752007433d8SBoyan Karatotev	BL32_CPPFLAGS += -DIMAGE_AT_EL3
753d5e97a1dSMasahiro Yamadaendif
754d5e97a1dSMasahiro Yamada
75554035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
75654035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
75754035fc4SSandrine Bailleux# This can be overridden by the platform.
75873c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
7594f6ad66aSAchin Gupta
760a4409008Sdp-arm################################################################################
761a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
762a4409008Sdp-arm################################################################################
763c5e1da83SJayanth Dodderi Chidanandifeq (${ARCH},aarch32)
764c5e1da83SJayanth Dodderi Chidanand        NEED_BL32 := yes
765c5e1da83SJayanth Dodderi Chidanand
766a4409008Sdp-arm        ifneq (${AARCH32_SP},none)
767a4409008Sdp-arm        # We expect to locate an sp.mk under the specified AARCH32_SP directory
768a4409008Sdp-arm		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
769a4409008Sdp-arm
770a4409008Sdp-arm                ifeq (${AARCH32_SP_MAKE},)
771a4409008Sdp-arm                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
772a4409008Sdp-arm                endif
773a4409008Sdp-arm                $(info Including ${AARCH32_SP_MAKE})
774a4409008Sdp-arm                include ${AARCH32_SP_MAKE}
775a4409008Sdp-arm        endif
776c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
7774f6ad66aSAchin Gupta
77873c99d4eSJuan Castillo################################################################################
77977f1f7a1SVarun Wadekar# Include libc if not overridden
78077f1f7a1SVarun Wadekar################################################################################
78177f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
78277f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
78377f1f7a1SVarun Wadekarendif
78477f1f7a1SVarun Wadekar
78577f1f7a1SVarun Wadekar################################################################################
786c5e1da83SJayanth Dodderi Chidanand# Check incompatible options and dependencies
787cf2c8a33SAntonio Nino Diaz################################################################################
788cf2c8a33SAntonio Nino Diaz
789c5e1da83SJayanth Dodderi Chidanand# USE_DEBUGFS experimental feature recommended only in debug builds
790c5e1da83SJayanth Dodderi Chidanandifeq (${USE_DEBUGFS},1)
791c5e1da83SJayanth Dodderi Chidanand        ifeq (${DEBUG},1)
792c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental feature is enabled.)
793c5e1da83SJayanth Dodderi Chidanand        else
794c5e1da83SJayanth Dodderi Chidanand                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
795c5e1da83SJayanth Dodderi Chidanand        endif
796c5e1da83SJayanth Dodderi Chidanandendif #(USE_DEBUGFS)
797c5e1da83SJayanth Dodderi Chidanand
798c5e1da83SJayanth Dodderi Chidanand# USE_SPINLOCK_CAS requires AArch64 build
799c5e1da83SJayanth Dodderi Chidanandifeq (${USE_SPINLOCK_CAS},1)
800c5e1da83SJayanth Dodderi Chidanand        ifneq (${ARCH},aarch64)
801c5e1da83SJayanth Dodderi Chidanand               $(error USE_SPINLOCK_CAS requires AArch64)
802c5e1da83SJayanth Dodderi Chidanand        endif
803c5e1da83SJayanth Dodderi Chidanandendif #(USE_SPINLOCK_CAS)
804c5e1da83SJayanth Dodderi Chidanand
805c5e1da83SJayanth Dodderi Chidanand# The cert_create tool cannot generate certificates individually, so we use the
806c5e1da83SJayanth Dodderi Chidanand# target 'certificates' to create them all
807c5e1da83SJayanth Dodderi Chidanandifneq (${GENERATE_COT},0)
808c5e1da83SJayanth Dodderi Chidanand        FIP_DEPS += certificates
809c5e1da83SJayanth Dodderi Chidanand        FWU_FIP_DEPS += fwu_certificates
810c5e1da83SJayanth Dodderi Chidanandendif
811c5e1da83SJayanth Dodderi Chidanand
812c5e1da83SJayanth Dodderi Chidanandifneq (${DECRYPTION_SUPPORT},none)
813c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -f ${FW_ENC_STATUS}
814c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -k ${ENC_KEY}
815c5e1da83SJayanth Dodderi Chidanand	ENC_ARGS += -n ${ENC_NONCE}
816c5e1da83SJayanth Dodderi Chidanand	FIP_DEPS += enctool
817c5e1da83SJayanth Dodderi Chidanand	FWU_FIP_DEPS += enctool
818c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
819c5e1da83SJayanth Dodderi Chidanand
820cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
82168450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
82268450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
82368450a6dSAntonio Nino Diaz		incompatible build options. EL3_PAYLOAD_BASE has priority.")
824cf2c8a33SAntonio Nino Diaz	endif
82576580f3dSQixiang Xu	ifneq (${GENERATE_COT},0)
826c5e1da83SJayanth Dodderi Chidanand                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
827c5e1da83SJayanth Dodderi Chidanand                build options.")
82876580f3dSQixiang Xu	endif
82976580f3dSQixiang Xu	ifneq (${TRUSTED_BOARD_BOOT},0)
830c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
831c5e1da83SJayanth Dodderi Chidanand                incompatible \ build options.")
83276580f3dSQixiang Xu	endif
833c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
834cf2c8a33SAntonio Nino Diaz
835cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
836cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
837cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
838cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
839cf2c8a33SAntonio Nino Diaz	endif
84068450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
84168450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
842c5e1da83SJayanth Dodderi Chidanand                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
843cf2c8a33SAntonio Nino Diaz	endif
844c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
845cf2c8a33SAntonio Nino Diaz
846d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
847d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
848d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
849d4593e47SJeenu Viswambharan        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
850d4593e47SJeenu Viswambharanendif
8511a0a3f06SYatharth Kochar
85242d4d3baSArvind Ram Prakash#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
85342d4d3baSArvind Ram Prakashifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
85442d4d3baSArvind Ram Prakash        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
8557d173fc5SJiafei Panendif
8567d173fc5SJiafei Pan
8579202d519SManish Pandey# RAS_EXTENSION is deprecated, provide alternate build options
85814c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
859c5e1da83SJayanth Dodderi Chidanand        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
860f87e54f7SManish Pandey        and HANDLE_EA_EL3_FIRST_NS instead")
8619202d519SManish Pandeyendif
862c5e1da83SJayanth Dodderi Chidanand
863c5e1da83SJayanth Dodderi Chidanand
8649202d519SManish Pandey# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
8651a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
8666503ff29SAndre Przywara	ifeq ($(ENABLE_FEAT_RAS),0)
8676503ff29SAndre Przywara                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
8681a7c1cfeSJeenu Viswambharan	endif
869c5e1da83SJayanth Dodderi Chidanandendif #(FAULT_INJECTION_SUPPORT)
8701a7c1cfeSJeenu Viswambharan
871ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
872209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
873209a60ccSSoby Mathew	ifeq (${TRUSTED_BOARD_BOOT}, 0)
874c5e1da83SJayanth Dodderi Chidanand                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
875c5e1da83SJayanth Dodderi Chidanand                to be set.")
876209a60ccSSoby Mathew	endif
877c5e1da83SJayanth Dodderi Chidanandendif #(DYN_DISABLE_AUTH)
878209a60ccSSoby Mathew
8792bf4f27fSManish V Badarkheifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
8802bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8812bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8822bf4f27fSManish V Badarkheelse ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
8832bf4f27fSManish V Badarkhe# Support authentication verification and hash calculation
8842bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 3
8852bf4f27fSManish V Badarkheelse ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
8862bf4f27fSManish V Badarkhe# Support hash calculation only
8872bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT := 2
8882bf4f27fSManish V Badarkheelse ifeq (${TRUSTED_BOARD_BOOT},1)
8892bf4f27fSManish V Badarkhe# Support authentication verification only
890c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 1
891c9c56f6eSManish V Badarkheelse
892c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT := 0
893c5e1da83SJayanth Dodderi Chidanandendif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
894c9c56f6eSManish V Badarkhe
895cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
896cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
897700e7685SManish Pandey        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
89884ef9cd8SManish V Badarkheendif
89984ef9cd8SManish V Badarkhe
900b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
9019fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
9029fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
903b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
9049fc59639SAlexei Fedorov	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
9059fc59639SAlexei Fedorov                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
90606715f85SAlexei Fedorov	endif
907c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_PAUTH)
9089fc59639SAlexei Fedorov
90906715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
9109fc59639SAlexei Fedorov	ifneq (${ARCH},aarch64)
9119fc59639SAlexei Fedorov                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
912b86048c4SAntonio Nino Diaz	endif
913c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_PAUTH_REGS)
9149fc59639SAlexei Fedorov
9156a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
9166a0da736SJayanth Dodderi Chidanand        $(info FEATURE_DETECTION is an experimental feature)
917c5e1da83SJayanth Dodderi Chidanandendif #(FEATURE_DETECTION)
9186a0da736SJayanth Dodderi Chidanand
91903d3c0d7SJayanth Dodderi Chidanandifneq ($(ENABLE_SME2_FOR_NS), 0)
92003d3c0d7SJayanth Dodderi Chidanand	ifeq (${ENABLE_SME_FOR_NS}, 0)
921c5e1da83SJayanth Dodderi Chidanand                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
922c5e1da83SJayanth Dodderi Chidanand                to be set")
92303d3c0d7SJayanth Dodderi Chidanand                $(warning "Forced ENABLE_SME_FOR_NS=1")
92403d3c0d7SJayanth Dodderi Chidanand		override ENABLE_SME_FOR_NS	:= 1
92503d3c0d7SJayanth Dodderi Chidanand	endif
926c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME2_FOR_NS)
92745007acdSJayanth Dodderi Chidanand
92860e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
92960e8f3cfSPetre-Ionut Tudor	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
930c5e1da83SJayanth Dodderi Chidanand                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
931c5e1da83SJayanth Dodderi Chidanand                library v2")
93260e8f3cfSPetre-Ionut Tudor	endif
933c5e1da83SJayanth Dodderi Chidanandendif #(ARM_XLAT_TABLES_LIB_V1)
93460e8f3cfSPetre-Ionut Tudor
9357cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
9367cda17bbSSumit Garg	ifeq (${TRUSTED_BOARD_BOOT}, 0)
937c5e1da83SJayanth Dodderi Chidanand                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
938c5e1da83SJayanth Dodderi Chidanand                to be set)
9397cda17bbSSumit Garg	endif
940c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
9417cda17bbSSumit Garg
942744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
943dc78e62dSjohpow01ifeq (${ARCH},aarch32)
944744ad974Sjohpow01
945744ad974Sjohpow01	# SME/SVE only supported on AArch64
94645007acdSJayanth Dodderi Chidanand	ifneq (${ENABLE_SME_FOR_NS},0)
947dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
948dc78e62dSjohpow01	endif
94903d3c0d7SJayanth Dodderi Chidanand
950dc78e62dSjohpow01	ifeq (${ENABLE_SVE_FOR_NS},1)
951dc78e62dSjohpow01		# Warning instead of error due to CI dependency on this
95224ab2c0aSYann Gautier                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
953dc78e62dSjohpow01	endif
954744ad974Sjohpow01
955ff86e0b4SJuan Pablo Conde	# BRBE is not supported in AArch32
956744ad974Sjohpow01	ifeq (${ENABLE_BRBE_FOR_NS},1)
957744ad974Sjohpow01                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
958744ad974Sjohpow01	endif
959744ad974Sjohpow01
960ff86e0b4SJuan Pablo Conde	# FEAT_RNG_TRAP is not supported in AArch32
961ff86e0b4SJuan Pablo Conde	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
962ff86e0b4SJuan Pablo Conde                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
963ff86e0b4SJuan Pablo Conde	endif
964c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch32)
965dc78e62dSjohpow01
9660d122947SBoyan Karatotevifneq (${ENABLE_SME_FOR_NS},0)
9670d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_NS},0)
9680d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
9690d122947SBoyan Karatotev	endif
970c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_NS)
9710d122947SBoyan Karatotev
972dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
973dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
974dc78e62dSjohpow01	ifeq (${ENABLE_SME_FOR_NS},0)
975dc78e62dSjohpow01                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
976dc78e62dSjohpow01	endif
9770d122947SBoyan Karatotev	ifeq (${ENABLE_SVE_FOR_SWD},0)
9780d122947SBoyan Karatotev                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
9790d122947SBoyan Karatotev	endif
980c5e1da83SJayanth Dodderi Chidanandendif #(ENABLE_SME_FOR_SWD)
981c5e1da83SJayanth Dodderi Chidanand
9823524d074SMadhukar Pappireddy# Enabling SVE for SWD requires enabling SVE for NWD due to ENABLE_FEAT
9833524d074SMadhukar Pappireddy# mechanism.
984dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
985dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
986dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
987dc78e62dSjohpow01    endif
9883524d074SMadhukar Pappireddyendif
989dc78e62dSjohpow01
9903524d074SMadhukar Pappireddy# Enabling SVE for both the worlds typically requires the context
9913524d074SMadhukar Pappireddy# management of SVE registers. The only exception being SPMC at S-EL2.
9923524d074SMadhukar Pappireddyifeq (${ENABLE_SVE_FOR_SWD}, 1)
9933524d074SMadhukar Pappireddy    ifneq (${ENABLE_SVE_FOR_NS}, 0)
9943524d074SMadhukar Pappireddy        ifeq (${CTX_INCLUDE_SVE_REGS}-$(SPMD_SPM_AT_SEL2),0-0)
9953524d074SMadhukar Pappireddy            $(warning "ENABLE_SVE_FOR_SWD and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
9963524d074SMadhukar Pappireddy        endif
9973524d074SMadhukar Pappireddy    endif
9983524d074SMadhukar Pappireddyendif
9993524d074SMadhukar Pappireddy
10003524d074SMadhukar Pappireddy# Enabling SVE in either world while enabling CTX_INCLUDE_FPREGS requires
10013524d074SMadhukar Pappireddy# CTX_INCLUDE_SVE_REGS to be enabled due to architectural dependency between FP
10023524d074SMadhukar Pappireddy# and SVE registers.
10033524d074SMadhukar Pappireddyifeq (${CTX_INCLUDE_FPREGS}, 1)
10043524d074SMadhukar Pappireddy    ifneq (${ENABLE_SVE_FOR_NS},0)
10053524d074SMadhukar Pappireddy        ifeq (${CTX_INCLUDE_SVE_REGS},0)
10063524d074SMadhukar Pappireddy	    # Warning instead of error due to CI dependency on this
10073524d074SMadhukar Pappireddy            $(warning "CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
10083524d074SMadhukar Pappireddy            $(warning "Forced ENABLE_SVE_FOR_NS=0")
10093524d074SMadhukar Pappireddy	    override ENABLE_SVE_FOR_NS	:= 0
10103524d074SMadhukar Pappireddy        endif
10113524d074SMadhukar Pappireddy    endif
10123524d074SMadhukar Pappireddyendif #(CTX_INCLUDE_FPREGS)
10133524d074SMadhukar Pappireddy
10143524d074SMadhukar Pappireddy# SVE context management is only required if secure world has access to SVE/FP
10153524d074SMadhukar Pappireddy# functionality.
10163524d074SMadhukar Pappireddyifeq (${CTX_INCLUDE_SVE_REGS},1)
10173524d074SMadhukar Pappireddy    ifeq (${ENABLE_SVE_FOR_SWD},0)
10183524d074SMadhukar Pappireddy        $(error "CTX_INCLUDE_SVE_REGS requires ENABLE_SVE_FOR_SWD to also be enabled")
10193524d074SMadhukar Pappireddy    endif
10203524d074SMadhukar Pappireddyendif
10213524d074SMadhukar Pappireddy
10223524d074SMadhukar Pappireddy# SME cannot be used with CTX_INCLUDE_FPREGS since SPM does its own context
10233524d074SMadhukar Pappireddy# management including FPU registers.
1024dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
102545007acdSJayanth Dodderi Chidanand    ifneq (${ENABLE_SME_FOR_NS},0)
1026dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1027dc78e62dSjohpow01    endif
1028c5e1da83SJayanth Dodderi Chidanandendif #(CTX_INCLUDE_FPREGS)
1029dc78e62dSjohpow01
103000e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
103100e28874SManish V Badarkhe        $(info DRTM_SUPPORT is an experimental feature)
103200e28874SManish V Badarkheendif
103300e28874SManish V Badarkhe
10343ba2c151SRaymond Maoifeq (${TRANSFER_LIST},1)
10353ba2c151SRaymond Mao        $(info TRANSFER_LIST is an experimental feature)
10363ba2c151SRaymond Maoendif
10373ba2c151SRaymond Mao
1038274a69e7SChris Kayifeq (${ENABLE_RME},1)
1039274a69e7SChris Kay	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1040274a69e7SChris Kay                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1041274a69e7SChris Kay	endif
1042274a69e7SChris Kayendif
1043274a69e7SChris Kay
10445782b890SManish V Badarkheifeq ($(PSA_CRYPTO),1)
10455782b890SManish V Badarkhe        $(info PSA_CRYPTO is an experimental feature)
10465782b890SManish V Badarkheendif
10475782b890SManish V Badarkhe
104882222db8SManish V Badarkheifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
104982222db8SManish V Badarkhe        $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
105082222db8SManish V Badarkheendif
105182222db8SManish V Badarkhe
1052cf2c8a33SAntonio Nino Diaz################################################################################
105373c99d4eSJuan Castillo# Process platform overrideable behaviour
105473c99d4eSJuan Castillo################################################################################
10554f6ad66aSAchin Gupta
10565f24ce96SManish Pandeyifdef BL1_SOURCES
10575f24ce96SManish Pandey	NEED_BL1 := yes
1058c5e1da83SJayanth Dodderi Chidanandendif #(BL1_SOURCES)
10595f24ce96SManish Pandey
10605f24ce96SManish Pandeyifdef BL2_SOURCES
10615f24ce96SManish Pandey	NEED_BL2 := yes
10625f24ce96SManish Pandey
1063bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1064bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
1065cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
1066cf2c8a33SAntonio Nino Diaz		# If booting an EL3 payload there is no need for a BL33 image
1067cf2c8a33SAntonio Nino Diaz		# in the FIP file.
10684c117f6cSSandrine Bailleux		NEED_BL33		:=	no
1069cf2c8a33SAntonio Nino Diaz	else
107068450a6dSAntonio Nino Diaz		ifdef PRELOADED_BL33_BASE
1071cf2c8a33SAntonio Nino Diaz			# If booting a BL33 preloaded image there is no need of
1072cf2c8a33SAntonio Nino Diaz			# another one in the FIP file.
1073cf2c8a33SAntonio Nino Diaz			NEED_BL33		:=	no
1074cf2c8a33SAntonio Nino Diaz		else
1075cf2c8a33SAntonio Nino Diaz			NEED_BL33		?=	yes
1076cf2c8a33SAntonio Nino Diaz		endif
10774c117f6cSSandrine Bailleux	endif
1078c5e1da83SJayanth Dodderi Chidanandendif #(BL2_SOURCES)
10796f971622SJuan Castillo
10805f24ce96SManish Pandeyifdef BL2U_SOURCES
10815f24ce96SManish Pandey	NEED_BL2U := yes
1082c5e1da83SJayanth Dodderi Chidanandendif #(BL2U_SOURCES)
10835f24ce96SManish Pandey
10844d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
10854d045d0eSMasahiro Yamadaifdef SCP_BL2
10864d045d0eSMasahiro Yamada	NEED_SCP_BL2		:=	yes
1087c5e1da83SJayanth Dodderi Chidanandendif #(SCP_BL2)
10884d045d0eSMasahiro Yamada
10895744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
10905744e874SSoby Mathewifneq (${ARCH},aarch32)
10915744e874SSoby Mathew	ifdef BL31_SOURCES
1092c5e1da83SJayanth Dodderi Chidanand	# When booting an EL3 payload, there is no need to compile the BL31
1093c5e1da83SJayanth Dodderi Chidanand	# image nor put it in the FIP.
10945744e874SSoby Mathew		ifndef EL3_PAYLOAD_BASE
10955744e874SSoby Mathew			NEED_BL31 := yes
10965744e874SSoby Mathew		endif
10975744e874SSoby Mathew	endif
1098c5e1da83SJayanth Dodderi Chidanandendif #(ARCH=aarch64)
10995744e874SSoby Mathew
110073c99d4eSJuan Castillo# Process TBB related flags
11016f971622SJuan Castilloifneq (${GENERATE_COT},0)
110273c99d4eSJuan Castillo	# Common cert_create options
11036f971622SJuan Castillo	ifneq (${CREATE_KEYS},0)
11046f971622SJuan Castillo                $(eval CRT_ARGS += -n)
11050191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
1106fd34e7baSJuan Castillo		ifneq (${SAVE_KEYS},0)
1107fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
11080191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
1109fd34e7baSJuan Castillo		endif
11106f971622SJuan Castillo	endif
111173c99d4eSJuan Castillo	# Include TBBR makefile (unless the platform indicates otherwise)
111273c99d4eSJuan Castillo	ifeq (${INCLUDE_TBBR_MK},1)
111373c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
111473c99d4eSJuan Castillo	endif
1115c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
11166f971622SJuan Castillo
11171c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
11181c75d5dfSMasahiro Yamada	FIP_ARGS += --align ${FIP_ALIGN}
1119c5e1da83SJayanth Dodderi Chidanandendif #(FIP_ALIGN)
11201c75d5dfSMasahiro Yamada
11215f24ce96SManish Pandeyifdef FDT_SOURCES
11225f24ce96SManish Pandey	NEED_FDT := yes
1123c5e1da83SJayanth Dodderi Chidanandendif #(FDT_SOURCES)
11245f24ce96SManish Pandey
112573c99d4eSJuan Castillo################################################################################
112646e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
112746e5e035SMichalis Pappas################################################################################
112846e5e035SMichalis Pappas
112946e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
113046e5e035SMichalis Pappas
113146e5e035SMichalis Pappas################################################################################
11328a86052dSSoby Mathew# Include BL specific makefiles
11338a86052dSSoby Mathew################################################################################
11345f24ce96SManish Pandey
11355f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
11368a86052dSSoby Mathewinclude bl1/bl1.mk
11378a86052dSSoby Mathewendif
11388a86052dSSoby Mathew
11395f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
11408a86052dSSoby Mathewinclude bl2/bl2.mk
11418a86052dSSoby Mathewendif
11428a86052dSSoby Mathew
11435f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
11448a86052dSSoby Mathewinclude bl2u/bl2u.mk
11458a86052dSSoby Mathewendif
11468a86052dSSoby Mathew
11475744e874SSoby Mathewifeq (${NEED_BL31},yes)
11488a86052dSSoby Mathewinclude bl31/bl31.mk
11498a86052dSSoby Mathewendif
115003b397a8SNishanth Menon
115173c99d4eSJuan Castillo################################################################################
115273c99d4eSJuan Castillo# Build options checks
115373c99d4eSJuan Castillo################################################################################
115473c99d4eSJuan Castillo
1155c5e1da83SJayanth Dodderi Chidanand# Boolean_Flags
1156327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
1157327131c4SLeonardo Sandoval    $(sort \
1158327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
115946789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1160327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1161327131c4SLeonardo Sandoval	CREATE_KEYS \
1162327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1163327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
116442422622SMadhukar Pappireddy	CTX_INCLUDE_SVE_REGS \
1165327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
11669acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1167327131c4SLeonardo Sandoval	DEBUG \
1168327131c4SLeonardo Sandoval	DYN_DISABLE_AUTH \
1169327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
11701fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1171742ca230SChris Kay	ENABLE_AMU_FCONF \
1172873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1173327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1174327131c4SLeonardo Sandoval	ENABLE_PIE \
1175327131c4SLeonardo Sandoval	ENABLE_PMF \
1176327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
1177327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1178dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
11790c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1180970a4a8dSManish Pandey	ENABLE_FEAT_RAS	\
1181f87e54f7SManish Pandey	FFH_SUPPORT	\
1182327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1183327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1184327131c4SLeonardo Sandoval	GENERATE_COT \
1185327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
118646cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1187538516f5SBipin Ravi	HARDEN_SLS \
1188327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1189327131c4SLeonardo Sandoval	MEASURED_BOOT \
1190e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
119100e28874SManish V Badarkhe	DRTM_SUPPORT \
1192327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1193327131c4SLeonardo Sandoval	OVERRIDE_LIBC \
1194327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1195327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1196327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
119764b4710bSWing Li	PSCI_OS_INIT_MODE \
1198327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1199327131c4SLeonardo Sandoval	SAVE_KEYS \
1200327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
120196a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1202327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1203308ebfa1SMadhukar Pappireddy	SEPARATE_SIMD_SECTION \
1204327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1205327131c4SLeonardo Sandoval	SPM_MM \
12061d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1207801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1208327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
1209890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
12103ba2c151SRaymond Mao	TRANSFER_LIST \
1211327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1212327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1213327131c4SLeonardo Sandoval	USE_DEBUGFS \
1214327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1215327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1216327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1217327131c4SLeonardo Sandoval	USE_ROMLIB \
1218327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1219327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
122042d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
1221327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1222327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1223327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1224327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1225327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1226327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
122700e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1228327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1229327131c4SLeonardo Sandoval	USE_SP804_TIMER \
1230396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
123111d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
123268120783SChris Kay	ENABLE_MPMM \
123368120783SChris Kay	ENABLE_MPMM_FCONF \
12346a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
12350b22e591SJayanth Dodderi Chidanand	TRNG_SUPPORT \
1236ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1237ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
123804c7303bSOkash Khawaja	CONDITIONAL_CMO \
12395782b890SManish V Badarkhe	PSA_CRYPTO	\
124085bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1241183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1242bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1243ae770fedSYann Gautier	EARLY_CONSOLE \
1244f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1245327131c4SLeonardo Sandoval)))
124673c99d4eSJuan Castillo
1247c5e1da83SJayanth Dodderi Chidanand# Numeric_Flags
1248327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1249327131c4SLeonardo Sandoval    $(sort \
1250327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1251327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
1252327131c4SLeonardo Sandoval	BRANCH_PROTECTION \
12536a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_PAUTH_REGS \
12546a0da736SJayanth Dodderi Chidanand	CTX_INCLUDE_NEVE_REGS \
12552bf4f27fSManish V Badarkhe	CRYPTO_SUPPORT \
125683a4dae1SBoyan Karatotev	DISABLE_MTPMU \
12571298f2f1SJayanth Dodderi Chidanand	ENABLE_BRBE_FOR_NS \
125847c681b7SJayanth Dodderi Chidanand	ENABLE_TRBE_FOR_NS \
12596a0da736SJayanth Dodderi Chidanand	ENABLE_BTI \
12606a0da736SJayanth Dodderi Chidanand	ENABLE_PAUTH \
1261d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
12626a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
12636a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
126430019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
126583271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
12666a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_DIT \
12676a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
12686a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
126933e6aaacSArvind Ram Prakash	ENABLE_FEAT_FGT2 \
12706a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_HCX \
12718e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
12726a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
12736a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_RNG \
1274ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
12756a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
1276d3331603SMark Brown	ENABLE_FEAT_TCR2 \
12770e4daed2SGovindraj Raja	ENABLE_FEAT_SB \
1278062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1279062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1280062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1281062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1282688ab57bSMark Brown	ENABLE_FEAT_GCS \
12836a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
1284edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
12856a0da736SJayanth Dodderi Chidanand	ENABLE_RME \
12866437a09aSAndre Przywara	ENABLE_SPE_FOR_NS \
1287603a0c6fSAndre Przywara	ENABLE_SYS_REG_TRACE_FOR_NS \
128845007acdSJayanth Dodderi Chidanand	ENABLE_SME_FOR_NS \
128903d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
12902b0bc4e0SJayanth Dodderi Chidanand	ENABLE_SVE_FOR_NS \
12916a0da736SJayanth Dodderi Chidanand	ENABLE_TRF_FOR_NS \
1292327131c4SLeonardo Sandoval	FW_ENC_STATUS \
12935357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
12945357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1295781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1296781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
1297bebcf27fSMark Brown	SVE_VECTOR_LEN \
12980ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1299327131c4SLeonardo Sandoval)))
1300c877b414SJeenu Viswambharan
1301aacff749SJustin Chadwellifdef KEY_SIZE
1302aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1303aacff749SJustin Chadwellendif
1304aacff749SJustin Chadwell
13051f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
13061f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
13071f461979SJustin Chadwellendif
13081f461979SJustin Chadwell
130973c99d4eSJuan Castillo################################################################################
131073c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
131173c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
131273c99d4eSJuan Castillo# platform to overwrite the default options
131373c99d4eSJuan Castillo################################################################################
131473c99d4eSJuan Castillo
1315327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1316327131c4SLeonardo Sandoval    $(sort \
1317327131c4SLeonardo Sandoval	ALLOW_RO_XLAT_TABLES \
1318327131c4SLeonardo Sandoval	ARM_ARCH_MAJOR \
1319327131c4SLeonardo Sandoval	ARM_ARCH_MINOR \
132046789a7cSBalint Dobszay	BL2_ENABLE_SP_LOAD \
1321327131c4SLeonardo Sandoval	COLD_BOOT_SINGLE_CPU \
1322327131c4SLeonardo Sandoval	CTX_INCLUDE_AARCH32_REGS \
1323327131c4SLeonardo Sandoval	CTX_INCLUDE_FPREGS \
132442422622SMadhukar Pappireddy	CTX_INCLUDE_SVE_REGS \
1325327131c4SLeonardo Sandoval	CTX_INCLUDE_PAUTH_REGS \
13269acff28aSArvind Ram Prakash	CTX_INCLUDE_MPAM_REGS \
1327327131c4SLeonardo Sandoval	EL3_EXCEPTION_HANDLING \
1328327131c4SLeonardo Sandoval	CTX_INCLUDE_EL2_REGS \
1329062f8aafSArunachalam Ganapathy	CTX_INCLUDE_NEVE_REGS \
1330327131c4SLeonardo Sandoval	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
13310063dd17SJavier Almansa Sobrino	DISABLE_MTPMU \
1332d23acc9eSAndre Przywara	ENABLE_FEAT_AMU \
13331fd685a7SChris Kay	ENABLE_AMU_AUXILIARY_COUNTERS \
1334742ca230SChris Kay	ENABLE_AMU_FCONF \
1335873d4241Sjohpow01	AMU_RESTRICT_COUNTERS \
1336327131c4SLeonardo Sandoval	ENABLE_ASSERTIONS \
1337327131c4SLeonardo Sandoval	ENABLE_BTI \
133883271d5aSArvind Ram Prakash	ENABLE_FEAT_DEBUGV8P9 \
1339edebefbcSArvind Ram Prakash	ENABLE_FEAT_MPAM \
1340327131c4SLeonardo Sandoval	ENABLE_PAUTH \
1341327131c4SLeonardo Sandoval	ENABLE_PIE \
1342327131c4SLeonardo Sandoval	ENABLE_PMF \
1343327131c4SLeonardo Sandoval	ENABLE_PSCI_STAT \
13445b18de09SZelalem Aweke	ENABLE_RME \
1345327131c4SLeonardo Sandoval	ENABLE_RUNTIME_INSTRUMENTATION \
1346dc78e62dSjohpow01	ENABLE_SME_FOR_NS \
134703d3c0d7SJayanth Dodderi Chidanand	ENABLE_SME2_FOR_NS \
1348dc78e62dSjohpow01	ENABLE_SME_FOR_SWD \
134990118bb5SAndre Przywara	ENABLE_SPE_FOR_NS \
1350327131c4SLeonardo Sandoval	ENABLE_SVE_FOR_NS \
13510c5e7d1cSMax Shvetsov	ENABLE_SVE_FOR_SWD \
1352970a4a8dSManish Pandey	ENABLE_FEAT_RAS \
1353f87e54f7SManish Pandey	FFH_SUPPORT \
1354327131c4SLeonardo Sandoval	ENCRYPT_BL31 \
1355327131c4SLeonardo Sandoval	ENCRYPT_BL32 \
1356327131c4SLeonardo Sandoval	ERROR_DEPRECATED \
1357327131c4SLeonardo Sandoval	FAULT_INJECTION_SUPPORT \
1358327131c4SLeonardo Sandoval	GICV2_G0_FOR_EL3 \
135946cc41d5SManish Pandey	HANDLE_EA_EL3_FIRST_NS \
1360327131c4SLeonardo Sandoval	HW_ASSISTED_COHERENCY \
1361327131c4SLeonardo Sandoval	LOG_LEVEL \
1362327131c4SLeonardo Sandoval	MEASURED_BOOT \
1363e7f1181fSTamas Ban	DICE_PROTECTION_ENVIRONMENT \
136400e28874SManish V Badarkhe	DRTM_SUPPORT \
1365327131c4SLeonardo Sandoval	NS_TIMER_SWITCH \
1366327131c4SLeonardo Sandoval	PL011_GENERIC_UART \
1367327131c4SLeonardo Sandoval	PLAT_${PLAT} \
1368327131c4SLeonardo Sandoval	PROGRAMMABLE_RESET_ADDRESS \
1369327131c4SLeonardo Sandoval	PSCI_EXTENDED_STATE_ID \
137064b4710bSWing Li	PSCI_OS_INIT_MODE \
1371327131c4SLeonardo Sandoval	RESET_TO_BL31 \
1372d766084fSAlexeiFedorov	RME_GPT_BITLOCK_BLOCK \
1373ec0088bbSAlexeiFedorov	RME_GPT_MAX_BLOCK \
1374327131c4SLeonardo Sandoval	SEPARATE_CODE_AND_RODATA \
137596a8ed14SJiafei Pan	SEPARATE_BL2_NOLOAD_REGION \
1376327131c4SLeonardo Sandoval	SEPARATE_NOBITS_REGION \
1377308ebfa1SMadhukar Pappireddy	SEPARATE_SIMD_SECTION \
1378327131c4SLeonardo Sandoval	RECLAIM_INIT_CODE \
1379327131c4SLeonardo Sandoval	SPD_${SPD} \
1380327131c4SLeonardo Sandoval	SPIN_ON_BL1_EXIT \
1381327131c4SLeonardo Sandoval	SPM_MM \
13821d63ae4dSMarc Bonnici	SPMC_AT_EL3 \
1383801cd3c8SNishant Sharma	SPMC_AT_EL3_SEL0_SP \
1384327131c4SLeonardo Sandoval	SPMD_SPM_AT_SEL2 \
13853ba2c151SRaymond Mao	TRANSFER_LIST \
1386327131c4SLeonardo Sandoval	TRUSTED_BOARD_BOOT \
1387c9c56f6eSManish V Badarkhe	CRYPTO_SUPPORT \
13887dfb9911SJimmy Brisson	TRNG_SUPPORT \
1389ffea3844SSona Mathew	ERRATA_ABI_SUPPORT \
1390ef63f5beSSona Mathew	ERRATA_NON_ARM_INTERCONNECT \
1391327131c4SLeonardo Sandoval	USE_COHERENT_MEM \
1392327131c4SLeonardo Sandoval	USE_DEBUGFS \
1393327131c4SLeonardo Sandoval	ARM_IO_IN_DTB \
1394327131c4SLeonardo Sandoval	SDEI_IN_FCONF \
1395327131c4SLeonardo Sandoval	SEC_INT_DESC_IN_FCONF \
1396327131c4SLeonardo Sandoval	USE_ROMLIB \
1397327131c4SLeonardo Sandoval	USE_TBBR_DEFS \
1398327131c4SLeonardo Sandoval	WARMBOOT_ENABLE_DCACHE_EARLY \
139942d4d3baSArvind Ram Prakash	RESET_TO_BL2 \
140042d4d3baSArvind Ram Prakash	BL2_RUNS_AT_EL3	\
1401327131c4SLeonardo Sandoval	BL2_IN_XIP_MEM \
1402327131c4SLeonardo Sandoval	BL2_INV_DCACHE \
1403327131c4SLeonardo Sandoval	USE_SPINLOCK_CAS \
1404327131c4SLeonardo Sandoval	ERRATA_SPECULATIVE_AT \
140500e8f79cSManish Pandey	RAS_TRAP_NS_ERR_REC_ACCESS \
1406327131c4SLeonardo Sandoval	COT_DESC_IN_DTB \
1407327131c4SLeonardo Sandoval	USE_SP804_TIMER \
140812cd65e0STomas Pilar	ENABLE_FEAT_RNG \
1409ff86e0b4SJuan Pablo Conde	ENABLE_FEAT_RNG_TRAP \
14104e04478aSChris Kay	ENABLE_FEAT_SB \
14117d33ffe4SDaniel Boulby	ENABLE_FEAT_DIT \
14125357f83dSManish V Badarkhe	NR_OF_FW_BANKS \
14135357f83dSManish V Badarkhe	NR_OF_IMAGES_IN_FW_BANK \
1414396b339dSManish V Badarkhe	PSA_FWU_SUPPORT \
141511d05a77SSughosh Ganu	PSA_FWU_METADATA_FW_STORE_DESC \
1416744ad974Sjohpow01	ENABLE_BRBE_FOR_NS \
1417813524eaSManish V Badarkhe	ENABLE_TRBE_FOR_NS \
1418d4582d30SManish V Badarkhe	ENABLE_SYS_REG_TRACE_FOR_NS \
14198fcd3d96SManish V Badarkhe	ENABLE_TRF_FOR_NS \
1420cb4ec47bSjohpow01	ENABLE_FEAT_HCX \
142168120783SChris Kay	ENABLE_MPMM \
142268120783SChris Kay	ENABLE_MPMM_FCONF \
1423f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_FGT \
142433e6aaacSArvind Ram Prakash	ENABLE_FEAT_FGT2 \
1425f74cb0beSJayanth Dodderi Chidanand	ENABLE_FEAT_ECV \
14266a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_AMUv1p1 \
14276a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_SEL2 \
14286a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_VHE \
14296a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_CSV2_2 \
143030019d86SSona Mathew	ENABLE_FEAT_CSV2_3 \
14316a0da736SJayanth Dodderi Chidanand	ENABLE_FEAT_PAN \
1432d3331603SMark Brown	ENABLE_FEAT_TCR2 \
1433062b6c6bSMark Brown	ENABLE_FEAT_S2PIE \
1434062b6c6bSMark Brown	ENABLE_FEAT_S1PIE \
1435062b6c6bSMark Brown	ENABLE_FEAT_S2POE \
1436062b6c6bSMark Brown	ENABLE_FEAT_S1POE \
1437688ab57bSMark Brown	ENABLE_FEAT_GCS \
14388e397889SGovindraj Raja	ENABLE_FEAT_MTE2 \
14396a0da736SJayanth Dodderi Chidanand	FEATURE_DETECTION \
1440781d07a4SJayanth Dodderi Chidanand	TWED_DELAY \
1441781d07a4SJayanth Dodderi Chidanand	ENABLE_FEAT_TWED \
144204c7303bSOkash Khawaja	CONDITIONAL_CMO \
14430ed3be6fSVarun Wadekar	IMPDEF_SYSREG_TRAP \
1444a8cf6faeSJayanth Dodderi Chidanand	SVE_VECTOR_LEN \
1445890b5088SRaghu Krishnamurthy	ENABLE_SPMD_LP \
14465782b890SManish V Badarkhe	PSA_CRYPTO	\
144785bebe18SSandrine Bailleux	ENABLE_CONSOLE_GETC \
1448183329a5SArvind Ram Prakash	INIT_UNUSED_NS_EL2	\
1449bfef8b90SJuan Pablo Conde	PLATFORM_REPORT_CTX_MEM_USE \
1450ae770fedSYann Gautier	EARLY_CONSOLE \
1451f99a69c3SArvind Ram Prakash	PRESERVE_DSU_PMU_REGS \
1452327131c4SLeonardo Sandoval)))
14532fae4b1eSJeenu Viswambharan
1454bfef8b90SJuan Pablo Condeifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1455bfef8b90SJuan Pablo Condeifeq (${DEBUG}, 0)
1456bfef8b90SJuan Pablo Conde        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1457bfef8b90SJuan Pablo Conde        override PLATFORM_REPORT_CTX_MEM_USE := 0
1458bfef8b90SJuan Pablo Condeendif
1459bfef8b90SJuan Pablo Condeendif
1460bfef8b90SJuan Pablo Conde
14611f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
14621f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
1463c5e1da83SJayanth Dodderi Chidanandendif #(SANITIZE_UB)
14641f461979SJustin Chadwell
14654c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
14664c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
14674c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1468cf2c8a33SAntonio Nino Diazelse
146968450a6dSAntonio Nino Diaz# Define the PRELOADED_BL33_BASE flag only if it is provided and
147068450a6dSAntonio Nino Diaz# EL3_PAYLOAD_BASE is not defined, as it has priority.
147168450a6dSAntonio Nino Diaz	ifdef PRELOADED_BL33_BASE
147268450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
14734c117f6cSSandrine Bailleux	endif
1474c5e1da83SJayanth Dodderi Chidanandendif #(EL3_PAYLOAD_BASE)
147573c99d4eSJuan Castillo
1476209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1477209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1478209a60ccSSoby Mathew        $(eval $(call add_define,DYN_DISABLE_AUTH))
1479209a60ccSSoby Mathewendif
1480209a60ccSSoby Mathew
14818620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link)
1482c2ad38ceSVarun Wadekar        $(eval $(call add_define,USE_ARM_LINK))
1483c2ad38ceSVarun Wadekarendif
1484c2ad38ceSVarun Wadekar
1485ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1486ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1487c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1488ce2b1ec6SManish Pandey	-include $(BUILD_PLAT)/sp_gen.mk
1489ce2b1ec6SManish Pandey	FIP_DEPS += sp
149007c44475SManish Pandey	CRT_DEPS += sp
1491ce2b1ec6SManish Pandey	NEED_SP_PKG := yes
1492ce2b1ec6SManish Pandeyelse
1493c33ff198SOlivier Deprez	ifeq (${SPMD_SPM_AT_SEL2},1)
1494c33ff198SOlivier Deprez                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1495c33ff198SOlivier Deprez	endif
1496c5e1da83SJayanth Dodderi Chidanandendif #(SP_LAYOUT_FILE)
1497c5e1da83SJayanth Dodderi Chidanandendif #(SPD)
1498ce2b1ec6SManish Pandey
149973c99d4eSJuan Castillo################################################################################
150073c99d4eSJuan Castillo# Build targets
150173c99d4eSJuan Castillo################################################################################
150273c99d4eSJuan Castillo
150390aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
150473c99d4eSJuan Castillo.SUFFIXES:
150573c99d4eSJuan Castillo
150673c99d4eSJuan Castilloall: msg_start
150773c99d4eSJuan Castillo
150873c99d4eSJuan Castillomsg_start:
15097c4e1eeaSChris Kay	$(s)echo "Building ${PLAT}"
151073c99d4eSJuan Castillo
15117a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1512d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
15138620bd0bSChris Kayifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1514c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1515c2ad38ceSVarun Wadekarelse
1516bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
15177a24cba5SSoby Mathewendif
1518c5e1da83SJayanth Dodderi Chidanandendif #(!ERROR_DEPRECATED)
15197a24cba5SSoby Mathew
152061f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
15215fee0287SRoberto Vargas
152273c99d4eSJuan Castillo# Expand build macros for the different images
152373c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1524b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1525434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
1526c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL1)
152773c99d4eSJuan Castillo
152873c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1529c5e1da83SJayanth Dodderi Chidanand
153042d4d3baSArvind Ram Prakashifeq (${RESET_TO_BL2}, 0)
1531c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1532c9b31ae8SRoberto Vargasendif
1533c9b31ae8SRoberto Vargas
1534eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1535eb1acfb6SChris Kay
153633950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1537434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1538c5e1da83SJayanth Dodderi Chidanand
1539c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2)
154073c99d4eSJuan Castillo
15414d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
154233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1543c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SCP_BL2)
15444d045d0eSMasahiro Yamada
154573c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
154673c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
154726d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
154826d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1549c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1550c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1551434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1552c6ba9b45SSumit Gargelse
155333950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1554434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
1555c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1556c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL31)
155773c99d4eSJuan Castillo
155870d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1559c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
156070d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
156173c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
156226d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
156326d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
15649cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
15659cd15239SMasahiro Yamada
1566c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1567434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1568c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1569c6ba9b45SSumit Gargelse
1570434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
157133950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1572c5e1da83SJayanth Dodderi Chidanandendif #(DECRYPTION_SUPPORT)
1573c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL32)
157473c99d4eSJuan Castillo
15755b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
15765b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
15775b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
15785b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
15795b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
15805b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
15815b18de09SZelalem Aweke
15825b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
15835b18de09SZelalem Aweke	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1584c5e1da83SJayanth Dodderi Chidanandendif #(NEED_RMM)
15855b18de09SZelalem Aweke
158673c99d4eSJuan Castillo# Add the BL33 image if required by the platform
158773c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
158833950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1589c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL33)
1590db6071c9SJuan Castillo
15919003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
159233950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1593434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1594c5e1da83SJayanth Dodderi Chidanandendif #(NEED_BL2U)
15959003fa0bSYatharth Kochar
159603b397a8SNishanth Menon# Expand build macros for the different images
159703b397a8SNishanth Menonifeq (${NEED_FDT},yes)
159803b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1599c5e1da83SJayanth Dodderi Chidanandendif #(NEED_FDT)
160003b397a8SNishanth Menon
1601ce2b1ec6SManish Pandey# Add Secure Partition packages
1602ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1603fd74ca0dSChris Kay$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
16047c4e1eeaSChris Kay	$(q)${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1605822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
16067c4e1eeaSChris Kay	$(s)echo
16077c4e1eeaSChris Kay	$(s)echo "Built SP Images successfully"
16087c4e1eeaSChris Kay	$(s)echo
1609c5e1da83SJayanth Dodderi Chidanandendif #(NEED_SP_PKG)
1610ce2b1ec6SManish Pandey
161136eaaf37SIan Spraylocate-checkpatch:
161236eaaf37SIan Sprayifndef CHECKPATCH
161366079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
161436eaaf37SIan Sprayelse
161536eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
161666079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
161736eaaf37SIan Sprayendif
1618c5e1da83SJayanth Dodderi Chidanandendif #(CHECKPATCH)
161936eaaf37SIan Spray
16204f6ad66aSAchin Guptaclean:
16217c4e1eeaSChris Kay	$(s)echo "  CLEAN"
1622f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
162388a1cf1eSSami Mujawarifdef UNIX_MK
16247c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
162588a1cf1eSSami Mujawarelse
162688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
162788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16287c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1629c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16307c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
16317c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
16327c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16334f6ad66aSAchin Gupta
1634eaaeece2SJames Morrisseyrealclean distclean:
16357c4e1eeaSChris Kay	$(s)echo "  REALCLEAN"
1636f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1637f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
163888a1cf1eSSami Mujawarifdef UNIX_MK
16397c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
164088a1cf1eSSami Mujawarelse
164188a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
164288a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
16437c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1644c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
16457c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
16467c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
16477c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
16484f6ad66aSAchin Gupta
164936eaaf37SIan Spraycheckcodebase:		locate-checkpatch
16507c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16517c4e1eeaSChris Kay	$(q)if test -d .git ; then						\
16521ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
16531a41e8c1SDan Handley		while read GIT_FILE ;					\
16541a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
16551a41e8c1SDan Handley		done ;							\
165636eaaf37SIan Spray	else								\
16571a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
16581a41e8c1SDan Handley		 -not -iwholename "*build*"				\
16591a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
166061f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
16611a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
16621ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
16631a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
166436eaaf37SIan Spray	fi
166536eaaf37SIan Spray
166636eaaf37SIan Spraycheckpatch:		locate-checkpatch
16677c4e1eeaSChris Kay	$(s)echo "  CHECKING STYLE"
16687c4e1eeaSChris Kay	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
166902a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
167002a76d5fSYann Gautier	fi
16717c4e1eeaSChris Kay	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
167277a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
167377a0a7f1SYann Gautier	do								\
167451d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
16751a721748SYann Gautier		( git log --format=email "$$commit~..$$commit"		\
16761a721748SYann Gautier			-- ${CHECK_PATHS} ;				\
167751d28937SAntonio Nino Diaz		  git diff --format=email "$$commit~..$$commit"		\
16781a721748SYann Gautier			-- ${CHECK_PATHS}; ) |				\
167902a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
168051d28937SAntonio Nino Diaz	done
168136eaaf37SIan Spray
168273c99d4eSJuan Castillocerttool: ${CRTTOOL}
168373c99d4eSJuan Castillo
1684a9812206SPali Rohár${CRTTOOL}: FORCE
16857c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
16867c4e1eeaSChris Kay	$(s)echo
16877c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16887c4e1eeaSChris Kay	$(s)echo
16896f971622SJuan Castillo
16906f971622SJuan Castilloifneq (${GENERATE_COT},0)
169173c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
16927c4e1eeaSChris Kay	$(q)${CRTTOOL} ${CRT_ARGS}
16937c4e1eeaSChris Kay	$(s)echo
16947c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
16957c4e1eeaSChris Kay	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
16967c4e1eeaSChris Kay	$(s)echo
1697c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
169827713fb4SSoby Mathew
169973c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
17004727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
17017c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FIP_ARGS} $@
17027c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
17037c4e1eeaSChris Kay	$(s)echo
17047c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17057c4e1eeaSChris Kay	$(s)echo
1706f58ad36fSHarry Liebel
17070191262dSYatharth Kocharifneq (${GENERATE_COT},0)
17080191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
17097c4e1eeaSChris Kay	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
17107c4e1eeaSChris Kay	$(s)echo
17117c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17127c4e1eeaSChris Kay	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
17137c4e1eeaSChris Kay	$(s)echo
1714c5e1da83SJayanth Dodderi Chidanandendif #(GENERATE_COT)
17150191262dSYatharth Kochar
17160191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
17174727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
17187c4e1eeaSChris Kay	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
17197c4e1eeaSChris Kay	$(q)${FIPTOOL} info $@
17207c4e1eeaSChris Kay	$(s)echo
17217c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17227c4e1eeaSChris Kay	$(s)echo
17230191262dSYatharth Kochar
172473c99d4eSJuan Castillofiptool: ${FIPTOOL}
172573c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
17260191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
172773c99d4eSJuan Castillo
1728a9812206SPali Rohár${FIPTOOL}: FORCE
172988a1cf1eSSami Mujawarifdef UNIX_MK
17307c4e1eeaSChris Kay	$(q)${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
173188a1cf1eSSami Mujawarelse
173288a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
173388a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
17347c4e1eeaSChris Kay	$(q)set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1735c5e1da83SJayanth Dodderi Chidanandendif #(UNIX_MK)
1736f58ad36fSHarry Liebel
1737a9812206SPali Rohárromlib.bin: libraries FORCE
17387c4e1eeaSChris Kay	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
17395accce5bSRoberto Vargas
1740cfe83910SLouis Mayencourtmemmap: all
1741af5b49e9SHarrison Mutaiifdef UNIX_MK
17427c4e1eeaSChris Kay	$(q)PYTHONPATH=${CURDIR}/tools/memory \
1743af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1744af5b49e9SHarrison Mutaielse
17457c4e1eeaSChris Kay	$(q)set PYTHONPATH=${CURDIR}/tools/memory && \
1746af5b49e9SHarrison Mutai		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1747af5b49e9SHarrison Mutaiendif
1748cfe83910SLouis Mayencourt
17496de32378SMadhukar Pappireddydoc:
17507c4e1eeaSChris Kay	$(s)echo "  BUILD DOCUMENTATION"
17517c4e1eeaSChris Kay	$(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
17526de32378SMadhukar Pappireddy
175390aa901fSSumit Gargenctool: ${ENCTOOL}
175490aa901fSSumit Garg
1755a9812206SPali Rohár${ENCTOOL}: FORCE
17567c4e1eeaSChris Kay	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
17577c4e1eeaSChris Kay	$(s)echo
17587c4e1eeaSChris Kay	$(s)echo "Built $@ successfully"
17597c4e1eeaSChris Kay	$(s)echo
176090aa901fSSumit Garg
176135fab8c9SJoakim Bechcscope:
17627c4e1eeaSChris Kay	$(s)echo "  CSCOPE"
17637c4e1eeaSChris Kay	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
17647c4e1eeaSChris Kay	$(q)cscope -b -q -k
176535fab8c9SJoakim Bech
176672ee3314SRyan Harkinhelp:
17677c4e1eeaSChris Kay	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
17687c4e1eeaSChris Kay	$(s)echo ""
17697c4e1eeaSChris Kay	$(s)echo "PLAT is used to specify which platform you wish to build."
17707c4e1eeaSChris Kay	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
17717c4e1eeaSChris Kay	$(s)echo ""
17727c4e1eeaSChris Kay	$(s)echo "platform = ${PLATFORM_LIST}"
17737c4e1eeaSChris Kay	$(s)echo ""
17747c4e1eeaSChris Kay	$(s)echo "Please refer to the User Guide for a list of all supported options."
17757c4e1eeaSChris Kay	$(s)echo "Note that the build system doesn't track dependencies for build "
17767c4e1eeaSChris Kay	$(s)echo "options. Therefore, if any of the build options are changed "
17777c4e1eeaSChris Kay	$(s)echo "from a previous build, a clean build must be performed."
17787c4e1eeaSChris Kay	$(s)echo ""
17797c4e1eeaSChris Kay	$(s)echo "Supported Targets:"
17807c4e1eeaSChris Kay	$(s)echo "  all            Build all individual bootloader binaries"
17817c4e1eeaSChris Kay	$(s)echo "  bl1            Build the BL1 binary"
17827c4e1eeaSChris Kay	$(s)echo "  bl2            Build the BL2 binary"
17837c4e1eeaSChris Kay	$(s)echo "  bl2u           Build the BL2U binary"
17847c4e1eeaSChris Kay	$(s)echo "  bl31           Build the BL31 binary"
17857c4e1eeaSChris Kay	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
17867c4e1eeaSChris Kay	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
17877c4e1eeaSChris Kay	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
17887c4e1eeaSChris Kay	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
17897c4e1eeaSChris Kay	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
17907c4e1eeaSChris Kay	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
17917c4e1eeaSChris Kay	$(s)echo "  checkpatch     Check the coding style on changes in the current"
17927c4e1eeaSChris Kay	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
17937c4e1eeaSChris Kay	$(s)echo "  clean          Clean the build for the selected platform"
17947c4e1eeaSChris Kay	$(s)echo "  cscope         Generate cscope index"
17957c4e1eeaSChris Kay	$(s)echo "  distclean      Remove all build artifacts for all platforms"
17967c4e1eeaSChris Kay	$(s)echo "  certtool       Build the Certificate generation tool"
17977c4e1eeaSChris Kay	$(s)echo "  enctool        Build the Firmware encryption tool"
17987c4e1eeaSChris Kay	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
17997c4e1eeaSChris Kay	$(s)echo "  sp             Build the Secure Partition Packages"
18007c4e1eeaSChris Kay	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
18017c4e1eeaSChris Kay	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
18027c4e1eeaSChris Kay	$(s)echo "  memmap         Print the memory map of the built binaries"
18037c4e1eeaSChris Kay	$(s)echo "  doc            Build html based documentation using Sphinx tool"
18047c4e1eeaSChris Kay	$(s)echo ""
18057c4e1eeaSChris Kay	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
18067c4e1eeaSChris Kay	$(s)echo ""
18077c4e1eeaSChris Kay	$(s)echo "example: build all targets for the FVP platform:"
18087c4e1eeaSChris Kay	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1809a9812206SPali Rohár
1810a9812206SPali Rohár.PHONY: FORCE
1811a9812206SPali RohárFORCE:;
1812