xref: /rk3399_ARM-atf/Makefile (revision 8fcd3d9600bb2cb6809c6fc68f945ce3ad89633d)
14f6ad66aSAchin Gupta#
27dfb9911SJimmy Brisson# Copyright (c) 2013-2021, 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
11ff2da9e3SMadhukar PappireddyVERSION_MINOR			:= 5
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
132c97cba4eSSoby Mathew# USE_SPINLOCK_CAS requires AArch64 build
133c97cba4eSSoby Mathewifeq (${USE_SPINLOCK_CAS},1)
134c97cba4eSSoby Mathewifneq (${ARCH},aarch64)
135c97cba4eSSoby Mathew        $(error USE_SPINLOCK_CAS requires AArch64)
136c97cba4eSSoby Mathewelse
137c97cba4eSSoby Mathew        $(info USE_SPINLOCK_CAS is an experimental feature)
138c97cba4eSSoby Mathewendif
139c97cba4eSSoby Mathewendif
140c97cba4eSSoby Mathew
1410ca3913dSOlivier Deprez# USE_DEBUGFS experimental feature recommended only in debug builds
1420ca3913dSOlivier Deprezifeq (${USE_DEBUGFS},1)
1430ca3913dSOlivier Deprezifeq (${DEBUG},1)
1440ca3913dSOlivier Deprez        $(warning DEBUGFS experimental feature is enabled.)
1450ca3913dSOlivier Deprezelse
1460ca3913dSOlivier Deprez        $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
1470ca3913dSOlivier Deprezendif
1480ca3913dSOlivier Deprezendif
1490ca3913dSOlivier Deprez
150c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
151c6ba9b45SSumit GargENC_ARGS += -f ${FW_ENC_STATUS}
152c6ba9b45SSumit GargENC_ARGS += -k ${ENC_KEY}
153c6ba9b45SSumit GargENC_ARGS += -n ${ENC_NONCE}
154c6ba9b45SSumit GargFIP_DEPS += enctool
155c6ba9b45SSumit GargFWU_FIP_DEPS += enctool
156c6ba9b45SSumit Gargendif
157c6ba9b45SSumit Garg
15873c99d4eSJuan Castillo################################################################################
15973c99d4eSJuan Castillo# Toolchain
16073c99d4eSJuan Castillo################################################################################
16173c99d4eSJuan Castillo
16272610c41Sdp-armHOSTCC			:=	gcc
16372610c41Sdp-armexport HOSTCC
16472610c41Sdp-arm
16573c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
16673c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
16773c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
16873c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1692adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
17073c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
17173c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
17273c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
17373c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
17438c14d88SSoby MathewDTC			:=	dtc
17573c99d4eSJuan Castillo
176b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
177b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1782adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1792adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
180b25a577fSJulius Wernerendif
181b25a577fSJulius Werner
18226e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
18326e63c44SEtienne Carrieretarget32-directive	= 	-target arm-none-eabi
18426e63c44SEtienne Carriere# Will set march32-directive from platform configuration
18526e63c44SEtienne Carriereelse
18626e63c44SEtienne Carrieretarget32-directive	= 	-target armv8a-none-eabi
187fa6f774bSAlexei Fedorov
188f1821790SAlexei Fedorov# Set the compiler's target architecture profile based on
189f1821790SAlexei Fedorov# ARM_ARCH_MAJOR ARM_ARCH_MINOR options
190fa6f774bSAlexei Fedorovifeq (${ARM_ARCH_MINOR},0)
191f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
192f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}-a
193fa6f774bSAlexei Fedorovelse
194f1821790SAlexei Fedorovmarch32-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
195f1821790SAlexei Fedorovmarch64-directive	= 	-march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
196fa6f774bSAlexei Fedorovendif
19726e63c44SEtienne Carriereendif
19826e63c44SEtienne Carriere
1997ff088d1SManish V Badarkhe# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards
2007ff088d1SManish V Badarkheifeq ($(ARCH), aarch64)
2014a565bd8SSami Mujawar# Check if revision is greater than or equal to 8.5
2024a565bd8SSami Mujawarifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2037ff088d1SManish V Badarkhemem_tag_arch_support	= 	yes
2047ff088d1SManish V Badarkheendif
2057ff088d1SManish V Badarkheendif
2067ff088d1SManish V Badarkhe
207f1821790SAlexei Fedorov# Get architecture feature modifiers
208f1821790SAlexei Fedorovarch-features		=	${ARM_ARCH_FEATURE}
209f1821790SAlexei Fedorov
210f1821790SAlexei Fedorov# Enable required options for memory stack tagging.
211f1821790SAlexei Fedorov# Currently, these options are enabled only for clang and armclang compiler.
2127ff088d1SManish V Badarkheifeq (${SUPPORT_STACK_MEMTAG},yes)
2137ff088d1SManish V Badarkheifdef mem_tag_arch_support
214f1821790SAlexei Fedorov# Check for armclang and clang compilers
2157ff088d1SManish V Badarkheifneq ( ,$(filter $(notdir $(CC)),armclang clang))
216f1821790SAlexei Fedorov# Add "memtag" architecture feature modifier if not specified
217f1821790SAlexei Fedorovifeq ( ,$(findstring memtag,$(arch-features)))
218f1821790SAlexei Fedorovarch-features       	:=       $(arch-features)+memtag
219f1821790SAlexei Fedorovendif	# memtag
2207ff088d1SManish V Badarkheifeq ($(notdir $(CC)),armclang)
2217ff088d1SManish V BadarkheTF_CFLAGS		+=	-mmemtag-stack
2227ff088d1SManish V Badarkheelse ifeq ($(notdir $(CC)),clang)
2237ff088d1SManish V BadarkheTF_CFLAGS		+=	-fsanitize=memtag
224f1821790SAlexei Fedorovendif	# armclang
225f1821790SAlexei Fedorovendif	# armclang clang
2267ff088d1SManish V Badarkheelse
2277ff088d1SManish V Badarkhe$(error "Error: stack memory tagging is not supported for architecture \
2287ff088d1SManish V Badarkhe	${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
229f1821790SAlexei Fedorovendif	# mem_tag_arch_support
230f1821790SAlexei Fedorovendif	# SUPPORT_STACK_MEMTAG
231f1821790SAlexei Fedorov
232f1821790SAlexei Fedorov# Set the compiler's architecture feature modifiers
233f1821790SAlexei Fedorovifneq ($(arch-features), none)
234f1821790SAlexei Fedorov# Strip "none+" from arch-features
235f1821790SAlexei Fedorovarch-features		:=	$(subst none+,,$(arch-features))
236f1821790SAlexei Fedorovifeq ($(ARCH), aarch32)
237f1821790SAlexei Fedorovmarch32-directive	:=	$(march32-directive)+$(arch-features)
238f1821790SAlexei Fedorovelse
239f1821790SAlexei Fedorovmarch64-directive	:=	$(march64-directive)+$(arch-features)
2407ff088d1SManish V Badarkheendif
241f1821790SAlexei Fedorov# Print features
242f1821790SAlexei Fedorov$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
243f1821790SAlexei Fedorovendif	# arch-features
2447ff088d1SManish V Badarkhe
24512cd65e0STomas Pilar# Determine if FEAT_RNG is supported
24612cd65e0STomas PilarENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
24712cd65e0STomas Pilar
2484e04478aSChris Kay# Determine if FEAT_SB is supported
2494e04478aSChris KayENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
2504e04478aSChris Kay
2514e04478aSChris Kayifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))"
2524e04478aSChris KayENABLE_FEAT_SB		= 	1
2534e04478aSChris Kayendif
2544e04478aSChris Kay
255fd18a8fcSVarun Wadekarifneq ($(findstring armclang,$(notdir $(CC))),)
25626e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
257fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi $(march64-directive)
2582adee763SRoberto VargasLD			=	$(LINKER)
2591684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2607040155eSRoberto VargasCPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2617040155eSRoberto VargasPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2627559633bSdp-armelse ifneq ($(findstring clang,$(notdir $(CC))),)
263eff737c1SArve HjønnevågCLANG_CCDIR		=	$(if $(filter-out ./,$(dir $(CC))),$(dir $(CC)),)
264e2bfec0bSYann GautierTF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
265fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-elf $(march64-directive)
266eff737c1SArve HjønnevågLD			=	$(CLANG_CCDIR)ld.lld
267641f16e7SAmbroise Vincentifeq (, $(shell which $(LD)))
268641f16e7SAmbroise Vincent$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker")
269641f16e7SAmbroise Vincentendif
2701684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2717040155eSRoberto VargasCPP			=	$(CC) -E
2727040155eSRoberto VargasPP			=	$(CC) -E
273edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
274edbce9aaSzelalem-awekeTF_CFLAGS_aarch32	=	$(march32-directive)
275edbce9aaSzelalem-awekeTF_CFLAGS_aarch64	=	$(march64-directive)
276edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
277edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
278edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
279edbce9aaSzelalem-aweke		LTO_CFLAGS	=	-flto
280edbce9aaSzelalem-aweke		# Use gcc as a wrapper for the ld, recommended for LTO
281edbce9aaSzelalem-aweke		LINKER		:=	${CROSS_COMPILE}gcc
282edbce9aaSzelalem-aweke	endif
283edbce9aaSzelalem-awekeendif
284edbce9aaSzelalem-awekeLD			=	$(LINKER)
285d5461857Sdp-armelse
28626e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	$(march32-directive)
287fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	$(march64-directive)
2882adee763SRoberto VargasLD			=	$(LINKER)
289d5461857Sdp-armendif
290d5461857Sdp-arm
29132b209bfSAhmad Fatoum# Process Debug flag
29232b209bfSAhmad Fatoum$(eval $(call add_define,DEBUG))
29332b209bfSAhmad Fatoumifneq (${DEBUG}, 0)
29432b209bfSAhmad Fatoum        BUILD_TYPE	:=	debug
29532b209bfSAhmad Fatoum        TF_CFLAGS	+= 	-g
29632b209bfSAhmad Fatoum
29732b209bfSAhmad Fatoum        ifneq ($(findstring clang,$(notdir $(CC))),)
29832b209bfSAhmad Fatoum             ASFLAGS		+= 	-g
29932b209bfSAhmad Fatoum        else
30032b209bfSAhmad Fatoum             ASFLAGS		+= 	-g -Wa,--gdwarf-2
30132b209bfSAhmad Fatoum        endif
30232b209bfSAhmad Fatoum
30332b209bfSAhmad Fatoum        # Use LOG_LEVEL_INFO by default for debug builds
30432b209bfSAhmad Fatoum        LOG_LEVEL	:=	40
30532b209bfSAhmad Fatoumelse
30632b209bfSAhmad Fatoum        BUILD_TYPE	:=	release
30732b209bfSAhmad Fatoum        # Use LOG_LEVEL_NOTICE by default for release builds
30832b209bfSAhmad Fatoum        LOG_LEVEL	:=	20
30932b209bfSAhmad Fatoumendif
31032b209bfSAhmad Fatoum
311f1de4c8fSPeiyuan Song# Default build string (git branch and commit)
312f1de4c8fSPeiyuan Songifeq (${BUILD_STRING},)
313f1de4c8fSPeiyuan Song        BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
314f1de4c8fSPeiyuan Songendif
315f1de4c8fSPeiyuan SongVERSION_STRING    :=  v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
316f1de4c8fSPeiyuan Song
3178fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
3188fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
3198fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
3208fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
3218fd9d4d5SAntonio Nino Diazelse
3228fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
3238fd9d4d5SAntonio Nino Diazendif
3248fd9d4d5SAntonio Nino Diaz
325a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
326d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
3279d29c227SSoby Mathew
3289fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
3299fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
3309fc59639SAlexei Fedorovendif
3319fc59639SAlexei Fedorov
33226e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
333fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
334b86048c4SAntonio Nino Diaz
3359ab81b5eSJustin Chadwell# General warnings
3369ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
337b7f6525dSJustin Chadwell				-Wdisabled-optimization -Wvla -Wshadow	\
338ca661a00SMadhukar Pappireddy				-Wno-unused-parameter -Wredundant-decls
3399ab81b5eSJustin Chadwell
3409ab81b5eSJustin Chadwell# Additional warnings
3419ab81b5eSJustin Chadwell# Level 1
342e7c645b5SYann GautierWARNING1 := -Wextra
343e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
344e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
345e7c645b5SYann GautierWARNING1 += -Wold-style-definition
346e7c645b5SYann Gautier
347b7f6525dSJustin Chadwell# Level 2
348e7c645b5SYann GautierWARNING2 := -Waggregate-return
349e7c645b5SYann GautierWARNING2 += -Wcast-align
350e7c645b5SYann GautierWARNING2 += -Wnested-externs
351e7c645b5SYann Gautier
352e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
353e7c645b5SYann GautierWARNING3 += -Wcast-qual
354e7c645b5SYann GautierWARNING3 += -Wconversion
355e7c645b5SYann GautierWARNING3 += -Wpacked
356e7c645b5SYann GautierWARNING3 += -Wpointer-arith
357e7c645b5SYann GautierWARNING3 += -Wswitch-default
358e7c645b5SYann Gautier
359e7c645b5SYann Gautierifeq (${W},1)
3609ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
361e7c645b5SYann Gautierelse ifeq (${W},2)
3629ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
363e7c645b5SYann Gautierelse ifeq (${W},3)
3649ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
365e7c645b5SYann Gautierendif
366e7c645b5SYann Gautier
3679ab81b5eSJustin Chadwell# Compiler specific warnings
36800296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
36993c690ebSJustin Chadwell# not using clang
370d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
371d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
372d7b4cd41SJustin Chadwell				-Wlogical-op
37393c690ebSJustin Chadwellelse
37493c690ebSJustin Chadwell# using clang
375d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
376d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
37700296576SAmbroise Vincentendif
37800296576SAmbroise Vincent
3796336b07aSYann Gautierifneq (${E},0)
3806336b07aSYann GautierERRORS := -Werror
3816336b07aSYann Gautierendif
3826336b07aSYann Gautier
383ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3849ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
38559de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
386d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
38759de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
388ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
389ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
390ebd6efaeSSamuel Holland				-Os -std=gnu99
39173c99d4eSJuan Castillo
3921f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3931f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
3941f461979SJustin Chadwellendif
3951f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
3961f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
3971f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
3981f461979SJustin Chadwellendif
3991f461979SJustin Chadwell
400f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
401f7ec31dbSdavid cunado
402641f16e7SAmbroise Vincent# LD = armlink
403c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
404c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
405c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
406edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
407641f16e7SAmbroise Vincent
408641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
409edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
410edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
411edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
412edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
413edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
414edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
415edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
416edbce9aaSzelalem-aweke	endif
417edbce9aaSzelalem-awekeendif
418edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
419edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
420edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
421edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
422edbce9aaSzelalem-awekeendif
423edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
424edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
425641f16e7SAmbroise Vincent
426641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
427c2ad38ceSVarun Wadekarelse
428c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
429c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
430641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
431641f16e7SAmbroise Vincent# therefore don't add those in that case
432641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
433c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
434edbce9aaSzelalem-awekeendif
435641f16e7SAmbroise Vincentendif
43673c99d4eSJuan Castillo
43703b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
438a6de824fSLouis MayencourtDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
439a6de824fSLouis Mayencourt				-x assembler-with-cpp $(DEFINES)
44003b397a8SNishanth Menon
4410ab49645SAlexei Fedorovifeq ($(MEASURED_BOOT),1)
4420ab49645SAlexei FedorovDTC_CPPFLAGS		+=	-DMEASURED_BOOT -DBL2_HASH_SIZE=${TCG_DIGEST_SIZE}
4430ab49645SAlexei Fedorovendif
4440ab49645SAlexei Fedorov
44573c99d4eSJuan Castillo################################################################################
44673c99d4eSJuan Castillo# Common sources and include directories
44773c99d4eSJuan Castillo################################################################################
448d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
44973c99d4eSJuan Castillo
45073c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
4517f56e9a3SSoby Mathew				common/tf_log.c				\
4529d29c227SSoby Mathew				common/${ARCH}/debug.S			\
45391b48c9fSJulius Werner				drivers/console/multi_console.c		\
4549d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
4559d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
456566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
4577f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
45875311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
4599d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
46061f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
461d7a6b0f8SRyan Harkin
4628422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
4638422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
4648422a840SAntonio Nino Diazendif
4658422a840SAntonio Nino Diaz
4661f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
4671f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
4681f461979SJustin Chadwellendif
4691f461979SJustin Chadwell
47001d237cbSYann GautierINCLUDES		+=	-Iinclude				\
471f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
47209d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
47309d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
47409d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
47509d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
47609d40e0eSAntonio Nino Diaz
4779c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
4789c6d1c50SAntonio Nino Diaz
47973c99d4eSJuan Castillo################################################################################
48073c99d4eSJuan Castillo# Generic definitions
48173c99d4eSJuan Castillo################################################################################
48273c99d4eSJuan Castillo
483231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
484231c1470SEvan Lloyd
48529214e95SGrant Likelyifeq (${BUILD_BASE},)
48673c99d4eSJuan Castillo     BUILD_BASE		:=	./build
48729214e95SGrant Likelyendif
48829214e95SGrant LikelyBUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
48973c99d4eSJuan Castillo
490231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
49173c99d4eSJuan Castillo
49273c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
49373c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
49473c99d4eSJuan Castillo
49573c99d4eSJuan Castillo
49673c99d4eSJuan Castillo################################################################################
49773c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
49873c99d4eSJuan Castillo################################################################################
49973c99d4eSJuan Castillo
50073c99d4eSJuan Castilloifneq (${SPD},none)
5019d29c227SSoby Mathew    ifeq (${ARCH},aarch32)
5029d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
5039d29c227SSoby Mathew    endif
50428f39f02SMax Shvetsov
5054c117f6cSSandrine Bailleux    ifdef EL3_PAYLOAD_BASE
5064c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
5074c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
5084c117f6cSSandrine Bailleux    endif
50928f39f02SMax Shvetsov
510c3fb00d9SAchin Gupta    ifeq (${SPD},spmd)
511033039f8SMax Shvetsov        $(warning "SPMD is an experimental feature")
512c3fb00d9SAchin Gupta        # SPMD is located in std_svc directory
513c3fb00d9SAchin Gupta        SPD_DIR := std_svc
51428f39f02SMax Shvetsov
515033039f8SMax Shvetsov        ifeq ($(SPMD_SPM_AT_SEL2),1)
51628f39f02SMax Shvetsov            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
517033039f8SMax Shvetsov                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
518033039f8SMax Shvetsov            endif
51928f39f02SMax Shvetsov        endif
520db1ef41aSOlivier Deprez
521db1ef41aSOlivier Deprez        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
522db1ef41aSOlivier Deprez            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
523db1ef41aSOlivier Deprez        endif
524ca932481SDavidson K
525ca932481SDavidson K        ifeq ($(TS_SP_FW_CONFIG),1)
526ca932481SDavidson K            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
527ca932481SDavidson K        endif
528c3fb00d9SAchin Gupta    else
529c3fb00d9SAchin Gupta        # All other SPDs in spd directory
530c3fb00d9SAchin Gupta        SPD_DIR := spd
531c3fb00d9SAchin Gupta    endif
532c3fb00d9SAchin Gupta
53373c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
534c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
535c3fb00d9SAchin Gupta
53673c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
537c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
53873c99d4eSJuan Castillo    endif
53973c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
54073c99d4eSJuan Castillo    include ${SPD_MAKE}
54173c99d4eSJuan Castillo
54270d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
54370d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
54470d1fc53SJuan Castillo    # supports two mutually exclusive options:
54570d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
54670d1fc53SJuan Castillo    #   of source files to build BL32
54770d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
54870d1fc53SJuan Castillo    #   that will be included in the FIP
54970d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
55070d1fc53SJuan Castillo    # over the sources.
551e35c4045SJeenu Viswambharanendif
552e35c4045SJeenu Viswambharan
55351faada7SDouglas Raillard################################################################################
55473c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
55573c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
55673c99d4eSJuan Castillo################################################################################
5572da8d8bfSJeenu Viswambharan
55873c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
5590f21c547SJuan Castillo
5608012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
5618012cc5cSMasahiro Yamada
56226e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
56326e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
56426e63c44SEtienne Carriereendif
56526e63c44SEtienne Carriere
5663bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
5673bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
5683bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
5693bd17c0fSSoby Mathewendif
570320920c1SMasahiro Yamada
571320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
572320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
573320920c1SMasahiro Yamadaelse
574320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
575320920c1SMasahiro Yamadaendif
576320920c1SMasahiro Yamada
577320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
57869af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
57969af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
58069af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
58169af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
58269af7fcfSMasahiro Yamadaendif
58369af7fcfSMasahiro Yamadaendif
584320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
585320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
586d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
587d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
588d974301dSMasahiro Yamadaendif
5893bd17c0fSSoby Mathew
590d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
5919cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
592d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
5939cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
594d5e97a1dSMasahiro Yamadaelse
5959cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
596d5e97a1dSMasahiro Yamadaendif
5979cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
5989cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
5999cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
600d5e97a1dSMasahiro Yamadaendif
601d5e97a1dSMasahiro Yamada
60254035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
60354035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
60454035fc4SSandrine Bailleux# This can be overridden by the platform.
60573c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6064f6ad66aSAchin Gupta
607a4409008Sdp-armifeq (${ARCH},aarch32)
608a4409008Sdp-armNEED_BL32 := yes
609a4409008Sdp-arm
610a4409008Sdp-arm################################################################################
611a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
612a4409008Sdp-arm################################################################################
613a4409008Sdp-armifneq (${AARCH32_SP},none)
614a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
615a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
616a4409008Sdp-arm
617a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
618a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
619a4409008Sdp-armendif
620a4409008Sdp-arm
621a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
622a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
623a4409008Sdp-armendif
624a4409008Sdp-arm
625a4409008Sdp-armendif
6264f6ad66aSAchin Gupta
62773c99d4eSJuan Castillo################################################################################
62877f1f7a1SVarun Wadekar# Include libc if not overridden
62977f1f7a1SVarun Wadekar################################################################################
63077f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
63177f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
63277f1f7a1SVarun Wadekarendif
63377f1f7a1SVarun Wadekar
63477f1f7a1SVarun Wadekar################################################################################
635cf2c8a33SAntonio Nino Diaz# Check incompatible options
636cf2c8a33SAntonio Nino Diaz################################################################################
637cf2c8a33SAntonio Nino Diaz
638cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
63968450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
64068450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
64168450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
642cf2c8a33SAntonio Nino Diaz        endif
64376580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
64476580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
64576580f3dSQixiang Xu        endif
64676580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
64776580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
64876580f3dSQixiang Xu        endif
649cf2c8a33SAntonio Nino Diazendif
650cf2c8a33SAntonio Nino Diaz
651cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
652cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
653cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
654cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
655cf2c8a33SAntonio Nino Diaz        endif
65668450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
65768450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
65868450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
65968450a6dSAntonio Nino Diaz                file.")
660cf2c8a33SAntonio Nino Diaz        endif
661cf2c8a33SAntonio Nino Diazendif
662cf2c8a33SAntonio Nino Diaz
663d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
664d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
665d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
666d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
667d4593e47SJeenu Viswambharanendif
6681a0a3f06SYatharth Kochar
6697d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
6707d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
6717d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
6727d173fc5SJiafei Panendif
6737d173fc5SJiafei Pan
67414c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
67514c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
67614c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
67714c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
67814c6016aSJeenu Viswambharan    endif
67914c6016aSJeenu Viswambharanendif
68014c6016aSJeenu Viswambharan
6811a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
6821a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
6831a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
6841a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
6851a7c1cfeSJeenu Viswambharan    endif
6861a7c1cfeSJeenu Viswambharanendif
6871a7c1cfeSJeenu Viswambharan
688ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
689209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
690209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
691209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
692209a60ccSSoby Mathew    endif
693209a60ccSSoby Mathewendif
694209a60ccSSoby Mathew
695cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
696cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
697cbf9e84aSBalint Dobszay$(error "SDEI_IN_FCONF is an experimental feature and is only supported when \
698cbf9e84aSBalint Dobszay	SDEI_SUPPORT is enabled")
699cbf9e84aSBalint Dobszayendif
700cbf9e84aSBalint Dobszay
70184ef9cd8SManish V Badarkheifeq ($(COT_DESC_IN_DTB),1)
70284ef9cd8SManish V Badarkhe    $(info CoT in device tree is an experimental feature)
70384ef9cd8SManish V Badarkheendif
70484ef9cd8SManish V Badarkhe
705b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7069fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7079fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
708b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7099fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7109fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
71106715f85SAlexei Fedorov    endif
7129fc59639SAlexei Fedorovendif
7139fc59639SAlexei Fedorov
71406715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7159fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7169fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
717dfc66a17SJohn Tsichritzis    else
71806715f85SAlexei Fedorov        $(info CTX_INCLUDE_PAUTH_REGS is an experimental feature)
719b86048c4SAntonio Nino Diaz    endif
720b86048c4SAntonio Nino Diazendif
7219fc59639SAlexei Fedorov
7229fc59639SAlexei Fedorovifeq ($(ENABLE_PAUTH),1)
7239fc59639SAlexei Fedorov    $(info Pointer Authentication is an experimental feature)
7249fc59639SAlexei Fedorovendif
7259fc59639SAlexei Fedorov
7269fc59639SAlexei Fedorovifeq ($(ENABLE_BTI),1)
7279fc59639SAlexei Fedorov    $(info Branch Protection is an experimental feature)
728dfc66a17SJohn Tsichritzisendif
729b86048c4SAntonio Nino Diaz
7309dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7319dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7329dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7339dd94382SJustin Chadwell    else
7349dd94382SJustin Chadwell        $(info CTX_INCLUDE_MTE_REGS is an experimental feature)
7359dd94382SJustin Chadwell    endif
7369dd94382SJustin Chadwellendif
7379dd94382SJustin Chadwell
738cc255b9fSSandrine Bailleux# Trusted Boot is a prerequisite for Measured Boot. It provides trust that the
739cc255b9fSSandrine Bailleux# code taking the measurements and recording them has not been tampered
740cc255b9fSSandrine Bailleux# with. This is referred to as the Root of Trust for Measurement.
7418c105290SAlexei Fedorovifeq ($(MEASURED_BOOT),1)
7428c105290SAlexei Fedorov    ifneq (${TRUSTED_BOARD_BOOT},1)
7437cda17bbSSumit Garg        $(error MEASURED_BOOT requires TRUSTED_BOARD_BOOT=1)
7448c105290SAlexei Fedorov    else
7458c105290SAlexei Fedorov        $(info MEASURED_BOOT is an experimental feature)
7468c105290SAlexei Fedorov    endif
7478c105290SAlexei Fedorovendif
7488c105290SAlexei Fedorov
749396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
750396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
751396b339dSManish V Badarkheendif
752396b339dSManish V Badarkhe
75360e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
75460e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
75560e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
75660e8f3cfSPetre-Ionut Tudor    endif
75760e8f3cfSPetre-Ionut Tudorendif
75860e8f3cfSPetre-Ionut Tudor
7597cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7607cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7617cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7627cda17bbSSumit Garg    else
7637cda17bbSSumit Garg        $(info DECRYPTION_SUPPORT is an experimental feature)
7647cda17bbSSumit Garg    endif
7657cda17bbSSumit Gargendif
7667cda17bbSSumit Garg
767cf2c8a33SAntonio Nino Diaz################################################################################
76873c99d4eSJuan Castillo# Process platform overrideable behaviour
76973c99d4eSJuan Castillo################################################################################
7704f6ad66aSAchin Gupta
771bd97f83aSJohn Tsichritzis# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
772bd97f83aSJohn Tsichritzis# Certificate generation tools. This flag can be overridden by the platform.
77373c99d4eSJuan Castilloifdef BL2_SOURCES
774cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
775cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
776cf2c8a33SAntonio Nino Diaz                # in the FIP file.
7774c117f6cSSandrine Bailleux                NEED_BL33		:=	no
778cf2c8a33SAntonio Nino Diaz        else
77968450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
780cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
781cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
782cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
783cf2c8a33SAntonio Nino Diaz                else
784cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
785cf2c8a33SAntonio Nino Diaz                endif
7864c117f6cSSandrine Bailleux        endif
78773c99d4eSJuan Castilloendif
7886f971622SJuan Castillo
7894d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
7904d045d0eSMasahiro Yamadaifdef SCP_BL2
7914d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
7924d045d0eSMasahiro Yamadaendif
7934d045d0eSMasahiro Yamada
7945744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
7955744e874SSoby Mathewifneq (${ARCH},aarch32)
7965744e874SSoby Mathew    ifdef BL31_SOURCES
7975744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
7985744e874SSoby Mathew        # put it in the FIP.
7995744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8005744e874SSoby Mathew            NEED_BL31 := yes
8015744e874SSoby Mathew        endif
8025744e874SSoby Mathew    endif
8035744e874SSoby Mathewendif
8045744e874SSoby Mathew
80573c99d4eSJuan Castillo# Process TBB related flags
8066f971622SJuan Castilloifneq (${GENERATE_COT},0)
80773c99d4eSJuan Castillo        # Common cert_create options
8086f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8096f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8100191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
811fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
812fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8130191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
814fd34e7baSJuan Castillo                endif
8156f971622SJuan Castillo        endif
81673c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
81773c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
81873c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
81973c99d4eSJuan Castillo        endif
8206f971622SJuan Castilloendif
8216f971622SJuan Castillo
8221c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
8231c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
8241c75d5dfSMasahiro Yamadaendif
8251c75d5dfSMasahiro Yamada
82673c99d4eSJuan Castillo################################################################################
82746e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
82846e5e035SMichalis Pappas################################################################################
82946e5e035SMichalis Pappas
83046e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
83146e5e035SMichalis Pappas
83246e5e035SMichalis Pappas################################################################################
833819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
83473c99d4eSJuan Castillo################################################################################
83573c99d4eSJuan Castillo
83673c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
83773c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
83842a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
83973c99d4eSJuan Castillo
84090aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
84190aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
84290aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
84390aa901fSSumit Garg
84473c99d4eSJuan Castillo# Variables for use with Firmware Image Package
845819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
846819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
84773c99d4eSJuan Castillo
84826010da1SAntonio Nino Diaz# Variables for use with sptool
84926010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
85026010da1SAntonio Nino DiazSPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
851ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
85226010da1SAntonio Nino Diaz
8535accce5bSRoberto Vargas# Variables for use with ROMLIB
8545accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
8555accce5bSRoberto Vargas
856cfe83910SLouis Mayencourt# Variable for use with Python
857cfe83910SLouis MayencourtPYTHON			?=	python3
858cfe83910SLouis Mayencourt
859cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
860cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
861cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
862cfe83910SLouis Mayencourt
8636de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
8646de32378SMadhukar PappireddyDOCS_PATH		?=	docs
8656de32378SMadhukar Pappireddy
8668a86052dSSoby Mathew################################################################################
8678a86052dSSoby Mathew# Include BL specific makefiles
8688a86052dSSoby Mathew################################################################################
8698a86052dSSoby Mathewifdef BL1_SOURCES
8708a86052dSSoby MathewNEED_BL1 := yes
8718a86052dSSoby Mathewinclude bl1/bl1.mk
8728a86052dSSoby Mathewendif
8738a86052dSSoby Mathew
8748a86052dSSoby Mathewifdef BL2_SOURCES
8758a86052dSSoby MathewNEED_BL2 := yes
8768a86052dSSoby Mathewinclude bl2/bl2.mk
8778a86052dSSoby Mathewendif
8788a86052dSSoby Mathew
8798a86052dSSoby Mathewifdef BL2U_SOURCES
8808a86052dSSoby MathewNEED_BL2U := yes
8818a86052dSSoby Mathewinclude bl2u/bl2u.mk
8828a86052dSSoby Mathewendif
8838a86052dSSoby Mathew
8845744e874SSoby Mathewifeq (${NEED_BL31},yes)
8858a86052dSSoby Mathewifdef BL31_SOURCES
8868a86052dSSoby Mathewinclude bl31/bl31.mk
8878a86052dSSoby Mathewendif
8888a86052dSSoby Mathewendif
8898a86052dSSoby Mathew
89003b397a8SNishanth Menonifdef FDT_SOURCES
89103b397a8SNishanth MenonNEED_FDT := yes
89203b397a8SNishanth Menonendif
89303b397a8SNishanth Menon
89473c99d4eSJuan Castillo################################################################################
89573c99d4eSJuan Castillo# Build options checks
89673c99d4eSJuan Castillo################################################################################
89773c99d4eSJuan Castillo
898327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
899327131c4SLeonardo Sandoval    $(sort \
900327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
901327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
902327131c4SLeonardo Sandoval        CREATE_KEYS \
903327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
904327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
905327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
906327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
907327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
908062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
909327131c4SLeonardo Sandoval        DEBUG \
9100063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
911327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
912327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
913327131c4SLeonardo Sandoval        ENABLE_AMU \
914873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
915327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
916327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
917327131c4SLeonardo Sandoval        ENABLE_PIE \
918327131c4SLeonardo Sandoval        ENABLE_PMF \
919327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
920327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
921327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
922327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
9230c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
924327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
925327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
926327131c4SLeonardo Sandoval        GENERATE_COT \
927327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
928327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
929327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
930327131c4SLeonardo Sandoval        INVERTED_MEMMAP \
931327131c4SLeonardo Sandoval        MEASURED_BOOT \
932327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
933327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
934327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
935327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
936327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
937327131c4SLeonardo Sandoval        RAS_EXTENSION \
938327131c4SLeonardo Sandoval        RESET_TO_BL31 \
939327131c4SLeonardo Sandoval        SAVE_KEYS \
940327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
941327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
942327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
943327131c4SLeonardo Sandoval        SPM_MM \
944327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
945327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
946327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
947327131c4SLeonardo Sandoval        USE_DEBUGFS \
948327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
949327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
950327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
951327131c4SLeonardo Sandoval        USE_ROMLIB \
952327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
953327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
954327131c4SLeonardo Sandoval        BL2_AT_EL3 \
955327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
956327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
957327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
958327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
959327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
960327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
961327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
962327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
963327131c4SLeonardo Sandoval        USE_SP804_TIMER \
96412cd65e0STomas Pilar        ENABLE_FEAT_RNG \
9654e04478aSChris Kay        ENABLE_FEAT_SB \
966396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
967813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
968d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
969*8fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
970327131c4SLeonardo Sandoval)))
97173c99d4eSJuan Castillo
972327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
973327131c4SLeonardo Sandoval    $(sort \
974327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
975327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
976327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
977327131c4SLeonardo Sandoval        FW_ENC_STATUS \
9785357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
9795357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
980327131c4SLeonardo Sandoval)))
981c877b414SJeenu Viswambharan
982aacff749SJustin Chadwellifdef KEY_SIZE
983aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
984aacff749SJustin Chadwellendif
985aacff749SJustin Chadwell
9861f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
9871f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
9881f461979SJustin Chadwellendif
9891f461979SJustin Chadwell
99073c99d4eSJuan Castillo################################################################################
99173c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
99273c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
99373c99d4eSJuan Castillo# platform to overwrite the default options
99473c99d4eSJuan Castillo################################################################################
99573c99d4eSJuan Castillo
996327131c4SLeonardo Sandoval$(eval $(call add_defines,\
997327131c4SLeonardo Sandoval    $(sort \
998327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
999327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1000327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1001327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1002327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1003327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1004327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1005327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1006327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1007327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1008062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1009327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
10100063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1011327131c4SLeonardo Sandoval        ENABLE_AMU \
1012873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1013327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1014327131c4SLeonardo Sandoval        ENABLE_BTI \
1015327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1016327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1017327131c4SLeonardo Sandoval        ENABLE_PIE \
1018327131c4SLeonardo Sandoval        ENABLE_PMF \
1019327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
1020327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1021327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1022327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
10230c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1024327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1025327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1026327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1027327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1028327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1029327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1030327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1031327131c4SLeonardo Sandoval        LOG_LEVEL \
1032327131c4SLeonardo Sandoval        MEASURED_BOOT \
1033327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1034327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1035327131c4SLeonardo Sandoval        PLAT_${PLAT} \
1036327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1037327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1038327131c4SLeonardo Sandoval        RAS_EXTENSION \
1039327131c4SLeonardo Sandoval        RESET_TO_BL31 \
1040327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
1041327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1042327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1043327131c4SLeonardo Sandoval        SPD_${SPD} \
1044327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1045327131c4SLeonardo Sandoval        SPM_MM \
1046327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1047327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
10487dfb9911SJimmy Brisson        TRNG_SUPPORT \
1049327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1050327131c4SLeonardo Sandoval        USE_DEBUGFS \
1051327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1052327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1053327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1054327131c4SLeonardo Sandoval        USE_ROMLIB \
1055327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1056327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1057327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1058327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1059327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1060327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1061327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1062327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1063327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1064327131c4SLeonardo Sandoval        USE_SP804_TIMER \
106512cd65e0STomas Pilar        ENABLE_FEAT_RNG \
10664e04478aSChris Kay        ENABLE_FEAT_SB \
10675357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10685357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1069396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1070813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1071d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
1072*8fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1073327131c4SLeonardo Sandoval)))
10742fae4b1eSJeenu Viswambharan
10751f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
10761f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
10771f461979SJustin Chadwellendif
10781f461979SJustin Chadwell
10794c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
10804c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
10814c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1082cf2c8a33SAntonio Nino Diazelse
108368450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
108468450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
108568450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
108668450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
10874c117f6cSSandrine Bailleux        endif
1088cf2c8a33SAntonio Nino Diazendif
108973c99d4eSJuan Castillo
1090209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1091209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1092209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1093209a60ccSSoby Mathewendif
1094209a60ccSSoby Mathew
1095c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1096c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1097c2ad38ceSVarun Wadekarendif
1098c2ad38ceSVarun Wadekar
1099ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1100ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1101c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1102c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},0)
1103c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL1 does not require SP_LAYOUT_FILE")
1104c33ff198SOlivier Deprez        endif
1105ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1106ce2b1ec6SManish Pandey        FIP_DEPS += sp
110707c44475SManish Pandey        CRT_DEPS += sp
1108ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1109ce2b1ec6SManish Pandeyelse
1110c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1111c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1112c33ff198SOlivier Deprez        endif
1113ce2b1ec6SManish Pandeyendif
1114ce2b1ec6SManish Pandeyendif
1115ce2b1ec6SManish Pandey
111673c99d4eSJuan Castillo################################################################################
111773c99d4eSJuan Castillo# Build targets
111873c99d4eSJuan Castillo################################################################################
111973c99d4eSJuan Castillo
112090aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
112173c99d4eSJuan Castillo.SUFFIXES:
112273c99d4eSJuan Castillo
112373c99d4eSJuan Castilloall: msg_start
112473c99d4eSJuan Castillo
112573c99d4eSJuan Castillomsg_start:
112673c99d4eSJuan Castillo	@echo "Building ${PLAT}"
112773c99d4eSJuan Castillo
11287a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1129d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1130c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1131c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1132c2ad38ceSVarun Wadekarelse
1133bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
11347a24cba5SSoby Mathewendif
1135d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
11367a24cba5SSoby Mathew
11375accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
113861f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
11395fee0287SRoberto Vargas
114073c99d4eSJuan Castillo# Expand build macros for the different images
114173c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
114273c99d4eSJuan Castillo$(eval $(call MAKE_BL,1))
114373c99d4eSJuan Castilloendif
114473c99d4eSJuan Castillo
114573c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1146c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1147c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1148c9b31ae8SRoberto Vargasendif
1149c9b31ae8SRoberto Vargas
115033950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1151c9b31ae8SRoberto Vargas	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
115273c99d4eSJuan Castilloendif
115373c99d4eSJuan Castillo
11544d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
115533950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
11564d045d0eSMasahiro Yamadaendif
11574d045d0eSMasahiro Yamada
115873c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
115973c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
116026d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
116126d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1162c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1163c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1164c6ba9b45SSumit Garg	$(eval $(call MAKE_BL,31,soc-fw,,$(ENCRYPT_BL31))))
1165c6ba9b45SSumit Gargelse
116633950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
11678f0617efSJuan Castillo	$(eval $(call MAKE_BL,31,soc-fw)))
116873c99d4eSJuan Castilloendif
1169c6ba9b45SSumit Gargendif
117073c99d4eSJuan Castillo
117170d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1172c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
117370d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
117473c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
117526d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
117626d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
11779cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
11789cd15239SMasahiro Yamada
1179c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1180c6ba9b45SSumit Garg$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw,,$(ENCRYPT_BL32))),\
1181c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1182c6ba9b45SSumit Gargelse
11839cd15239SMasahiro Yamada$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
118433950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
118573c99d4eSJuan Castilloendif
1186c6ba9b45SSumit Gargendif
118773c99d4eSJuan Castillo
118873c99d4eSJuan Castillo# Add the BL33 image if required by the platform
118973c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
119033950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1191db6071c9SJuan Castilloendif
1192db6071c9SJuan Castillo
11939003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
119433950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
11951dc0714fSMasahiro Yamada	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
11969003fa0bSYatharth Kocharendif
11979003fa0bSYatharth Kochar
119803b397a8SNishanth Menon# Expand build macros for the different images
119903b397a8SNishanth Menonifeq (${NEED_FDT},yes)
120003b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
120103b397a8SNishanth Menonendif
120203b397a8SNishanth Menon
1203ce2b1ec6SManish Pandey# Add Secure Partition packages
1204ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1205ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
12061e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1207ce2b1ec6SManish Pandeysp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1208ce2b1ec6SManish Pandey	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1209ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1210ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1211ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1212ce2b1ec6SManish Pandeyendif
1213ce2b1ec6SManish Pandey
121436eaaf37SIan Spraylocate-checkpatch:
121536eaaf37SIan Sprayifndef CHECKPATCH
121666079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
121736eaaf37SIan Sprayelse
121836eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
121966079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
122036eaaf37SIan Sprayendif
122136eaaf37SIan Sprayendif
122236eaaf37SIan Spray
12234f6ad66aSAchin Guptaclean:
12244f6ad66aSAchin Gupta	@echo "  CLEAN"
1225f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
122688a1cf1eSSami Mujawarifdef UNIX_MK
12272f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
122888a1cf1eSSami Mujawarelse
122988a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
123088a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
123188a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
123288a1cf1eSSami Mujawarendif
12336f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
123490aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
12355accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
12364f6ad66aSAchin Gupta
1237eaaeece2SJames Morrisseyrealclean distclean:
1238eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1239f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1240f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
124188a1cf1eSSami Mujawarifdef UNIX_MK
12422f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
124388a1cf1eSSami Mujawarelse
124488a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
124588a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
124688a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
124788a1cf1eSSami Mujawarendif
124826010da1SAntonio Nino Diaz	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
12496f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
125090aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
12515accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
12524f6ad66aSAchin Gupta
125336eaaf37SIan Spraycheckcodebase:		locate-checkpatch
125436eaaf37SIan Spray	@echo "  CHECKING STYLE"
125536eaaf37SIan Spray	@if test -d .git ; then						\
12561ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
12571a41e8c1SDan Handley		while read GIT_FILE ;					\
12581a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
12591a41e8c1SDan Handley		done ;							\
126036eaaf37SIan Spray	else								\
12611a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
12621a41e8c1SDan Handley		 -not -iwholename "*build*"				\
12631a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
126461f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
12651a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
12661ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
12671a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
126836eaaf37SIan Spray	fi
126936eaaf37SIan Spray
127036eaaf37SIan Spraycheckpatch:		locate-checkpatch
127136eaaf37SIan Spray	@echo "  CHECKING STYLE"
127202a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
127302a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
127402a76d5fSYann Gautier	fi
127551d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
127651d28937SAntonio Nino Diaz	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
127751d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
127851d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
127902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
128002a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
128151d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
128202a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
128302a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
128451d28937SAntonio Nino Diaz	done
128536eaaf37SIan Spray
128673c99d4eSJuan Castillocerttool: ${CRTTOOL}
128773c99d4eSJuan Castillo
1288a9812206SPali Rohár${CRTTOOL}: FORCE
1289fafd3ec9SManish 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}
1290f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
12916f971622SJuan Castillo	@echo "Built $@ successfully"
1292f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
12936f971622SJuan Castillo
12946f971622SJuan Castilloifneq (${GENERATE_COT},0)
129573c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
12966f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1297f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
12986f971622SJuan Castillo	@echo "Built $@ successfully"
12996f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1300f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
130173c99d4eSJuan Castilloendif
130227713fb4SSoby Mathew
130373c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
13044727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1305819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1306819281eeSdp-arm	${Q}${FIPTOOL} info $@
1307f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
13082f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1309f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1310f58ad36fSHarry Liebel
13110191262dSYatharth Kocharifneq (${GENERATE_COT},0)
13120191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
13130191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1314052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13150191262dSYatharth Kochar	@echo "Built $@ successfully"
13160191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1317052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13180191262dSYatharth Kocharendif
13190191262dSYatharth Kochar
13200191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
13214727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1322819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1323819281eeSdp-arm	${Q}${FIPTOOL} info $@
1324052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13250191262dSYatharth Kochar	@echo "Built $@ successfully"
1326052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13270191262dSYatharth Kochar
132873c99d4eSJuan Castillofiptool: ${FIPTOOL}
132973c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
13300191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
133173c99d4eSJuan Castillo
1332a9812206SPali Rohár${FIPTOOL}: FORCE
133388a1cf1eSSami Mujawarifdef UNIX_MK
1334fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} --no-print-directory -C ${FIPTOOLPATH}
133588a1cf1eSSami Mujawarelse
133688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
133788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
133888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
133988a1cf1eSSami Mujawarendif
1340f58ad36fSHarry Liebel
134126010da1SAntonio Nino Diazsptool: ${SPTOOL}
1342a9812206SPali Rohár${SPTOOL}: FORCE
1343fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH}
134426010da1SAntonio Nino Diaz
1345a9812206SPali Rohárromlib.bin: libraries FORCE
1346bbb24f61SJohn 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
13475accce5bSRoberto Vargas
1348cfe83910SLouis Mayencourt# Call print_memory_map tool
1349cfe83910SLouis Mayencourtmemmap: all
1350b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1351cfe83910SLouis Mayencourt
13526de32378SMadhukar Pappireddydoc:
13536de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
13546de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
13556de32378SMadhukar Pappireddy
135690aa901fSSumit Gargenctool: ${ENCTOOL}
135790aa901fSSumit Garg
1358a9812206SPali Rohár${ENCTOOL}: FORCE
1359fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
136090aa901fSSumit Garg	@${ECHO_BLANK_LINE}
136190aa901fSSumit Garg	@echo "Built $@ successfully"
136290aa901fSSumit Garg	@${ECHO_BLANK_LINE}
136390aa901fSSumit Garg
136435fab8c9SJoakim Bechcscope:
136535fab8c9SJoakim Bech	@echo "  CSCOPE"
136635fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
136735fab8c9SJoakim Bech	${Q}cscope -b -q -k
136835fab8c9SJoakim Bech
136972ee3314SRyan Harkinhelp:
13707c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
137172ee3314SRyan Harkin	@echo ""
137272ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
137308c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
137472ee3314SRyan Harkin	@echo ""
13757c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
13767c23126cSJohn Tsichritzis	@echo ""
13771b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
13781b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
13791b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
13801b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
13811b578596SSandrine Bailleux	@echo ""
138272ee3314SRyan Harkin	@echo "Supported Targets:"
13831b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
138436eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
13858aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
13869003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1387d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
13889d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
13899d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
139073c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
13911b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
13920191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
139336eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
139436eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
139536eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
139672ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
139735fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
139872ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
13996f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
140090aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1401f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1402ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
140326010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
140438c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1405cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
14066de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
140772ee3314SRyan Harkin	@echo ""
14081b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
140972ee3314SRyan Harkin	@echo ""
141072ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
141172ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1412a9812206SPali Rohár
1413a9812206SPali Rohár.PHONY: FORCE
1414a9812206SPali RohárFORCE:;
1415