xref: /rk3399_ARM-atf/Makefile (revision 781d07a421380cdaede14a9f5932d9aa5bff1903)
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
266fd18a8fcSVarun Wadekarifneq ($(findstring armclang,$(notdir $(CC))),)
26726e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
268fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi $(march64-directive)
2692adee763SRoberto VargasLD			=	$(LINKER)
2701684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2717040155eSRoberto VargasCPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2727040155eSRoberto VargasPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2737559633bSdp-armelse ifneq ($(findstring clang,$(notdir $(CC))),)
274eff737c1SArve HjønnevågCLANG_CCDIR		=	$(if $(filter-out ./,$(dir $(CC))),$(dir $(CC)),)
275e2bfec0bSYann GautierTF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
276fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-elf $(march64-directive)
277eff737c1SArve HjønnevågLD			=	$(CLANG_CCDIR)ld.lld
278641f16e7SAmbroise Vincentifeq (, $(shell which $(LD)))
279641f16e7SAmbroise Vincent$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker")
280641f16e7SAmbroise Vincentendif
2811684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2827040155eSRoberto VargasCPP			=	$(CC) -E
2837040155eSRoberto VargasPP			=	$(CC) -E
284edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
285edbce9aaSzelalem-awekeTF_CFLAGS_aarch32	=	$(march32-directive)
286edbce9aaSzelalem-awekeTF_CFLAGS_aarch64	=	$(march64-directive)
287edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
288edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
289edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
290edbce9aaSzelalem-aweke		LTO_CFLAGS	=	-flto
291edbce9aaSzelalem-aweke		# Use gcc as a wrapper for the ld, recommended for LTO
292edbce9aaSzelalem-aweke		LINKER		:=	${CROSS_COMPILE}gcc
293edbce9aaSzelalem-aweke	endif
294edbce9aaSzelalem-awekeendif
295edbce9aaSzelalem-awekeLD			=	$(LINKER)
296d5461857Sdp-armelse
29726e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	$(march32-directive)
298fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	$(march64-directive)
2992adee763SRoberto VargasLD			=	$(LINKER)
300d5461857Sdp-armendif
301d5461857Sdp-arm
30232b209bfSAhmad Fatoum# Process Debug flag
30332b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
30432b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
30532b209bfSAhmad Fatoum        BUILD_TYPE	:=	debug
30632b209bfSAhmad Fatoum        TF_CFLAGS	+= 	-g
30732b209bfSAhmad Fatoum
30832b209bfSAhmad Fatoum        ifneq ($(findstring clang,$(notdir $(CC))),)
30932b209bfSAhmad Fatoum             ASFLAGS		+= 	-g
31032b209bfSAhmad Fatoum        else
31132b209bfSAhmad Fatoum             ASFLAGS		+= 	-g -Wa,--gdwarf-2
31232b209bfSAhmad Fatoum        endif
31332b209bfSAhmad Fatoum
31432b209bfSAhmad Fatoum        # Use LOG_LEVEL_INFO by default for debug builds
31532b209bfSAhmad Fatoum        LOG_LEVEL	:=	40
31632b209bfSAhmad Fatoumelse
31732b209bfSAhmad Fatoum        BUILD_TYPE	:=	release
31832b209bfSAhmad Fatoum        # Use LOG_LEVEL_NOTICE by default for release builds
31932b209bfSAhmad Fatoum        LOG_LEVEL	:=	20
32032b209bfSAhmad Fatoumendif
32132b209bfSAhmad Fatoum
322f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
323f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
324f1de4c8fSPeiyuan Song        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
325f1de4c8fSPeiyuan Songendif
326f1de4c8fSPeiyuan SongVERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
327f1de4c8fSPeiyuan Song
3288fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3298fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
3308fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3318fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
3328fd9d4d5SAntonio Nino Diazelse
3338fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
3348fd9d4d5SAntonio Nino Diazendif
3358fd9d4d5SAntonio Nino Diaz
336a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
337d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3389d29c227SSoby Mathew
3399fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3409fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
3419fc59639SAlexei Fedorovendif
3429fc59639SAlexei Fedorov
34326e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
344fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
345b86048c4SAntonio Nino Diaz
3469ab81b5eSJustin Chadwell# General warnings
3479ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
348b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
349ca661a00SMadhukar Pappireddy				-Wno-unused-parameter -Wredundant-decls
3509ab81b5eSJustin Chadwell
3519ab81b5eSJustin Chadwell# Additional warnings
3529ab81b5eSJustin Chadwell# Level 1
353e7c645b5SYann GautierWARNING1 := -Wextra
354e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
355e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
356e7c645b5SYann GautierWARNING1 += -Wold-style-definition
357e7c645b5SYann Gautier
358b7f6525dSJustin Chadwell# Level 2
359e7c645b5SYann GautierWARNING2 := -Waggregate-return
360e7c645b5SYann GautierWARNING2 += -Wcast-align
361e7c645b5SYann GautierWARNING2 += -Wnested-externs
362e7c645b5SYann Gautier
363e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
364e7c645b5SYann GautierWARNING3 += -Wcast-qual
365e7c645b5SYann GautierWARNING3 += -Wconversion
366e7c645b5SYann GautierWARNING3 += -Wpacked
367e7c645b5SYann GautierWARNING3 += -Wpointer-arith
368e7c645b5SYann GautierWARNING3 += -Wswitch-default
369e7c645b5SYann Gautier
370e7c645b5SYann Gautierifeq (${W},1)
3719ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
372e7c645b5SYann Gautierelse ifeq (${W},2)
3739ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
374e7c645b5SYann Gautierelse ifeq (${W},3)
3759ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
376e7c645b5SYann Gautierendif
377e7c645b5SYann Gautier
3789ab81b5eSJustin Chadwell# Compiler specific warnings
37900296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
38093c690ebSJustin Chadwell# not using clang
381d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
382d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
383d7b4cd41SJustin Chadwell				-Wlogical-op
38493c690ebSJustin Chadwellelse
38593c690ebSJustin Chadwell# using clang
386d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
387d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
38800296576SAmbroise Vincentendif
38900296576SAmbroise Vincent
3906336b07aSYann Gautierifneq (${E},0)
3916336b07aSYann GautierERRORS := -Werror
3926336b07aSYann Gautierendif
3936336b07aSYann Gautier
394ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3959ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
39659de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
397d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
39859de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
399ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
400ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
401ebd6efaeSSamuel Holland				-Os -std=gnu99
40273c99d4eSJuan Castillo
4031f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4041f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
4051f461979SJustin Chadwellendif
4061f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
4071f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
4081f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
4091f461979SJustin Chadwellendif
4101f461979SJustin Chadwell
411f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
412f7ec31dbSdavid cunado
413641f16e7SAmbroise Vincent# LD = armlink
414c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
415c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
416c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
417edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
418641f16e7SAmbroise Vincent
419641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
420edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
421edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
422edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
423edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
424edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
425edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
426edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
427edbce9aaSzelalem-aweke	endif
428edbce9aaSzelalem-awekeendif
429edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
430edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
431edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
432edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
433edbce9aaSzelalem-awekeendif
434edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
435edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
436641f16e7SAmbroise Vincent
437641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
438c2ad38ceSVarun Wadekarelse
439c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
440c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
441641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
442641f16e7SAmbroise Vincent# therefore don't add those in that case
443641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
444c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
445edbce9aaSzelalem-awekeendif
446641f16e7SAmbroise Vincentendif
44773c99d4eSJuan Castillo
44803b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
449a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
450a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
45103b397a8SNishanth Menon
45273c99d4eSJuan Castillo################################################################################
45373c99d4eSJuan Castillo# Common sources and include directories
45473c99d4eSJuan Castillo################################################################################
4556a0da736SJayanth Dodderi Chidanandinclude ${MAKE_HELPERS_DIRECTORY}arch_features.mk
456d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
45773c99d4eSJuan Castillo
45873c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4597f56e9a3SSoby Mathew				common/tf_log.c				\
4609d29c227SSoby Mathew				common/${ARCH}/debug.S			\
46191b48c9fSJulius Werner				drivers/console/multi_console.c		\
4629d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4639d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
464566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4657f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
46675311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4679d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
46861f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
469d7a6b0f8SRyan Harkin
4708422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4718422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4728422a840SAntonio Nino Diazendif
4738422a840SAntonio Nino Diaz
4741f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4751f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
4761f461979SJustin Chadwellendif
4771f461979SJustin Chadwell
47801d237cbSYann GautierINCLUDES		+=	-Iinclude				\
479f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
48009d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
48109d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
48209d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
48309d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
48409d40e0eSAntonio Nino Diaz
4859c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4869c6d1c50SAntonio Nino Diaz
48773c99d4eSJuan Castillo################################################################################
48873c99d4eSJuan Castillo# Generic definitions
48973c99d4eSJuan Castillo################################################################################
49073c99d4eSJuan Castillo
491231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
492231c1470SEvan Lloyd
49329214e95SGrant Likelyifeq (${BUILD_BASE},)
49473c99d4eSJuan Castillo     BUILD_BASE		:=	./build
49529214e95SGrant Likelyendif
49629214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
49773c99d4eSJuan Castillo
498231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
49973c99d4eSJuan Castillo
50073c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
50173c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
50273c99d4eSJuan Castillo
50373c99d4eSJuan Castillo
50473c99d4eSJuan Castillo################################################################################
50573c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
50673c99d4eSJuan Castillo################################################################################
50773c99d4eSJuan Castillo
50873c99d4eSJuan Castilloifneq (${SPD},none)
5099d29c227SSoby Mathew    ifeq (${ARCH},aarch32)
5109d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
5119d29c227SSoby Mathew    endif
51228f39f02SMax Shvetsov
5134c117f6cSSandrine Bailleux    ifdef EL3_PAYLOAD_BASE
5144c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
5154c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
5164c117f6cSSandrine Bailleux    endif
51728f39f02SMax Shvetsov
518c3fb00d9SAchin Gupta    ifeq (${SPD},spmd)
519c3fb00d9SAchin Gupta        # SPMD is located in std_svc directory
520c3fb00d9SAchin Gupta        SPD_DIR := std_svc
52128f39f02SMax Shvetsov
522033039f8SMax Shvetsov        ifeq ($(SPMD_SPM_AT_SEL2),1)
52328f39f02SMax Shvetsov            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
524033039f8SMax Shvetsov                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
525033039f8SMax Shvetsov            endif
52628f39f02SMax Shvetsov        endif
527db1ef41aSOlivier Deprez
528db1ef41aSOlivier Deprez        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
529db1ef41aSOlivier Deprez            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
530db1ef41aSOlivier Deprez        endif
531ca932481SDavidson K
532ca932481SDavidson K        ifeq ($(TS_SP_FW_CONFIG),1)
533ca932481SDavidson K            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
534ca932481SDavidson K        endif
53533993a37SBalint Dobszay
53633993a37SBalint Dobszay        ifneq ($(ARM_BL2_SP_LIST_DTS),)
53733993a37SBalint Dobszay            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
53833993a37SBalint Dobszay        endif
53946789a7cSBalint Dobszay
54046789a7cSBalint Dobszay        ifneq ($(SP_LAYOUT_FILE),)
54146789a7cSBalint Dobszay            BL2_ENABLE_SP_LOAD := 1
54246789a7cSBalint Dobszay        endif
543c3fb00d9SAchin Gupta    else
544c3fb00d9SAchin Gupta        # All other SPDs in spd directory
545c3fb00d9SAchin Gupta        SPD_DIR := spd
546c3fb00d9SAchin Gupta    endif
547c3fb00d9SAchin Gupta
54873c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
549c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
550c3fb00d9SAchin Gupta
55173c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
552c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
55373c99d4eSJuan Castillo    endif
55473c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
55573c99d4eSJuan Castillo    include ${SPD_MAKE}
55673c99d4eSJuan Castillo
55770d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
55870d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
55970d1fc53SJuan Castillo    # supports two mutually exclusive options:
56070d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
56170d1fc53SJuan Castillo    #   of source files to build BL32
56270d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
56370d1fc53SJuan Castillo    #   that will be included in the FIP
56470d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
56570d1fc53SJuan Castillo    # over the sources.
566e35c4045SJeenu Viswambharanendif
567e35c4045SJeenu Viswambharan
56851faada7SDouglas Raillard################################################################################
5695b18de09SZelalem Aweke# Include rmmd Makefile if RME is enabled
5705b18de09SZelalem Aweke################################################################################
5715b18de09SZelalem Aweke
5725b18de09SZelalem Awekeifneq (${ENABLE_RME},0)
5735b18de09SZelalem Awekeifneq (${ARCH},aarch64)
5745b18de09SZelalem Aweke	$(error ENABLE_RME requires AArch64)
5755b18de09SZelalem Awekeendif
5765b18de09SZelalem Awekeinclude services/std_svc/rmmd/rmmd.mk
5775b18de09SZelalem Aweke$(warning "RME is an experimental feature")
5785b18de09SZelalem Awekeendif
5795b18de09SZelalem Aweke
5805b18de09SZelalem Aweke################################################################################
58173c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
58273c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
58373c99d4eSJuan Castillo################################################################################
5842da8d8bfSJeenu Viswambharan
58573c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
5860f21c547SJuan Castillo
5878012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
5888012cc5cSMasahiro Yamada
58926e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
59026e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
59126e63c44SEtienne Carriereendif
59226e63c44SEtienne Carriere
5933bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
5943bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
5953bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
5963bd17c0fSSoby Mathewendif
597320920c1SMasahiro Yamada
598320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
599320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
600320920c1SMasahiro Yamadaelse
601320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
602320920c1SMasahiro Yamadaendif
603320920c1SMasahiro Yamada
604320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
60569af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
60669af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
60769af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
60869af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
60969af7fcfSMasahiro Yamadaendif
61069af7fcfSMasahiro Yamadaendif
611320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
612320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
613d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
614d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
615d974301dSMasahiro Yamadaendif
6163bd17c0fSSoby Mathew
617d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
6189cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
619d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
6209cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
621d5e97a1dSMasahiro Yamadaelse
6229cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
623d5e97a1dSMasahiro Yamadaendif
6249cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
6259cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
6269cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
627d5e97a1dSMasahiro Yamadaendif
628d5e97a1dSMasahiro Yamada
62954035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
63054035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
63154035fc4SSandrine Bailleux# This can be overridden by the platform.
63273c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6334f6ad66aSAchin Gupta
634a4409008Sdp-armifeq (${ARCH},aarch32)
635a4409008Sdp-armNEED_BL32 := yes
636a4409008Sdp-arm
637a4409008Sdp-arm################################################################################
638a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
639a4409008Sdp-arm################################################################################
640a4409008Sdp-armifneq (${AARCH32_SP},none)
641a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
642a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
643a4409008Sdp-arm
644a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
645a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
646a4409008Sdp-armendif
647a4409008Sdp-arm
648a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
649a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
650a4409008Sdp-armendif
651a4409008Sdp-arm
652a4409008Sdp-armendif
6534f6ad66aSAchin Gupta
65473c99d4eSJuan Castillo################################################################################
65577f1f7a1SVarun Wadekar# Include libc if not overridden
65677f1f7a1SVarun Wadekar################################################################################
65777f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
65877f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
65977f1f7a1SVarun Wadekarendif
66077f1f7a1SVarun Wadekar
66177f1f7a1SVarun Wadekar################################################################################
662cf2c8a33SAntonio Nino Diaz# Check incompatible options
663cf2c8a33SAntonio Nino Diaz################################################################################
664cf2c8a33SAntonio Nino Diaz
665cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
66668450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
66768450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
66868450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
669cf2c8a33SAntonio Nino Diaz        endif
67076580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
67176580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
67276580f3dSQixiang Xu        endif
67376580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
67476580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
67576580f3dSQixiang Xu        endif
676cf2c8a33SAntonio Nino Diazendif
677cf2c8a33SAntonio Nino Diaz
678cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
679cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
680cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
681cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
682cf2c8a33SAntonio Nino Diaz        endif
68368450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
68468450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
68568450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
68668450a6dSAntonio Nino Diaz                file.")
687cf2c8a33SAntonio Nino Diaz        endif
688cf2c8a33SAntonio Nino Diazendif
689cf2c8a33SAntonio Nino Diaz
690d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
691d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
692d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
693d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
694d4593e47SJeenu Viswambharanendif
6951a0a3f06SYatharth Kochar
6967d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
6977d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
6987d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
6997d173fc5SJiafei Panendif
7007d173fc5SJiafei Pan
70114c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
70214c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
70314c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
70414c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
70514c6016aSJeenu Viswambharan    endif
70614c6016aSJeenu Viswambharanendif
70714c6016aSJeenu Viswambharan
7081a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
7091a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
7101a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
7111a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
7121a7c1cfeSJeenu Viswambharan    endif
7131a7c1cfeSJeenu Viswambharanendif
7141a7c1cfeSJeenu Viswambharan
715ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
716209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
717209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
718209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
719209a60ccSSoby Mathew    endif
720209a60ccSSoby Mathewendif
721209a60ccSSoby Mathew
722c9c56f6eSManish V Badarkheifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
723c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 1
724c9c56f6eSManish V Badarkheelse
725c9c56f6eSManish V Badarkhe    CRYPTO_SUPPORT := 0
726c9c56f6eSManish V Badarkheendif
727c9c56f6eSManish V Badarkhe
728cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
729cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
730700e7685SManish Pandey$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
73184ef9cd8SManish V Badarkheendif
73284ef9cd8SManish V Badarkhe
733b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7349fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7359fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
736b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7379fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7389fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
73906715f85SAlexei Fedorov    endif
7409fc59639SAlexei Fedorovendif
7419fc59639SAlexei Fedorov
74206715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7439fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7449fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
745b86048c4SAntonio Nino Diaz    endif
746b86048c4SAntonio Nino Diazendif
7479fc59639SAlexei Fedorov
7489dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7499dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7509dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7519dd94382SJustin Chadwell    endif
7529dd94382SJustin Chadwellendif
7539dd94382SJustin Chadwell
754396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
755396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
756396b339dSManish V Badarkheendif
757396b339dSManish V Badarkhe
7586a0da736SJayanth Dodderi Chidanandifeq ($(FEATURE_DETECTION),1)
7596a0da736SJayanth Dodderi Chidanand    $(info FEATURE_DETECTION is an experimental feature)
7606a0da736SJayanth Dodderi Chidanandendif
7616a0da736SJayanth Dodderi Chidanand
76260e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
76360e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
76460e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
76560e8f3cfSPetre-Ionut Tudor    endif
76660e8f3cfSPetre-Ionut Tudorendif
76760e8f3cfSPetre-Ionut Tudor
7687cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7697cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7707cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7717cda17bbSSumit Garg    endif
7727cda17bbSSumit Gargendif
7737cda17bbSSumit Garg
774dc78e62dSjohpow01# SME/SVE only supported on AArch64
775dc78e62dSjohpow01ifeq (${ARCH},aarch32)
776dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
777dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
778dc78e62dSjohpow01    endif
779dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
780dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
78124ab2c0aSYann Gautier        $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
782dc78e62dSjohpow01    endif
783dc78e62dSjohpow01endif
784dc78e62dSjohpow01
785dc78e62dSjohpow01# Ensure ENABLE_RME is not used with SME
786dc78e62dSjohpow01ifeq (${ENABLE_RME},1)
787dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
788dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
789dc78e62dSjohpow01    endif
790dc78e62dSjohpow01endif
791dc78e62dSjohpow01
792dc78e62dSjohpow01# Secure SME/SVE requires the non-secure component as well
793dc78e62dSjohpow01ifeq (${ENABLE_SME_FOR_SWD},1)
794dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},0)
795dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
796dc78e62dSjohpow01    endif
797dc78e62dSjohpow01endif
798dc78e62dSjohpow01ifeq (${ENABLE_SVE_FOR_SWD},1)
799dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},0)
800dc78e62dSjohpow01        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
801dc78e62dSjohpow01    endif
802dc78e62dSjohpow01endif
803dc78e62dSjohpow01
804dc78e62dSjohpow01# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
805dc78e62dSjohpow01# its own context management including FPU registers.
806dc78e62dSjohpow01ifeq (${CTX_INCLUDE_FPREGS},1)
807dc78e62dSjohpow01    ifeq (${ENABLE_SME_FOR_NS},1)
808dc78e62dSjohpow01        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
809dc78e62dSjohpow01    endif
810dc78e62dSjohpow01    ifeq (${ENABLE_SVE_FOR_NS},1)
811dc78e62dSjohpow01        # Warning instead of error due to CI dependency on this
812dc78e62dSjohpow01        $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
813dc78e62dSjohpow01        $(warning "Forced ENABLE_SVE_FOR_NS=0")
814dc78e62dSjohpow01        override ENABLE_SVE_FOR_NS	:= 0
815dc78e62dSjohpow01    endif
816dc78e62dSjohpow01endif
817dc78e62dSjohpow01
818cf2c8a33SAntonio Nino Diaz################################################################################
81973c99d4eSJuan Castillo# Process platform overrideable behaviour
82073c99d4eSJuan Castillo################################################################################
8214f6ad66aSAchin Gupta
8225f24ce96SManish Pandeyifdef BL1_SOURCES
8235f24ce96SManish PandeyNEED_BL1 := yes
8245f24ce96SManish Pandeyendif
8255f24ce96SManish Pandey
8265f24ce96SManish Pandeyifdef BL2_SOURCES
8275f24ce96SManish Pandey	NEED_BL2 := yes
8285f24ce96SManish Pandey
829bd97f83aSJohn Tsichritzis	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
830bd97f83aSJohn Tsichritzis	# Certificate generation tools. This flag can be overridden by the platform.
831cf2c8a33SAntonio Nino Diaz	ifdef EL3_PAYLOAD_BASE
832cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
833cf2c8a33SAntonio Nino Diaz                # in the FIP file.
8344c117f6cSSandrine Bailleux                NEED_BL33		:=	no
835cf2c8a33SAntonio Nino Diaz        else
83668450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
837cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
838cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
839cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
840cf2c8a33SAntonio Nino Diaz                else
841cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
842cf2c8a33SAntonio Nino Diaz                endif
8434c117f6cSSandrine Bailleux        endif
84473c99d4eSJuan Castilloendif
8456f971622SJuan Castillo
8465f24ce96SManish Pandeyifdef BL2U_SOURCES
8475f24ce96SManish PandeyNEED_BL2U := yes
8485f24ce96SManish Pandeyendif
8495f24ce96SManish Pandey
8504d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
8514d045d0eSMasahiro Yamadaifdef SCP_BL2
8524d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
8534d045d0eSMasahiro Yamadaendif
8544d045d0eSMasahiro Yamada
8555744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
8565744e874SSoby Mathewifneq (${ARCH},aarch32)
8575744e874SSoby Mathew    ifdef BL31_SOURCES
8585744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
8595744e874SSoby Mathew        # put it in the FIP.
8605744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8615744e874SSoby Mathew            NEED_BL31 := yes
8625744e874SSoby Mathew        endif
8635744e874SSoby Mathew    endif
8645744e874SSoby Mathewendif
8655744e874SSoby Mathew
86673c99d4eSJuan Castillo# Process TBB related flags
8676f971622SJuan Castilloifneq (${GENERATE_COT},0)
86873c99d4eSJuan Castillo        # Common cert_create options
8696f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8706f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8710191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
872fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
873fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8740191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
875fd34e7baSJuan Castillo                endif
8766f971622SJuan Castillo        endif
87773c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
87873c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
87973c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
88073c99d4eSJuan Castillo        endif
8816f971622SJuan Castilloendif
8826f971622SJuan Castillo
8831c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
8841c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
8851c75d5dfSMasahiro Yamadaendif
8861c75d5dfSMasahiro Yamada
8875f24ce96SManish Pandeyifdef FDT_SOURCES
8885f24ce96SManish PandeyNEED_FDT := yes
8895f24ce96SManish Pandeyendif
8905f24ce96SManish Pandey
89173c99d4eSJuan Castillo################################################################################
89246e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
89346e5e035SMichalis Pappas################################################################################
89446e5e035SMichalis Pappas
89546e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
89646e5e035SMichalis Pappas
89746e5e035SMichalis Pappas################################################################################
898819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
89973c99d4eSJuan Castillo################################################################################
90073c99d4eSJuan Castillo
90173c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
90273c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
90342a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
90473c99d4eSJuan Castillo
90590aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
90690aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
90790aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
90890aa901fSSumit Garg
90973c99d4eSJuan Castillo# Variables for use with Firmware Image Package
910819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
911819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
91273c99d4eSJuan Castillo
91326010da1SAntonio Nino Diaz# Variables for use with sptool
91426010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
91526010da1SAntonio Nino DiazSPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
916ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
91726010da1SAntonio Nino Diaz
9185accce5bSRoberto Vargas# Variables for use with ROMLIB
9195accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
9205accce5bSRoberto Vargas
921cfe83910SLouis Mayencourt# Variable for use with Python
922cfe83910SLouis MayencourtPYTHON			?=	python3
923cfe83910SLouis Mayencourt
924cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
925cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
926cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
927cfe83910SLouis Mayencourt
9286de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
9296de32378SMadhukar PappireddyDOCS_PATH		?=	docs
9306de32378SMadhukar Pappireddy
9311f1c0206SAbdul Halim, Muhammad Hadi Asyrafi# Defination of SIMICS flag
9321f1c0206SAbdul Halim, Muhammad Hadi AsyrafiSIMICS_BUILD	?=	0
9331f1c0206SAbdul Halim, Muhammad Hadi Asyrafi
9348a86052dSSoby Mathew################################################################################
9358a86052dSSoby Mathew# Include BL specific makefiles
9368a86052dSSoby Mathew################################################################################
9375f24ce96SManish Pandey
9385f24ce96SManish Pandeyifeq (${NEED_BL1},yes)
9398a86052dSSoby Mathewinclude bl1/bl1.mk
9408a86052dSSoby Mathewendif
9418a86052dSSoby Mathew
9425f24ce96SManish Pandeyifeq (${NEED_BL2},yes)
9438a86052dSSoby Mathewinclude bl2/bl2.mk
9448a86052dSSoby Mathewendif
9458a86052dSSoby Mathew
9465f24ce96SManish Pandeyifeq (${NEED_BL2U},yes)
9478a86052dSSoby Mathewinclude bl2u/bl2u.mk
9488a86052dSSoby Mathewendif
9498a86052dSSoby Mathew
9505744e874SSoby Mathewifeq (${NEED_BL31},yes)
9518a86052dSSoby Mathewinclude bl31/bl31.mk
9528a86052dSSoby Mathewendif
95303b397a8SNishanth Menon
95473c99d4eSJuan Castillo################################################################################
95573c99d4eSJuan Castillo# Build options checks
95673c99d4eSJuan Castillo################################################################################
95773c99d4eSJuan Castillo
958327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
959327131c4SLeonardo Sandoval    $(sort \
960327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
96146789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
962327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
963327131c4SLeonardo Sandoval        CREATE_KEYS \
964327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
965327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
966327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
967327131c4SLeonardo Sandoval        DEBUG \
9680063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
969327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
970327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
971327131c4SLeonardo Sandoval        ENABLE_AMU \
9721fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
973742ca230SChris Kay        ENABLE_AMU_FCONF \
974873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
975327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
976327131c4SLeonardo Sandoval        ENABLE_PIE \
977327131c4SLeonardo Sandoval        ENABLE_PMF \
978327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
979327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
980dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
981dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
982327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
983327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
9840c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
985327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
986327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
987327131c4SLeonardo Sandoval        GENERATE_COT \
988327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
989327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
990327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
991327131c4SLeonardo Sandoval        INVERTED_MEMMAP \
992327131c4SLeonardo Sandoval        MEASURED_BOOT \
993327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
994327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
995327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
996327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
997327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
998327131c4SLeonardo Sandoval        RESET_TO_BL31 \
999327131c4SLeonardo Sandoval        SAVE_KEYS \
1000327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
100196a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1002327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1003327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1004327131c4SLeonardo Sandoval        SPM_MM \
1005327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1006327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1007c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
1008327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1009327131c4SLeonardo Sandoval        USE_DEBUGFS \
1010327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1011327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1012327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1013327131c4SLeonardo Sandoval        USE_ROMLIB \
1014327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1015327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1016327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1017327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1018327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1019327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1020327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1021327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1022327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1023327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1024327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1025327131c4SLeonardo Sandoval        USE_SP804_TIMER \
1026396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1027813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1028d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
102968120783SChris Kay        ENABLE_MPMM \
103068120783SChris Kay        ENABLE_MPMM_FCONF \
10311f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
10326a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1033327131c4SLeonardo Sandoval)))
103473c99d4eSJuan Castillo
1035327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
1036327131c4SLeonardo Sandoval    $(sort \
1037327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1038327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1039327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
10406a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_PAUTH_REGS \
10416a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_MTE_REGS \
10426a0da736SJayanth Dodderi Chidanand        CTX_INCLUDE_NEVE_REGS \
10436a0da736SJayanth Dodderi Chidanand        ENABLE_BTI \
10446a0da736SJayanth Dodderi Chidanand        ENABLE_PAUTH \
10456a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
10466a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
10476a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
10486a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_DIT \
10496a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
10506a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
10516a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_HCX \
10526a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
10536a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_RNG \
10546a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SB \
10556a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
10566a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
10576a0da736SJayanth Dodderi Chidanand        ENABLE_MPAM_FOR_LOWER_ELS \
10586a0da736SJayanth Dodderi Chidanand        ENABLE_RME \
10596a0da736SJayanth Dodderi Chidanand        ENABLE_TRF_FOR_NS \
1060327131c4SLeonardo Sandoval        FW_ENC_STATUS \
10615357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10625357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
10636a0da736SJayanth Dodderi Chidanand        RAS_EXTENSION \
1064*781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1065*781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1066327131c4SLeonardo Sandoval)))
1067c877b414SJeenu Viswambharan
1068aacff749SJustin Chadwellifdef KEY_SIZE
1069aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
1070aacff749SJustin Chadwellendif
1071aacff749SJustin Chadwell
10721f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
10731f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
10741f461979SJustin Chadwellendif
10751f461979SJustin Chadwell
107673c99d4eSJuan Castillo################################################################################
107773c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
107873c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
107973c99d4eSJuan Castillo# platform to overwrite the default options
108073c99d4eSJuan Castillo################################################################################
108173c99d4eSJuan Castillo
1082327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1083327131c4SLeonardo Sandoval    $(sort \
1084327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
1085327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1086327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
108746789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
1088327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1089327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1090327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1091327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1092327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1093327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1094327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1095062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1096327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
10970063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1098327131c4SLeonardo Sandoval        ENABLE_AMU \
10991fd685a7SChris Kay        ENABLE_AMU_AUXILIARY_COUNTERS \
1100742ca230SChris Kay        ENABLE_AMU_FCONF \
1101873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1102327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1103327131c4SLeonardo Sandoval        ENABLE_BTI \
1104327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1105327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1106327131c4SLeonardo Sandoval        ENABLE_PIE \
1107327131c4SLeonardo Sandoval        ENABLE_PMF \
1108327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
11095b18de09SZelalem Aweke        ENABLE_RME \
1110327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1111dc78e62dSjohpow01        ENABLE_SME_FOR_NS \
1112dc78e62dSjohpow01        ENABLE_SME_FOR_SWD \
1113327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1114327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
11150c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1116327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1117327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1118327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1119327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1120327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1121327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1122327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1123327131c4SLeonardo Sandoval        LOG_LEVEL \
1124327131c4SLeonardo Sandoval        MEASURED_BOOT \
1125327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1126327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1127327131c4SLeonardo Sandoval        PLAT_${PLAT} \
1128327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1129327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1130327131c4SLeonardo Sandoval        RAS_EXTENSION \
1131327131c4SLeonardo Sandoval        RESET_TO_BL31 \
1132327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
113396a8ed14SJiafei Pan        SEPARATE_BL2_NOLOAD_REGION \
1134327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1135327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1136327131c4SLeonardo Sandoval        SPD_${SPD} \
1137327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1138327131c4SLeonardo Sandoval        SPM_MM \
1139327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1140327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
1141c9c56f6eSManish V Badarkhe        CRYPTO_SUPPORT \
11427dfb9911SJimmy Brisson        TRNG_SUPPORT \
1143327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1144327131c4SLeonardo Sandoval        USE_DEBUGFS \
1145327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1146327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1147327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1148327131c4SLeonardo Sandoval        USE_ROMLIB \
1149327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1150327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1151327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1152327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1153327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1154327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1155327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1156327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1157327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1158327131c4SLeonardo Sandoval        USE_SP804_TIMER \
115912cd65e0STomas Pilar        ENABLE_FEAT_RNG \
11604e04478aSChris Kay        ENABLE_FEAT_SB \
11617d33ffe4SDaniel Boulby        ENABLE_FEAT_DIT \
11625357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
11635357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1164396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1165813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1166d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
11678fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1168cb4ec47bSjohpow01        ENABLE_FEAT_HCX \
116968120783SChris Kay        ENABLE_MPMM \
117068120783SChris Kay        ENABLE_MPMM_FCONF \
1171f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_FGT \
1172f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1 \
1173f74cb0beSJayanth Dodderi Chidanand        ENABLE_FEAT_ECV \
11741f1c0206SAbdul Halim, Muhammad Hadi Asyrafi        SIMICS_BUILD \
11756a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_AMUv1p1 \
11766a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_SEL2 \
11776a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_VHE \
11786a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_CSV2_2 \
11796a0da736SJayanth Dodderi Chidanand        ENABLE_FEAT_PAN \
11806a0da736SJayanth Dodderi Chidanand        FEATURE_DETECTION \
1181*781d07a4SJayanth Dodderi Chidanand        TWED_DELAY \
1182*781d07a4SJayanth Dodderi Chidanand        ENABLE_FEAT_TWED \
1183327131c4SLeonardo Sandoval)))
11842fae4b1eSJeenu Viswambharan
11851f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
11861f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
11871f461979SJustin Chadwellendif
11881f461979SJustin Chadwell
11894c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
11904c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
11914c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1192cf2c8a33SAntonio Nino Diazelse
119368450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
119468450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
119568450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
119668450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
11974c117f6cSSandrine Bailleux        endif
1198cf2c8a33SAntonio Nino Diazendif
119973c99d4eSJuan Castillo
1200209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1201209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1202209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1203209a60ccSSoby Mathewendif
1204209a60ccSSoby Mathew
1205c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1206c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1207c2ad38ceSVarun Wadekarendif
1208c2ad38ceSVarun Wadekar
1209ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1210ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1211c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1212ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1213ce2b1ec6SManish Pandey        FIP_DEPS += sp
121407c44475SManish Pandey        CRT_DEPS += sp
1215ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1216ce2b1ec6SManish Pandeyelse
1217c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1218c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1219c33ff198SOlivier Deprez        endif
1220ce2b1ec6SManish Pandeyendif
1221ce2b1ec6SManish Pandeyendif
1222ce2b1ec6SManish Pandey
122373c99d4eSJuan Castillo################################################################################
122473c99d4eSJuan Castillo# Build targets
122573c99d4eSJuan Castillo################################################################################
122673c99d4eSJuan Castillo
122790aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
122873c99d4eSJuan Castillo.SUFFIXES:
122973c99d4eSJuan Castillo
123073c99d4eSJuan Castilloall: msg_start
123173c99d4eSJuan Castillo
123273c99d4eSJuan Castillomsg_start:
123373c99d4eSJuan Castillo	@echo "Building ${PLAT}"
123473c99d4eSJuan Castillo
12357a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1236d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1237c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1238c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1239c2ad38ceSVarun Wadekarelse
1240bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
12417a24cba5SSoby Mathewendif
1242d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
12437a24cba5SSoby Mathew
12445accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
124561f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
12465fee0287SRoberto Vargas
124773c99d4eSJuan Castillo# Expand build macros for the different images
124873c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
1249b34635a0SChris KayBL1_SOURCES := $(sort ${BL1_SOURCES})
1250b34635a0SChris Kay
1251434d0491SZelalem Aweke$(eval $(call MAKE_BL,bl1))
125273c99d4eSJuan Castilloendif
125373c99d4eSJuan Castillo
125473c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1255c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1256c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1257c9b31ae8SRoberto Vargasendif
1258c9b31ae8SRoberto Vargas
1259eb1acfb6SChris KayBL2_SOURCES := $(sort ${BL2_SOURCES})
1260eb1acfb6SChris Kay
126133950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1262434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
126373c99d4eSJuan Castilloendif
126473c99d4eSJuan Castillo
12654d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
126633950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
12674d045d0eSMasahiro Yamadaendif
12684d045d0eSMasahiro Yamada
126973c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
127073c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
127126d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
127226d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1273c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1274c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1275434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1276c6ba9b45SSumit Gargelse
127733950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1278434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl31,soc-fw)))
127973c99d4eSJuan Castilloendif
1280c6ba9b45SSumit Gargendif
128173c99d4eSJuan Castillo
128270d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1283c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
128470d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
128573c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
128626d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
128726d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
12889cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
12899cd15239SMasahiro Yamada
1290c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1291434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1292c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1293c6ba9b45SSumit Gargelse
1294434d0491SZelalem Aweke$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
129533950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
129673c99d4eSJuan Castilloendif
1297c6ba9b45SSumit Gargendif
129873c99d4eSJuan Castillo
12995b18de09SZelalem Aweke# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
13005b18de09SZelalem Aweke# needs to be built from RMM_SOURCES.
13015b18de09SZelalem Awekeifeq (${NEED_RMM},yes)
13025b18de09SZelalem Aweke# Sort RMM source files to remove duplicates
13035b18de09SZelalem AwekeRMM_SOURCES := $(sort ${RMM_SOURCES})
13045b18de09SZelalem AwekeBUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
13055b18de09SZelalem Aweke
13065b18de09SZelalem Aweke$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
13075b18de09SZelalem Aweke         $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
13085b18de09SZelalem Awekeendif
13095b18de09SZelalem Aweke
131073c99d4eSJuan Castillo# Add the BL33 image if required by the platform
131173c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
131233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1313db6071c9SJuan Castilloendif
1314db6071c9SJuan Castillo
13159003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
131633950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1317434d0491SZelalem Aweke	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
13189003fa0bSYatharth Kocharendif
13199003fa0bSYatharth Kochar
132003b397a8SNishanth Menon# Expand build macros for the different images
132103b397a8SNishanth Menonifeq (${NEED_FDT},yes)
132203b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
132303b397a8SNishanth Menonendif
132403b397a8SNishanth Menon
1325ce2b1ec6SManish Pandey# Add Secure Partition packages
1326ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1327ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
13281e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1329ce2b1ec6SManish Pandeysp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1330ce2b1ec6SManish Pandey	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1331ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1332ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1333ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1334ce2b1ec6SManish Pandeyendif
1335ce2b1ec6SManish Pandey
133636eaaf37SIan Spraylocate-checkpatch:
133736eaaf37SIan Sprayifndef CHECKPATCH
133866079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
133936eaaf37SIan Sprayelse
134036eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
134166079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
134236eaaf37SIan Sprayendif
134336eaaf37SIan Sprayendif
134436eaaf37SIan Spray
13454f6ad66aSAchin Guptaclean:
13464f6ad66aSAchin Gupta	@echo "  CLEAN"
1347f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
134888a1cf1eSSami Mujawarifdef UNIX_MK
13492f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
135088a1cf1eSSami Mujawarelse
135188a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
135288a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
135388a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
135488a1cf1eSSami Mujawarendif
13556f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
135690aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
13575accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13584f6ad66aSAchin Gupta
1359eaaeece2SJames Morrisseyrealclean distclean:
1360eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1361f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1362f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
136388a1cf1eSSami Mujawarifdef UNIX_MK
13642f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
136588a1cf1eSSami Mujawarelse
136688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
136788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
136888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
136988a1cf1eSSami Mujawarendif
137026010da1SAntonio Nino Diaz	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
1371e15591aaSNicolas Boulenguez	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
137290aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
13735accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
13744f6ad66aSAchin Gupta
137536eaaf37SIan Spraycheckcodebase:		locate-checkpatch
137636eaaf37SIan Spray	@echo "  CHECKING STYLE"
137736eaaf37SIan Spray	@if test -d .git ; then						\
13781ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
13791a41e8c1SDan Handley		while read GIT_FILE ;					\
13801a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
13811a41e8c1SDan Handley		done ;							\
138236eaaf37SIan Spray	else								\
13831a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
13841a41e8c1SDan Handley		 -not -iwholename "*build*"				\
13851a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
138661f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
13871a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
13881ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
13891a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
139036eaaf37SIan Spray	fi
139136eaaf37SIan Spray
139236eaaf37SIan Spraycheckpatch:		locate-checkpatch
139336eaaf37SIan Spray	@echo "  CHECKING STYLE"
139402a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
139502a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
139602a76d5fSYann Gautier	fi
139751d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
139877a0a7f1SYann Gautier	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
139977a0a7f1SYann Gautier	do								\
140051d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
140151d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
140202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
140302a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
140451d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
140502a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
140602a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
140751d28937SAntonio Nino Diaz	done
140836eaaf37SIan Spray
140973c99d4eSJuan Castillocerttool: ${CRTTOOL}
141073c99d4eSJuan Castillo
1411a9812206SPali Rohár${CRTTOOL}: FORCE
1412fafd3ec9SManish 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}
1413f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14146f971622SJuan Castillo	@echo "Built $@ successfully"
1415f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14166f971622SJuan Castillo
14176f971622SJuan Castilloifneq (${GENERATE_COT},0)
141873c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
14196f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1420f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14216f971622SJuan Castillo	@echo "Built $@ successfully"
14226f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1423f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
142473c99d4eSJuan Castilloendif
142527713fb4SSoby Mathew
142673c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
14274727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1428819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1429819281eeSdp-arm	${Q}${FIPTOOL} info $@
1430f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
14312f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1432f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1433f58ad36fSHarry Liebel
14340191262dSYatharth Kocharifneq (${GENERATE_COT},0)
14350191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
14360191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1437052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14380191262dSYatharth Kochar	@echo "Built $@ successfully"
14390191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1440052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14410191262dSYatharth Kocharendif
14420191262dSYatharth Kochar
14430191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
14444727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1445819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1446819281eeSdp-arm	${Q}${FIPTOOL} info $@
1447052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14480191262dSYatharth Kochar	@echo "Built $@ successfully"
1449052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
14500191262dSYatharth Kochar
145173c99d4eSJuan Castillofiptool: ${FIPTOOL}
145273c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
14530191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
145473c99d4eSJuan Castillo
1455a9812206SPali Rohár${FIPTOOL}: FORCE
145688a1cf1eSSami Mujawarifdef UNIX_MK
14570a956f81SRoss Burton	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH}
145888a1cf1eSSami Mujawarelse
145988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
146088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
146188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
146288a1cf1eSSami Mujawarendif
1463f58ad36fSHarry Liebel
146426010da1SAntonio Nino Diazsptool: ${SPTOOL}
1465a9812206SPali Rohár${SPTOOL}: FORCE
1466fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH}
146726010da1SAntonio Nino Diaz
1468a9812206SPali Rohárromlib.bin: libraries FORCE
1469bbb24f61SJohn 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
14705accce5bSRoberto Vargas
1471cfe83910SLouis Mayencourt# Call print_memory_map tool
1472cfe83910SLouis Mayencourtmemmap: all
1473b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1474cfe83910SLouis Mayencourt
14756de32378SMadhukar Pappireddydoc:
14766de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
14776de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
14786de32378SMadhukar Pappireddy
147990aa901fSSumit Gargenctool: ${ENCTOOL}
148090aa901fSSumit Garg
1481a9812206SPali Rohár${ENCTOOL}: FORCE
1482fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
148390aa901fSSumit Garg	@${ECHO_BLANK_LINE}
148490aa901fSSumit Garg	@echo "Built $@ successfully"
148590aa901fSSumit Garg	@${ECHO_BLANK_LINE}
148690aa901fSSumit Garg
148735fab8c9SJoakim Bechcscope:
148835fab8c9SJoakim Bech	@echo "  CSCOPE"
148935fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
149035fab8c9SJoakim Bech	${Q}cscope -b -q -k
149135fab8c9SJoakim Bech
149272ee3314SRyan Harkinhelp:
14937c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
149472ee3314SRyan Harkin	@echo ""
149572ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
149608c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
149772ee3314SRyan Harkin	@echo ""
14987c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
14997c23126cSJohn Tsichritzis	@echo ""
15001b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
15011b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
15021b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
15031b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
15041b578596SSandrine Bailleux	@echo ""
150572ee3314SRyan Harkin	@echo "Supported Targets:"
15061b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
150736eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
15088aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
15099003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1510d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
15119d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
15129d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
151373c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
15141b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
15150191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
151636eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
151736eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
151836eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
151972ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
152035fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
152172ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
15226f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
152390aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1524f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1525ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
152626010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
152738c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1528cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
15296de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
153072ee3314SRyan Harkin	@echo ""
15311b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
153272ee3314SRyan Harkin	@echo ""
153372ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
153472ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1535a9812206SPali Rohár
1536a9812206SPali Rohár.PHONY: FORCE
1537a9812206SPali RohárFORCE:;
1538