xref: /rk3399_ARM-atf/Makefile (revision bebcf27f1c75f48cc129e8608cba113d0db32ef8)
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
1124c5d206SJayanth Dodderi ChidanandVERSION_MINOR			:= 7
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
3104466cf82SDaniel Boulby        TF_CFLAGS	+=	-g -gdwarf-4
3114466cf82SDaniel Boulby        ASFLAGS		+=	-g -Wa,-gdwarf-4
31232b209bfSAhmad Fatoum
31332b209bfSAhmad Fatoum        # Use LOG_LEVEL_INFO by default for debug builds
31432b209bfSAhmad Fatoum        LOG_LEVEL	:=	40
31532b209bfSAhmad Fatoumelse
31632b209bfSAhmad Fatoum        BUILD_TYPE	:=	release
31732b209bfSAhmad Fatoum        # Use LOG_LEVEL_NOTICE by default for release builds
31832b209bfSAhmad Fatoum        LOG_LEVEL	:=	20
31932b209bfSAhmad Fatoumendif
32032b209bfSAhmad Fatoum
321f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
322f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
323f1de4c8fSPeiyuan Song        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
324f1de4c8fSPeiyuan Songendif
325f1de4c8fSPeiyuan SongVERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
326f1de4c8fSPeiyuan Song
3278fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3288fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
3298fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3308fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
3318fd9d4d5SAntonio Nino Diazelse
3328fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
3338fd9d4d5SAntonio Nino Diazendif
3348fd9d4d5SAntonio Nino Diaz
335a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
336d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3379d29c227SSoby Mathew
3389fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3399fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
3409fc59639SAlexei Fedorovendif
3419fc59639SAlexei Fedorov
34226e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
343fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
344b86048c4SAntonio Nino Diaz
3459ab81b5eSJustin Chadwell# General warnings
3469ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
347b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
348ca661a00SMadhukar Pappireddy				-Wno-unused-parameter -Wredundant-decls
3499ab81b5eSJustin Chadwell
3509ab81b5eSJustin Chadwell# Additional warnings
3519ab81b5eSJustin Chadwell# Level 1
352e7c645b5SYann GautierWARNING1 := -Wextra
353e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
354e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
355e7c645b5SYann GautierWARNING1 += -Wold-style-definition
356e7c645b5SYann Gautier
357b7f6525dSJustin Chadwell# Level 2
358e7c645b5SYann GautierWARNING2 := -Waggregate-return
359e7c645b5SYann GautierWARNING2 += -Wcast-align
360e7c645b5SYann GautierWARNING2 += -Wnested-externs
361e7c645b5SYann Gautier
362e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
363e7c645b5SYann GautierWARNING3 += -Wcast-qual
364e7c645b5SYann GautierWARNING3 += -Wconversion
365e7c645b5SYann GautierWARNING3 += -Wpacked
366e7c645b5SYann GautierWARNING3 += -Wpointer-arith
367e7c645b5SYann GautierWARNING3 += -Wswitch-default
368e7c645b5SYann Gautier
369e7c645b5SYann Gautierifeq (${W},1)
3709ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
371e7c645b5SYann Gautierelse ifeq (${W},2)
3729ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
373e7c645b5SYann Gautierelse ifeq (${W},3)
3749ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
375e7c645b5SYann Gautierendif
376e7c645b5SYann Gautier
3779ab81b5eSJustin Chadwell# Compiler specific warnings
37800296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
37993c690ebSJustin Chadwell# not using clang
380d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
381d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
382d7b4cd41SJustin Chadwell				-Wlogical-op
38393c690ebSJustin Chadwellelse
38493c690ebSJustin Chadwell# using clang
385d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
386d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
38700296576SAmbroise Vincentendif
38800296576SAmbroise Vincent
3896336b07aSYann Gautierifneq (${E},0)
3906336b07aSYann GautierERRORS := -Werror
3916336b07aSYann Gautierendif
3926336b07aSYann Gautier
393ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3949ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
39559de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
396d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
39759de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
398ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
399ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
400ebd6efaeSSamuel Holland				-Os -std=gnu99
40173c99d4eSJuan Castillo
402*bebcf27fSMark Brown$(eval $(call add_define,SVE_VECTOR_LEN))
403*bebcf27fSMark Brown
4041f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4051f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
4061f461979SJustin Chadwellendif
4071f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4081f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
4091f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
4101f461979SJustin Chadwellendif
4111f461979SJustin Chadwell
412f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
413f7ec31dbSdavid cunado
414641f16e7SAmbroise Vincent# LD = armlink
415c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
416c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
417c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
418edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
419641f16e7SAmbroise Vincent
420641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
421edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
422edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
423edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
424edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
425edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
426edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
427edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
428edbce9aaSzelalem-aweke	endif
429edbce9aaSzelalem-awekeendif
430edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
431edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
432edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
433edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
434edbce9aaSzelalem-awekeendif
435edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
436edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
437641f16e7SAmbroise Vincent
438641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
439c2ad38ceSVarun Wadekarelse
440c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
441c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
442641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
443641f16e7SAmbroise Vincent# therefore don't add those in that case
444641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
445c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
446edbce9aaSzelalem-awekeendif
447641f16e7SAmbroise Vincentendif
44873c99d4eSJuan Castillo
44903b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
450a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
451a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
45203b397a8SNishanth Menon
45373c99d4eSJuan Castillo################################################################################
45473c99d4eSJuan Castillo# Common sources and include directories
45573c99d4eSJuan Castillo################################################################################
4566a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
457d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
45873c99d4eSJuan Castillo
45973c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4607f56e9a3SSoby Mathew				common/tf_log.c				\
4619d29c227SSoby Mathew				common/${ARCH}/debug.S			\
46291b48c9fSJulius Werner				drivers/console/multi_console.c		\
4639d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4649d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
465566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4667f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
46775311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4689d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
46961f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
470d7a6b0f8SRyan Harkin
4718422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4728422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4738422a840SAntonio Nino Diazendif
4748422a840SAntonio Nino Diaz
4751f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4761f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
4771f461979SJustin Chadwellendif
4781f461979SJustin Chadwell
47901d237cbSYann GautierINCLUDES		+=	-Iinclude				\
480f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
48109d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
48209d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
48309d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
48409d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
48509d40e0eSAntonio Nino Diaz
4869c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4879c6d1c50SAntonio Nino Diaz
48873c99d4eSJuan Castillo################################################################################
48973c99d4eSJuan Castillo# Generic definitions
49073c99d4eSJuan Castillo################################################################################
49173c99d4eSJuan Castillo
492231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
493231c1470SEvan Lloyd
49429214e95SGrant Likelyifeq (${BUILD_BASE},)
49573c99d4eSJuan Castillo     BUILD_BASE		:=	./build
49629214e95SGrant Likelyendif
49729214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
49873c99d4eSJuan Castillo
499231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
50073c99d4eSJuan Castillo
50173c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
50273c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
50373c99d4eSJuan Castillo
50473c99d4eSJuan Castillo
50573c99d4eSJuan Castillo################################################################################
50673c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
50773c99d4eSJuan Castillo################################################################################
50873c99d4eSJuan Castillo
50973c99d4eSJuan Castilloifneq (${SPD},none)
5109d29c227SSoby Mathew    ifeq (${ARCH},aarch32)
5119d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
5129d29c227SSoby Mathew    endif
51328f39f02SMax Shvetsov
5144c117f6cSSandrine Bailleux    ifdef EL3_PAYLOAD_BASE
5154c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
5164c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
5174c117f6cSSandrine Bailleux    endif
51828f39f02SMax Shvetsov
519c3fb00d9SAchin Gupta    ifeq (${SPD},spmd)
520c3fb00d9SAchin Gupta        # SPMD is located in std_svc directory
521c3fb00d9SAchin Gupta        SPD_DIR := std_svc
52228f39f02SMax Shvetsov
523033039f8SMax Shvetsov        ifeq ($(SPMD_SPM_AT_SEL2),1)
52428f39f02SMax Shvetsov            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
525033039f8SMax Shvetsov                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
526033039f8SMax Shvetsov            endif
5271d63ae4dSMarc Bonnici	    ifeq ($(SPMC_AT_EL3),1)
5281d63ae4dSMarc Bonnici                $(error SPM cannot be enabled in both S-EL2 and EL3.)
5291d63ae4dSMarc Bonnici            endif
53028f39f02SMax Shvetsov        endif
531db1ef41aSOlivier Deprez
532db1ef41aSOlivier Deprez        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
533db1ef41aSOlivier Deprez            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
534db1ef41aSOlivier Deprez        endif
535ca932481SDavidson K
536ca932481SDavidson K        ifeq ($(TS_SP_FW_CONFIG),1)
537ca932481SDavidson K            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
538ca932481SDavidson K        endif
53933993a37SBalint Dobszay
54033993a37SBalint Dobszay        ifneq ($(ARM_BL2_SP_LIST_DTS),)
54133993a37SBalint Dobszay            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
54233993a37SBalint Dobszay        endif
54346789a7cSBalint Dobszay
54446789a7cSBalint Dobszay        ifneq ($(SP_LAYOUT_FILE),)
54546789a7cSBalint Dobszay            BL2_ENABLE_SP_LOAD := 1
54646789a7cSBalint Dobszay        endif
547c3fb00d9SAchin Gupta    else
548c3fb00d9SAchin Gupta        # All other SPDs in spd directory
549c3fb00d9SAchin Gupta        SPD_DIR := spd
550c3fb00d9SAchin Gupta    endif
551c3fb00d9SAchin Gupta
55273c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
553c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
554c3fb00d9SAchin Gupta
55573c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
556c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
55773c99d4eSJuan Castillo    endif
55873c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
55973c99d4eSJuan Castillo    include ${SPD_MAKE}
56073c99d4eSJuan Castillo
56170d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
56270d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
56370d1fc53SJuan Castillo    # supports two mutually exclusive options:
56470d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
56570d1fc53SJuan Castillo    #   of source files to build BL32
56670d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
56770d1fc53SJuan Castillo    #   that will be included in the FIP
56870d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
56970d1fc53SJuan Castillo    # over the sources.
570e35c4045SJeenu Viswambharanendif
571e35c4045SJeenu Viswambharan
57251faada7SDouglas Raillard################################################################################
5735b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
5745b18de09SZelalem Aweke################################################################################
5755b18de09SZelalem Aweke
5765b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
5775b18de09SZelalem Awekeifneq (${ARCH},aarch64)
5785b18de09SZelalem Aweke	$(error ENABLE_RME requires AArch64)
5795b18de09SZelalem Awekeendif
5801d63ae4dSMarc Bonniciifeq ($(SPMC_AT_EL3),1)
5811d63ae4dSMarc Bonnici	$(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
5821d63ae4dSMarc Bonniciendif
5835b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
5845b18de09SZelalem Aweke$(warning "RME is an experimental feature")
5855b18de09SZelalem Awekeendif
5865b18de09SZelalem Aweke
5875b18de09SZelalem Aweke################################################################################
58873c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
58973c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
59073c99d4eSJuan Castillo################################################################################
5912da8d8bfSJeenu Viswambharan
59273c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
5930f21c547SJuan Castillo
5948012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
5958012cc5cSMasahiro Yamada
59626e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
59726e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
59826e63c44SEtienne Carriereendif
59926e63c44SEtienne Carriere
6003bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6013bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6023bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6033bd17c0fSSoby Mathewendif
604320920c1SMasahiro Yamada
605320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
606320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
607320920c1SMasahiro Yamadaelse
608320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
609320920c1SMasahiro Yamadaendif
610320920c1SMasahiro Yamada
611320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
61269af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
61369af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
61469af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
61569af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
61669af7fcfSMasahiro Yamadaendif
61769af7fcfSMasahiro Yamadaendif
618320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
619320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
620d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
621d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
622d974301dSMasahiro Yamadaendif
6233bd17c0fSSoby Mathew
624d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
6259cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
626d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
6279cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
628d5e97a1dSMasahiro Yamadaelse
6299cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
630d5e97a1dSMasahiro Yamadaendif
6319cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
6329cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
6339cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
634d5e97a1dSMasahiro Yamadaendif
635d5e97a1dSMasahiro Yamada
63654035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
63754035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
63854035fc4SSandrine Bailleux# This can be overridden by the platform.
63973c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6404f6ad66aSAchin Gupta
641a4409008Sdp-armifeq (${ARCH},aarch32)
642a4409008Sdp-armNEED_BL32 := yes
643a4409008Sdp-arm
644a4409008Sdp-arm################################################################################
645a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
646a4409008Sdp-arm################################################################################
647a4409008Sdp-armifneq (${AARCH32_SP},none)
648a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
649a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
650a4409008Sdp-arm
651a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
652a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
653a4409008Sdp-armendif
654a4409008Sdp-arm
655a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
656a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
657a4409008Sdp-armendif
658a4409008Sdp-arm
659a4409008Sdp-armendif
6604f6ad66aSAchin Gupta
66173c99d4eSJuan Castillo################################################################################
66277f1f7a1SVarun Wadekar# Include libc if not overridden
66377f1f7a1SVarun Wadekar################################################################################
66477f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
66577f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
66677f1f7a1SVarun Wadekarendif
66777f1f7a1SVarun Wadekar
66877f1f7a1SVarun Wadekar################################################################################
669cf2c8a33SAntonio Nino Diaz# Check incompatible options
670cf2c8a33SAntonio Nino Diaz################################################################################
671cf2c8a33SAntonio Nino Diaz
672cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
67368450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
67468450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
67568450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
676cf2c8a33SAntonio Nino Diaz        endif
67776580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
67876580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
67976580f3dSQixiang Xu        endif
68076580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
68176580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
68276580f3dSQixiang Xu        endif
683cf2c8a33SAntonio Nino Diazendif
684cf2c8a33SAntonio Nino Diaz
685cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
686cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
687cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
688cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
689cf2c8a33SAntonio Nino Diaz        endif
69068450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
69168450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
69268450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
69368450a6dSAntonio Nino Diaz                file.")
694cf2c8a33SAntonio Nino Diaz        endif
695cf2c8a33SAntonio Nino Diazendif
696cf2c8a33SAntonio Nino Diaz
697d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
698d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
699d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
700d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
701d4593e47SJeenu Viswambharanendif
7021a0a3f06SYatharth Kochar
7037d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
7047d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
7057d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
7067d173fc5SJiafei Panendif
7077d173fc5SJiafei Pan
70814c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
70914c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
71014c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
71114c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
71214c6016aSJeenu Viswambharan    endif
71314c6016aSJeenu Viswambharanendif
71414c6016aSJeenu Viswambharan
7151a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
7161a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
7171a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
7181a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
7191a7c1cfeSJeenu Viswambharan    endif
7201a7c1cfeSJeenu Viswambharanendif
7211a7c1cfeSJeenu Viswambharan
722ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
723209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
724209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
725209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
726209a60ccSSoby Mathew    endif
727209a60ccSSoby Mathewendif
728209a60ccSSoby Mathew
729c9c56f6eSManish V Badarkheifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
730c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 1
731c9c56f6eSManish V Badarkheelse
732c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 0
733c9c56f6eSManish V Badarkheendif
734c9c56f6eSManish V Badarkhe
735cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
736cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
737700e7685SManish Pandey$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
73884ef9cd8SManish V Badarkheendif
73984ef9cd8SManish V Badarkhe
740b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7419fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7429fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
743b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7449fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7459fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
74606715f85SAlexei Fedorov    endif
7479fc59639SAlexei Fedorovendif
7489fc59639SAlexei Fedorov
74906715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7509fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7519fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
752b86048c4SAntonio Nino Diaz    endif
753b86048c4SAntonio Nino Diazendif
7549fc59639SAlexei Fedorov
7559dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7569dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7579dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7589dd94382SJustin Chadwell    endif
7599dd94382SJustin Chadwellendif
7609dd94382SJustin Chadwell
761396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
762396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
763396b339dSManish V Badarkheendif
764396b339dSManish V Badarkhe
7656a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
7666a0da736SJayanth Dodderi Chidanand    $(info FEATURE_DETECTION is an experimental feature)
7676a0da736SJayanth Dodderi Chidanandendif
7686a0da736SJayanth Dodderi Chidanand
76960e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
77060e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
77160e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
77260e8f3cfSPetre-Ionut Tudor    endif
77360e8f3cfSPetre-Ionut Tudorendif
77460e8f3cfSPetre-Ionut Tudor
7757cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7767cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7777cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7787cda17bbSSumit Garg    endif
7797cda17bbSSumit Gargendif
7807cda17bbSSumit Garg
781744ad974Sjohpow01# Ensure that no Aarch64-only features are enabled in Aarch32 build
782dc78e62dSjohpow01ifeq (${ARCH},aarch32)
783744ad974Sjohpow01
784744ad974Sjohpow01    # SME/SVE only supported on AArch64
785dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
786dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
787dc78e62dSjohpow01    endif
788dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
789dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
79024ab2c0aSYann Gautier        $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
791dc78e62dSjohpow01    endif
792744ad974Sjohpow01
793744ad974Sjohpow01    # BRBE is not supported in Aarch32
794744ad974Sjohpow01    ifeq (${ENABLE_BRBE_FOR_NS},1)
795744ad974Sjohpow01        $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
796744ad974Sjohpow01    endif
797744ad974Sjohpow01
798dc78e62dSjohpow01endif
799dc78e62dSjohpow01
800dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
801dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
802dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
803dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
804dc78e62dSjohpow01    endif
805dc78e62dSjohpow01endif
806dc78e62dSjohpow01
807dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
808dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
809dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},0)
810dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
811dc78e62dSjohpow01    endif
812dc78e62dSjohpow01endif
813dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
814dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
815dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
816dc78e62dSjohpow01    endif
817dc78e62dSjohpow01endif
818dc78e62dSjohpow01
819dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
820dc78e62dSjohpow01# its own context management including FPU registers.
821dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
822dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
823dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
824dc78e62dSjohpow01    endif
825dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
826dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
827dc78e62dSjohpow01        $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
828dc78e62dSjohpow01        $(warning "Forced ENABLE_SVE_FOR_NS=0")
829dc78e62dSjohpow01        override ENABLE_SVE_FOR_NS	:= 0
830dc78e62dSjohpow01    endif
831dc78e62dSjohpow01endif
832dc78e62dSjohpow01
83300e28874SManish V Badarkheifeq ($(DRTM_SUPPORT),1)
83400e28874SManish V Badarkhe    $(info DRTM_SUPPORT is an experimental feature)
83500e28874SManish V Badarkheendif
83600e28874SManish V Badarkhe
837cf2c8a33SAntonio Nino Diaz################################################################################
83873c99d4eSJuan Castillo# Process platform overrideable behaviour
83973c99d4eSJuan Castillo################################################################################
8404f6ad66aSAchin Gupta
8415f24ce96SManish Pandeyifdef BL1_SOURCES
8425f24ce96SManish PandeyNEED_BL1 := yes
8435f24ce96SManish Pandeyendif
8445f24ce96SManish Pandey
8455f24ce96SManish Pandeyifdef BL2_SOURCES
8465f24ce96SManish Pandey	NEED_BL2 := yes
8475f24ce96SManish Pandey
848bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
849bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
850cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
851cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
852cf2c8a33SAntonio Nino Diaz                # in the FIP file.
8534c117f6cSSandrine Bailleux                NEED_BL33		:=	no
854cf2c8a33SAntonio Nino Diaz        else
85568450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
856cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
857cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
858cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
859cf2c8a33SAntonio Nino Diaz                else
860cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
861cf2c8a33SAntonio Nino Diaz                endif
8624c117f6cSSandrine Bailleux        endif
86373c99d4eSJuan Castilloendif
8646f971622SJuan Castillo
8655f24ce96SManish Pandeyifdef BL2U_SOURCES
8665f24ce96SManish PandeyNEED_BL2U := yes
8675f24ce96SManish Pandeyendif
8685f24ce96SManish Pandey
8694d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
8704d045d0eSMasahiro Yamadaifdef SCP_BL2
8714d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
8724d045d0eSMasahiro Yamadaendif
8734d045d0eSMasahiro Yamada
8745744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
8755744e874SSoby Mathewifneq (${ARCH},aarch32)
8765744e874SSoby Mathew    ifdef BL31_SOURCES
8775744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
8785744e874SSoby Mathew        # put it in the FIP.
8795744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8805744e874SSoby Mathew            NEED_BL31 := yes
8815744e874SSoby Mathew        endif
8825744e874SSoby Mathew    endif
8835744e874SSoby Mathewendif
8845744e874SSoby Mathew
88573c99d4eSJuan Castillo# Process TBB related flags
8866f971622SJuan Castilloifneq (${GENERATE_COT},0)
88773c99d4eSJuan Castillo        # Common cert_create options
8886f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8896f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8900191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
891fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
892fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8930191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
894fd34e7baSJuan Castillo                endif
8956f971622SJuan Castillo        endif
89673c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
89773c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
89873c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
89973c99d4eSJuan Castillo        endif
9006f971622SJuan Castilloendif
9016f971622SJuan Castillo
9021c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
9031c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
9041c75d5dfSMasahiro Yamadaendif
9051c75d5dfSMasahiro Yamada
9065f24ce96SManish Pandeyifdef FDT_SOURCES
9075f24ce96SManish PandeyNEED_FDT := yes
9085f24ce96SManish Pandeyendif
9095f24ce96SManish Pandey
91073c99d4eSJuan Castillo################################################################################
91146e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
91246e5e035SMichalis Pappas################################################################################
91346e5e035SMichalis Pappas
91446e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
91546e5e035SMichalis Pappas
91646e5e035SMichalis Pappas################################################################################
917819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
91873c99d4eSJuan Castillo################################################################################
91973c99d4eSJuan Castillo
92073c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
92173c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
92242a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
92373c99d4eSJuan Castillo
92490aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
92590aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
92690aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
92790aa901fSSumit Garg
92873c99d4eSJuan Castillo# Variables for use with Firmware Image Package
929819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
930819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
93173c99d4eSJuan Castillo
93226010da1SAntonio Nino Diaz# Variables for use with sptool
93326010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
934822c7279SJ-AlvesSPTOOL			?=	${SPTOOLPATH}/sptool.py
935ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
93626010da1SAntonio Nino Diaz
9375accce5bSRoberto Vargas# Variables for use with ROMLIB
9385accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
9395accce5bSRoberto Vargas
940cfe83910SLouis Mayencourt# Variable for use with Python
941cfe83910SLouis MayencourtPYTHON			?=	python3
942cfe83910SLouis Mayencourt
943cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
944cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
945cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
946cfe83910SLouis Mayencourt
9476de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
9486de32378SMadhukar PappireddyDOCS_PATH		?=	docs
9496de32378SMadhukar Pappireddy
9501f1c0206SAbdul Halim, Muhammad Hadi Asyrafi# Defination of SIMICS flag
9511f1c0206SAbdul Halim, Muhammad Hadi AsyrafiSIMICS_BUILD	?=	0
9521f1c0206SAbdul Halim, Muhammad Hadi Asyrafi
9538a86052dSSoby Mathew################################################################################
9548a86052dSSoby Mathew# Include BL specific makefiles
9558a86052dSSoby Mathew################################################################################
9565f24ce96SManish Pandey
9575f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
9588a86052dSSoby Mathewinclude bl1/bl1.mk
9598a86052dSSoby Mathewendif
9608a86052dSSoby Mathew
9615f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
9628a86052dSSoby Mathewinclude bl2/bl2.mk
9638a86052dSSoby Mathewendif
9648a86052dSSoby Mathew
9655f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
9668a86052dSSoby Mathewinclude bl2u/bl2u.mk
9678a86052dSSoby Mathewendif
9688a86052dSSoby Mathew
9695744e874SSoby Mathewifeq (${NEED_BL31},yes)
9708a86052dSSoby Mathewinclude bl31/bl31.mk
9718a86052dSSoby Mathewendif
97203b397a8SNishanth Menon
97373c99d4eSJuan Castillo################################################################################
97473c99d4eSJuan Castillo# Build options checks
97573c99d4eSJuan Castillo################################################################################
97673c99d4eSJuan Castillo
977327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
978327131c4SLeonardo Sandoval    $(sort \
979327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
98046789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
981327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
982327131c4SLeonardo Sandoval        CREATE_KEYS \
983327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
984327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
985327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
986327131c4SLeonardo Sandoval        DEBUG \
9870063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
988327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
989327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
990327131c4SLeonardo Sandoval        ENABLE_AMU \
9911fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
992742ca230SChris Kay        ENABLE_AMU_FCONF \
993873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
994327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
995327131c4SLeonardo Sandoval        ENABLE_PIE \
996327131c4SLeonardo Sandoval        ENABLE_PMF \
997327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
998327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
999dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1000dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1001327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1002327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
10030c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1004327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1005327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1006327131c4SLeonardo Sandoval        GENERATE_COT \
1007327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1008327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1009327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1010327131c4SLeonardo Sandoval        INVERTED_MEMMAP \
1011327131c4SLeonardo Sandoval        MEASURED_BOOT \
101200e28874SManish V Badarkhe        DRTM_SUPPORT \
1013327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1014327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
1015327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
10160ce2072dSTamas Ban        PLAT_RSS_NOT_SUPPORTED \
1017327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1018327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1019327131c4SLeonardo Sandoval        RESET_TO_BL31 \
102025844ff7SJorge Ramirez-Ortiz        RESET_TO_BL31_WITH_PARAMS \
1021327131c4SLeonardo Sandoval        SAVE_KEYS \
1022327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
102396a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1024327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1025327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1026327131c4SLeonardo Sandoval        SPM_MM \
10271d63ae4dSMarc Bonnici        SPMC_AT_EL3 \
1028327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1029327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1030c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
1031327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1032327131c4SLeonardo Sandoval        USE_DEBUGFS \
1033327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1034327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1035327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1036327131c4SLeonardo Sandoval        USE_ROMLIB \
1037327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1038327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1039327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1040327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1041327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1042327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1043327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1044327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1045327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1046327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1047327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1048327131c4SLeonardo Sandoval        USE_SP804_TIMER \
1049396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1050d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
105168120783SChris Kay        ENABLE_MPMM \
105268120783SChris Kay        ENABLE_MPMM_FCONF \
10531f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
10546a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1055327131c4SLeonardo Sandoval)))
105673c99d4eSJuan Castillo
1057327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1058327131c4SLeonardo Sandoval    $(sort \
1059327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1060327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1061327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
10626a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_PAUTH_REGS \
10636a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_MTE_REGS \
10646a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_NEVE_REGS \
10651298f2f1SJayanth Dodderi Chidanand        ENABLE_BRBE_FOR_NS \
106647c681b7SJayanth Dodderi Chidanand        ENABLE_TRBE_FOR_NS \
10676a0da736SJayanth Dodderi Chidanand        ENABLE_BTI \
10686a0da736SJayanth Dodderi Chidanand        ENABLE_PAUTH \
10696a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
10706a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
10716a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
10726a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_DIT \
10736a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
10746a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
10756a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_HCX \
10766a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
10776a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_RNG \
10786a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SB \
10796a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
10806a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
10816a0da736SJayanth Dodderi Chidanand        ENABLE_MPAM_FOR_LOWER_ELS \
10826a0da736SJayanth Dodderi Chidanand        ENABLE_RME \
10836a0da736SJayanth Dodderi Chidanand        ENABLE_TRF_FOR_NS \
1084327131c4SLeonardo Sandoval        FW_ENC_STATUS \
10855357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10865357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
10876a0da736SJayanth Dodderi Chidanand        RAS_EXTENSION \
1088781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1089781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1090*bebcf27fSMark Brown        SVE_VECTOR_LEN \
1091327131c4SLeonardo Sandoval)))
1092c877b414SJeenu Viswambharan
1093aacff749SJustin Chadwellifdef KEY_SIZE
1094aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1095aacff749SJustin Chadwellendif
1096aacff749SJustin Chadwell
10971f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
10981f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
10991f461979SJustin Chadwellendif
11001f461979SJustin Chadwell
110173c99d4eSJuan Castillo################################################################################
110273c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
110373c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
110473c99d4eSJuan Castillo# platform to overwrite the default options
110573c99d4eSJuan Castillo################################################################################
110673c99d4eSJuan Castillo
1107327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1108327131c4SLeonardo Sandoval    $(sort \
1109327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
1110327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1111327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
111246789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
1113327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1114327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1115327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1116327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1117327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1118327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1119327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1120062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1121327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
11220063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1123327131c4SLeonardo Sandoval        ENABLE_AMU \
11241fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
1125742ca230SChris Kay        ENABLE_AMU_FCONF \
1126873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1127327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1128327131c4SLeonardo Sandoval        ENABLE_BTI \
1129327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1130327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1131327131c4SLeonardo Sandoval        ENABLE_PIE \
1132327131c4SLeonardo Sandoval        ENABLE_PMF \
1133327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
11345b18de09SZelalem Aweke        ENABLE_RME \
1135327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1136dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1137dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1138327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1139327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
11400c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1141327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1142327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1143327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1144327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1145327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1146327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1147327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1148327131c4SLeonardo Sandoval        LOG_LEVEL \
1149327131c4SLeonardo Sandoval        MEASURED_BOOT \
115000e28874SManish V Badarkhe        DRTM_SUPPORT \
1151327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1152327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1153327131c4SLeonardo Sandoval        PLAT_${PLAT} \
11540ce2072dSTamas Ban        PLAT_RSS_NOT_SUPPORTED \
1155327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1156327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1157327131c4SLeonardo Sandoval        RAS_EXTENSION \
1158327131c4SLeonardo Sandoval        RESET_TO_BL31 \
115925844ff7SJorge Ramirez-Ortiz        RESET_TO_BL31_WITH_PARAMS \
1160327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
116196a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1162327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1163327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1164327131c4SLeonardo Sandoval        SPD_${SPD} \
1165327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1166327131c4SLeonardo Sandoval        SPM_MM \
11671d63ae4dSMarc Bonnici        SPMC_AT_EL3 \
1168327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1169327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1170c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
11717dfb9911SJimmy Brisson        TRNG_SUPPORT \
1172327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1173327131c4SLeonardo Sandoval        USE_DEBUGFS \
1174327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1175327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1176327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1177327131c4SLeonardo Sandoval        USE_ROMLIB \
1178327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1179327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1180327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1181327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1182327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1183327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1184327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1185327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1186327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1187327131c4SLeonardo Sandoval        USE_SP804_TIMER \
118812cd65e0STomas Pilar        ENABLE_FEAT_RNG \
11894e04478aSChris Kay        ENABLE_FEAT_SB \
11907d33ffe4SDaniel Boulby        ENABLE_FEAT_DIT \
11915357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
11925357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1193396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1194744ad974Sjohpow01        ENABLE_BRBE_FOR_NS \
1195813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1196d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
11978fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1198cb4ec47bSjohpow01        ENABLE_FEAT_HCX \
119968120783SChris Kay        ENABLE_MPMM \
120068120783SChris Kay        ENABLE_MPMM_FCONF \
1201f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
1202f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
1203f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
12041f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
12056a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
12066a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
12076a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
12086a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
12096a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
12106a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1211781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1212781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1213327131c4SLeonardo Sandoval)))
12142fae4b1eSJeenu Viswambharan
12151f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
12161f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
12171f461979SJustin Chadwellendif
12181f461979SJustin Chadwell
12194c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
12204c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
12214c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1222cf2c8a33SAntonio Nino Diazelse
122368450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
122468450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
122568450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
122668450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
12274c117f6cSSandrine Bailleux        endif
1228cf2c8a33SAntonio Nino Diazendif
122973c99d4eSJuan Castillo
1230209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1231209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1232209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1233209a60ccSSoby Mathewendif
1234209a60ccSSoby Mathew
1235c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1236c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1237c2ad38ceSVarun Wadekarendif
1238c2ad38ceSVarun Wadekar
1239ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1240ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1241c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1242ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1243ce2b1ec6SManish Pandey        FIP_DEPS += sp
124407c44475SManish Pandey        CRT_DEPS += sp
1245ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1246ce2b1ec6SManish Pandeyelse
1247c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1248c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1249c33ff198SOlivier Deprez        endif
1250ce2b1ec6SManish Pandeyendif
1251ce2b1ec6SManish Pandeyendif
1252ce2b1ec6SManish Pandey
125373c99d4eSJuan Castillo################################################################################
125473c99d4eSJuan Castillo# Build targets
125573c99d4eSJuan Castillo################################################################################
125673c99d4eSJuan Castillo
125790aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
125873c99d4eSJuan Castillo.SUFFIXES:
125973c99d4eSJuan Castillo
126073c99d4eSJuan Castilloall: msg_start
126173c99d4eSJuan Castillo
126273c99d4eSJuan Castillomsg_start:
126373c99d4eSJuan Castillo	@echo "Building ${PLAT}"
126473c99d4eSJuan Castillo
12657a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1266d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1267c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1268c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1269c2ad38ceSVarun Wadekarelse
1270bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
12717a24cba5SSoby Mathewendif
1272d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
12737a24cba5SSoby Mathew
12745accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
127561f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
12765fee0287SRoberto Vargas
127773c99d4eSJuan Castillo# Expand build macros for the different images
127873c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1279b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1280b34635a0SChris Kay
1281434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
128273c99d4eSJuan Castilloendif
128373c99d4eSJuan Castillo
128473c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1285c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1286c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1287c9b31ae8SRoberto Vargasendif
1288c9b31ae8SRoberto Vargas
1289eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1290eb1acfb6SChris Kay
129133950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1292434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
129373c99d4eSJuan Castilloendif
129473c99d4eSJuan Castillo
12954d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
129633950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
12974d045d0eSMasahiro Yamadaendif
12984d045d0eSMasahiro Yamada
129973c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
130073c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
130126d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
130226d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1303c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1304c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1305434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1306c6ba9b45SSumit Gargelse
130733950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1308434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
130973c99d4eSJuan Castilloendif
1310c6ba9b45SSumit Gargendif
131173c99d4eSJuan Castillo
131270d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1313c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
131470d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
131573c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
131626d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
131726d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
13189cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
13199cd15239SMasahiro Yamada
1320c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1321434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1322c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1323c6ba9b45SSumit Gargelse
1324434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
132533950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
132673c99d4eSJuan Castilloendif
1327c6ba9b45SSumit Gargendif
132873c99d4eSJuan Castillo
13295b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
13305b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
13315b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
13325b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
13335b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
13345b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
13355b18de09SZelalem Aweke
13365b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
13375b18de09SZelalem Aweke         $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
13385b18de09SZelalem Awekeendif
13395b18de09SZelalem Aweke
134073c99d4eSJuan Castillo# Add the BL33 image if required by the platform
134173c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
134233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1343db6071c9SJuan Castilloendif
1344db6071c9SJuan Castillo
13459003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
134633950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1347434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
13489003fa0bSYatharth Kocharendif
13499003fa0bSYatharth Kochar
135003b397a8SNishanth Menon# Expand build macros for the different images
135103b397a8SNishanth Menonifeq (${NEED_FDT},yes)
135203b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
135303b397a8SNishanth Menonendif
135403b397a8SNishanth Menon
1355ce2b1ec6SManish Pandey# Add Secure Partition packages
1356ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1357ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
13581e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1359822c7279SJ-Alvessp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1360ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1361ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1362ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1363ce2b1ec6SManish Pandeyendif
1364ce2b1ec6SManish Pandey
136536eaaf37SIan Spraylocate-checkpatch:
136636eaaf37SIan Sprayifndef CHECKPATCH
136766079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
136836eaaf37SIan Sprayelse
136936eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
137066079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
137136eaaf37SIan Sprayendif
137236eaaf37SIan Sprayendif
137336eaaf37SIan Spray
13744f6ad66aSAchin Guptaclean:
13754f6ad66aSAchin Gupta	@echo "  CLEAN"
1376f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
137788a1cf1eSSami Mujawarifdef UNIX_MK
13782f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
137988a1cf1eSSami Mujawarelse
138088a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
138188a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
138288a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
138388a1cf1eSSami Mujawarendif
13846f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
138590aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
13865accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13874f6ad66aSAchin Gupta
1388eaaeece2SJames Morrisseyrealclean distclean:
1389eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1390f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1391f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
139288a1cf1eSSami Mujawarifdef UNIX_MK
13932f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
139488a1cf1eSSami Mujawarelse
139588a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
139688a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
139788a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
139888a1cf1eSSami Mujawarendif
1399e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
140090aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
14015accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
14024f6ad66aSAchin Gupta
140336eaaf37SIan Spraycheckcodebase:		locate-checkpatch
140436eaaf37SIan Spray	@echo "  CHECKING STYLE"
140536eaaf37SIan Spray	@if test -d .git ; then						\
14061ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
14071a41e8c1SDan Handley		while read GIT_FILE ;					\
14081a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
14091a41e8c1SDan Handley		done ;							\
141036eaaf37SIan Spray	else								\
14111a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
14121a41e8c1SDan Handley		 -not -iwholename "*build*"				\
14131a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
141461f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
14151a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
14161ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
14171a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
141836eaaf37SIan Spray	fi
141936eaaf37SIan Spray
142036eaaf37SIan Spraycheckpatch:		locate-checkpatch
142136eaaf37SIan Spray	@echo "  CHECKING STYLE"
142202a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
142302a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
142402a76d5fSYann Gautier	fi
142551d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
142677a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
142777a0a7f1SYann Gautier	do								\
142851d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
142951d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
143002a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
143102a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
143251d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
143302a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
143402a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
143551d28937SAntonio Nino Diaz	done
143636eaaf37SIan Spray
143773c99d4eSJuan Castillocerttool: ${CRTTOOL}
143873c99d4eSJuan Castillo
1439a9812206SPali Rohár${CRTTOOL}: FORCE
1440fafd3ec9SManish 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}
1441f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14426f971622SJuan Castillo	@echo "Built $@ successfully"
1443f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14446f971622SJuan Castillo
14456f971622SJuan Castilloifneq (${GENERATE_COT},0)
144673c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
14476f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1448f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14496f971622SJuan Castillo	@echo "Built $@ successfully"
14506f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1451f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
145273c99d4eSJuan Castilloendif
145327713fb4SSoby Mathew
145473c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
14554727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1456819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1457819281eeSdp-arm	${Q}${FIPTOOL} info $@
1458f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14592f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1460f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1461f58ad36fSHarry Liebel
14620191262dSYatharth Kocharifneq (${GENERATE_COT},0)
14630191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
14640191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1465052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14660191262dSYatharth Kochar	@echo "Built $@ successfully"
14670191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1468052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14690191262dSYatharth Kocharendif
14700191262dSYatharth Kochar
14710191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
14724727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1473819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1474819281eeSdp-arm	${Q}${FIPTOOL} info $@
1475052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14760191262dSYatharth Kochar	@echo "Built $@ successfully"
1477052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14780191262dSYatharth Kochar
147973c99d4eSJuan Castillofiptool: ${FIPTOOL}
148073c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
14810191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
148273c99d4eSJuan Castillo
1483a9812206SPali Rohár${FIPTOOL}: FORCE
148488a1cf1eSSami Mujawarifdef UNIX_MK
14850a956f81SRoss Burton	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH}
148688a1cf1eSSami Mujawarelse
148788a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
148888a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
148988a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
149088a1cf1eSSami Mujawarendif
1491f58ad36fSHarry Liebel
1492a9812206SPali Rohárromlib.bin: libraries FORCE
1493bbb24f61SJohn 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
14945accce5bSRoberto Vargas
1495cfe83910SLouis Mayencourt# Call print_memory_map tool
1496cfe83910SLouis Mayencourtmemmap: all
1497b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1498cfe83910SLouis Mayencourt
14996de32378SMadhukar Pappireddydoc:
15006de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
15016de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
15026de32378SMadhukar Pappireddy
150390aa901fSSumit Gargenctool: ${ENCTOOL}
150490aa901fSSumit Garg
1505a9812206SPali Rohár${ENCTOOL}: FORCE
1506fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
150790aa901fSSumit Garg	@${ECHO_BLANK_LINE}
150890aa901fSSumit Garg	@echo "Built $@ successfully"
150990aa901fSSumit Garg	@${ECHO_BLANK_LINE}
151090aa901fSSumit Garg
151135fab8c9SJoakim Bechcscope:
151235fab8c9SJoakim Bech	@echo "  CSCOPE"
151335fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
151435fab8c9SJoakim Bech	${Q}cscope -b -q -k
151535fab8c9SJoakim Bech
151672ee3314SRyan Harkinhelp:
15177c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
151872ee3314SRyan Harkin	@echo ""
151972ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
152008c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
152172ee3314SRyan Harkin	@echo ""
15227c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
15237c23126cSJohn Tsichritzis	@echo ""
15241b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
15251b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
15261b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
15271b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
15281b578596SSandrine Bailleux	@echo ""
152972ee3314SRyan Harkin	@echo "Supported Targets:"
15301b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
153136eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
15328aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
15339003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1534d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
15359d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
15369d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
153773c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
15381b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
15390191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
154036eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
154136eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
154236eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
154372ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
154435fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
154572ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
15466f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
154790aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1548f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1549ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
155026010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
155138c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1552cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
15536de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
155472ee3314SRyan Harkin	@echo ""
15551b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
155672ee3314SRyan Harkin	@echo ""
155772ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
155872ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1559a9812206SPali Rohár
1560a9812206SPali Rohár.PHONY: FORCE
1561a9812206SPali RohárFORCE:;
1562