xref: /rk3399_ARM-atf/Makefile (revision 1f1c0206d8513e07a64b84b374b461c3db61b49c)
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
1385b18de09SZelalem Aweke# RME requires AARCH64
1395b18de09SZelalem Awekeifneq (${ARCH},aarch64)
1405b18de09SZelalem Aweke        $(error ENABLE_RME requires AArch64)
1415b18de09SZelalem Awekeendif
1425b18de09SZelalem Aweke# RME requires el2 context to be saved for now.
1435b18de09SZelalem AwekeCTX_INCLUDE_EL2_REGS := 1
1445b18de09SZelalem AwekeCTX_INCLUDE_AARCH32_REGS := 0
1455b18de09SZelalem AwekeARM_ARCH_MAJOR := 8
1465b18de09SZelalem AwekeARM_ARCH_MINOR := 6
1475b18de09SZelalem Awekeendif
1485b18de09SZelalem Aweke
149c97cba4eSSoby Mathew# USE_SPINLOCK_CAS requires AArch64 build
150c97cba4eSSoby Mathewifeq (${USE_SPINLOCK_CAS},1)
151c97cba4eSSoby Mathewifneq (${ARCH},aarch64)
152c97cba4eSSoby Mathew        $(error USE_SPINLOCK_CAS requires AArch64)
153c97cba4eSSoby Mathewendif
154c97cba4eSSoby Mathewendif
155c97cba4eSSoby Mathew
1560ca3913dSOlivier Deprez# USE_DEBUGFS experimental feature recommended only in debug builds
1570ca3913dSOlivier Deprezifeq (${USE_DEBUGFS},1)
1580ca3913dSOlivier Deprezifeq (${DEBUG},1)
1590ca3913dSOlivier Deprez        $(warning DEBUGFS experimental feature is enabled.)
1600ca3913dSOlivier Deprezelse
1610ca3913dSOlivier Deprez        $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
1620ca3913dSOlivier Deprezendif
1630ca3913dSOlivier Deprezendif
1640ca3913dSOlivier Deprez
165c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
166c6ba9b45SSumit GargENC_ARGS += -f ${FW_ENC_STATUS}
167c6ba9b45SSumit GargENC_ARGS += -k ${ENC_KEY}
168c6ba9b45SSumit GargENC_ARGS += -n ${ENC_NONCE}
169c6ba9b45SSumit GargFIP_DEPS += enctool
170c6ba9b45SSumit GargFWU_FIP_DEPS += enctool
171c6ba9b45SSumit Gargendif
172c6ba9b45SSumit Garg
17373c99d4eSJuan Castillo################################################################################
17473c99d4eSJuan Castillo# Toolchain
17573c99d4eSJuan Castillo################################################################################
17673c99d4eSJuan Castillo
17772610c41Sdp-armHOSTCC			:=	gcc
17872610c41Sdp-armexport HOSTCC
17972610c41Sdp-arm
18073c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
18173c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
18273c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
18373c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1842adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
18573c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
18673c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
18773c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
18873c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
18938c14d88SSoby MathewDTC			:=	dtc
19073c99d4eSJuan Castillo
191b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
192b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1932adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1942adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
195b25a577fSJulius Wernerendif
196b25a577fSJulius Werner
19726e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
19826e63c44SEtienne Carrieretarget32-directive	= 	-target arm-none-eabi
19926e63c44SEtienne Carriere# Will set march32-directive from platform configuration
20026e63c44SEtienne Carriereelse
20126e63c44SEtienne Carrieretarget32-directive	= 	-target armv8a-none-eabi
202fa6f774bSAlexei Fedorov
203f1821790SAlexei Fedorov# Set the compiler's target architecture profile based on
204f1821790SAlexei Fedorov# ARM_ARCH_MAJOR ARM_ARCH_MINOR options
205fa6f774bSAlexei Fedorovifeq (${ARM_ARCH_MINOR},0)
206f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
207f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
208fa6f774bSAlexei Fedorovelse
209f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
210f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
211fa6f774bSAlexei Fedorovendif
21226e63c44SEtienne Carriereendif
21326e63c44SEtienne Carriere
2147ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2157ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2164a565bd8SSami Mujawar# Check if revision is greater than or equal to 8.5
2174a565bd8SSami Mujawarifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2187ff088d1SManish V Badarkhemem_tag_arch_support	= 	yes
2197ff088d1SManish V Badarkheendif
2207ff088d1SManish V Badarkheendif
2217ff088d1SManish V Badarkhe
222f1821790SAlexei Fedorov# Get architecture feature modifiers
223f1821790SAlexei Fedorovarch-features		=	${ARM_ARCH_FEATURE}
224f1821790SAlexei Fedorov
225f1821790SAlexei Fedorov# Enable required options for memory stack tagging.
226f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2277ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2287ff088d1SManish V Badarkheifdef mem_tag_arch_support
229f1821790SAlexei Fedorov# Check for armclang and clang compilers
2307ff088d1SManish V Badarkheifneq ( ,$(filter $(notdir $(CC)),armclang clang))
231f1821790SAlexei Fedorov# Add "memtag" architecture feature modifier if not specified
232f1821790SAlexei Fedorovifeq ( ,$(findstring memtag,$(arch-features)))
233f1821790SAlexei Fedorovarch-features       	:=       $(arch-features)+memtag
234f1821790SAlexei Fedorovendif	# memtag
2357ff088d1SManish V Badarkheifeq ($(notdir $(CC)),armclang)
2367ff088d1SManish V BadarkheTF_CFLAGS		+=	-mmemtag-stack
2377ff088d1SManish V Badarkheelse ifeq ($(notdir $(CC)),clang)
2387ff088d1SManish V BadarkheTF_CFLAGS		+=	-fsanitize=memtag
239f1821790SAlexei Fedorovendif	# armclang
240f1821790SAlexei Fedorovendif	# armclang clang
2417ff088d1SManish V Badarkheelse
2427ff088d1SManish V Badarkhe$(error "Error: stack memory tagging is not supported for architecture \
2437ff088d1SManish V Badarkhe	${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
244f1821790SAlexei Fedorovendif	# mem_tag_arch_support
245f1821790SAlexei Fedorovendif	# SUPPORT_STACK_MEMTAG
246f1821790SAlexei Fedorov
247f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
248f1821790SAlexei Fedorovifneq ($(arch-features), none)
249f1821790SAlexei Fedorov# Strip "none+" from arch-features
250f1821790SAlexei Fedorovarch-features		:=	$(subst none+,,$(arch-features))
251f1821790SAlexei Fedorovifeq ($(ARCH), aarch32)
252f1821790SAlexei Fedorovmarch32-directive	:=	$(march32-directive)+$(arch-features)
253f1821790SAlexei Fedorovelse
254f1821790SAlexei Fedorovmarch64-directive	:=	$(march64-directive)+$(arch-features)
2557ff088d1SManish V Badarkheendif
256f1821790SAlexei Fedorov# Print features
257f1821790SAlexei Fedorov$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
258f1821790SAlexei Fedorovendif	# arch-features
2597ff088d1SManish V Badarkhe
26012cd65e0STomas Pilar# Determine if FEAT_RNG is supported
26112cd65e0STomas PilarENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
26212cd65e0STomas Pilar
2634e04478aSChris Kay# Determine if FEAT_SB is supported
2644e04478aSChris KayENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
2654e04478aSChris Kay
2664e04478aSChris Kayifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2674e04478aSChris KayENABLE_FEAT_SB		= 	1
2684e04478aSChris Kayendif
2694e04478aSChris Kay
270f74cb0beSJayanth Dodderi Chidanand# Determine and enable FEAT_FGT to access HDFGRTR_EL2 register for v8.6 and higher versions.
271f74cb0beSJayanth Dodderi Chidanandifeq "8.6" "$(word 1, $(sort 8.6 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
272f74cb0beSJayanth Dodderi ChidanandENABLE_FEAT_FGT		=	1
273f74cb0beSJayanth Dodderi Chidanandendif
274f74cb0beSJayanth Dodderi Chidanand
275f74cb0beSJayanth Dodderi Chidanand# Determine and enable FEAT_ECV to access CNTPOFF_EL2 register for v8.6 and higher versions.
276f74cb0beSJayanth Dodderi Chidanandifeq "8.6" "$(word 1, $(sort 8.6 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
277f74cb0beSJayanth Dodderi ChidanandENABLE_FEAT_ECV		=	1
278f74cb0beSJayanth Dodderi Chidanandendif
279f74cb0beSJayanth Dodderi Chidanand
2807d33ffe4SDaniel Boulbyifeq "8.4" "$(word 1, $(sort 8.4 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2817d33ffe4SDaniel BoulbyENABLE_FEAT_DIT		= 	1
2827d33ffe4SDaniel Boulbyendif
2837d33ffe4SDaniel Boulby
284fd18a8fcSVarun Wadekarifneq ($(findstring armclang,$(notdir $(CC))),)
28526e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
286fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi $(march64-directive)
2872adee763SRoberto VargasLD			=	$(LINKER)
2881684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2897040155eSRoberto VargasCPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2907040155eSRoberto VargasPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2917559633bSdp-armelse ifneq ($(findstring clang,$(notdir $(CC))),)
292eff737c1SArve HjønnevågCLANG_CCDIR		=	$(if $(filter-out ./,$(dir $(CC))),$(dir $(CC)),)
293e2bfec0bSYann GautierTF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
294fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-elf $(march64-directive)
295eff737c1SArve HjønnevågLD			=	$(CLANG_CCDIR)ld.lld
296641f16e7SAmbroise Vincentifeq (, $(shell which $(LD)))
297641f16e7SAmbroise Vincent$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker")
298641f16e7SAmbroise Vincentendif
2991684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
3007040155eSRoberto VargasCPP			=	$(CC) -E
3017040155eSRoberto VargasPP			=	$(CC) -E
302edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
303edbce9aaSzelalem-awekeTF_CFLAGS_aarch32	=	$(march32-directive)
304edbce9aaSzelalem-awekeTF_CFLAGS_aarch64	=	$(march64-directive)
305edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
306edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
307edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
308edbce9aaSzelalem-aweke		LTO_CFLAGS	=	-flto
309edbce9aaSzelalem-aweke		# Use gcc as a wrapper for the ld, recommended for LTO
310edbce9aaSzelalem-aweke		LINKER		:=	${CROSS_COMPILE}gcc
311edbce9aaSzelalem-aweke	endif
312edbce9aaSzelalem-awekeendif
313edbce9aaSzelalem-awekeLD			=	$(LINKER)
314d5461857Sdp-armelse
31526e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	$(march32-directive)
316fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	$(march64-directive)
3172adee763SRoberto VargasLD			=	$(LINKER)
318d5461857Sdp-armendif
319d5461857Sdp-arm
32032b209bfSAhmad Fatoum# Process Debug flag
32132b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
32232b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
32332b209bfSAhmad Fatoum        BUILD_TYPE	:=	debug
32432b209bfSAhmad Fatoum        TF_CFLAGS	+= 	-g
32532b209bfSAhmad Fatoum
32632b209bfSAhmad Fatoum        ifneq ($(findstring clang,$(notdir $(CC))),)
32732b209bfSAhmad Fatoum             ASFLAGS		+= 	-g
32832b209bfSAhmad Fatoum        else
32932b209bfSAhmad Fatoum             ASFLAGS		+= 	-g -Wa,--gdwarf-2
33032b209bfSAhmad Fatoum        endif
33132b209bfSAhmad Fatoum
33232b209bfSAhmad Fatoum        # Use LOG_LEVEL_INFO by default for debug builds
33332b209bfSAhmad Fatoum        LOG_LEVEL	:=	40
33432b209bfSAhmad Fatoumelse
33532b209bfSAhmad Fatoum        BUILD_TYPE	:=	release
33632b209bfSAhmad Fatoum        # Use LOG_LEVEL_NOTICE by default for release builds
33732b209bfSAhmad Fatoum        LOG_LEVEL	:=	20
33832b209bfSAhmad Fatoumendif
33932b209bfSAhmad Fatoum
340f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
341f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
342f1de4c8fSPeiyuan Song        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
343f1de4c8fSPeiyuan Songendif
344f1de4c8fSPeiyuan SongVERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
345f1de4c8fSPeiyuan Song
3468fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3478fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
3488fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3498fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
3508fd9d4d5SAntonio Nino Diazelse
3518fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
3528fd9d4d5SAntonio Nino Diazendif
3538fd9d4d5SAntonio Nino Diaz
354a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
355d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3569d29c227SSoby Mathew
3579fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3589fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
3599fc59639SAlexei Fedorovendif
3609fc59639SAlexei Fedorov
36126e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
362fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
363b86048c4SAntonio Nino Diaz
3649ab81b5eSJustin Chadwell# General warnings
3659ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
366b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
367ca661a00SMadhukar Pappireddy				-Wno-unused-parameter -Wredundant-decls
3689ab81b5eSJustin Chadwell
3699ab81b5eSJustin Chadwell# Additional warnings
3709ab81b5eSJustin Chadwell# Level 1
371e7c645b5SYann GautierWARNING1 := -Wextra
372e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
373e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
374e7c645b5SYann GautierWARNING1 += -Wold-style-definition
375e7c645b5SYann Gautier
376b7f6525dSJustin Chadwell# Level 2
377e7c645b5SYann GautierWARNING2 := -Waggregate-return
378e7c645b5SYann GautierWARNING2 += -Wcast-align
379e7c645b5SYann GautierWARNING2 += -Wnested-externs
380e7c645b5SYann Gautier
381e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
382e7c645b5SYann GautierWARNING3 += -Wcast-qual
383e7c645b5SYann GautierWARNING3 += -Wconversion
384e7c645b5SYann GautierWARNING3 += -Wpacked
385e7c645b5SYann GautierWARNING3 += -Wpointer-arith
386e7c645b5SYann GautierWARNING3 += -Wswitch-default
387e7c645b5SYann Gautier
388e7c645b5SYann Gautierifeq (${W},1)
3899ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
390e7c645b5SYann Gautierelse ifeq (${W},2)
3919ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
392e7c645b5SYann Gautierelse ifeq (${W},3)
3939ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
394e7c645b5SYann Gautierendif
395e7c645b5SYann Gautier
3969ab81b5eSJustin Chadwell# Compiler specific warnings
39700296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
39893c690ebSJustin Chadwell# not using clang
399d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
400d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
401d7b4cd41SJustin Chadwell				-Wlogical-op
40293c690ebSJustin Chadwellelse
40393c690ebSJustin Chadwell# using clang
404d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
405d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
40600296576SAmbroise Vincentendif
40700296576SAmbroise Vincent
4086336b07aSYann Gautierifneq (${E},0)
4096336b07aSYann GautierERRORS := -Werror
4106336b07aSYann Gautierendif
4116336b07aSYann Gautier
412ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
4139ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
41459de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
415d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
41659de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
417ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
418ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
419ebd6efaeSSamuel Holland				-Os -std=gnu99
42073c99d4eSJuan Castillo
4211f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4221f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
4231f461979SJustin Chadwellendif
4241f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4251f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
4261f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
4271f461979SJustin Chadwellendif
4281f461979SJustin Chadwell
429f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
430f7ec31dbSdavid cunado
431641f16e7SAmbroise Vincent# LD = armlink
432c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
433c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
434c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
435edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
436641f16e7SAmbroise Vincent
437641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
438edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
439edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
440edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
441edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
442edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
443edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
444edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
445edbce9aaSzelalem-aweke	endif
446edbce9aaSzelalem-awekeendif
447edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
448edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
449edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
450edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
451edbce9aaSzelalem-awekeendif
452edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
453edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
454641f16e7SAmbroise Vincent
455641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
456c2ad38ceSVarun Wadekarelse
457c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
458c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
459641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
460641f16e7SAmbroise Vincent# therefore don't add those in that case
461641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
462c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
463edbce9aaSzelalem-awekeendif
464641f16e7SAmbroise Vincentendif
46573c99d4eSJuan Castillo
46603b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
467a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
468a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
46903b397a8SNishanth Menon
4700ab49645SAlexei Fedorovifeq ($(MEASURED_BOOT),1)
4710ab49645SAlexei FedorovDTC_CPPFLAGS		+=	-DMEASURED_BOOT -DBL2_HASH_SIZE=${TCG_DIGEST_SIZE}
4720ab49645SAlexei Fedorovendif
4730ab49645SAlexei Fedorov
47473c99d4eSJuan Castillo################################################################################
47573c99d4eSJuan Castillo# Common sources and include directories
47673c99d4eSJuan Castillo################################################################################
477d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
47873c99d4eSJuan Castillo
47973c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4807f56e9a3SSoby Mathew				common/tf_log.c				\
4819d29c227SSoby Mathew				common/${ARCH}/debug.S			\
48291b48c9fSJulius Werner				drivers/console/multi_console.c		\
4839d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4849d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
485566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4867f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
48775311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4889d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
48961f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
490d7a6b0f8SRyan Harkin
4918422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4928422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4938422a840SAntonio Nino Diazendif
4948422a840SAntonio Nino Diaz
4951f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4961f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
4971f461979SJustin Chadwellendif
4981f461979SJustin Chadwell
49901d237cbSYann GautierINCLUDES		+=	-Iinclude				\
500f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
50109d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
50209d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
50309d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
50409d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
50509d40e0eSAntonio Nino Diaz
5069c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
5079c6d1c50SAntonio Nino Diaz
50873c99d4eSJuan Castillo################################################################################
50973c99d4eSJuan Castillo# Generic definitions
51073c99d4eSJuan Castillo################################################################################
51173c99d4eSJuan Castillo
512231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
513231c1470SEvan Lloyd
51429214e95SGrant Likelyifeq (${BUILD_BASE},)
51573c99d4eSJuan Castillo     BUILD_BASE		:=	./build
51629214e95SGrant Likelyendif
51729214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
51873c99d4eSJuan Castillo
519231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
52073c99d4eSJuan Castillo
52173c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
52273c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
52373c99d4eSJuan Castillo
52473c99d4eSJuan Castillo
52573c99d4eSJuan Castillo################################################################################
52673c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
52773c99d4eSJuan Castillo################################################################################
52873c99d4eSJuan Castillo
52973c99d4eSJuan Castilloifneq (${SPD},none)
5309d29c227SSoby Mathew    ifeq (${ARCH},aarch32)
5319d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
5329d29c227SSoby Mathew    endif
53328f39f02SMax Shvetsov
5344c117f6cSSandrine Bailleux    ifdef EL3_PAYLOAD_BASE
5354c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
5364c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
5374c117f6cSSandrine Bailleux    endif
53828f39f02SMax Shvetsov
539c3fb00d9SAchin Gupta    ifeq (${SPD},spmd)
540c3fb00d9SAchin Gupta        # SPMD is located in std_svc directory
541c3fb00d9SAchin Gupta        SPD_DIR := std_svc
54228f39f02SMax Shvetsov
543033039f8SMax Shvetsov        ifeq ($(SPMD_SPM_AT_SEL2),1)
54428f39f02SMax Shvetsov            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
545033039f8SMax Shvetsov                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
546033039f8SMax Shvetsov            endif
54728f39f02SMax Shvetsov        endif
548db1ef41aSOlivier Deprez
549db1ef41aSOlivier Deprez        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
550db1ef41aSOlivier Deprez            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
551db1ef41aSOlivier Deprez        endif
552ca932481SDavidson K
553ca932481SDavidson K        ifeq ($(TS_SP_FW_CONFIG),1)
554ca932481SDavidson K            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
555ca932481SDavidson K        endif
55633993a37SBalint Dobszay
55733993a37SBalint Dobszay        ifneq ($(ARM_BL2_SP_LIST_DTS),)
55833993a37SBalint Dobszay            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
55933993a37SBalint Dobszay        endif
56046789a7cSBalint Dobszay
56146789a7cSBalint Dobszay        ifneq ($(SP_LAYOUT_FILE),)
56246789a7cSBalint Dobszay            BL2_ENABLE_SP_LOAD := 1
56346789a7cSBalint Dobszay        endif
564c3fb00d9SAchin Gupta    else
565c3fb00d9SAchin Gupta        # All other SPDs in spd directory
566c3fb00d9SAchin Gupta        SPD_DIR := spd
567c3fb00d9SAchin Gupta    endif
568c3fb00d9SAchin Gupta
56973c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
570c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
571c3fb00d9SAchin Gupta
57273c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
573c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
57473c99d4eSJuan Castillo    endif
57573c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
57673c99d4eSJuan Castillo    include ${SPD_MAKE}
57773c99d4eSJuan Castillo
57870d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
57970d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
58070d1fc53SJuan Castillo    # supports two mutually exclusive options:
58170d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
58270d1fc53SJuan Castillo    #   of source files to build BL32
58370d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
58470d1fc53SJuan Castillo    #   that will be included in the FIP
58570d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
58670d1fc53SJuan Castillo    # over the sources.
587e35c4045SJeenu Viswambharanendif
588e35c4045SJeenu Viswambharan
58951faada7SDouglas Raillard################################################################################
5905b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
5915b18de09SZelalem Aweke################################################################################
5925b18de09SZelalem Aweke
5935b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
5945b18de09SZelalem Awekeifneq (${ARCH},aarch64)
5955b18de09SZelalem Aweke	$(error ENABLE_RME requires AArch64)
5965b18de09SZelalem Awekeendif
5975b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
5985b18de09SZelalem Aweke$(warning "RME is an experimental feature")
5995b18de09SZelalem Awekeendif
6005b18de09SZelalem Aweke
6015b18de09SZelalem Aweke################################################################################
60273c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
60373c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
60473c99d4eSJuan Castillo################################################################################
6052da8d8bfSJeenu Viswambharan
60673c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
6070f21c547SJuan Castillo
6088012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
6098012cc5cSMasahiro Yamada
61026e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
61126e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
61226e63c44SEtienne Carriereendif
61326e63c44SEtienne Carriere
6143bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
6153bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
6163bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
6173bd17c0fSSoby Mathewendif
618320920c1SMasahiro Yamada
619320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
620320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
621320920c1SMasahiro Yamadaelse
622320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
623320920c1SMasahiro Yamadaendif
624320920c1SMasahiro Yamada
625320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
62669af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
62769af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
62869af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
62969af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
63069af7fcfSMasahiro Yamadaendif
63169af7fcfSMasahiro Yamadaendif
632320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
633320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
634d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
635d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
636d974301dSMasahiro Yamadaendif
6373bd17c0fSSoby Mathew
638d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
6399cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
640d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
6419cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
642d5e97a1dSMasahiro Yamadaelse
6439cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
644d5e97a1dSMasahiro Yamadaendif
6459cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
6469cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
6479cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
648d5e97a1dSMasahiro Yamadaendif
649d5e97a1dSMasahiro Yamada
65054035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
65154035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
65254035fc4SSandrine Bailleux# This can be overridden by the platform.
65373c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6544f6ad66aSAchin Gupta
655a4409008Sdp-armifeq (${ARCH},aarch32)
656a4409008Sdp-armNEED_BL32 := yes
657a4409008Sdp-arm
658a4409008Sdp-arm################################################################################
659a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
660a4409008Sdp-arm################################################################################
661a4409008Sdp-armifneq (${AARCH32_SP},none)
662a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
663a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
664a4409008Sdp-arm
665a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
666a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
667a4409008Sdp-armendif
668a4409008Sdp-arm
669a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
670a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
671a4409008Sdp-armendif
672a4409008Sdp-arm
673a4409008Sdp-armendif
6744f6ad66aSAchin Gupta
67573c99d4eSJuan Castillo################################################################################
67677f1f7a1SVarun Wadekar# Include libc if not overridden
67777f1f7a1SVarun Wadekar################################################################################
67877f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
67977f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
68077f1f7a1SVarun Wadekarendif
68177f1f7a1SVarun Wadekar
68277f1f7a1SVarun Wadekar################################################################################
683cf2c8a33SAntonio Nino Diaz# Check incompatible options
684cf2c8a33SAntonio Nino Diaz################################################################################
685cf2c8a33SAntonio Nino Diaz
686cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
68768450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
68868450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
68968450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
690cf2c8a33SAntonio Nino Diaz        endif
69176580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
69276580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
69376580f3dSQixiang Xu        endif
69476580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
69576580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
69676580f3dSQixiang Xu        endif
697cf2c8a33SAntonio Nino Diazendif
698cf2c8a33SAntonio Nino Diaz
699cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
700cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
701cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
702cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
703cf2c8a33SAntonio Nino Diaz        endif
70468450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
70568450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
70668450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
70768450a6dSAntonio Nino Diaz                file.")
708cf2c8a33SAntonio Nino Diaz        endif
709cf2c8a33SAntonio Nino Diazendif
710cf2c8a33SAntonio Nino Diaz
711d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
712d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
713d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
714d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
715d4593e47SJeenu Viswambharanendif
7161a0a3f06SYatharth Kochar
7177d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
7187d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
7197d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
7207d173fc5SJiafei Panendif
7217d173fc5SJiafei Pan
72214c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
72314c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
72414c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
72514c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
72614c6016aSJeenu Viswambharan    endif
72714c6016aSJeenu Viswambharanendif
72814c6016aSJeenu Viswambharan
7291a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
7301a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
7311a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
7321a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
7331a7c1cfeSJeenu Viswambharan    endif
7341a7c1cfeSJeenu Viswambharanendif
7351a7c1cfeSJeenu Viswambharan
736ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
737209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
738209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
739209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
740209a60ccSSoby Mathew    endif
741209a60ccSSoby Mathewendif
742209a60ccSSoby Mathew
743c9c56f6eSManish V Badarkheifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
744c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 1
745c9c56f6eSManish V Badarkheelse
746c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 0
747c9c56f6eSManish V Badarkheendif
748c9c56f6eSManish V Badarkhe
749cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
750cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
751700e7685SManish Pandey$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
75284ef9cd8SManish V Badarkheendif
75384ef9cd8SManish V Badarkhe
754b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7559fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7569fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
757b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7589fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7599fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
76006715f85SAlexei Fedorov    endif
7619fc59639SAlexei Fedorovendif
7629fc59639SAlexei Fedorov
76306715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7649fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7659fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
766b86048c4SAntonio Nino Diaz    endif
767b86048c4SAntonio Nino Diazendif
7689fc59639SAlexei Fedorov
7699dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7709dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7719dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7729dd94382SJustin Chadwell    endif
7739dd94382SJustin Chadwellendif
7749dd94382SJustin Chadwell
775396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
776396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
777396b339dSManish V Badarkheendif
778396b339dSManish V Badarkhe
77960e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
78060e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
78160e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
78260e8f3cfSPetre-Ionut Tudor    endif
78360e8f3cfSPetre-Ionut Tudorendif
78460e8f3cfSPetre-Ionut Tudor
7857cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7867cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7877cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7887cda17bbSSumit Garg    endif
7897cda17bbSSumit Gargendif
7907cda17bbSSumit Garg
791dc78e62dSjohpow01# SME/SVE only supported on AArch64
792dc78e62dSjohpow01ifeq (${ARCH},aarch32)
793dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
794dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
795dc78e62dSjohpow01    endif
796dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
797dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
79824ab2c0aSYann Gautier        $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
799dc78e62dSjohpow01    endif
800dc78e62dSjohpow01endif
801dc78e62dSjohpow01
802dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
803dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
804dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
805dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
806dc78e62dSjohpow01    endif
807dc78e62dSjohpow01endif
808dc78e62dSjohpow01
809dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
810dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
811dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},0)
812dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
813dc78e62dSjohpow01    endif
814dc78e62dSjohpow01endif
815dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
816dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
817dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
818dc78e62dSjohpow01    endif
819dc78e62dSjohpow01endif
820dc78e62dSjohpow01
821dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
822dc78e62dSjohpow01# its own context management including FPU registers.
823dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
824dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
825dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
826dc78e62dSjohpow01    endif
827dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
828dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
829dc78e62dSjohpow01        $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
830dc78e62dSjohpow01        $(warning "Forced ENABLE_SVE_FOR_NS=0")
831dc78e62dSjohpow01        override ENABLE_SVE_FOR_NS	:= 0
832dc78e62dSjohpow01    endif
833dc78e62dSjohpow01endif
834dc78e62dSjohpow01
835cf2c8a33SAntonio Nino Diaz################################################################################
83673c99d4eSJuan Castillo# Process platform overrideable behaviour
83773c99d4eSJuan Castillo################################################################################
8384f6ad66aSAchin Gupta
8395f24ce96SManish Pandeyifdef BL1_SOURCES
8405f24ce96SManish PandeyNEED_BL1 := yes
8415f24ce96SManish Pandeyendif
8425f24ce96SManish Pandey
8435f24ce96SManish Pandeyifdef BL2_SOURCES
8445f24ce96SManish Pandey	NEED_BL2 := yes
8455f24ce96SManish Pandey
846bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
847bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
848cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
849cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
850cf2c8a33SAntonio Nino Diaz                # in the FIP file.
8514c117f6cSSandrine Bailleux                NEED_BL33		:=	no
852cf2c8a33SAntonio Nino Diaz        else
85368450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
854cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
855cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
856cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
857cf2c8a33SAntonio Nino Diaz                else
858cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
859cf2c8a33SAntonio Nino Diaz                endif
8604c117f6cSSandrine Bailleux        endif
86173c99d4eSJuan Castilloendif
8626f971622SJuan Castillo
8635f24ce96SManish Pandeyifdef BL2U_SOURCES
8645f24ce96SManish PandeyNEED_BL2U := yes
8655f24ce96SManish Pandeyendif
8665f24ce96SManish Pandey
8674d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
8684d045d0eSMasahiro Yamadaifdef SCP_BL2
8694d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
8704d045d0eSMasahiro Yamadaendif
8714d045d0eSMasahiro Yamada
8725744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
8735744e874SSoby Mathewifneq (${ARCH},aarch32)
8745744e874SSoby Mathew    ifdef BL31_SOURCES
8755744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
8765744e874SSoby Mathew        # put it in the FIP.
8775744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8785744e874SSoby Mathew            NEED_BL31 := yes
8795744e874SSoby Mathew        endif
8805744e874SSoby Mathew    endif
8815744e874SSoby Mathewendif
8825744e874SSoby Mathew
88373c99d4eSJuan Castillo# Process TBB related flags
8846f971622SJuan Castilloifneq (${GENERATE_COT},0)
88573c99d4eSJuan Castillo        # Common cert_create options
8866f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8876f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8880191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
889fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
890fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8910191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
892fd34e7baSJuan Castillo                endif
8936f971622SJuan Castillo        endif
89473c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
89573c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
89673c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
89773c99d4eSJuan Castillo        endif
8986f971622SJuan Castilloendif
8996f971622SJuan Castillo
9001c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
9011c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
9021c75d5dfSMasahiro Yamadaendif
9031c75d5dfSMasahiro Yamada
9045f24ce96SManish Pandeyifdef FDT_SOURCES
9055f24ce96SManish PandeyNEED_FDT := yes
9065f24ce96SManish Pandeyendif
9075f24ce96SManish Pandey
90873c99d4eSJuan Castillo################################################################################
90946e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
91046e5e035SMichalis Pappas################################################################################
91146e5e035SMichalis Pappas
91246e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
91346e5e035SMichalis Pappas
91446e5e035SMichalis Pappas################################################################################
915819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
91673c99d4eSJuan Castillo################################################################################
91773c99d4eSJuan Castillo
91873c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
91973c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
92042a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
92173c99d4eSJuan Castillo
92290aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
92390aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
92490aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
92590aa901fSSumit Garg
92673c99d4eSJuan Castillo# Variables for use with Firmware Image Package
927819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
928819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
92973c99d4eSJuan Castillo
93026010da1SAntonio Nino Diaz# Variables for use with sptool
93126010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
93226010da1SAntonio Nino DiazSPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
933ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
93426010da1SAntonio Nino Diaz
9355accce5bSRoberto Vargas# Variables for use with ROMLIB
9365accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
9375accce5bSRoberto Vargas
938cfe83910SLouis Mayencourt# Variable for use with Python
939cfe83910SLouis MayencourtPYTHON			?=	python3
940cfe83910SLouis Mayencourt
941cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
942cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
943cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
944cfe83910SLouis Mayencourt
9456de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
9466de32378SMadhukar PappireddyDOCS_PATH		?=	docs
9476de32378SMadhukar Pappireddy
948*1f1c0206SAbdul Halim, Muhammad Hadi Asyrafi# Defination of SIMICS flag
949*1f1c0206SAbdul Halim, Muhammad Hadi AsyrafiSIMICS_BUILD	?=	0
950*1f1c0206SAbdul Halim, Muhammad Hadi Asyrafi
9518a86052dSSoby Mathew################################################################################
9528a86052dSSoby Mathew# Include BL specific makefiles
9538a86052dSSoby Mathew################################################################################
9545f24ce96SManish Pandey
9555f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
9568a86052dSSoby Mathewinclude bl1/bl1.mk
9578a86052dSSoby Mathewendif
9588a86052dSSoby Mathew
9595f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
9608a86052dSSoby Mathewinclude bl2/bl2.mk
9618a86052dSSoby Mathewendif
9628a86052dSSoby Mathew
9635f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
9648a86052dSSoby Mathewinclude bl2u/bl2u.mk
9658a86052dSSoby Mathewendif
9668a86052dSSoby Mathew
9675744e874SSoby Mathewifeq (${NEED_BL31},yes)
9688a86052dSSoby Mathewinclude bl31/bl31.mk
9698a86052dSSoby Mathewendif
97003b397a8SNishanth Menon
97173c99d4eSJuan Castillo################################################################################
97273c99d4eSJuan Castillo# Build options checks
97373c99d4eSJuan Castillo################################################################################
97473c99d4eSJuan Castillo
975327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
976327131c4SLeonardo Sandoval    $(sort \
977327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
97846789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
979327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
980327131c4SLeonardo Sandoval        CREATE_KEYS \
981327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
982327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
983327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
984327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
985327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
986062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
987327131c4SLeonardo Sandoval        DEBUG \
9880063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
989327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
990327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
991327131c4SLeonardo Sandoval        ENABLE_AMU \
9921fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
993742ca230SChris Kay        ENABLE_AMU_FCONF \
994873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
995327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
996327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
997327131c4SLeonardo Sandoval        ENABLE_PIE \
998327131c4SLeonardo Sandoval        ENABLE_PMF \
999327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
10005b18de09SZelalem Aweke        ENABLE_RME \
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 \
1015327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1016327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
1017327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1018327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1019327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1020327131c4SLeonardo Sandoval        RAS_EXTENSION \
1021327131c4SLeonardo Sandoval        RESET_TO_BL31 \
1022327131c4SLeonardo Sandoval        SAVE_KEYS \
1023327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
1024327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1025327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1026327131c4SLeonardo Sandoval        SPM_MM \
1027327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1028327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1029c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
1030327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1031327131c4SLeonardo Sandoval        USE_DEBUGFS \
1032327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1033327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1034327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1035327131c4SLeonardo Sandoval        USE_ROMLIB \
1036327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1037327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1038327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1039327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1040327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1041327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1042327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1043327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1044327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1045327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1046327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1047327131c4SLeonardo Sandoval        USE_SP804_TIMER \
104812cd65e0STomas Pilar        ENABLE_FEAT_RNG \
10494e04478aSChris Kay        ENABLE_FEAT_SB \
10507d33ffe4SDaniel Boulby        ENABLE_FEAT_DIT \
1051396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1052813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1053d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
10548fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1055cb4ec47bSjohpow01        ENABLE_FEAT_HCX \
105668120783SChris Kay        ENABLE_MPMM \
105768120783SChris Kay        ENABLE_MPMM_FCONF \
1058f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
1059f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
1060f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
1061*1f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
1062327131c4SLeonardo Sandoval)))
106373c99d4eSJuan Castillo
1064327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1065327131c4SLeonardo Sandoval    $(sort \
1066327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1067327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1068327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
1069327131c4SLeonardo Sandoval        FW_ENC_STATUS \
10705357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10715357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1072327131c4SLeonardo Sandoval)))
1073c877b414SJeenu Viswambharan
1074aacff749SJustin Chadwellifdef KEY_SIZE
1075aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1076aacff749SJustin Chadwellendif
1077aacff749SJustin Chadwell
10781f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
10791f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
10801f461979SJustin Chadwellendif
10811f461979SJustin Chadwell
108273c99d4eSJuan Castillo################################################################################
108373c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
108473c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
108573c99d4eSJuan Castillo# platform to overwrite the default options
108673c99d4eSJuan Castillo################################################################################
108773c99d4eSJuan Castillo
1088327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1089327131c4SLeonardo Sandoval    $(sort \
1090327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
1091327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1092327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
109346789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
1094327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1095327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1096327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1097327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1098327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1099327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1100327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1101062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1102327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
11030063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1104327131c4SLeonardo Sandoval        ENABLE_AMU \
11051fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
1106742ca230SChris Kay        ENABLE_AMU_FCONF \
1107873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1108327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1109327131c4SLeonardo Sandoval        ENABLE_BTI \
1110327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1111327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1112327131c4SLeonardo Sandoval        ENABLE_PIE \
1113327131c4SLeonardo Sandoval        ENABLE_PMF \
1114327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
11155b18de09SZelalem Aweke        ENABLE_RME \
1116327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1117dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1118dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1119327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1120327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
11210c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1122327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1123327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1124327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1125327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1126327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1127327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1128327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1129327131c4SLeonardo Sandoval        LOG_LEVEL \
1130327131c4SLeonardo Sandoval        MEASURED_BOOT \
1131327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1132327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1133327131c4SLeonardo Sandoval        PLAT_${PLAT} \
1134327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1135327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1136327131c4SLeonardo Sandoval        RAS_EXTENSION \
1137327131c4SLeonardo Sandoval        RESET_TO_BL31 \
1138327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
1139327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1140327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1141327131c4SLeonardo Sandoval        SPD_${SPD} \
1142327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1143327131c4SLeonardo Sandoval        SPM_MM \
1144327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1145327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1146c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
11477dfb9911SJimmy Brisson        TRNG_SUPPORT \
1148327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1149327131c4SLeonardo Sandoval        USE_DEBUGFS \
1150327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1151327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1152327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1153327131c4SLeonardo Sandoval        USE_ROMLIB \
1154327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1155327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1156327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1157327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1158327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1159327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1160327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1161327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1162327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1163327131c4SLeonardo Sandoval        USE_SP804_TIMER \
116412cd65e0STomas Pilar        ENABLE_FEAT_RNG \
11654e04478aSChris Kay        ENABLE_FEAT_SB \
11667d33ffe4SDaniel Boulby        ENABLE_FEAT_DIT \
11675357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
11685357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1169396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1170813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1171d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
11728fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1173cb4ec47bSjohpow01        ENABLE_FEAT_HCX \
117468120783SChris Kay        ENABLE_MPMM \
117568120783SChris Kay        ENABLE_MPMM_FCONF \
1176f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
1177f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
1178f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
1179*1f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
1180327131c4SLeonardo Sandoval)))
11812fae4b1eSJeenu Viswambharan
11821f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
11831f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
11841f461979SJustin Chadwellendif
11851f461979SJustin Chadwell
11864c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
11874c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
11884c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1189cf2c8a33SAntonio Nino Diazelse
119068450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
119168450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
119268450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
119368450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
11944c117f6cSSandrine Bailleux        endif
1195cf2c8a33SAntonio Nino Diazendif
119673c99d4eSJuan Castillo
1197209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1198209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1199209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1200209a60ccSSoby Mathewendif
1201209a60ccSSoby Mathew
1202c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1203c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1204c2ad38ceSVarun Wadekarendif
1205c2ad38ceSVarun Wadekar
1206ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1207ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1208c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1209ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1210ce2b1ec6SManish Pandey        FIP_DEPS += sp
121107c44475SManish Pandey        CRT_DEPS += sp
1212ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1213ce2b1ec6SManish Pandeyelse
1214c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1215c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1216c33ff198SOlivier Deprez        endif
1217ce2b1ec6SManish Pandeyendif
1218ce2b1ec6SManish Pandeyendif
1219ce2b1ec6SManish Pandey
122073c99d4eSJuan Castillo################################################################################
122173c99d4eSJuan Castillo# Build targets
122273c99d4eSJuan Castillo################################################################################
122373c99d4eSJuan Castillo
122490aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
122573c99d4eSJuan Castillo.SUFFIXES:
122673c99d4eSJuan Castillo
122773c99d4eSJuan Castilloall: msg_start
122873c99d4eSJuan Castillo
122973c99d4eSJuan Castillomsg_start:
123073c99d4eSJuan Castillo	@echo "Building ${PLAT}"
123173c99d4eSJuan Castillo
12327a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1233d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1234c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1235c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1236c2ad38ceSVarun Wadekarelse
1237bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
12387a24cba5SSoby Mathewendif
1239d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
12407a24cba5SSoby Mathew
12415accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
124261f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
12435fee0287SRoberto Vargas
124473c99d4eSJuan Castillo# Expand build macros for the different images
124573c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1246b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1247b34635a0SChris Kay
1248434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
124973c99d4eSJuan Castilloendif
125073c99d4eSJuan Castillo
125173c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1252c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1253c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1254c9b31ae8SRoberto Vargasendif
1255c9b31ae8SRoberto Vargas
1256eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1257eb1acfb6SChris Kay
125833950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1259434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
126073c99d4eSJuan Castilloendif
126173c99d4eSJuan Castillo
12624d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
126333950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
12644d045d0eSMasahiro Yamadaendif
12654d045d0eSMasahiro Yamada
126673c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
126773c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
126826d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
126926d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1270c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1271c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1272434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1273c6ba9b45SSumit Gargelse
127433950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1275434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
127673c99d4eSJuan Castilloendif
1277c6ba9b45SSumit Gargendif
127873c99d4eSJuan Castillo
127970d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1280c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
128170d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
128273c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
128326d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
128426d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
12859cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
12869cd15239SMasahiro Yamada
1287c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1288434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1289c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1290c6ba9b45SSumit Gargelse
1291434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
129233950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
129373c99d4eSJuan Castilloendif
1294c6ba9b45SSumit Gargendif
129573c99d4eSJuan Castillo
12965b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
12975b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
12985b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
12995b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
13005b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
13015b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
13025b18de09SZelalem Aweke
13035b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
13045b18de09SZelalem Aweke         $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
13055b18de09SZelalem Awekeendif
13065b18de09SZelalem Aweke
130773c99d4eSJuan Castillo# Add the BL33 image if required by the platform
130873c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
130933950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1310db6071c9SJuan Castilloendif
1311db6071c9SJuan Castillo
13129003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
131333950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1314434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
13159003fa0bSYatharth Kocharendif
13169003fa0bSYatharth Kochar
131703b397a8SNishanth Menon# Expand build macros for the different images
131803b397a8SNishanth Menonifeq (${NEED_FDT},yes)
131903b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
132003b397a8SNishanth Menonendif
132103b397a8SNishanth Menon
1322ce2b1ec6SManish Pandey# Add Secure Partition packages
1323ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1324ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
13251e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1326ce2b1ec6SManish Pandeysp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1327ce2b1ec6SManish Pandey	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1328ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1329ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1330ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1331ce2b1ec6SManish Pandeyendif
1332ce2b1ec6SManish Pandey
133336eaaf37SIan Spraylocate-checkpatch:
133436eaaf37SIan Sprayifndef CHECKPATCH
133566079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
133636eaaf37SIan Sprayelse
133736eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
133866079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
133936eaaf37SIan Sprayendif
134036eaaf37SIan Sprayendif
134136eaaf37SIan Spray
13424f6ad66aSAchin Guptaclean:
13434f6ad66aSAchin Gupta	@echo "  CLEAN"
1344f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
134588a1cf1eSSami Mujawarifdef UNIX_MK
13462f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
134788a1cf1eSSami Mujawarelse
134888a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
134988a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
135088a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
135188a1cf1eSSami Mujawarendif
13526f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
135390aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
13545accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13554f6ad66aSAchin Gupta
1356eaaeece2SJames Morrisseyrealclean distclean:
1357eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1358f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1359f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
136088a1cf1eSSami Mujawarifdef UNIX_MK
13612f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
136288a1cf1eSSami Mujawarelse
136388a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
136488a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
136588a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
136688a1cf1eSSami Mujawarendif
136726010da1SAntonio Nino Diaz	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
1368e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
136990aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
13705accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13714f6ad66aSAchin Gupta
137236eaaf37SIan Spraycheckcodebase:		locate-checkpatch
137336eaaf37SIan Spray	@echo "  CHECKING STYLE"
137436eaaf37SIan Spray	@if test -d .git ; then						\
13751ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
13761a41e8c1SDan Handley		while read GIT_FILE ;					\
13771a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
13781a41e8c1SDan Handley		done ;							\
137936eaaf37SIan Spray	else								\
13801a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
13811a41e8c1SDan Handley		 -not -iwholename "*build*"				\
13821a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
138361f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
13841a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
13851ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
13861a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
138736eaaf37SIan Spray	fi
138836eaaf37SIan Spray
138936eaaf37SIan Spraycheckpatch:		locate-checkpatch
139036eaaf37SIan Spray	@echo "  CHECKING STYLE"
139102a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
139202a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
139302a76d5fSYann Gautier	fi
139451d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
139577a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
139677a0a7f1SYann Gautier	do								\
139751d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
139851d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
139902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
140002a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
140151d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
140202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
140302a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
140451d28937SAntonio Nino Diaz	done
140536eaaf37SIan Spray
140673c99d4eSJuan Castillocerttool: ${CRTTOOL}
140773c99d4eSJuan Castillo
1408a9812206SPali Rohár${CRTTOOL}: FORCE
1409fafd3ec9SManish 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}
1410f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14116f971622SJuan Castillo	@echo "Built $@ successfully"
1412f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14136f971622SJuan Castillo
14146f971622SJuan Castilloifneq (${GENERATE_COT},0)
141573c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
14166f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1417f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14186f971622SJuan Castillo	@echo "Built $@ successfully"
14196f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1420f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
142173c99d4eSJuan Castilloendif
142227713fb4SSoby Mathew
142373c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
14244727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1425819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1426819281eeSdp-arm	${Q}${FIPTOOL} info $@
1427f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14282f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1429f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1430f58ad36fSHarry Liebel
14310191262dSYatharth Kocharifneq (${GENERATE_COT},0)
14320191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
14330191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1434052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14350191262dSYatharth Kochar	@echo "Built $@ successfully"
14360191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1437052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14380191262dSYatharth Kocharendif
14390191262dSYatharth Kochar
14400191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
14414727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1442819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1443819281eeSdp-arm	${Q}${FIPTOOL} info $@
1444052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14450191262dSYatharth Kochar	@echo "Built $@ successfully"
1446052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14470191262dSYatharth Kochar
144873c99d4eSJuan Castillofiptool: ${FIPTOOL}
144973c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
14500191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
145173c99d4eSJuan Castillo
1452a9812206SPali Rohár${FIPTOOL}: FORCE
145388a1cf1eSSami Mujawarifdef UNIX_MK
14540a956f81SRoss Burton	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH}
145588a1cf1eSSami Mujawarelse
145688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
145788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
145888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
145988a1cf1eSSami Mujawarendif
1460f58ad36fSHarry Liebel
146126010da1SAntonio Nino Diazsptool: ${SPTOOL}
1462a9812206SPali Rohár${SPTOOL}: FORCE
1463fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH}
146426010da1SAntonio Nino Diaz
1465a9812206SPali Rohárromlib.bin: libraries FORCE
1466bbb24f61SJohn 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
14675accce5bSRoberto Vargas
1468cfe83910SLouis Mayencourt# Call print_memory_map tool
1469cfe83910SLouis Mayencourtmemmap: all
1470b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1471cfe83910SLouis Mayencourt
14726de32378SMadhukar Pappireddydoc:
14736de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
14746de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
14756de32378SMadhukar Pappireddy
147690aa901fSSumit Gargenctool: ${ENCTOOL}
147790aa901fSSumit Garg
1478a9812206SPali Rohár${ENCTOOL}: FORCE
1479fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
148090aa901fSSumit Garg	@${ECHO_BLANK_LINE}
148190aa901fSSumit Garg	@echo "Built $@ successfully"
148290aa901fSSumit Garg	@${ECHO_BLANK_LINE}
148390aa901fSSumit Garg
148435fab8c9SJoakim Bechcscope:
148535fab8c9SJoakim Bech	@echo "  CSCOPE"
148635fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
148735fab8c9SJoakim Bech	${Q}cscope -b -q -k
148835fab8c9SJoakim Bech
148972ee3314SRyan Harkinhelp:
14907c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
149172ee3314SRyan Harkin	@echo ""
149272ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
149308c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
149472ee3314SRyan Harkin	@echo ""
14957c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
14967c23126cSJohn Tsichritzis	@echo ""
14971b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
14981b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
14991b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
15001b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
15011b578596SSandrine Bailleux	@echo ""
150272ee3314SRyan Harkin	@echo "Supported Targets:"
15031b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
150436eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
15058aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
15069003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1507d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
15089d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
15099d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
151073c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
15111b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
15120191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
151336eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
151436eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
151536eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
151672ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
151735fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
151872ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
15196f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
152090aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1521f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1522ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
152326010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
152438c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1525cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
15266de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
152772ee3314SRyan Harkin	@echo ""
15281b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
152972ee3314SRyan Harkin	@echo ""
153072ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
153172ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1532a9812206SPali Rohár
1533a9812206SPali Rohár.PHONY: FORCE
1534a9812206SPali RohárFORCE:;
1535