xref: /rk3399_ARM-atf/Makefile (revision 46789a7c711d650ae9b2bad0c2b817c4ba4a214a)
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
52833993a37SBalint Dobszay
52933993a37SBalint Dobszay        ifneq ($(ARM_BL2_SP_LIST_DTS),)
53033993a37SBalint Dobszay            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
53133993a37SBalint Dobszay        endif
532*46789a7cSBalint Dobszay
533*46789a7cSBalint Dobszay        ifneq ($(SP_LAYOUT_FILE),)
534*46789a7cSBalint Dobszay            BL2_ENABLE_SP_LOAD := 1
535*46789a7cSBalint Dobszay        endif
536c3fb00d9SAchin Gupta    else
537c3fb00d9SAchin Gupta        # All other SPDs in spd directory
538c3fb00d9SAchin Gupta        SPD_DIR := spd
539c3fb00d9SAchin Gupta    endif
540c3fb00d9SAchin Gupta
54173c99d4eSJuan Castillo    # We expect to locate an spd.mk under the specified SPD directory
542c3fb00d9SAchin Gupta    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
543c3fb00d9SAchin Gupta
54473c99d4eSJuan Castillo    ifeq (${SPD_MAKE},)
545c3fb00d9SAchin Gupta        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
54673c99d4eSJuan Castillo    endif
54773c99d4eSJuan Castillo    $(info Including ${SPD_MAKE})
54873c99d4eSJuan Castillo    include ${SPD_MAKE}
54973c99d4eSJuan Castillo
55070d1fc53SJuan Castillo    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
55170d1fc53SJuan Castillo    # Makefile would set NEED_BL32 to "yes". In this case, the build system
55270d1fc53SJuan Castillo    # supports two mutually exclusive options:
55370d1fc53SJuan Castillo    # * BL32 is built from source: then BL32_SOURCES must contain the list
55470d1fc53SJuan Castillo    #   of source files to build BL32
55570d1fc53SJuan Castillo    # * BL32 is a prebuilt binary: then BL32 must point to the image file
55670d1fc53SJuan Castillo    #   that will be included in the FIP
55770d1fc53SJuan Castillo    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
55870d1fc53SJuan Castillo    # over the sources.
559e35c4045SJeenu Viswambharanendif
560e35c4045SJeenu Viswambharan
56151faada7SDouglas Raillard################################################################################
56273c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
56373c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
56473c99d4eSJuan Castillo################################################################################
5652da8d8bfSJeenu Viswambharan
56673c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
5670f21c547SJuan Castillo
5688012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
5698012cc5cSMasahiro Yamada
57026e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
57126e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
57226e63c44SEtienne Carriereendif
57326e63c44SEtienne Carriere
5743bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
5753bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
5763bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
5773bd17c0fSSoby Mathewendif
578320920c1SMasahiro Yamada
579320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
580320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
581320920c1SMasahiro Yamadaelse
582320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
583320920c1SMasahiro Yamadaendif
584320920c1SMasahiro Yamada
585320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
58669af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
58769af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
58869af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
58969af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
59069af7fcfSMasahiro Yamadaendif
59169af7fcfSMasahiro Yamadaendif
592320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
593320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
594d974301dSMasahiro Yamada	BL32_CFLAGS	+=	-fpie
595d974301dSMasahiro Yamada	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
596d974301dSMasahiro Yamadaendif
5973bd17c0fSSoby Mathew
598d5e97a1dSMasahiro Yamadaifeq (${ARCH},aarch64)
5999cefb4b1SMasahiro YamadaBL1_CPPFLAGS += -DIMAGE_AT_EL3
600d5e97a1dSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
6019cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL3
602d5e97a1dSMasahiro Yamadaelse
6039cefb4b1SMasahiro YamadaBL2_CPPFLAGS += -DIMAGE_AT_EL1
604d5e97a1dSMasahiro Yamadaendif
6059cefb4b1SMasahiro YamadaBL2U_CPPFLAGS += -DIMAGE_AT_EL1
6069cefb4b1SMasahiro YamadaBL31_CPPFLAGS += -DIMAGE_AT_EL3
6079cefb4b1SMasahiro YamadaBL32_CPPFLAGS += -DIMAGE_AT_EL1
608d5e97a1dSMasahiro Yamadaendif
609d5e97a1dSMasahiro Yamada
61054035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
61154035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
61254035fc4SSandrine Bailleux# This can be overridden by the platform.
61373c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
6144f6ad66aSAchin Gupta
615a4409008Sdp-armifeq (${ARCH},aarch32)
616a4409008Sdp-armNEED_BL32 := yes
617a4409008Sdp-arm
618a4409008Sdp-arm################################################################################
619a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
620a4409008Sdp-arm################################################################################
621a4409008Sdp-armifneq (${AARCH32_SP},none)
622a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
623a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
624a4409008Sdp-arm
625a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
626a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
627a4409008Sdp-armendif
628a4409008Sdp-arm
629a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
630a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
631a4409008Sdp-armendif
632a4409008Sdp-arm
633a4409008Sdp-armendif
6344f6ad66aSAchin Gupta
63573c99d4eSJuan Castillo################################################################################
63677f1f7a1SVarun Wadekar# Include libc if not overridden
63777f1f7a1SVarun Wadekar################################################################################
63877f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
63977f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
64077f1f7a1SVarun Wadekarendif
64177f1f7a1SVarun Wadekar
64277f1f7a1SVarun Wadekar################################################################################
643cf2c8a33SAntonio Nino Diaz# Check incompatible options
644cf2c8a33SAntonio Nino Diaz################################################################################
645cf2c8a33SAntonio Nino Diaz
646cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
64768450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
64868450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
64968450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
650cf2c8a33SAntonio Nino Diaz        endif
65176580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
65276580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
65376580f3dSQixiang Xu        endif
65476580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
65576580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
65676580f3dSQixiang Xu        endif
657cf2c8a33SAntonio Nino Diazendif
658cf2c8a33SAntonio Nino Diaz
659cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
660cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
661cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
662cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
663cf2c8a33SAntonio Nino Diaz        endif
66468450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
66568450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
66668450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
66768450a6dSAntonio Nino Diaz                file.")
668cf2c8a33SAntonio Nino Diaz        endif
669cf2c8a33SAntonio Nino Diazendif
670cf2c8a33SAntonio Nino Diaz
671d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
672d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
673d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
674d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
675d4593e47SJeenu Viswambharanendif
6761a0a3f06SYatharth Kochar
6777d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
6787d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
6797d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
6807d173fc5SJiafei Panendif
6817d173fc5SJiafei Pan
68214c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
68314c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
68414c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
68514c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
68614c6016aSJeenu Viswambharan    endif
68714c6016aSJeenu Viswambharanendif
68814c6016aSJeenu Viswambharan
6891a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
6901a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
6911a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
6921a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
6931a7c1cfeSJeenu Viswambharan    endif
6941a7c1cfeSJeenu Viswambharanendif
6951a7c1cfeSJeenu Viswambharan
696ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
697209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
698209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
699209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
700209a60ccSSoby Mathew    endif
701209a60ccSSoby Mathewendif
702209a60ccSSoby Mathew
703cbf9e84aSBalint Dobszay# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
704cbf9e84aSBalint Dobszayifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
705cbf9e84aSBalint Dobszay$(error "SDEI_IN_FCONF is an experimental feature and is only supported when \
706cbf9e84aSBalint Dobszay	SDEI_SUPPORT is enabled")
707cbf9e84aSBalint Dobszayendif
708cbf9e84aSBalint Dobszay
70984ef9cd8SManish V Badarkheifeq ($(COT_DESC_IN_DTB),1)
71084ef9cd8SManish V Badarkhe    $(info CoT in device tree is an experimental feature)
71184ef9cd8SManish V Badarkheendif
71284ef9cd8SManish V Badarkhe
713b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
7149fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
7159fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
716b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
7179fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
7189fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
71906715f85SAlexei Fedorov    endif
7209fc59639SAlexei Fedorovendif
7219fc59639SAlexei Fedorov
72206715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
7239fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
7249fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
725dfc66a17SJohn Tsichritzis    else
72606715f85SAlexei Fedorov        $(info CTX_INCLUDE_PAUTH_REGS is an experimental feature)
727b86048c4SAntonio Nino Diaz    endif
728b86048c4SAntonio Nino Diazendif
7299fc59639SAlexei Fedorov
7309fc59639SAlexei Fedorovifeq ($(ENABLE_PAUTH),1)
7319fc59639SAlexei Fedorov    $(info Pointer Authentication is an experimental feature)
7329fc59639SAlexei Fedorovendif
7339fc59639SAlexei Fedorov
7349fc59639SAlexei Fedorovifeq ($(ENABLE_BTI),1)
7359fc59639SAlexei Fedorov    $(info Branch Protection is an experimental feature)
736dfc66a17SJohn Tsichritzisendif
737b86048c4SAntonio Nino Diaz
7389dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
7399dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
7409dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
7419dd94382SJustin Chadwell    else
7429dd94382SJustin Chadwell        $(info CTX_INCLUDE_MTE_REGS is an experimental feature)
7439dd94382SJustin Chadwell    endif
7449dd94382SJustin Chadwellendif
7459dd94382SJustin Chadwell
746cc255b9fSSandrine Bailleux# Trusted Boot is a prerequisite for Measured Boot. It provides trust that the
747cc255b9fSSandrine Bailleux# code taking the measurements and recording them has not been tampered
748cc255b9fSSandrine Bailleux# with. This is referred to as the Root of Trust for Measurement.
7498c105290SAlexei Fedorovifeq ($(MEASURED_BOOT),1)
7508c105290SAlexei Fedorov    ifneq (${TRUSTED_BOARD_BOOT},1)
7517cda17bbSSumit Garg        $(error MEASURED_BOOT requires TRUSTED_BOARD_BOOT=1)
7528c105290SAlexei Fedorov    else
7538c105290SAlexei Fedorov        $(info MEASURED_BOOT is an experimental feature)
7548c105290SAlexei Fedorov    endif
7558c105290SAlexei Fedorovendif
7568c105290SAlexei Fedorov
757396b339dSManish V Badarkheifeq ($(PSA_FWU_SUPPORT),1)
758396b339dSManish V Badarkhe    $(info PSA_FWU_SUPPORT is an experimental feature)
759396b339dSManish V Badarkheendif
760396b339dSManish V Badarkhe
76160e8f3cfSPetre-Ionut Tudorifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
76260e8f3cfSPetre-Ionut Tudor    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
76360e8f3cfSPetre-Ionut Tudor        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
76460e8f3cfSPetre-Ionut Tudor    endif
76560e8f3cfSPetre-Ionut Tudorendif
76660e8f3cfSPetre-Ionut Tudor
7677cda17bbSSumit Gargifneq (${DECRYPTION_SUPPORT},none)
7687cda17bbSSumit Garg    ifeq (${TRUSTED_BOARD_BOOT}, 0)
7697cda17bbSSumit Garg        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
7707cda17bbSSumit Garg    else
7717cda17bbSSumit Garg        $(info DECRYPTION_SUPPORT is an experimental feature)
7727cda17bbSSumit Garg    endif
7737cda17bbSSumit Gargendif
7747cda17bbSSumit Garg
775cf2c8a33SAntonio Nino Diaz################################################################################
77673c99d4eSJuan Castillo# Process platform overrideable behaviour
77773c99d4eSJuan Castillo################################################################################
7784f6ad66aSAchin Gupta
779bd97f83aSJohn Tsichritzis# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
780bd97f83aSJohn Tsichritzis# Certificate generation tools. This flag can be overridden by the platform.
78173c99d4eSJuan Castilloifdef BL2_SOURCES
782cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
783cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
784cf2c8a33SAntonio Nino Diaz                # in the FIP file.
7854c117f6cSSandrine Bailleux                NEED_BL33		:=	no
786cf2c8a33SAntonio Nino Diaz        else
78768450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
788cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
789cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
790cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
791cf2c8a33SAntonio Nino Diaz                else
792cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
793cf2c8a33SAntonio Nino Diaz                endif
7944c117f6cSSandrine Bailleux        endif
79573c99d4eSJuan Castilloendif
7966f971622SJuan Castillo
7974d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
7984d045d0eSMasahiro Yamadaifdef SCP_BL2
7994d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
8004d045d0eSMasahiro Yamadaendif
8014d045d0eSMasahiro Yamada
8025744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
8035744e874SSoby Mathewifneq (${ARCH},aarch32)
8045744e874SSoby Mathew    ifdef BL31_SOURCES
8055744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
8065744e874SSoby Mathew        # put it in the FIP.
8075744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
8085744e874SSoby Mathew            NEED_BL31 := yes
8095744e874SSoby Mathew        endif
8105744e874SSoby Mathew    endif
8115744e874SSoby Mathewendif
8125744e874SSoby Mathew
81373c99d4eSJuan Castillo# Process TBB related flags
8146f971622SJuan Castilloifneq (${GENERATE_COT},0)
81573c99d4eSJuan Castillo        # Common cert_create options
8166f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
8176f971622SJuan Castillo                $(eval CRT_ARGS += -n)
8180191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
819fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
820fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
8210191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
822fd34e7baSJuan Castillo                endif
8236f971622SJuan Castillo        endif
82473c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
82573c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
82673c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
82773c99d4eSJuan Castillo        endif
8286f971622SJuan Castilloendif
8296f971622SJuan Castillo
8301c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
8311c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
8321c75d5dfSMasahiro Yamadaendif
8331c75d5dfSMasahiro Yamada
83473c99d4eSJuan Castillo################################################################################
83546e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
83646e5e035SMichalis Pappas################################################################################
83746e5e035SMichalis Pappas
83846e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
83946e5e035SMichalis Pappas
84046e5e035SMichalis Pappas################################################################################
841819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
84273c99d4eSJuan Castillo################################################################################
84373c99d4eSJuan Castillo
84473c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
84573c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
84642a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
84773c99d4eSJuan Castillo
84890aa901fSSumit Garg# Variables for use with Firmware Encryption Tool
84990aa901fSSumit GargENCTOOLPATH		?=	tools/encrypt_fw
85090aa901fSSumit GargENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
85190aa901fSSumit Garg
85273c99d4eSJuan Castillo# Variables for use with Firmware Image Package
853819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
854819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
85573c99d4eSJuan Castillo
85626010da1SAntonio Nino Diaz# Variables for use with sptool
85726010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
85826010da1SAntonio Nino DiazSPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
859ce2b1ec6SManish PandeySP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
86026010da1SAntonio Nino Diaz
8615accce5bSRoberto Vargas# Variables for use with ROMLIB
8625accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
8635accce5bSRoberto Vargas
864cfe83910SLouis Mayencourt# Variable for use with Python
865cfe83910SLouis MayencourtPYTHON			?=	python3
866cfe83910SLouis Mayencourt
867cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
868cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
869cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
870cfe83910SLouis Mayencourt
8716de32378SMadhukar Pappireddy# Variables for use with documentation build using Sphinx tool
8726de32378SMadhukar PappireddyDOCS_PATH		?=	docs
8736de32378SMadhukar Pappireddy
8748a86052dSSoby Mathew################################################################################
8758a86052dSSoby Mathew# Include BL specific makefiles
8768a86052dSSoby Mathew################################################################################
8778a86052dSSoby Mathewifdef BL1_SOURCES
8788a86052dSSoby MathewNEED_BL1 := yes
8798a86052dSSoby Mathewinclude bl1/bl1.mk
8808a86052dSSoby Mathewendif
8818a86052dSSoby Mathew
8828a86052dSSoby Mathewifdef BL2_SOURCES
8838a86052dSSoby MathewNEED_BL2 := yes
8848a86052dSSoby Mathewinclude bl2/bl2.mk
8858a86052dSSoby Mathewendif
8868a86052dSSoby Mathew
8878a86052dSSoby Mathewifdef BL2U_SOURCES
8888a86052dSSoby MathewNEED_BL2U := yes
8898a86052dSSoby Mathewinclude bl2u/bl2u.mk
8908a86052dSSoby Mathewendif
8918a86052dSSoby Mathew
8925744e874SSoby Mathewifeq (${NEED_BL31},yes)
8938a86052dSSoby Mathewifdef BL31_SOURCES
8948a86052dSSoby Mathewinclude bl31/bl31.mk
8958a86052dSSoby Mathewendif
8968a86052dSSoby Mathewendif
8978a86052dSSoby Mathew
89803b397a8SNishanth Menonifdef FDT_SOURCES
89903b397a8SNishanth MenonNEED_FDT := yes
90003b397a8SNishanth Menonendif
90103b397a8SNishanth Menon
90273c99d4eSJuan Castillo################################################################################
90373c99d4eSJuan Castillo# Build options checks
90473c99d4eSJuan Castillo################################################################################
90573c99d4eSJuan Castillo
906327131c4SLeonardo Sandoval$(eval $(call assert_booleans,\
907327131c4SLeonardo Sandoval    $(sort \
908327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
909*46789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
910327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
911327131c4SLeonardo Sandoval        CREATE_KEYS \
912327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
913327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
914327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
915327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
916327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
917062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
918327131c4SLeonardo Sandoval        DEBUG \
9190063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
920327131c4SLeonardo Sandoval        DYN_DISABLE_AUTH \
921327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
922327131c4SLeonardo Sandoval        ENABLE_AMU \
923873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
924327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
925327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
926327131c4SLeonardo Sandoval        ENABLE_PIE \
927327131c4SLeonardo Sandoval        ENABLE_PMF \
928327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
929327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
930327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
931327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
9320c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
933327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
934327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
935327131c4SLeonardo Sandoval        GENERATE_COT \
936327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
937327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
938327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
939327131c4SLeonardo Sandoval        INVERTED_MEMMAP \
940327131c4SLeonardo Sandoval        MEASURED_BOOT \
941327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
942327131c4SLeonardo Sandoval        OVERRIDE_LIBC \
943327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
944327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
945327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
946327131c4SLeonardo Sandoval        RAS_EXTENSION \
947327131c4SLeonardo Sandoval        RESET_TO_BL31 \
948327131c4SLeonardo Sandoval        SAVE_KEYS \
949327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
950327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
951327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
952327131c4SLeonardo Sandoval        SPM_MM \
953327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
954327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
955327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
956327131c4SLeonardo Sandoval        USE_DEBUGFS \
957327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
958327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
959327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
960327131c4SLeonardo Sandoval        USE_ROMLIB \
961327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
962327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
963327131c4SLeonardo Sandoval        BL2_AT_EL3 \
964327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
965327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
966327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
967327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
968327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
969327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
970327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
971327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
972327131c4SLeonardo Sandoval        USE_SP804_TIMER \
97312cd65e0STomas Pilar        ENABLE_FEAT_RNG \
9744e04478aSChris Kay        ENABLE_FEAT_SB \
975396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
976813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
977d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
9788fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
979327131c4SLeonardo Sandoval)))
98073c99d4eSJuan Castillo
981327131c4SLeonardo Sandoval$(eval $(call assert_numerics,\
982327131c4SLeonardo Sandoval    $(sort \
983327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
984327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
985327131c4SLeonardo Sandoval        BRANCH_PROTECTION \
986327131c4SLeonardo Sandoval        FW_ENC_STATUS \
9875357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
9885357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
989327131c4SLeonardo Sandoval)))
990c877b414SJeenu Viswambharan
991aacff749SJustin Chadwellifdef KEY_SIZE
992aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
993aacff749SJustin Chadwellendif
994aacff749SJustin Chadwell
9951f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
9961f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
9971f461979SJustin Chadwellendif
9981f461979SJustin Chadwell
99973c99d4eSJuan Castillo################################################################################
100073c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
100173c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
100273c99d4eSJuan Castillo# platform to overwrite the default options
100373c99d4eSJuan Castillo################################################################################
100473c99d4eSJuan Castillo
1005327131c4SLeonardo Sandoval$(eval $(call add_defines,\
1006327131c4SLeonardo Sandoval    $(sort \
1007327131c4SLeonardo Sandoval        ALLOW_RO_XLAT_TABLES \
1008327131c4SLeonardo Sandoval        ARM_ARCH_MAJOR \
1009327131c4SLeonardo Sandoval        ARM_ARCH_MINOR \
1010*46789a7cSBalint Dobszay        BL2_ENABLE_SP_LOAD \
1011327131c4SLeonardo Sandoval        COLD_BOOT_SINGLE_CPU \
1012327131c4SLeonardo Sandoval        CTX_INCLUDE_AARCH32_REGS \
1013327131c4SLeonardo Sandoval        CTX_INCLUDE_FPREGS \
1014327131c4SLeonardo Sandoval        CTX_INCLUDE_PAUTH_REGS \
1015327131c4SLeonardo Sandoval        EL3_EXCEPTION_HANDLING \
1016327131c4SLeonardo Sandoval        CTX_INCLUDE_MTE_REGS \
1017327131c4SLeonardo Sandoval        CTX_INCLUDE_EL2_REGS \
1018062f8aafSArunachalam Ganapathy        CTX_INCLUDE_NEVE_REGS \
1019327131c4SLeonardo Sandoval        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
10200063dd17SJavier Almansa Sobrino        DISABLE_MTPMU \
1021327131c4SLeonardo Sandoval        ENABLE_AMU \
1022873d4241Sjohpow01        AMU_RESTRICT_COUNTERS \
1023327131c4SLeonardo Sandoval        ENABLE_ASSERTIONS \
1024327131c4SLeonardo Sandoval        ENABLE_BTI \
1025327131c4SLeonardo Sandoval        ENABLE_MPAM_FOR_LOWER_ELS \
1026327131c4SLeonardo Sandoval        ENABLE_PAUTH \
1027327131c4SLeonardo Sandoval        ENABLE_PIE \
1028327131c4SLeonardo Sandoval        ENABLE_PMF \
1029327131c4SLeonardo Sandoval        ENABLE_PSCI_STAT \
1030327131c4SLeonardo Sandoval        ENABLE_RUNTIME_INSTRUMENTATION \
1031327131c4SLeonardo Sandoval        ENABLE_SPE_FOR_LOWER_ELS \
1032327131c4SLeonardo Sandoval        ENABLE_SVE_FOR_NS \
10330c5e7d1cSMax Shvetsov        ENABLE_SVE_FOR_SWD \
1034327131c4SLeonardo Sandoval        ENCRYPT_BL31 \
1035327131c4SLeonardo Sandoval        ENCRYPT_BL32 \
1036327131c4SLeonardo Sandoval        ERROR_DEPRECATED \
1037327131c4SLeonardo Sandoval        FAULT_INJECTION_SUPPORT \
1038327131c4SLeonardo Sandoval        GICV2_G0_FOR_EL3 \
1039327131c4SLeonardo Sandoval        HANDLE_EA_EL3_FIRST \
1040327131c4SLeonardo Sandoval        HW_ASSISTED_COHERENCY \
1041327131c4SLeonardo Sandoval        LOG_LEVEL \
1042327131c4SLeonardo Sandoval        MEASURED_BOOT \
1043327131c4SLeonardo Sandoval        NS_TIMER_SWITCH \
1044327131c4SLeonardo Sandoval        PL011_GENERIC_UART \
1045327131c4SLeonardo Sandoval        PLAT_${PLAT} \
1046327131c4SLeonardo Sandoval        PROGRAMMABLE_RESET_ADDRESS \
1047327131c4SLeonardo Sandoval        PSCI_EXTENDED_STATE_ID \
1048327131c4SLeonardo Sandoval        RAS_EXTENSION \
1049327131c4SLeonardo Sandoval        RESET_TO_BL31 \
1050327131c4SLeonardo Sandoval        SEPARATE_CODE_AND_RODATA \
1051327131c4SLeonardo Sandoval        SEPARATE_NOBITS_REGION \
1052327131c4SLeonardo Sandoval        RECLAIM_INIT_CODE \
1053327131c4SLeonardo Sandoval        SPD_${SPD} \
1054327131c4SLeonardo Sandoval        SPIN_ON_BL1_EXIT \
1055327131c4SLeonardo Sandoval        SPM_MM \
1056327131c4SLeonardo Sandoval        SPMD_SPM_AT_SEL2 \
1057327131c4SLeonardo Sandoval        TRUSTED_BOARD_BOOT \
10587dfb9911SJimmy Brisson        TRNG_SUPPORT \
1059327131c4SLeonardo Sandoval        USE_COHERENT_MEM \
1060327131c4SLeonardo Sandoval        USE_DEBUGFS \
1061327131c4SLeonardo Sandoval        ARM_IO_IN_DTB \
1062327131c4SLeonardo Sandoval        SDEI_IN_FCONF \
1063327131c4SLeonardo Sandoval        SEC_INT_DESC_IN_FCONF \
1064327131c4SLeonardo Sandoval        USE_ROMLIB \
1065327131c4SLeonardo Sandoval        USE_TBBR_DEFS \
1066327131c4SLeonardo Sandoval        WARMBOOT_ENABLE_DCACHE_EARLY \
1067327131c4SLeonardo Sandoval        BL2_AT_EL3 \
1068327131c4SLeonardo Sandoval        BL2_IN_XIP_MEM \
1069327131c4SLeonardo Sandoval        BL2_INV_DCACHE \
1070327131c4SLeonardo Sandoval        USE_SPINLOCK_CAS \
1071327131c4SLeonardo Sandoval        ERRATA_SPECULATIVE_AT \
1072327131c4SLeonardo Sandoval        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1073327131c4SLeonardo Sandoval        COT_DESC_IN_DTB \
1074327131c4SLeonardo Sandoval        USE_SP804_TIMER \
107512cd65e0STomas Pilar        ENABLE_FEAT_RNG \
10764e04478aSChris Kay        ENABLE_FEAT_SB \
10775357f83dSManish V Badarkhe        NR_OF_FW_BANKS \
10785357f83dSManish V Badarkhe        NR_OF_IMAGES_IN_FW_BANK \
1079396b339dSManish V Badarkhe        PSA_FWU_SUPPORT \
1080813524eaSManish V Badarkhe        ENABLE_TRBE_FOR_NS \
1081d4582d30SManish V Badarkhe        ENABLE_SYS_REG_TRACE_FOR_NS \
10828fcd3d96SManish V Badarkhe        ENABLE_TRF_FOR_NS \
1083327131c4SLeonardo Sandoval)))
10842fae4b1eSJeenu Viswambharan
10851f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
10861f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
10871f461979SJustin Chadwellendif
10881f461979SJustin Chadwell
10894c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
10904c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
10914c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1092cf2c8a33SAntonio Nino Diazelse
109368450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
109468450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
109568450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
109668450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
10974c117f6cSSandrine Bailleux        endif
1098cf2c8a33SAntonio Nino Diazendif
109973c99d4eSJuan Castillo
1100209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
1101209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
1102209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
1103209a60ccSSoby Mathewendif
1104209a60ccSSoby Mathew
1105c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
1106c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
1107c2ad38ceSVarun Wadekarendif
1108c2ad38ceSVarun Wadekar
1109ce2b1ec6SManish Pandey# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1110ce2b1ec6SManish Pandeyifeq (${SPD},spmd)
1111c33ff198SOlivier Deprezifdef SP_LAYOUT_FILE
1112ce2b1ec6SManish Pandey        -include $(BUILD_PLAT)/sp_gen.mk
1113ce2b1ec6SManish Pandey        FIP_DEPS += sp
111407c44475SManish Pandey        CRT_DEPS += sp
1115ce2b1ec6SManish Pandey        NEED_SP_PKG := yes
1116ce2b1ec6SManish Pandeyelse
1117c33ff198SOlivier Deprez        ifeq (${SPMD_SPM_AT_SEL2},1)
1118c33ff198SOlivier Deprez            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1119c33ff198SOlivier Deprez        endif
1120ce2b1ec6SManish Pandeyendif
1121ce2b1ec6SManish Pandeyendif
1122ce2b1ec6SManish Pandey
112373c99d4eSJuan Castillo################################################################################
112473c99d4eSJuan Castillo# Build targets
112573c99d4eSJuan Castillo################################################################################
112673c99d4eSJuan Castillo
112790aa901fSSumit Garg.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
112873c99d4eSJuan Castillo.SUFFIXES:
112973c99d4eSJuan Castillo
113073c99d4eSJuan Castilloall: msg_start
113173c99d4eSJuan Castillo
113273c99d4eSJuan Castillomsg_start:
113373c99d4eSJuan Castillo	@echo "Building ${PLAT}"
113473c99d4eSJuan Castillo
11357a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
1136d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
1137c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
1138c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1139c2ad38ceSVarun Wadekarelse
1140bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
11417a24cba5SSoby Mathewendif
1142d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
11437a24cba5SSoby Mathew
11445accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
114561f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
11465fee0287SRoberto Vargas
114773c99d4eSJuan Castillo# Expand build macros for the different images
114873c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
114973c99d4eSJuan Castillo$(eval $(call MAKE_BL,1))
115073c99d4eSJuan Castilloendif
115173c99d4eSJuan Castillo
115273c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
1153c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
1154c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
1155c9b31ae8SRoberto Vargasendif
1156c9b31ae8SRoberto Vargas
115733950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1158c9b31ae8SRoberto Vargas	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
115973c99d4eSJuan Castilloendif
116073c99d4eSJuan Castillo
11614d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
116233950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
11634d045d0eSMasahiro Yamadaendif
11644d045d0eSMasahiro Yamada
116573c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
116673c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
116726d1e0c3SMadhukar Pappireddy# Sort BL31 source files to remove duplicates
116826d1e0c3SMadhukar PappireddyBL31_SOURCES := $(sort ${BL31_SOURCES})
1169c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1170c6ba9b45SSumit Garg$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1171c6ba9b45SSumit Garg	$(eval $(call MAKE_BL,31,soc-fw,,$(ENCRYPT_BL31))))
1172c6ba9b45SSumit Gargelse
117333950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
11748f0617efSJuan Castillo	$(eval $(call MAKE_BL,31,soc-fw)))
117573c99d4eSJuan Castilloendif
1176c6ba9b45SSumit Gargendif
117773c99d4eSJuan Castillo
117870d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1179c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
118070d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
118173c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
118226d1e0c3SMadhukar Pappireddy# Sort BL32 source files to remove duplicates
118326d1e0c3SMadhukar PappireddyBL32_SOURCES := $(sort ${BL32_SOURCES})
11849cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
11859cd15239SMasahiro Yamada
1186c6ba9b45SSumit Gargifneq (${DECRYPTION_SUPPORT},none)
1187c6ba9b45SSumit Garg$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw,,$(ENCRYPT_BL32))),\
1188c6ba9b45SSumit Garg	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1189c6ba9b45SSumit Gargelse
11909cd15239SMasahiro Yamada$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
119133950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
119273c99d4eSJuan Castilloendif
1193c6ba9b45SSumit Gargendif
119473c99d4eSJuan Castillo
119573c99d4eSJuan Castillo# Add the BL33 image if required by the platform
119673c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
119733950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1198db6071c9SJuan Castilloendif
1199db6071c9SJuan Castillo
12009003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
120133950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
12021dc0714fSMasahiro Yamada	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
12039003fa0bSYatharth Kocharendif
12049003fa0bSYatharth Kochar
120503b397a8SNishanth Menon# Expand build macros for the different images
120603b397a8SNishanth Menonifeq (${NEED_FDT},yes)
120703b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
120803b397a8SNishanth Menonendif
120903b397a8SNishanth Menon
1210ce2b1ec6SManish Pandey# Add Secure Partition packages
1211ce2b1ec6SManish Pandeyifeq (${NEED_SP_PKG},yes)
1212ce2b1ec6SManish Pandey$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
12131e7528ecSRuari Phipps	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1214ce2b1ec6SManish Pandeysp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1215ce2b1ec6SManish Pandey	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1216ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1217ce2b1ec6SManish Pandey	@echo "Built SP Images successfully"
1218ce2b1ec6SManish Pandey	@${ECHO_BLANK_LINE}
1219ce2b1ec6SManish Pandeyendif
1220ce2b1ec6SManish Pandey
122136eaaf37SIan Spraylocate-checkpatch:
122236eaaf37SIan Sprayifndef CHECKPATCH
122366079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
122436eaaf37SIan Sprayelse
122536eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
122666079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
122736eaaf37SIan Sprayendif
122836eaaf37SIan Sprayendif
122936eaaf37SIan Spray
12304f6ad66aSAchin Guptaclean:
12314f6ad66aSAchin Gupta	@echo "  CLEAN"
1232f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
123388a1cf1eSSami Mujawarifdef UNIX_MK
12342f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
123588a1cf1eSSami Mujawarelse
123688a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
123788a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
123888a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
123988a1cf1eSSami Mujawarendif
12406f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
124190aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
12425accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
12434f6ad66aSAchin Gupta
1244eaaeece2SJames Morrisseyrealclean distclean:
1245eaaeece2SJames Morrissey	@echo "  REALCLEAN"
1246f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1247f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
124888a1cf1eSSami Mujawarifdef UNIX_MK
12492f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
125088a1cf1eSSami Mujawarelse
125188a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
125288a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
125388a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
125488a1cf1eSSami Mujawarendif
125526010da1SAntonio Nino Diaz	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
12566f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
125790aa901fSSumit Garg	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
12585accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
12594f6ad66aSAchin Gupta
126036eaaf37SIan Spraycheckcodebase:		locate-checkpatch
126136eaaf37SIan Spray	@echo "  CHECKING STYLE"
126236eaaf37SIan Spray	@if test -d .git ; then						\
12631ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
12641a41e8c1SDan Handley		while read GIT_FILE ;					\
12651a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
12661a41e8c1SDan Handley		done ;							\
126736eaaf37SIan Spray	else								\
12681a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
12691a41e8c1SDan Handley		 -not -iwholename "*build*"				\
12701a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
127161f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
12721a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
12731ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
12741a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
127536eaaf37SIan Spray	fi
127636eaaf37SIan Spray
127736eaaf37SIan Spraycheckpatch:		locate-checkpatch
127836eaaf37SIan Spray	@echo "  CHECKING STYLE"
127902a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
128002a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
128102a76d5fSYann Gautier	fi
128251d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
128351d28937SAntonio Nino Diaz	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
128451d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
128551d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
128602a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
128702a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
128851d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
128902a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
129002a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
129151d28937SAntonio Nino Diaz	done
129236eaaf37SIan Spray
129373c99d4eSJuan Castillocerttool: ${CRTTOOL}
129473c99d4eSJuan Castillo
1295a9812206SPali Rohár${CRTTOOL}: FORCE
1296fafd3ec9SManish 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}
1297f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
12986f971622SJuan Castillo	@echo "Built $@ successfully"
1299f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
13006f971622SJuan Castillo
13016f971622SJuan Castilloifneq (${GENERATE_COT},0)
130273c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
13036f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1304f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
13056f971622SJuan Castillo	@echo "Built $@ successfully"
13066f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1307f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
130873c99d4eSJuan Castilloendif
130927713fb4SSoby Mathew
131073c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
13114727fd13SPali Rohár	$(eval ${CHECK_FIP_CMD})
1312819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1313819281eeSdp-arm	${Q}${FIPTOOL} info $@
1314f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
13152f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1316f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1317f58ad36fSHarry Liebel
13180191262dSYatharth Kocharifneq (${GENERATE_COT},0)
13190191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
13200191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1321052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13220191262dSYatharth Kochar	@echo "Built $@ successfully"
13230191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1324052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13250191262dSYatharth Kocharendif
13260191262dSYatharth Kochar
13270191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
13284727fd13SPali Rohár	$(eval ${CHECK_FWU_FIP_CMD})
1329819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1330819281eeSdp-arm	${Q}${FIPTOOL} info $@
1331052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13320191262dSYatharth Kochar	@echo "Built $@ successfully"
1333052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
13340191262dSYatharth Kochar
133573c99d4eSJuan Castillofiptool: ${FIPTOOL}
133673c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
13370191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
133873c99d4eSJuan Castillo
1339a9812206SPali Rohár${FIPTOOL}: FORCE
134088a1cf1eSSami Mujawarifdef UNIX_MK
1341fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} --no-print-directory -C ${FIPTOOLPATH}
134288a1cf1eSSami Mujawarelse
134388a1cf1eSSami Mujawar# Clear the MAKEFLAGS as we do not want
134488a1cf1eSSami Mujawar# to pass the gnumake flags to nmake.
134588a1cf1eSSami Mujawar	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
134688a1cf1eSSami Mujawarendif
1347f58ad36fSHarry Liebel
134826010da1SAntonio Nino Diazsptool: ${SPTOOL}
1349a9812206SPali Rohár${SPTOOL}: FORCE
1350fafd3ec9SManish V Badarkhe	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH}
135126010da1SAntonio Nino Diaz
1352a9812206SPali Rohárromlib.bin: libraries FORCE
1353bbb24f61SJohn 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
13545accce5bSRoberto Vargas
1355cfe83910SLouis Mayencourt# Call print_memory_map tool
1356cfe83910SLouis Mayencourtmemmap: all
1357b890b36dSLouis Mayencourt	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1358cfe83910SLouis Mayencourt
13596de32378SMadhukar Pappireddydoc:
13606de32378SMadhukar Pappireddy	@echo "  BUILD DOCUMENTATION"
13616de32378SMadhukar Pappireddy	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
13626de32378SMadhukar Pappireddy
136390aa901fSSumit Gargenctool: ${ENCTOOL}
136490aa901fSSumit Garg
1365a9812206SPali Rohár${ENCTOOL}: FORCE
1366fafd3ec9SManish V Badarkhe	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
136790aa901fSSumit Garg	@${ECHO_BLANK_LINE}
136890aa901fSSumit Garg	@echo "Built $@ successfully"
136990aa901fSSumit Garg	@${ECHO_BLANK_LINE}
137090aa901fSSumit Garg
137135fab8c9SJoakim Bechcscope:
137235fab8c9SJoakim Bech	@echo "  CSCOPE"
137335fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
137435fab8c9SJoakim Bech	${Q}cscope -b -q -k
137535fab8c9SJoakim Bech
137672ee3314SRyan Harkinhelp:
13777c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
137872ee3314SRyan Harkin	@echo ""
137972ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
138008c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
138172ee3314SRyan Harkin	@echo ""
13827c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
13837c23126cSJohn Tsichritzis	@echo ""
13841b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
13851b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
13861b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
13871b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
13881b578596SSandrine Bailleux	@echo ""
138972ee3314SRyan Harkin	@echo "Supported Targets:"
13901b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
139136eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
13928aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
13939003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1394d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
13959d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
13969d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
139773c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
13981b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
13990191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
140036eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
140136eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
140236eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
140372ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
140435fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
140572ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
14066f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
140790aa901fSSumit Garg	@echo "  enctool        Build the Firmware encryption tool"
1408f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1409ce2b1ec6SManish Pandey	@echo "  sp             Build the Secure Partition Packages"
141026010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
141138c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1412cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
14136de32378SMadhukar Pappireddy	@echo "  doc            Build html based documentation using Sphinx tool"
141472ee3314SRyan Harkin	@echo ""
14151b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
141672ee3314SRyan Harkin	@echo ""
141772ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
141872ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1419a9812206SPali Rohár
1420a9812206SPali Rohár.PHONY: FORCE
1421a9812206SPali RohárFORCE:;
1422