xref: /rk3399_ARM-atf/Makefile (revision 00e28874df909daf24f58cea1665fde02ccbad1e)
14f6ad66aSAchin Gupta#
2c9c56f6eSManish V Badarkhe# Copyright (c) 2013-2022, 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
1163d2e960SManish V BadarkheVERSION_MINOR			:= 6
12aaa3e722SJuan Castillo
1388154678SJuan Castillo# Default goal is build all images
1488154678SJuan Castillo.DEFAULT_GOAL			:= all
1588154678SJuan Castillo
1672fc70edSDouglas Raillard# Avoid any implicit propagation of command line variable definitions to
1772fc70edSDouglas Raillard# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
1872fc70edSDouglas Raillard# usage. Other command line options like "-s" are still propagated as usual.
1972fc70edSDouglas RaillardMAKEOVERRIDES =
2072fc70edSDouglas Raillard
21231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := make_helpers/
22231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
23e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
2473c99d4eSJuan Castillo
2573c99d4eSJuan Castillo################################################################################
262fae4b1eSJeenu Viswambharan# Default values for build configurations, and their dependencies
2773c99d4eSJuan Castillo################################################################################
28e35c4045SJeenu Viswambharan
292fae4b1eSJeenu Viswambharaninclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
30872be88aSdp-arm
31cc8b5632SAntonio Nino Diaz# Assertions enabled for DEBUG builds by default
32cc8b5632SAntonio Nino DiazENABLE_ASSERTIONS		:= ${DEBUG}
332fae4b1eSJeenu ViswambharanENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
342fae4b1eSJeenu ViswambharanPLAT				:= ${DEFAULT_PLAT}
3573c99d4eSJuan Castillo
3673c99d4eSJuan Castillo################################################################################
3773c99d4eSJuan Castillo# Checkpatch script options
3873c99d4eSJuan Castillo################################################################################
3973c99d4eSJuan Castillo
40f607739cSSandrine BailleuxCHECKCODE_ARGS		:=	--no-patch
41f0b489c1SDan Handley# Do not check the coding style on imported library files or documentation files
424501843fSGilad Ben-YossefINC_ARM_DIRS_TO_CHECK	:=	$(sort $(filter-out                     \
434501843fSGilad Ben-Yossef					include/drivers/arm/cryptocell,	\
444501843fSGilad Ben-Yossef					$(wildcard include/drivers/arm/*)))
454501843fSGilad Ben-YossefINC_ARM_DIRS_TO_CHECK	+=	include/drivers/arm/cryptocell/*.h
464501843fSGilad Ben-YossefINC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
474501843fSGilad Ben-Yossef					include/drivers/arm,		\
484501843fSGilad Ben-Yossef					$(wildcard include/drivers/*)))
49f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
501a41e8c1SDan Handley					include/lib/libfdt		\
5161f72a34SRoberto Vargas					include/lib/libc,		\
52f0b489c1SDan Handley					$(wildcard include/lib/*)))
53f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
544501843fSGilad Ben-Yossef					include/lib			\
554501843fSGilad Ben-Yossef					include/drivers,		\
56f0b489c1SDan Handley					$(wildcard include/*)))
57f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
58d801fbb0Sdp-arm					lib/compiler-rt			\
5955cdcf75SAntonio Nino Diaz					lib/libfdt%			\
6061f72a34SRoberto Vargas					lib/libc,			\
61f0b489c1SDan Handley					$(wildcard lib/*)))
62f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
63f0b489c1SDan Handley					lib				\
64f0b489c1SDan Handley					include				\
65f0b489c1SDan Handley					docs				\
661ef35512SPaul Beesley					%.rst,				\
67f0b489c1SDan Handley					$(wildcard *)))
68f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
69f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
70f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
714501843fSGilad Ben-Yossef				${LIB_DIRS_TO_CHECK}			\
724501843fSGilad Ben-Yossef				${INC_DRV_DIRS_TO_CHECK}		\
734501843fSGilad Ben-Yossef				${INC_ARM_DIRS_TO_CHECK}
7436eaaf37SIan Spray
7573c99d4eSJuan Castillo
7673c99d4eSJuan Castillo################################################################################
7773c99d4eSJuan Castillo# Process build options
7873c99d4eSJuan Castillo################################################################################
7973c99d4eSJuan Castillo
8073c99d4eSJuan Castillo# Verbose flag
81e35c4045SJeenu Viswambharanifeq (${V},0)
82b169f6a9SEvan Lloyd        Q:=@
83ee1ba6d4SAndre Przywara        ECHO:=@echo
8436eaaf37SIan Spray        CHECKCODE_ARGS	+=	--no-summary --terse
854f6ad66aSAchin Guptaelse
86b169f6a9SEvan Lloyd        Q:=
87b5a0f4bdSAntonio Nino Diaz        ECHO:=$(ECHO_QUIET)
884f6ad66aSAchin Guptaendif
89ee1ba6d4SAndre Przywara
90ee1ba6d4SAndre Przywaraifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
91ee1ba6d4SAndre Przywara        Q:=@
92b5a0f4bdSAntonio Nino Diaz        ECHO:=$(ECHO_QUIET)
93ee1ba6d4SAndre Przywaraendif
94ee1ba6d4SAndre Przywara
95ee1ba6d4SAndre Przywaraexport Q ECHO
962f2cef46SJeenu Viswambharan
9773c99d4eSJuan Castillo# The cert_create tool cannot generate certificates individually, so we use the
9873c99d4eSJuan Castillo# target 'certificates' to create them all
9973c99d4eSJuan Castilloifneq (${GENERATE_COT},0)
10073c99d4eSJuan Castillo        FIP_DEPS += certificates
1010191262dSYatharth Kochar        FWU_FIP_DEPS += fwu_certificates
10273c99d4eSJuan Castilloendif
10373c99d4eSJuan Castillo
1049fc59639SAlexei Fedorov# Process BRANCH_PROTECTION value and set
1059fc59639SAlexei Fedorov# Pointer Authentication and Branch Target Identification flags
1069fc59639SAlexei Fedorovifeq (${BRANCH_PROTECTION},0)
1079fc59639SAlexei Fedorov	# Default value turns off all types of branch protection
1089fc59639SAlexei Fedorov	BP_OPTION := none
1099fc59639SAlexei Fedorovelse ifneq (${ARCH},aarch64)
1109fc59639SAlexei Fedorov        $(error BRANCH_PROTECTION requires AArch64)
1119fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},1)
1129fc59639SAlexei Fedorov	# Enables all types of branch protection features
1139fc59639SAlexei Fedorov	BP_OPTION := standard
1149fc59639SAlexei Fedorov	ENABLE_BTI := 1
1159fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1169fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},2)
1179fc59639SAlexei Fedorov	# Return address signing to its standard level
1189fc59639SAlexei Fedorov	BP_OPTION := pac-ret
1199fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1209fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},3)
1219fc59639SAlexei Fedorov	# Extend the signing to include leaf functions
1229fc59639SAlexei Fedorov	BP_OPTION := pac-ret+leaf
1239fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1243768fecfSAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},4)
1253768fecfSAlexei Fedorov	# Turn on branch target identification mechanism
1263768fecfSAlexei Fedorov	BP_OPTION := bti
1273768fecfSAlexei Fedorov	ENABLE_BTI := 1
1289fc59639SAlexei Fedorovelse
1299fc59639SAlexei Fedorov        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
1309fc59639SAlexei Fedorovendif
13173c99d4eSJuan Castillo
1325b18de09SZelalem Aweke# FEAT_RME
1335b18de09SZelalem Awekeifeq (${ENABLE_RME},1)
1345b18de09SZelalem Aweke# RME doesn't support PIE
1355b18de09SZelalem Awekeifneq (${ENABLE_PIE},0)
1365b18de09SZelalem Aweke        $(error ENABLE_RME does not support PIE)
1375b18de09SZelalem Awekeendif
138744ad974Sjohpow01# RME doesn't support BRBE
139744ad974Sjohpow01ifneq (${ENABLE_BRBE_FOR_NS},0)
140744ad974Sjohpow01        $(error ENABLE_RME does not support BRBE.)
141744ad974Sjohpow01endif
1425b18de09SZelalem Aweke# RME requires AARCH64
1435b18de09SZelalem Awekeifneq (${ARCH},aarch64)
1445b18de09SZelalem Aweke        $(error ENABLE_RME requires AArch64)
1455b18de09SZelalem Awekeendif
1465b18de09SZelalem Aweke# RME requires el2 context to be saved for now.
1475b18de09SZelalem AwekeCTX_INCLUDE_EL2_REGS := 1
1485b18de09SZelalem AwekeCTX_INCLUDE_AARCH32_REGS := 0
1495b18de09SZelalem AwekeARM_ARCH_MAJOR := 8
1505b18de09SZelalem AwekeARM_ARCH_MINOR := 6
1515b18de09SZelalem Awekeendif
1525b18de09SZelalem Aweke
153c97cba4eSSoby Mathew# USE_SPINLOCK_CAS requires AArch64 build
154c97cba4eSSoby Mathewifeq (${USE_SPINLOCK_CAS},1)
155c97cba4eSSoby Mathewifneq (${ARCH},aarch64)
156c97cba4eSSoby Mathew        $(error USE_SPINLOCK_CAS requires AArch64)
157c97cba4eSSoby Mathewendif
158c97cba4eSSoby Mathewendif
159c97cba4eSSoby Mathew
1600ca3913dSOlivier Deprez# USE_DEBUGFS experimental feature recommended only in debug builds
1610ca3913dSOlivier Deprezifeq (${USE_DEBUGFS},1)
1620ca3913dSOlivier Deprezifeq (${DEBUG},1)
1630ca3913dSOlivier Deprez        $(warning DEBUGFS experimental feature is enabled.)
1640ca3913dSOlivier Deprezelse
1650ca3913dSOlivier Deprez        $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
1660ca3913dSOlivier Deprezendif
1670ca3913dSOlivier Deprezendif
1680ca3913dSOlivier Deprez
169c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
170c6ba9b45SSumit GargENC_ARGS += -f ${FW_ENC_STATUS}
171c6ba9b45SSumit GargENC_ARGS += -k ${ENC_KEY}
172c6ba9b45SSumit GargENC_ARGS += -n ${ENC_NONCE}
173c6ba9b45SSumit GargFIP_DEPS += enctool
174c6ba9b45SSumit GargFWU_FIP_DEPS += enctool
175c6ba9b45SSumit Gargendif
176c6ba9b45SSumit Garg
17773c99d4eSJuan Castillo################################################################################
17873c99d4eSJuan Castillo# Toolchain
17973c99d4eSJuan Castillo################################################################################
18073c99d4eSJuan Castillo
18172610c41Sdp-armHOSTCC			:=	gcc
18272610c41Sdp-armexport HOSTCC
18372610c41Sdp-arm
18473c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
18573c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
18673c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
18773c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1882adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
18973c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
19073c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
19173c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
19273c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
19338c14d88SSoby MathewDTC			:=	dtc
19473c99d4eSJuan Castillo
195b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
196b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1972adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1982adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
199b25a577fSJulius Wernerendif
200b25a577fSJulius Werner
20126e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
20226e63c44SEtienne Carrieretarget32-directive	= 	-target arm-none-eabi
20326e63c44SEtienne Carriere# Will set march32-directive from platform configuration
20426e63c44SEtienne Carriereelse
20526e63c44SEtienne Carrieretarget32-directive	= 	-target armv8a-none-eabi
206fa6f774bSAlexei Fedorov
207f1821790SAlexei Fedorov# Set the compiler's target architecture profile based on
208f1821790SAlexei Fedorov# ARM_ARCH_MAJOR ARM_ARCH_MINOR options
209fa6f774bSAlexei Fedorovifeq (${ARM_ARCH_MINOR},0)
210f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
211f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
212fa6f774bSAlexei Fedorovelse
213f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
214f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
215fa6f774bSAlexei Fedorovendif
21626e63c44SEtienne Carriereendif
21726e63c44SEtienne Carriere
2187ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2197ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2204a565bd8SSami Mujawar# Check if revision is greater than or equal to 8.5
2214a565bd8SSami Mujawarifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2227ff088d1SManish V Badarkhemem_tag_arch_support	= 	yes
2237ff088d1SManish V Badarkheendif
2247ff088d1SManish V Badarkheendif
2257ff088d1SManish V Badarkhe
226f1821790SAlexei Fedorov# Get architecture feature modifiers
227f1821790SAlexei Fedorovarch-features		=	${ARM_ARCH_FEATURE}
228f1821790SAlexei Fedorov
229f1821790SAlexei Fedorov# Enable required options for memory stack tagging.
230f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2317ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2327ff088d1SManish V Badarkheifdef mem_tag_arch_support
233f1821790SAlexei Fedorov# Check for armclang and clang compilers
2347ff088d1SManish V Badarkheifneq ( ,$(filter $(notdir $(CC)),armclang clang))
235f1821790SAlexei Fedorov# Add "memtag" architecture feature modifier if not specified
236f1821790SAlexei Fedorovifeq ( ,$(findstring memtag,$(arch-features)))
237f1821790SAlexei Fedorovarch-features       	:=       $(arch-features)+memtag
238f1821790SAlexei Fedorovendif	# memtag
2397ff088d1SManish V Badarkheifeq ($(notdir $(CC)),armclang)
2407ff088d1SManish V BadarkheTF_CFLAGS		+=	-mmemtag-stack
2417ff088d1SManish V Badarkheelse ifeq ($(notdir $(CC)),clang)
2427ff088d1SManish V BadarkheTF_CFLAGS		+=	-fsanitize=memtag
243f1821790SAlexei Fedorovendif	# armclang
244f1821790SAlexei Fedorovendif	# armclang clang
2457ff088d1SManish V Badarkheelse
2467ff088d1SManish V Badarkhe$(error "Error: stack memory tagging is not supported for architecture \
2477ff088d1SManish V Badarkhe	${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
248f1821790SAlexei Fedorovendif	# mem_tag_arch_support
249f1821790SAlexei Fedorovendif	# SUPPORT_STACK_MEMTAG
250f1821790SAlexei Fedorov
251f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
252f1821790SAlexei Fedorovifneq ($(arch-features), none)
253f1821790SAlexei Fedorov# Strip "none+" from arch-features
254f1821790SAlexei Fedorovarch-features		:=	$(subst none+,,$(arch-features))
255f1821790SAlexei Fedorovifeq ($(ARCH), aarch32)
256f1821790SAlexei Fedorovmarch32-directive	:=	$(march32-directive)+$(arch-features)
257f1821790SAlexei Fedorovelse
258f1821790SAlexei Fedorovmarch64-directive	:=	$(march64-directive)+$(arch-features)
2597ff088d1SManish V Badarkheendif
260f1821790SAlexei Fedorov# Print features
261f1821790SAlexei Fedorov$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
262f1821790SAlexei Fedorovendif	# arch-features
2637ff088d1SManish V Badarkhe
26412cd65e0STomas Pilar# Determine if FEAT_RNG is supported
26512cd65e0STomas PilarENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
26612cd65e0STomas Pilar
2674e04478aSChris Kay# Determine if FEAT_SB is supported
2684e04478aSChris KayENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
2694e04478aSChris Kay
270c8a992fdSoriginifneq ($(findstring clang,$(notdir $(CC))),)
271fd18a8fcSVarun Wadekar	ifneq ($(findstring armclang,$(notdir $(CC))),)
272c8a992fdSorigin		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi $(march32-directive)
273c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi $(march64-directive)
274c8a992fdSorigin		LD			:=	$(LINKER)
275c8a992fdSorigin	else
276c8a992fdSorigin		TF_CFLAGS_aarch32	:=	$(target32-directive) $(march32-directive)
277c8a992fdSorigin		TF_CFLAGS_aarch64	:=	-target aarch64-elf $(march64-directive)
278c8a992fdSorigin		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
279c8a992fdSorigin
280c8a992fdSorigin		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
281c8a992fdSorigin		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
282c8a992fdSorigin		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
283641f16e7SAmbroise Vincent	endif
284c8a992fdSorigin
285c8a992fdSorigin	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
286c8a992fdSorigin	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
287c8a992fdSorigin	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
288edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
289edbce9aaSzelalem-awekeTF_CFLAGS_aarch32	=	$(march32-directive)
290edbce9aaSzelalem-awekeTF_CFLAGS_aarch64	=	$(march64-directive)
291edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
292edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
293edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
294edbce9aaSzelalem-aweke		LTO_CFLAGS	=	-flto
295edbce9aaSzelalem-aweke		# Use gcc as a wrapper for the ld, recommended for LTO
296edbce9aaSzelalem-aweke		LINKER		:=	${CROSS_COMPILE}gcc
297edbce9aaSzelalem-aweke	endif
298edbce9aaSzelalem-awekeendif
299edbce9aaSzelalem-awekeLD			=	$(LINKER)
300d5461857Sdp-armelse
30126e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	$(march32-directive)
302fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	$(march64-directive)
3032adee763SRoberto VargasLD			=	$(LINKER)
304d5461857Sdp-armendif
305d5461857Sdp-arm
30632b209bfSAhmad Fatoum# Process Debug flag
30732b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
30832b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
30932b209bfSAhmad Fatoum        BUILD_TYPE	:=	debug
31032b209bfSAhmad Fatoum        TF_CFLAGS	+= 	-g
31132b209bfSAhmad Fatoum
31232b209bfSAhmad Fatoum        ifneq ($(findstring clang,$(notdir $(CC))),)
31332b209bfSAhmad Fatoum             ASFLAGS		+= 	-g
31432b209bfSAhmad Fatoum        else
31532b209bfSAhmad Fatoum             ASFLAGS		+= 	-g -Wa,--gdwarf-2
31632b209bfSAhmad Fatoum        endif
31732b209bfSAhmad Fatoum
31832b209bfSAhmad Fatoum        # Use LOG_LEVEL_INFO by default for debug builds
31932b209bfSAhmad Fatoum        LOG_LEVEL	:=	40
32032b209bfSAhmad Fatoumelse
32132b209bfSAhmad Fatoum        BUILD_TYPE	:=	release
32232b209bfSAhmad Fatoum        # Use LOG_LEVEL_NOTICE by default for release builds
32332b209bfSAhmad Fatoum        LOG_LEVEL	:=	20
32432b209bfSAhmad Fatoumendif
32532b209bfSAhmad Fatoum
326f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
327f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
328f1de4c8fSPeiyuan Song        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
329f1de4c8fSPeiyuan Songendif
330f1de4c8fSPeiyuan SongVERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
331f1de4c8fSPeiyuan Song
3328fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3338fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
3348fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3358fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
3368fd9d4d5SAntonio Nino Diazelse
3378fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
3388fd9d4d5SAntonio Nino Diazendif
3398fd9d4d5SAntonio Nino Diaz
340a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
341d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3429d29c227SSoby Mathew
3439fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3449fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
3459fc59639SAlexei Fedorovendif
3469fc59639SAlexei Fedorov
34726e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
348fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
349b86048c4SAntonio Nino Diaz
3509ab81b5eSJustin Chadwell# General warnings
3519ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
352b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
353ca661a00SMadhukar Pappireddy				-Wno-unused-parameter -Wredundant-decls
3549ab81b5eSJustin Chadwell
3559ab81b5eSJustin Chadwell# Additional warnings
3569ab81b5eSJustin Chadwell# Level 1
357e7c645b5SYann GautierWARNING1 := -Wextra
358e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
359e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
360e7c645b5SYann GautierWARNING1 += -Wold-style-definition
361e7c645b5SYann Gautier
362b7f6525dSJustin Chadwell# Level 2
363e7c645b5SYann GautierWARNING2 := -Waggregate-return
364e7c645b5SYann GautierWARNING2 += -Wcast-align
365e7c645b5SYann GautierWARNING2 += -Wnested-externs
366e7c645b5SYann Gautier
367e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
368e7c645b5SYann GautierWARNING3 += -Wcast-qual
369e7c645b5SYann GautierWARNING3 += -Wconversion
370e7c645b5SYann GautierWARNING3 += -Wpacked
371e7c645b5SYann GautierWARNING3 += -Wpointer-arith
372e7c645b5SYann GautierWARNING3 += -Wswitch-default
373e7c645b5SYann Gautier
374e7c645b5SYann Gautierifeq (${W},1)
3759ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
376e7c645b5SYann Gautierelse ifeq (${W},2)
3779ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
378e7c645b5SYann Gautierelse ifeq (${W},3)
3799ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
380e7c645b5SYann Gautierendif
381e7c645b5SYann Gautier
3829ab81b5eSJustin Chadwell# Compiler specific warnings
38300296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
38493c690ebSJustin Chadwell# not using clang
385d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
386d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
387d7b4cd41SJustin Chadwell				-Wlogical-op
38893c690ebSJustin Chadwellelse
38993c690ebSJustin Chadwell# using clang
390d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
391d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
39200296576SAmbroise Vincentendif
39300296576SAmbroise Vincent
3946336b07aSYann Gautierifneq (${E},0)
3956336b07aSYann GautierERRORS := -Werror
3966336b07aSYann Gautierendif
3976336b07aSYann Gautier
398ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3999ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
40059de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
401d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
40259de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
403ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
404ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
405ebd6efaeSSamuel Holland				-Os -std=gnu99
40673c99d4eSJuan Castillo
4071f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4081f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
4091f461979SJustin Chadwellendif
4101f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4111f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
4121f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
4131f461979SJustin Chadwellendif
4141f461979SJustin Chadwell
415f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
416f7ec31dbSdavid cunado
417641f16e7SAmbroise Vincent# LD = armlink
418c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
419c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
420c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
421edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
422641f16e7SAmbroise Vincent
423641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
424edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
425edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
426edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
427edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
428edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
429edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
430edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
431edbce9aaSzelalem-aweke	endif
432edbce9aaSzelalem-awekeendif
433edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
434edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
435edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
436edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
437edbce9aaSzelalem-awekeendif
438edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
439edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
440641f16e7SAmbroise Vincent
441641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
442c2ad38ceSVarun Wadekarelse
443c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
444c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
445641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
446641f16e7SAmbroise Vincent# therefore don't add those in that case
447641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
448c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
449edbce9aaSzelalem-awekeendif
450641f16e7SAmbroise Vincentendif
45173c99d4eSJuan Castillo
45203b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
453a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
454a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
45503b397a8SNishanth Menon
45673c99d4eSJuan Castillo################################################################################
45773c99d4eSJuan Castillo# Common sources and include directories
45873c99d4eSJuan Castillo################################################################################
4596a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
460d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
46173c99d4eSJuan Castillo
46273c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4637f56e9a3SSoby Mathew				common/tf_log.c				\
4649d29c227SSoby Mathew				common/${ARCH}/debug.S			\
46591b48c9fSJulius Werner				drivers/console/multi_console.c		\
4669d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4679d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
468566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4697f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
47075311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4719d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
47261f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
473d7a6b0f8SRyan Harkin
4748422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4758422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4768422a840SAntonio Nino Diazendif
4778422a840SAntonio Nino Diaz
4781f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4791f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
4801f461979SJustin Chadwellendif
4811f461979SJustin Chadwell
48201d237cbSYann GautierINCLUDES		+=	-Iinclude				\
483f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
48409d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
48509d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
48609d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
48709d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
48809d40e0eSAntonio Nino Diaz
4899c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4909c6d1c50SAntonio Nino Diaz
49173c99d4eSJuan Castillo################################################################################
49273c99d4eSJuan Castillo# Generic definitions
49373c99d4eSJuan Castillo################################################################################
49473c99d4eSJuan Castillo
495231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
496231c1470SEvan Lloyd
49729214e95SGrant Likelyifeq (${BUILD_BASE},)
49873c99d4eSJuan Castillo     BUILD_BASE		:=	./build
49929214e95SGrant Likelyendif
50029214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
50173c99d4eSJuan Castillo
502231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
50373c99d4eSJuan Castillo
50473c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
50573c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
50673c99d4eSJuan Castillo
50773c99d4eSJuan Castillo
50873c99d4eSJuan Castillo################################################################################
50973c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
51073c99d4eSJuan Castillo################################################################################
51173c99d4eSJuan Castillo
51273c99d4eSJuan Castilloifneq (${SPD},none)
5139d29c227SSoby Mathew    ifeq (${ARCH},aarch32)
5149d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
5159d29c227SSoby Mathew    endif
51628f39f02SMax Shvetsov
5174c117f6cSSandrine Bailleux    ifdef EL3_PAYLOAD_BASE
5184c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
5194c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
5204c117f6cSSandrine Bailleux    endif
52128f39f02SMax Shvetsov
522c3fb00d9SAchin Gupta    ifeq (${SPD},spmd)
523c3fb00d9SAchin Gupta        # SPMD is located in std_svc directory
524c3fb00d9SAchin Gupta        SPD_DIR := std_svc
52528f39f02SMax Shvetsov
526033039f8SMax Shvetsov        ifeq ($(SPMD_SPM_AT_SEL2),1)
52728f39f02SMax Shvetsov            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
528033039f8SMax Shvetsov                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
529033039f8SMax Shvetsov            endif
5301d63ae4dSMarc Bonnici	    ifeq ($(SPMC_AT_EL3),1)
5311d63ae4dSMarc Bonnici                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5321d63ae4dSMarc Bonnici            endif
53328f39f02SMax Shvetsov        endif
534db1ef41aSOlivier Deprez
535db1ef41aSOlivier Deprez        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
536db1ef41aSOlivier Deprez            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
537db1ef41aSOlivier Deprez        endif
538ca932481SDavidson K
539ca932481SDavidson K        ifeq ($(TS_SP_FW_CONFIG),1)
540ca932481SDavidson K            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
541ca932481SDavidson K        endif
54233993a37SBalint Dobszay
54333993a37SBalint Dobszay        ifneq ($(ARM_BL2_SP_LIST_DTS),)
54433993a37SBalint Dobszay            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
54533993a37SBalint Dobszay        endif
54646789a7cSBalint Dobszay
54746789a7cSBalint Dobszay        ifneq ($(SP_LAYOUT_FILE),)
54846789a7cSBalint Dobszay            BL2_ENABLE_SP_LOAD := 1
54946789a7cSBalint Dobszay        endif
550c3fb00d9SAchin Gupta    else
551c3fb00d9SAchin Gupta        # All other SPDs in spd directory
552c3fb00d9SAchin Gupta        SPD_DIR := spd
553c3fb00d9SAchin Gupta    endif
554c3fb00d9SAchin Gupta
55573c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
556c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
557c3fb00d9SAchin Gupta
55873c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
559c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
56073c99d4eSJuan Castillo    endif
56173c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
56273c99d4eSJuan Castillo    include ${SPD_MAKE}
56373c99d4eSJuan Castillo
56470d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
56570d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
56670d1fc53SJuan Castillo    # supports two mutually exclusive options:
56770d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
56870d1fc53SJuan Castillo    #   of source files to build BL32
56970d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
57070d1fc53SJuan Castillo    #   that will be included in the FIP
57170d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
57270d1fc53SJuan Castillo    # over the sources.
573e35c4045SJeenu Viswambharanendif
574e35c4045SJeenu Viswambharan
57551faada7SDouglas Raillard################################################################################
5765b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
5775b18de09SZelalem Aweke################################################################################
5785b18de09SZelalem Aweke
5795b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
5805b18de09SZelalem Awekeifneq (${ARCH},aarch64)
5815b18de09SZelalem Aweke	$(error ENABLE_RME requires AArch64)
5825b18de09SZelalem Awekeendif
5831d63ae4dSMarc Bonniciifeq ($(SPMC_AT_EL3),1)
5841d63ae4dSMarc Bonnici	$(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
5851d63ae4dSMarc Bonniciendif
5865b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
5875b18de09SZelalem Aweke$(warning "RME is an experimental feature")
5885b18de09SZelalem Awekeendif
5895b18de09SZelalem Aweke
5905b18de09SZelalem Aweke################################################################################
59173c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
59273c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
59373c99d4eSJuan Castillo################################################################################
5942da8d8bfSJeenu Viswambharan
59573c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
5960f21c547SJuan Castillo
5978012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
5988012cc5cSMasahiro Yamada
59926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
60026e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
60126e63c44SEtienne Carriereendif
60226e63c44SEtienne Carriere
6033bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6043bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6053bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6063bd17c0fSSoby Mathewendif
607320920c1SMasahiro Yamada
608320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
609320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
610320920c1SMasahiro Yamadaelse
611320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
612320920c1SMasahiro Yamadaendif
613320920c1SMasahiro Yamada
614320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
61569af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
61669af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
61769af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
61869af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
61969af7fcfSMasahiro Yamadaendif
62069af7fcfSMasahiro Yamadaendif
621320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
622320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
623d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
624d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
625d974301dSMasahiro Yamadaendif
6263bd17c0fSSoby Mathew
627d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
6289cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
629d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
6309cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
631d5e97a1dSMasahiro Yamadaelse
6329cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
633d5e97a1dSMasahiro Yamadaendif
6349cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
6359cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
6369cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
637d5e97a1dSMasahiro Yamadaendif
638d5e97a1dSMasahiro Yamada
63954035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
64054035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
64154035fc4SSandrine Bailleux# This can be overridden by the platform.
64273c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6434f6ad66aSAchin Gupta
644a4409008Sdp-armifeq (${ARCH},aarch32)
645a4409008Sdp-armNEED_BL32 := yes
646a4409008Sdp-arm
647a4409008Sdp-arm################################################################################
648a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
649a4409008Sdp-arm################################################################################
650a4409008Sdp-armifneq (${AARCH32_SP},none)
651a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
652a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
653a4409008Sdp-arm
654a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
655a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
656a4409008Sdp-armendif
657a4409008Sdp-arm
658a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
659a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
660a4409008Sdp-armendif
661a4409008Sdp-arm
662a4409008Sdp-armendif
6634f6ad66aSAchin Gupta
66473c99d4eSJuan Castillo################################################################################
66577f1f7a1SVarun Wadekar# Include libc if not overridden
66677f1f7a1SVarun Wadekar################################################################################
66777f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
66877f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
66977f1f7a1SVarun Wadekarendif
67077f1f7a1SVarun Wadekar
67177f1f7a1SVarun Wadekar################################################################################
672cf2c8a33SAntonio Nino Diaz# Check incompatible options
673cf2c8a33SAntonio Nino Diaz################################################################################
674cf2c8a33SAntonio Nino Diaz
675cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
67668450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
67768450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
67868450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
679cf2c8a33SAntonio Nino Diaz        endif
68076580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
68176580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
68276580f3dSQixiang Xu        endif
68376580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
68476580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
68576580f3dSQixiang Xu        endif
686cf2c8a33SAntonio Nino Diazendif
687cf2c8a33SAntonio Nino Diaz
688cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
689cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
690cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
691cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
692cf2c8a33SAntonio Nino Diaz        endif
69368450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
69468450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
69568450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
69668450a6dSAntonio Nino Diaz                file.")
697cf2c8a33SAntonio Nino Diaz        endif
698cf2c8a33SAntonio Nino Diazendif
699cf2c8a33SAntonio Nino Diaz
700d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
701d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
702d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
703d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
704d4593e47SJeenu Viswambharanendif
7051a0a3f06SYatharth Kochar
7067d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
7077d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
7087d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
7097d173fc5SJiafei Panendif
7107d173fc5SJiafei Pan
71114c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
71214c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
71314c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
71414c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
71514c6016aSJeenu Viswambharan    endif
71614c6016aSJeenu Viswambharanendif
71714c6016aSJeenu Viswambharan
7181a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
7191a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
7201a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
7211a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
7221a7c1cfeSJeenu Viswambharan    endif
7231a7c1cfeSJeenu Viswambharanendif
7241a7c1cfeSJeenu Viswambharan
725ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
726209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
727209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
728209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
729209a60ccSSoby Mathew    endif
730209a60ccSSoby Mathewendif
731209a60ccSSoby Mathew
732c9c56f6eSManish V Badarkheifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
733c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 1
734c9c56f6eSManish V Badarkheelse
735c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 0
736c9c56f6eSManish V Badarkheendif
737c9c56f6eSManish V Badarkhe
738cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
739cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
740700e7685SManish Pandey$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
74184ef9cd8SManish V Badarkheendif
74284ef9cd8SManish V Badarkhe
743b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7449fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7459fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
746b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7479fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7489fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
74906715f85SAlexei Fedorov    endif
7509fc59639SAlexei Fedorovendif
7519fc59639SAlexei Fedorov
75206715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7539fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7549fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
755b86048c4SAntonio Nino Diaz    endif
756b86048c4SAntonio Nino Diazendif
7579fc59639SAlexei Fedorov
7589dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7599dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7609dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7619dd94382SJustin Chadwell    endif
7629dd94382SJustin Chadwellendif
7639dd94382SJustin Chadwell
764396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
765396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
766396b339dSManish V Badarkheendif
767396b339dSManish V Badarkhe
7686a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
7696a0da736SJayanth Dodderi Chidanand    $(info FEATURE_DETECTION is an experimental feature)
7706a0da736SJayanth Dodderi Chidanandendif
7716a0da736SJayanth Dodderi Chidanand
77260e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
77360e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
77460e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
77560e8f3cfSPetre-Ionut Tudor    endif
77660e8f3cfSPetre-Ionut Tudorendif
77760e8f3cfSPetre-Ionut Tudor
7787cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7797cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7807cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7817cda17bbSSumit Garg    endif
7827cda17bbSSumit Gargendif
7837cda17bbSSumit Garg
784744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
785dc78e62dSjohpow01ifeq (${ARCH},aarch32)
786744ad974Sjohpow01
787744ad974Sjohpow01    # SME/SVE only supported on AArch64
788dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
789dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
790dc78e62dSjohpow01    endif
791dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
792dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
79324ab2c0aSYann Gautier        $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
794dc78e62dSjohpow01    endif
795744ad974Sjohpow01
796744ad974Sjohpow01    # BRBE is not supported in Aarch32
797744ad974Sjohpow01    ifeq (${ENABLE_BRBE_FOR_NS},1)
798744ad974Sjohpow01        $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
799744ad974Sjohpow01    endif
800744ad974Sjohpow01
801dc78e62dSjohpow01endif
802dc78e62dSjohpow01
803dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
804dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
805dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
806dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
807dc78e62dSjohpow01    endif
808dc78e62dSjohpow01endif
809dc78e62dSjohpow01
810dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
811dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
812dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},0)
813dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
814dc78e62dSjohpow01    endif
815dc78e62dSjohpow01endif
816dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
817dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
818dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
819dc78e62dSjohpow01    endif
820dc78e62dSjohpow01endif
821dc78e62dSjohpow01
822dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
823dc78e62dSjohpow01# its own context management including FPU registers.
824dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
825dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
826dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
827dc78e62dSjohpow01    endif
828dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
829dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
830dc78e62dSjohpow01        $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
831dc78e62dSjohpow01        $(warning "Forced ENABLE_SVE_FOR_NS=0")
832dc78e62dSjohpow01        override ENABLE_SVE_FOR_NS	:= 0
833dc78e62dSjohpow01    endif
834dc78e62dSjohpow01endif
835dc78e62dSjohpow01
836*00e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
837*00e28874SManish V Badarkhe    $(info DRTM_SUPPORT is an experimental feature)
838*00e28874SManish V Badarkheendif
839*00e28874SManish V Badarkhe
840cf2c8a33SAntonio Nino Diaz################################################################################
84173c99d4eSJuan Castillo# Process platform overrideable behaviour
84273c99d4eSJuan Castillo################################################################################
8434f6ad66aSAchin Gupta
8445f24ce96SManish Pandeyifdef BL1_SOURCES
8455f24ce96SManish PandeyNEED_BL1 := yes
8465f24ce96SManish Pandeyendif
8475f24ce96SManish Pandey
8485f24ce96SManish Pandeyifdef BL2_SOURCES
8495f24ce96SManish Pandey	NEED_BL2 := yes
8505f24ce96SManish Pandey
851bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
852bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
853cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
854cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
855cf2c8a33SAntonio Nino Diaz                # in the FIP file.
8564c117f6cSSandrine Bailleux                NEED_BL33		:=	no
857cf2c8a33SAntonio Nino Diaz        else
85868450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
859cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
860cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
861cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
862cf2c8a33SAntonio Nino Diaz                else
863cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
864cf2c8a33SAntonio Nino Diaz                endif
8654c117f6cSSandrine Bailleux        endif
86673c99d4eSJuan Castilloendif
8676f971622SJuan Castillo
8685f24ce96SManish Pandeyifdef BL2U_SOURCES
8695f24ce96SManish PandeyNEED_BL2U := yes
8705f24ce96SManish Pandeyendif
8715f24ce96SManish Pandey
8724d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
8734d045d0eSMasahiro Yamadaifdef SCP_BL2
8744d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
8754d045d0eSMasahiro Yamadaendif
8764d045d0eSMasahiro Yamada
8775744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
8785744e874SSoby Mathewifneq (${ARCH},aarch32)
8795744e874SSoby Mathew    ifdef BL31_SOURCES
8805744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
8815744e874SSoby Mathew        # put it in the FIP.
8825744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8835744e874SSoby Mathew            NEED_BL31 := yes
8845744e874SSoby Mathew        endif
8855744e874SSoby Mathew    endif
8865744e874SSoby Mathewendif
8875744e874SSoby Mathew
88873c99d4eSJuan Castillo# Process TBB related flags
8896f971622SJuan Castilloifneq (${GENERATE_COT},0)
89073c99d4eSJuan Castillo        # Common cert_create options
8916f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8926f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8930191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
894fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
895fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8960191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
897fd34e7baSJuan Castillo                endif
8986f971622SJuan Castillo        endif
89973c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
90073c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
90173c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
90273c99d4eSJuan Castillo        endif
9036f971622SJuan Castilloendif
9046f971622SJuan Castillo
9051c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
9061c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
9071c75d5dfSMasahiro Yamadaendif
9081c75d5dfSMasahiro Yamada
9095f24ce96SManish Pandeyifdef FDT_SOURCES
9105f24ce96SManish PandeyNEED_FDT := yes
9115f24ce96SManish Pandeyendif
9125f24ce96SManish Pandey
91373c99d4eSJuan Castillo################################################################################
91446e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
91546e5e035SMichalis Pappas################################################################################
91646e5e035SMichalis Pappas
91746e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
91846e5e035SMichalis Pappas
91946e5e035SMichalis Pappas################################################################################
920819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
92173c99d4eSJuan Castillo################################################################################
92273c99d4eSJuan Castillo
92373c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
92473c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
92542a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
92673c99d4eSJuan Castillo
92790aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
92890aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
92990aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
93090aa901fSSumit Garg
93173c99d4eSJuan Castillo# Variables for use with Firmware Image Package
932819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
933819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
93473c99d4eSJuan Castillo
93526010da1SAntonio Nino Diaz# Variables for use with sptool
93626010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
937822c7279SJ-AlvesSPTOOL			?=	${SPTOOLPATH}/sptool.py
938ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
93926010da1SAntonio Nino Diaz
9405accce5bSRoberto Vargas# Variables for use with ROMLIB
9415accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
9425accce5bSRoberto Vargas
943cfe83910SLouis Mayencourt# Variable for use with Python
944cfe83910SLouis MayencourtPYTHON			?=	python3
945cfe83910SLouis Mayencourt
946cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
947cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
948cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
949cfe83910SLouis Mayencourt
9506de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
9516de32378SMadhukar PappireddyDOCS_PATH		?=	docs
9526de32378SMadhukar Pappireddy
9531f1c0206SAbdul Halim, Muhammad Hadi Asyrafi# Defination of SIMICS flag
9541f1c0206SAbdul Halim, Muhammad Hadi AsyrafiSIMICS_BUILD	?=	0
9551f1c0206SAbdul Halim, Muhammad Hadi Asyrafi
9568a86052dSSoby Mathew################################################################################
9578a86052dSSoby Mathew# Include BL specific makefiles
9588a86052dSSoby Mathew################################################################################
9595f24ce96SManish Pandey
9605f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
9618a86052dSSoby Mathewinclude bl1/bl1.mk
9628a86052dSSoby Mathewendif
9638a86052dSSoby Mathew
9645f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
9658a86052dSSoby Mathewinclude bl2/bl2.mk
9668a86052dSSoby Mathewendif
9678a86052dSSoby Mathew
9685f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
9698a86052dSSoby Mathewinclude bl2u/bl2u.mk
9708a86052dSSoby Mathewendif
9718a86052dSSoby Mathew
9725744e874SSoby Mathewifeq (${NEED_BL31},yes)
9738a86052dSSoby Mathewinclude bl31/bl31.mk
9748a86052dSSoby Mathewendif
97503b397a8SNishanth Menon
97673c99d4eSJuan Castillo################################################################################
97773c99d4eSJuan Castillo# Build options checks
97873c99d4eSJuan Castillo################################################################################
97973c99d4eSJuan Castillo
980327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
981327131c4SLeonardo Sandoval    $(sort \
982327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
98346789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
984327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
985327131c4SLeonardo Sandoval        CREATE_KEYS \
986327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
987327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
988327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
989327131c4SLeonardo Sandoval        DEBUG \
9900063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
991327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
992327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
993327131c4SLeonardo Sandoval        ENABLE_AMU \
9941fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
995742ca230SChris Kay        ENABLE_AMU_FCONF \
996873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
997327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
998327131c4SLeonardo Sandoval        ENABLE_PIE \
999327131c4SLeonardo Sandoval        ENABLE_PMF \
1000327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
1001327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1002dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1003dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1004327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1005327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
10060c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1007327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1008327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1009327131c4SLeonardo Sandoval        GENERATE_COT \
1010327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1011327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1012327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1013327131c4SLeonardo Sandoval        INVERTED_MEMMAP \
1014327131c4SLeonardo Sandoval        MEASURED_BOOT \
1015*00e28874SManish V Badarkhe        DRTM_SUPPORT \
1016327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1017327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
1018327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
10190ce2072dSTamas Ban        PLAT_RSS_NOT_SUPPORTED \
1020327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1021327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1022327131c4SLeonardo Sandoval        RESET_TO_BL31 \
102325844ff7SJorge Ramirez-Ortiz        RESET_TO_BL31_WITH_PARAMS \
1024327131c4SLeonardo Sandoval        SAVE_KEYS \
1025327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
102696a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1027327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1028327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1029327131c4SLeonardo Sandoval        SPM_MM \
10301d63ae4dSMarc Bonnici        SPMC_AT_EL3 \
1031327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1032327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1033c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
1034327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1035327131c4SLeonardo Sandoval        USE_DEBUGFS \
1036327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1037327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1038327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1039327131c4SLeonardo Sandoval        USE_ROMLIB \
1040327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1041327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1042327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1043327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1044327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1045327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1046327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1047327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1048327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1049327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1050327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1051327131c4SLeonardo Sandoval        USE_SP804_TIMER \
1052396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1053744ad974Sjohpow01        ENABLE_BRBE_FOR_NS \
1054813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1055d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
105668120783SChris Kay        ENABLE_MPMM \
105768120783SChris Kay        ENABLE_MPMM_FCONF \
10581f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
10596a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1060327131c4SLeonardo Sandoval)))
106173c99d4eSJuan Castillo
1062327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1063327131c4SLeonardo Sandoval    $(sort \
1064327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1065327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1066327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
10676a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_PAUTH_REGS \
10686a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_MTE_REGS \
10696a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_NEVE_REGS \
10706a0da736SJayanth Dodderi Chidanand        ENABLE_BTI \
10716a0da736SJayanth Dodderi Chidanand        ENABLE_PAUTH \
10726a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
10736a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
10746a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
10756a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_DIT \
10766a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
10776a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
10786a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_HCX \
10796a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
10806a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_RNG \
10816a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SB \
10826a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
10836a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
10846a0da736SJayanth Dodderi Chidanand        ENABLE_MPAM_FOR_LOWER_ELS \
10856a0da736SJayanth Dodderi Chidanand        ENABLE_RME \
10866a0da736SJayanth Dodderi Chidanand        ENABLE_TRF_FOR_NS \
1087327131c4SLeonardo Sandoval        FW_ENC_STATUS \
10885357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10895357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
10906a0da736SJayanth Dodderi Chidanand        RAS_EXTENSION \
1091781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1092781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1093327131c4SLeonardo Sandoval)))
1094c877b414SJeenu Viswambharan
1095aacff749SJustin Chadwellifdef KEY_SIZE
1096aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1097aacff749SJustin Chadwellendif
1098aacff749SJustin Chadwell
10991f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
11001f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
11011f461979SJustin Chadwellendif
11021f461979SJustin Chadwell
110373c99d4eSJuan Castillo################################################################################
110473c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
110573c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
110673c99d4eSJuan Castillo# platform to overwrite the default options
110773c99d4eSJuan Castillo################################################################################
110873c99d4eSJuan Castillo
1109327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1110327131c4SLeonardo Sandoval    $(sort \
1111327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
1112327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1113327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
111446789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
1115327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1116327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1117327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1118327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1119327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1120327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1121327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1122062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1123327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
11240063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1125327131c4SLeonardo Sandoval        ENABLE_AMU \
11261fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
1127742ca230SChris Kay        ENABLE_AMU_FCONF \
1128873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1129327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1130327131c4SLeonardo Sandoval        ENABLE_BTI \
1131327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1132327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1133327131c4SLeonardo Sandoval        ENABLE_PIE \
1134327131c4SLeonardo Sandoval        ENABLE_PMF \
1135327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
11365b18de09SZelalem Aweke        ENABLE_RME \
1137327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1138dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1139dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1140327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1141327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
11420c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1143327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1144327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1145327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1146327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1147327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1148327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1149327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1150327131c4SLeonardo Sandoval        LOG_LEVEL \
1151327131c4SLeonardo Sandoval        MEASURED_BOOT \
1152*00e28874SManish V Badarkhe        DRTM_SUPPORT \
1153327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1154327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1155327131c4SLeonardo Sandoval        PLAT_${PLAT} \
11560ce2072dSTamas Ban        PLAT_RSS_NOT_SUPPORTED \
1157327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1158327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1159327131c4SLeonardo Sandoval        RAS_EXTENSION \
1160327131c4SLeonardo Sandoval        RESET_TO_BL31 \
116125844ff7SJorge Ramirez-Ortiz        RESET_TO_BL31_WITH_PARAMS \
1162327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
116396a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1164327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1165327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1166327131c4SLeonardo Sandoval        SPD_${SPD} \
1167327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1168327131c4SLeonardo Sandoval        SPM_MM \
11691d63ae4dSMarc Bonnici        SPMC_AT_EL3 \
1170327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1171327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1172c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
11737dfb9911SJimmy Brisson        TRNG_SUPPORT \
1174327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1175327131c4SLeonardo Sandoval        USE_DEBUGFS \
1176327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1177327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1178327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1179327131c4SLeonardo Sandoval        USE_ROMLIB \
1180327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1181327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1182327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1183327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1184327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1185327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1186327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1187327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1188327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1189327131c4SLeonardo Sandoval        USE_SP804_TIMER \
119012cd65e0STomas Pilar        ENABLE_FEAT_RNG \
11914e04478aSChris Kay        ENABLE_FEAT_SB \
11927d33ffe4SDaniel Boulby        ENABLE_FEAT_DIT \
11935357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
11945357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1195396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1196744ad974Sjohpow01        ENABLE_BRBE_FOR_NS \
1197813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1198d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
11998fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1200cb4ec47bSjohpow01        ENABLE_FEAT_HCX \
120168120783SChris Kay        ENABLE_MPMM \
120268120783SChris Kay        ENABLE_MPMM_FCONF \
1203f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
1204f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
1205f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
12061f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
12076a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
12086a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
12096a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
12106a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
12116a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
12126a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1213781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1214781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1215327131c4SLeonardo Sandoval)))
12162fae4b1eSJeenu Viswambharan
12171f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
12181f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
12191f461979SJustin Chadwellendif
12201f461979SJustin Chadwell
12214c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
12224c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
12234c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1224cf2c8a33SAntonio Nino Diazelse
122568450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
122668450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
122768450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
122868450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
12294c117f6cSSandrine Bailleux        endif
1230cf2c8a33SAntonio Nino Diazendif
123173c99d4eSJuan Castillo
1232209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1233209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1234209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1235209a60ccSSoby Mathewendif
1236209a60ccSSoby Mathew
1237c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1238c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1239c2ad38ceSVarun Wadekarendif
1240c2ad38ceSVarun Wadekar
1241ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1242ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1243c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1244ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1245ce2b1ec6SManish Pandey        FIP_DEPS += sp
124607c44475SManish Pandey        CRT_DEPS += sp
1247ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1248ce2b1ec6SManish Pandeyelse
1249c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1250c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1251c33ff198SOlivier Deprez        endif
1252ce2b1ec6SManish Pandeyendif
1253ce2b1ec6SManish Pandeyendif
1254ce2b1ec6SManish Pandey
125573c99d4eSJuan Castillo################################################################################
125673c99d4eSJuan Castillo# Build targets
125773c99d4eSJuan Castillo################################################################################
125873c99d4eSJuan Castillo
125990aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
126073c99d4eSJuan Castillo.SUFFIXES:
126173c99d4eSJuan Castillo
126273c99d4eSJuan Castilloall: msg_start
126373c99d4eSJuan Castillo
126473c99d4eSJuan Castillomsg_start:
126573c99d4eSJuan Castillo	@echo "Building ${PLAT}"
126673c99d4eSJuan Castillo
12677a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1268d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1269c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1270c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1271c2ad38ceSVarun Wadekarelse
1272bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
12737a24cba5SSoby Mathewendif
1274d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
12757a24cba5SSoby Mathew
12765accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
127761f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
12785fee0287SRoberto Vargas
127973c99d4eSJuan Castillo# Expand build macros for the different images
128073c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1281b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1282b34635a0SChris Kay
1283434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
128473c99d4eSJuan Castilloendif
128573c99d4eSJuan Castillo
128673c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1287c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1288c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1289c9b31ae8SRoberto Vargasendif
1290c9b31ae8SRoberto Vargas
1291eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1292eb1acfb6SChris Kay
129333950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1294434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
129573c99d4eSJuan Castilloendif
129673c99d4eSJuan Castillo
12974d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
129833950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
12994d045d0eSMasahiro Yamadaendif
13004d045d0eSMasahiro Yamada
130173c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
130273c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
130326d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
130426d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1305c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1306c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1307434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1308c6ba9b45SSumit Gargelse
130933950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1310434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
131173c99d4eSJuan Castilloendif
1312c6ba9b45SSumit Gargendif
131373c99d4eSJuan Castillo
131470d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1315c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
131670d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
131773c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
131826d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
131926d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
13209cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
13219cd15239SMasahiro Yamada
1322c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1323434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1324c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1325c6ba9b45SSumit Gargelse
1326434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
132733950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
132873c99d4eSJuan Castilloendif
1329c6ba9b45SSumit Gargendif
133073c99d4eSJuan Castillo
13315b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
13325b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
13335b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
13345b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
13355b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
13365b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
13375b18de09SZelalem Aweke
13385b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
13395b18de09SZelalem Aweke         $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
13405b18de09SZelalem Awekeendif
13415b18de09SZelalem Aweke
134273c99d4eSJuan Castillo# Add the BL33 image if required by the platform
134373c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
134433950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1345db6071c9SJuan Castilloendif
1346db6071c9SJuan Castillo
13479003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
134833950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1349434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
13509003fa0bSYatharth Kocharendif
13519003fa0bSYatharth Kochar
135203b397a8SNishanth Menon# Expand build macros for the different images
135303b397a8SNishanth Menonifeq (${NEED_FDT},yes)
135403b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
135503b397a8SNishanth Menonendif
135603b397a8SNishanth Menon
1357ce2b1ec6SManish Pandey# Add Secure Partition packages
1358ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1359ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
13601e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1361822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1362ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1363ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1364ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1365ce2b1ec6SManish Pandeyendif
1366ce2b1ec6SManish Pandey
136736eaaf37SIan Spraylocate-checkpatch:
136836eaaf37SIan Sprayifndef CHECKPATCH
136966079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
137036eaaf37SIan Sprayelse
137136eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
137266079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
137336eaaf37SIan Sprayendif
137436eaaf37SIan Sprayendif
137536eaaf37SIan Spray
13764f6ad66aSAchin Guptaclean:
13774f6ad66aSAchin Gupta	@echo "  CLEAN"
1378f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
137988a1cf1eSSami Mujawarifdef UNIX_MK
13802f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
138188a1cf1eSSami Mujawarelse
138288a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
138388a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
138488a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
138588a1cf1eSSami Mujawarendif
13866f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
138790aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
13885accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13894f6ad66aSAchin Gupta
1390eaaeece2SJames Morrisseyrealclean distclean:
1391eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1392f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1393f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
139488a1cf1eSSami Mujawarifdef UNIX_MK
13952f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
139688a1cf1eSSami Mujawarelse
139788a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
139888a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
139988a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
140088a1cf1eSSami Mujawarendif
1401e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
140290aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
14035accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
14044f6ad66aSAchin Gupta
140536eaaf37SIan Spraycheckcodebase:		locate-checkpatch
140636eaaf37SIan Spray	@echo "  CHECKING STYLE"
140736eaaf37SIan Spray	@if test -d .git ; then						\
14081ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
14091a41e8c1SDan Handley		while read GIT_FILE ;					\
14101a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
14111a41e8c1SDan Handley		done ;							\
141236eaaf37SIan Spray	else								\
14131a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
14141a41e8c1SDan Handley		 -not -iwholename "*build*"				\
14151a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
141661f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
14171a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
14181ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
14191a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
142036eaaf37SIan Spray	fi
142136eaaf37SIan Spray
142236eaaf37SIan Spraycheckpatch:		locate-checkpatch
142336eaaf37SIan Spray	@echo "  CHECKING STYLE"
142402a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
142502a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
142602a76d5fSYann Gautier	fi
142751d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
142877a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
142977a0a7f1SYann Gautier	do								\
143051d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
143151d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
143202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
143302a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
143451d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
143502a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
143602a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
143751d28937SAntonio Nino Diaz	done
143836eaaf37SIan Spray
143973c99d4eSJuan Castillocerttool: ${CRTTOOL}
144073c99d4eSJuan Castillo
1441a9812206SPali Rohár${CRTTOOL}: FORCE
1442fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} --no-print-directory -C ${CRTTOOLPATH}
1443f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14446f971622SJuan Castillo	@echo "Built $@ successfully"
1445f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14466f971622SJuan Castillo
14476f971622SJuan Castilloifneq (${GENERATE_COT},0)
144873c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
14496f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1450f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14516f971622SJuan Castillo	@echo "Built $@ successfully"
14526f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1453f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
145473c99d4eSJuan Castilloendif
145527713fb4SSoby Mathew
145673c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
14574727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1458819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1459819281eeSdp-arm	${Q}${FIPTOOL} info $@
1460f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14612f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1462f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1463f58ad36fSHarry Liebel
14640191262dSYatharth Kocharifneq (${GENERATE_COT},0)
14650191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
14660191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1467052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14680191262dSYatharth Kochar	@echo "Built $@ successfully"
14690191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1470052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14710191262dSYatharth Kocharendif
14720191262dSYatharth Kochar
14730191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
14744727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1475819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1476819281eeSdp-arm	${Q}${FIPTOOL} info $@
1477052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14780191262dSYatharth Kochar	@echo "Built $@ successfully"
1479052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14800191262dSYatharth Kochar
148173c99d4eSJuan Castillofiptool: ${FIPTOOL}
148273c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
14830191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
148473c99d4eSJuan Castillo
1485a9812206SPali Rohár${FIPTOOL}: FORCE
148688a1cf1eSSami Mujawarifdef UNIX_MK
14870a956f81SRoss Burton	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH}
148888a1cf1eSSami Mujawarelse
148988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
149088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
149188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
149288a1cf1eSSami Mujawarendif
1493f58ad36fSHarry Liebel
1494a9812206SPali Rohárromlib.bin: libraries FORCE
1495bbb24f61SJohn Tsichritzis	${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
14965accce5bSRoberto Vargas
1497cfe83910SLouis Mayencourt# Call print_memory_map tool
1498cfe83910SLouis Mayencourtmemmap: all
1499b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1500cfe83910SLouis Mayencourt
15016de32378SMadhukar Pappireddydoc:
15026de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
15036de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
15046de32378SMadhukar Pappireddy
150590aa901fSSumit Gargenctool: ${ENCTOOL}
150690aa901fSSumit Garg
1507a9812206SPali Rohár${ENCTOOL}: FORCE
1508fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
150990aa901fSSumit Garg	@${ECHO_BLANK_LINE}
151090aa901fSSumit Garg	@echo "Built $@ successfully"
151190aa901fSSumit Garg	@${ECHO_BLANK_LINE}
151290aa901fSSumit Garg
151335fab8c9SJoakim Bechcscope:
151435fab8c9SJoakim Bech	@echo "  CSCOPE"
151535fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
151635fab8c9SJoakim Bech	${Q}cscope -b -q -k
151735fab8c9SJoakim Bech
151872ee3314SRyan Harkinhelp:
15197c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
152072ee3314SRyan Harkin	@echo ""
152172ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
152208c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
152372ee3314SRyan Harkin	@echo ""
15247c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
15257c23126cSJohn Tsichritzis	@echo ""
15261b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
15271b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
15281b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
15291b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
15301b578596SSandrine Bailleux	@echo ""
153172ee3314SRyan Harkin	@echo "Supported Targets:"
15321b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
153336eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
15348aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
15359003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1536d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
15379d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
15389d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
153973c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
15401b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
15410191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
154236eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
154336eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
154436eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
154572ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
154635fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
154772ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
15486f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
154990aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1550f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1551ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
155226010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
155338c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1554cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
15556de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
155672ee3314SRyan Harkin	@echo ""
15571b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
155872ee3314SRyan Harkin	@echo ""
155972ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
156072ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1561a9812206SPali Rohár
1562a9812206SPali Rohár.PHONY: FORCE
1563a9812206SPali RohárFORCE:;
1564