xref: /rk3399_ARM-atf/Makefile (revision 69af7fcf99bcce85ed218c97df0b76c377b3ed16)
14f6ad66aSAchin Gupta#
22d51b55eSBalint Dobszay# Copyright (c) 2013-2020, 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
112ee6b2bcSDeepika BhavnaniVERSION_MINOR			:= 2
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
42f0b489c1SDan HandleyINC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
431a41e8c1SDan Handley					include/lib/libfdt		\
4461f72a34SRoberto Vargas					include/lib/libc,		\
45f0b489c1SDan Handley					$(wildcard include/lib/*)))
46f0b489c1SDan HandleyINC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
47f0b489c1SDan Handley					include/lib,			\
48f0b489c1SDan Handley					$(wildcard include/*)))
49f0b489c1SDan HandleyLIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
50d801fbb0Sdp-arm					lib/compiler-rt			\
5155cdcf75SAntonio Nino Diaz					lib/libfdt%			\
5261f72a34SRoberto Vargas					lib/libc,			\
53f0b489c1SDan Handley					$(wildcard lib/*)))
54f0b489c1SDan HandleyROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
55f0b489c1SDan Handley					lib				\
56f0b489c1SDan Handley					include				\
57f0b489c1SDan Handley					docs				\
581ef35512SPaul Beesley					%.rst,				\
59f0b489c1SDan Handley					$(wildcard *)))
60f0b489c1SDan HandleyCHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
61f0b489c1SDan Handley				${INC_DIRS_TO_CHECK}			\
62f0b489c1SDan Handley				${INC_LIB_DIRS_TO_CHECK}		\
63f0b489c1SDan Handley				${LIB_DIRS_TO_CHECK}
6436eaaf37SIan Spray
6573c99d4eSJuan Castillo
6673c99d4eSJuan Castillo################################################################################
6773c99d4eSJuan Castillo# Process build options
6873c99d4eSJuan Castillo################################################################################
6973c99d4eSJuan Castillo
7073c99d4eSJuan Castillo# Verbose flag
71e35c4045SJeenu Viswambharanifeq (${V},0)
72b169f6a9SEvan Lloyd        Q:=@
73ee1ba6d4SAndre Przywara        ECHO:=@echo
7436eaaf37SIan Spray        CHECKCODE_ARGS	+=	--no-summary --terse
754f6ad66aSAchin Guptaelse
76b169f6a9SEvan Lloyd        Q:=
77b5a0f4bdSAntonio Nino Diaz        ECHO:=$(ECHO_QUIET)
784f6ad66aSAchin Guptaendif
79ee1ba6d4SAndre Przywara
80ee1ba6d4SAndre Przywaraifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
81ee1ba6d4SAndre Przywara        Q:=@
82b5a0f4bdSAntonio Nino Diaz        ECHO:=$(ECHO_QUIET)
83ee1ba6d4SAndre Przywaraendif
84ee1ba6d4SAndre Przywara
85ee1ba6d4SAndre Przywaraexport Q ECHO
862f2cef46SJeenu Viswambharan
8773c99d4eSJuan Castillo# Process Debug flag
8873c99d4eSJuan Castillo$(eval $(call add_define,DEBUG))
89eaaeece2SJames Morrisseyifneq (${DEBUG}, 0)
90eaaeece2SJames Morrissey        BUILD_TYPE	:=	debug
91403973c9SSandrine Bailleux        TF_CFLAGS	+= 	-g
921684b873SRoberto Vargas
931684b873SRoberto Vargas        ifneq ($(findstring clang,$(notdir $(CC))),)
941684b873SRoberto Vargas             ASFLAGS		+= 	-g
951684b873SRoberto Vargas        else
9673c99d4eSJuan Castillo             ASFLAGS		+= 	-g -Wa,--gdwarf-2
971684b873SRoberto Vargas        endif
981684b873SRoberto Vargas
99289c28a8SDan Handley        # Use LOG_LEVEL_INFO by default for debug builds
100289c28a8SDan Handley        LOG_LEVEL	:=	40
101eaaeece2SJames Morrisseyelse
102eaaeece2SJames Morrissey        BUILD_TYPE	:=	release
103289c28a8SDan Handley        # Use LOG_LEVEL_NOTICE by default for release builds
104289c28a8SDan Handley        LOG_LEVEL	:=	20
105eaaeece2SJames Morrisseyendif
106eaaeece2SJames Morrissey
107aaa3e722SJuan Castillo# Default build string (git branch and commit)
108aaa3e722SJuan Castilloifeq (${BUILD_STRING},)
109bee71c7aSMasahiro Yamada        BUILD_STRING	:=	$(shell git describe --always --dirty --tags 2> /dev/null)
110aaa3e722SJuan Castilloendif
111aaa3e722SJuan CastilloVERSION_STRING		:=	v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
112aaa3e722SJuan Castillo
11373c99d4eSJuan Castillo# The cert_create tool cannot generate certificates individually, so we use the
11473c99d4eSJuan Castillo# target 'certificates' to create them all
11573c99d4eSJuan Castilloifneq (${GENERATE_COT},0)
11673c99d4eSJuan Castillo        FIP_DEPS += certificates
1170191262dSYatharth Kochar        FWU_FIP_DEPS += fwu_certificates
11873c99d4eSJuan Castilloendif
11973c99d4eSJuan Castillo
1209fc59639SAlexei Fedorov# Process BRANCH_PROTECTION value and set
1219fc59639SAlexei Fedorov# Pointer Authentication and Branch Target Identification flags
1229fc59639SAlexei Fedorovifeq (${BRANCH_PROTECTION},0)
1239fc59639SAlexei Fedorov	# Default value turns off all types of branch protection
1249fc59639SAlexei Fedorov	BP_OPTION := none
1259fc59639SAlexei Fedorovelse ifneq (${ARCH},aarch64)
1269fc59639SAlexei Fedorov        $(error BRANCH_PROTECTION requires AArch64)
1279fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},1)
1289fc59639SAlexei Fedorov	# Enables all types of branch protection features
1299fc59639SAlexei Fedorov	BP_OPTION := standard
1309fc59639SAlexei Fedorov	ENABLE_BTI := 1
1319fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1329fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},2)
1339fc59639SAlexei Fedorov	# Return address signing to its standard level
1349fc59639SAlexei Fedorov	BP_OPTION := pac-ret
1359fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1369fc59639SAlexei Fedorovelse ifeq (${BRANCH_PROTECTION},3)
1379fc59639SAlexei Fedorov	# Extend the signing to include leaf functions
1389fc59639SAlexei Fedorov	BP_OPTION := pac-ret+leaf
1399fc59639SAlexei Fedorov	ENABLE_PAUTH := 1
1409fc59639SAlexei Fedorovelse
1419fc59639SAlexei Fedorov        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
1429fc59639SAlexei Fedorovendif
14373c99d4eSJuan Castillo
144c97cba4eSSoby Mathew# USE_SPINLOCK_CAS requires AArch64 build
145c97cba4eSSoby Mathewifeq (${USE_SPINLOCK_CAS},1)
146c97cba4eSSoby Mathewifneq (${ARCH},aarch64)
147c97cba4eSSoby Mathew        $(error USE_SPINLOCK_CAS requires AArch64)
148c97cba4eSSoby Mathewelse
149c97cba4eSSoby Mathew        $(info USE_SPINLOCK_CAS is an experimental feature)
150c97cba4eSSoby Mathewendif
151c97cba4eSSoby Mathewendif
152c97cba4eSSoby Mathew
1530ca3913dSOlivier Deprez# USE_DEBUGFS experimental feature recommended only in debug builds
1540ca3913dSOlivier Deprezifeq (${USE_DEBUGFS},1)
1550ca3913dSOlivier Deprezifeq (${DEBUG},1)
1560ca3913dSOlivier Deprez        $(warning DEBUGFS experimental feature is enabled.)
1570ca3913dSOlivier Deprezelse
1580ca3913dSOlivier Deprez        $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
1590ca3913dSOlivier Deprezendif
1600ca3913dSOlivier Deprezendif
1610ca3913dSOlivier Deprez
16273c99d4eSJuan Castillo################################################################################
16373c99d4eSJuan Castillo# Toolchain
16473c99d4eSJuan Castillo################################################################################
16573c99d4eSJuan Castillo
16672610c41Sdp-armHOSTCC			:=	gcc
16772610c41Sdp-armexport HOSTCC
16872610c41Sdp-arm
16973c99d4eSJuan CastilloCC			:=	${CROSS_COMPILE}gcc
17073c99d4eSJuan CastilloCPP			:=	${CROSS_COMPILE}cpp
17173c99d4eSJuan CastilloAS			:=	${CROSS_COMPILE}gcc
17273c99d4eSJuan CastilloAR			:=	${CROSS_COMPILE}ar
1732adee763SRoberto VargasLINKER			:=	${CROSS_COMPILE}ld
17473c99d4eSJuan CastilloOC			:=	${CROSS_COMPILE}objcopy
17573c99d4eSJuan CastilloOD			:=	${CROSS_COMPILE}objdump
17673c99d4eSJuan CastilloNM			:=	${CROSS_COMPILE}nm
17773c99d4eSJuan CastilloPP			:=	${CROSS_COMPILE}gcc -E
17838c14d88SSoby MathewDTC			:=	dtc
17973c99d4eSJuan Castillo
180b25a577fSJulius Werner# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
181b25a577fSJulius Wernerifneq ($(strip $(wildcard ${LD}.bfd) \
1822adee763SRoberto Vargas	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
1832adee763SRoberto VargasLINKER			:=	${LINKER}.bfd
184b25a577fSJulius Wernerendif
185b25a577fSJulius Werner
18626e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
18726e63c44SEtienne Carrieretarget32-directive	= 	-target arm-none-eabi
18826e63c44SEtienne Carriere# Will set march32-directive from platform configuration
18926e63c44SEtienne Carriereelse
19026e63c44SEtienne Carrieretarget32-directive	= 	-target armv8a-none-eabi
191fa6f774bSAlexei Fedorov
192fa6f774bSAlexei Fedorov# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
193fa6f774bSAlexei Fedorovifeq (${ARM_ARCH_MINOR},0)
194da547d4bSSandrine Bailleuxmarch32-directive	= 	-march=armv8-a
195fa6f774bSAlexei Fedorovmarch64-directive	= 	-march=armv8-a
196fa6f774bSAlexei Fedorovelse
197fa6f774bSAlexei Fedorovmarch32-directive	= 	-march=armv8.${ARM_ARCH_MINOR}-a
198fa6f774bSAlexei Fedorovmarch64-directive	= 	-march=armv8.${ARM_ARCH_MINOR}-a
199fa6f774bSAlexei Fedorovendif
20026e63c44SEtienne Carriereendif
20126e63c44SEtienne Carriere
202fd18a8fcSVarun Wadekarifneq ($(findstring armclang,$(notdir $(CC))),)
20326e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
204fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi $(march64-directive)
2052adee763SRoberto VargasLD			=	$(LINKER)
2061684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2077040155eSRoberto VargasCPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2087040155eSRoberto VargasPP			=	$(CC) -E $(TF_CFLAGS_$(ARCH))
2097559633bSdp-armelse ifneq ($(findstring clang,$(notdir $(CC))),)
210e2bfec0bSYann GautierTF_CFLAGS_aarch32	=	$(target32-directive) $(march32-directive)
211fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	-target aarch64-elf $(march64-directive)
212641f16e7SAmbroise VincentLD			=	ld.lld
213641f16e7SAmbroise Vincentifeq (, $(shell which $(LD)))
214641f16e7SAmbroise Vincent$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker")
215641f16e7SAmbroise Vincentendif
2161684b873SRoberto VargasAS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
2177040155eSRoberto VargasCPP			=	$(CC) -E
2187040155eSRoberto VargasPP			=	$(CC) -E
219edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(CC))),)
220edbce9aaSzelalem-awekeTF_CFLAGS_aarch32	=	$(march32-directive)
221edbce9aaSzelalem-awekeTF_CFLAGS_aarch64	=	$(march64-directive)
222edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
223edbce9aaSzelalem-aweke	# Enable LTO only for aarch64
224edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
225edbce9aaSzelalem-aweke		LTO_CFLAGS	=	-flto
226edbce9aaSzelalem-aweke		# Use gcc as a wrapper for the ld, recommended for LTO
227edbce9aaSzelalem-aweke		LINKER		:=	${CROSS_COMPILE}gcc
228edbce9aaSzelalem-aweke	endif
229edbce9aaSzelalem-awekeendif
230edbce9aaSzelalem-awekeLD			=	$(LINKER)
231d5461857Sdp-armelse
23226e63c44SEtienne CarriereTF_CFLAGS_aarch32	=	$(march32-directive)
233fa6f774bSAlexei FedorovTF_CFLAGS_aarch64	=	$(march64-directive)
2342adee763SRoberto VargasLD			=	$(LINKER)
235d5461857Sdp-armendif
236d5461857Sdp-arm
2378fd9d4d5SAntonio Nino Diazifeq (${AARCH32_INSTRUCTION_SET},A32)
2388fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-marm
2398fd9d4d5SAntonio Nino Diazelse ifeq (${AARCH32_INSTRUCTION_SET},T32)
2408fd9d4d5SAntonio Nino DiazTF_CFLAGS_aarch32	+=	-mthumb
2418fd9d4d5SAntonio Nino Diazelse
2428fd9d4d5SAntonio Nino Diaz$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
2438fd9d4d5SAntonio Nino Diazendif
2448fd9d4d5SAntonio Nino Diaz
245a9c4dde3SSandrine BailleuxTF_CFLAGS_aarch32	+=	-mno-unaligned-access
246d5461857Sdp-armTF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
2479d29c227SSoby Mathew
2489fc59639SAlexei Fedorovifneq (${BP_OPTION},none)
2499fc59639SAlexei FedorovTF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
2509fc59639SAlexei Fedorovendif
2519fc59639SAlexei Fedorov
25226e63c44SEtienne CarriereASFLAGS_aarch32		=	$(march32-directive)
253fa6f774bSAlexei FedorovASFLAGS_aarch64		=	$(march64-directive)
254b86048c4SAntonio Nino Diaz
2559ab81b5eSJustin Chadwell# General warnings
2569ab81b5eSJustin ChadwellWARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
257b7f6525dSJustin Chadwell				-Wdisabled-optimization	-Wvla -Wshadow	\
2589ab81b5eSJustin Chadwell				-Wno-unused-parameter
2599ab81b5eSJustin Chadwell
2609ab81b5eSJustin Chadwell# Additional warnings
2619ab81b5eSJustin Chadwell# Level 1
262e7c645b5SYann GautierWARNING1 := -Wextra
263e7c645b5SYann GautierWARNING1 += -Wmissing-format-attribute
264e7c645b5SYann GautierWARNING1 += -Wmissing-prototypes
265e7c645b5SYann GautierWARNING1 += -Wold-style-definition
266e7c645b5SYann Gautier
267b7f6525dSJustin Chadwell# Level 2
268e7c645b5SYann GautierWARNING2 := -Waggregate-return
269e7c645b5SYann GautierWARNING2 += -Wcast-align
270e7c645b5SYann GautierWARNING2 += -Wnested-externs
271e7c645b5SYann Gautier
272e7c645b5SYann GautierWARNING3 := -Wbad-function-cast
273e7c645b5SYann GautierWARNING3 += -Wcast-qual
274e7c645b5SYann GautierWARNING3 += -Wconversion
275e7c645b5SYann GautierWARNING3 += -Wpacked
276e7c645b5SYann GautierWARNING3 += -Wpointer-arith
277e7c645b5SYann GautierWARNING3 += -Wredundant-decls
278e7c645b5SYann GautierWARNING3 += -Wswitch-default
279e7c645b5SYann Gautier
280e7c645b5SYann Gautierifeq (${W},1)
2819ab81b5eSJustin ChadwellWARNINGS += $(WARNING1)
282e7c645b5SYann Gautierelse ifeq (${W},2)
2839ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2)
284e7c645b5SYann Gautierelse ifeq (${W},3)
2859ab81b5eSJustin ChadwellWARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
286e7c645b5SYann Gautierendif
287e7c645b5SYann Gautier
2889ab81b5eSJustin Chadwell# Compiler specific warnings
28900296576SAmbroise Vincentifeq ($(findstring clang,$(notdir $(CC))),)
29093c690ebSJustin Chadwell# not using clang
291d7b4cd41SJustin ChadwellWARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
292d7b4cd41SJustin Chadwell				-Wpacked-bitfield-compat -Wshift-overflow=2 \
293d7b4cd41SJustin Chadwell				-Wlogical-op
29493c690ebSJustin Chadwellelse
29593c690ebSJustin Chadwell# using clang
296d7b4cd41SJustin ChadwellWARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
297d7b4cd41SJustin Chadwell				-Wlogical-op-parentheses
29800296576SAmbroise Vincentendif
29900296576SAmbroise Vincent
3006336b07aSYann Gautierifneq (${E},0)
3016336b07aSYann GautierERRORS := -Werror
3026336b07aSYann Gautierendif
3036336b07aSYann Gautier
304ea7a57a3SRoberto VargasCPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
3059ab81b5eSJustin Chadwell				$(ERRORS) $(WARNINGS)
30659de5096SMasahiro YamadaASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
307d5dfdeb6SJulius Werner				-ffreestanding -Wa,--fatal-warnings
30859de5096SMasahiro YamadaTF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
309ebd6efaeSSamuel Holland				-ffunction-sections -fdata-sections		\
310ebd6efaeSSamuel Holland				-ffreestanding -fno-builtin -fno-common		\
311ebd6efaeSSamuel Holland				-Os -std=gnu99
31273c99d4eSJuan Castillo
3131f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3141f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover
3151f461979SJustin Chadwellendif
3161f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
3171f461979SJustin ChadwellTF_CFLAGS		+=	-fsanitize=undefined -fno-sanitize-recover	\
3181f461979SJustin Chadwell				-fsanitize-undefined-trap-on-error
3191f461979SJustin Chadwellendif
3201f461979SJustin Chadwell
321f7ec31dbSdavid cunadoGCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
322f7ec31dbSdavid cunado
323641f16e7SAmbroise Vincent# LD = armlink
324c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
325c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
326c2ad38ceSVarun WadekarTF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
327edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
328641f16e7SAmbroise Vincent
329641f16e7SAmbroise Vincent# LD = gcc (used when GCC LTO is enabled)
330edbce9aaSzelalem-awekeelse ifneq ($(findstring gcc,$(notdir $(LD))),)
331edbce9aaSzelalem-aweke# Pass ld options with Wl or Xlinker switches
332edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
333edbce9aaSzelalem-awekeTF_LDFLAGS		+=	-Wl,--gc-sections
334edbce9aaSzelalem-awekeifeq ($(ENABLE_LTO),1)
335edbce9aaSzelalem-aweke	ifeq (${ARCH},aarch64)
336edbce9aaSzelalem-aweke		TF_LDFLAGS	+=	-flto -fuse-linker-plugin
337edbce9aaSzelalem-aweke	endif
338edbce9aaSzelalem-awekeendif
339edbce9aaSzelalem-aweke# GCC automatically adds fix-cortex-a53-843419 flag when used to link
340edbce9aaSzelalem-aweke# which breaks some builds, so disable if errata fix is not explicitly enabled
341edbce9aaSzelalem-awekeifneq (${ERRATA_A53_843419},1)
342edbce9aaSzelalem-aweke	TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
343edbce9aaSzelalem-awekeendif
344edbce9aaSzelalem-awekeTF_LDFLAGS		+= 	-nostdlib
345edbce9aaSzelalem-awekeTF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
346641f16e7SAmbroise Vincent
347641f16e7SAmbroise Vincent# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
348c2ad38ceSVarun Wadekarelse
349c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--fatal-warnings -O1
350c2b8806fSDouglas RaillardTF_LDFLAGS		+=	--gc-sections
351641f16e7SAmbroise Vincent# ld.lld doesn't recognize the errata flags,
352641f16e7SAmbroise Vincent# therefore don't add those in that case
353641f16e7SAmbroise Vincentifeq ($(findstring ld.lld,$(notdir $(LD))),)
354c2b8806fSDouglas RaillardTF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
355edbce9aaSzelalem-awekeendif
356641f16e7SAmbroise Vincentendif
35773c99d4eSJuan Castillo
35803b397a8SNishanth MenonDTC_FLAGS		+=	-I dts -O dtb
3592d51b55eSBalint DobszayDTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef -x assembler-with-cpp
36003b397a8SNishanth Menon
36173c99d4eSJuan Castillo################################################################################
36273c99d4eSJuan Castillo# Common sources and include directories
36373c99d4eSJuan Castillo################################################################################
364d801fbb0Sdp-arminclude lib/compiler-rt/compiler-rt.mk
36573c99d4eSJuan Castillo
36673c99d4eSJuan CastilloBL_COMMON_SOURCES	+=	common/bl_common.c			\
3677f56e9a3SSoby Mathew				common/tf_log.c				\
3689d29c227SSoby Mathew				common/${ARCH}/debug.S			\
36991b48c9fSJulius Werner				drivers/console/multi_console.c		\
3709d29c227SSoby Mathew				lib/${ARCH}/cache_helpers.S		\
3719d29c227SSoby Mathew				lib/${ARCH}/misc_helpers.S		\
372566034fcSSoby Mathew				plat/common/plat_bl_common.c		\
3737f56e9a3SSoby Mathew				plat/common/plat_log_common.c		\
37475311203Sdp-arm				plat/common/${ARCH}/plat_common.c	\
3759d29c227SSoby Mathew				plat/common/${ARCH}/platform_helpers.S	\
37661f72a34SRoberto Vargas				${COMPILER_RT_SRCS}
377d7a6b0f8SRyan Harkin
3788422a840SAntonio Nino Diazifeq ($(notdir $(CC)),armclang)
3798422a840SAntonio Nino DiazBL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
3808422a840SAntonio Nino Diazendif
3818422a840SAntonio Nino Diaz
3821f461979SJustin Chadwellifeq (${SANITIZE_UB},on)
3831f461979SJustin ChadwellBL_COMMON_SOURCES	+=	plat/common/ubsan.c
3841f461979SJustin Chadwellendif
3851f461979SJustin Chadwell
38601d237cbSYann GautierINCLUDES		+=	-Iinclude				\
387f5478dedSAntonio Nino Diaz				-Iinclude/arch/${ARCH}			\
38809d40e0eSAntonio Nino Diaz				-Iinclude/lib/cpus/${ARCH}		\
38909d40e0eSAntonio Nino Diaz				-Iinclude/lib/el3_runtime/${ARCH}	\
39009d40e0eSAntonio Nino Diaz				${PLAT_INCLUDES}			\
39109d40e0eSAntonio Nino Diaz				${SPD_INCLUDES}
39209d40e0eSAntonio Nino Diaz
3939c6d1c50SAntonio Nino Diazinclude common/backtrace/backtrace.mk
3949c6d1c50SAntonio Nino Diaz
39573c99d4eSJuan Castillo################################################################################
39673c99d4eSJuan Castillo# Generic definitions
39773c99d4eSJuan Castillo################################################################################
39873c99d4eSJuan Castillo
399231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
400231c1470SEvan Lloyd
40173c99d4eSJuan CastilloBUILD_BASE		:=	./build
40273c99d4eSJuan CastilloBUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
40373c99d4eSJuan Castillo
404231c1470SEvan LloydSPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
40573c99d4eSJuan Castillo
40673c99d4eSJuan Castillo# Platforms providing their own TBB makefile may override this value
40773c99d4eSJuan CastilloINCLUDE_TBBR_MK		:=	1
40873c99d4eSJuan Castillo
40973c99d4eSJuan Castillo
41073c99d4eSJuan Castillo################################################################################
41173c99d4eSJuan Castillo# Include SPD Makefile if one has been specified
41273c99d4eSJuan Castillo################################################################################
41373c99d4eSJuan Castillo
41473c99d4eSJuan Castilloifneq (${SPD},none)
4159d29c227SSoby Mathewifeq (${ARCH},aarch32)
4169d29c227SSoby Mathew        $(error "Error: SPD is incompatible with AArch32.")
4179d29c227SSoby Mathewendif
4184c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
4194c117f6cSSandrine Bailleux        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
4204c117f6cSSandrine Bailleux        $(warning "The SPD and its BL32 companion will be present but ignored.")
4214c117f6cSSandrine Bailleuxendif
42273c99d4eSJuan Castillo        # We expect to locate an spd.mk under the specified SPD directory
423231c1470SEvan Lloyd        SPD_MAKE	:=	$(wildcard services/spd/${SPD}/${SPD}.mk)
42473c99d4eSJuan Castillo
42573c99d4eSJuan Castillo        ifeq (${SPD_MAKE},)
42673c99d4eSJuan Castillo                $(error Error: No services/spd/${SPD}/${SPD}.mk located)
42773c99d4eSJuan Castillo        endif
42873c99d4eSJuan Castillo        $(info Including ${SPD_MAKE})
42973c99d4eSJuan Castillo        include ${SPD_MAKE}
43073c99d4eSJuan Castillo
43170d1fc53SJuan Castillo        # If there's BL32 companion for the chosen SPD, we expect that the SPD's
43270d1fc53SJuan Castillo        # Makefile would set NEED_BL32 to "yes". In this case, the build system
43370d1fc53SJuan Castillo        # supports two mutually exclusive options:
43470d1fc53SJuan Castillo        # * BL32 is built from source: then BL32_SOURCES must contain the list
43570d1fc53SJuan Castillo        #   of source files to build BL32
43670d1fc53SJuan Castillo        # * BL32 is a prebuilt binary: then BL32 must point to the image file
43770d1fc53SJuan Castillo        #   that will be included in the FIP
43870d1fc53SJuan Castillo        # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
43970d1fc53SJuan Castillo        # over the sources.
440e35c4045SJeenu Viswambharanendif
441e35c4045SJeenu Viswambharan
44251faada7SDouglas Raillard################################################################################
44373c99d4eSJuan Castillo# Include the platform specific Makefile after the SPD Makefile (the platform
44473c99d4eSJuan Castillo# makefile may use all previous definitions in this file)
44573c99d4eSJuan Castillo################################################################################
4462da8d8bfSJeenu Viswambharan
44773c99d4eSJuan Castilloinclude ${PLAT_MAKEFILE_FULL}
4480f21c547SJuan Castillo
4498012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
4508012cc5cSMasahiro Yamada
45126e63c44SEtienne Carriereifeq (${ARM_ARCH_MAJOR},7)
45226e63c44SEtienne Carriereinclude make_helpers/armv7-a-cpus.mk
45326e63c44SEtienne Carriereendif
45426e63c44SEtienne Carriere
4553bd17c0fSSoby MathewPIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
4563bd17c0fSSoby Mathewifneq ($(PIE_FOUND),)
4573bd17c0fSSoby Mathew	TF_CFLAGS	+=	-fno-PIE
4583bd17c0fSSoby Mathewendif
459320920c1SMasahiro Yamada
460320920c1SMasahiro Yamadaifneq ($(findstring gcc,$(notdir $(LD))),)
461320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
462320920c1SMasahiro Yamadaelse
463320920c1SMasahiro Yamada	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
464320920c1SMasahiro Yamadaendif
465320920c1SMasahiro Yamada
466320920c1SMasahiro Yamadaifeq ($(ENABLE_PIE),1)
467*69af7fcfSMasahiro Yamadaifeq ($(BL2_AT_EL3),1)
468*69af7fcfSMasahiro Yamadaifneq ($(BL2_IN_XIP_MEM),1)
469*69af7fcfSMasahiro Yamada	BL2_CFLAGS	+=	-fpie
470*69af7fcfSMasahiro Yamada	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
471*69af7fcfSMasahiro Yamadaendif
472*69af7fcfSMasahiro Yamadaendif
473320920c1SMasahiro Yamada	BL31_CFLAGS	+=	-fpie
474320920c1SMasahiro Yamada	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
4753bd17c0fSSoby Mathewendif
4763bd17c0fSSoby Mathew
47754035fc4SSandrine Bailleux# Include the CPU specific operations makefile, which provides default
47854035fc4SSandrine Bailleux# values for all CPU errata workarounds and CPU specific optimisations.
47954035fc4SSandrine Bailleux# This can be overridden by the platform.
48073c99d4eSJuan Castilloinclude lib/cpus/cpu-ops.mk
4814f6ad66aSAchin Gupta
482a4409008Sdp-armifeq (${ARCH},aarch32)
483a4409008Sdp-armNEED_BL32 := yes
484a4409008Sdp-arm
485a4409008Sdp-arm################################################################################
486a4409008Sdp-arm# Build `AARCH32_SP` as BL32 image for AArch32
487a4409008Sdp-arm################################################################################
488a4409008Sdp-armifneq (${AARCH32_SP},none)
489a4409008Sdp-arm# We expect to locate an sp.mk under the specified AARCH32_SP directory
490a4409008Sdp-armAARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
491a4409008Sdp-arm
492a4409008Sdp-armifeq (${AARCH32_SP_MAKE},)
493a4409008Sdp-arm  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
494a4409008Sdp-armendif
495a4409008Sdp-arm
496a4409008Sdp-arm$(info Including ${AARCH32_SP_MAKE})
497a4409008Sdp-arminclude ${AARCH32_SP_MAKE}
498a4409008Sdp-armendif
499a4409008Sdp-arm
500a4409008Sdp-armendif
5014f6ad66aSAchin Gupta
50273c99d4eSJuan Castillo################################################################################
50377f1f7a1SVarun Wadekar# Include libc if not overridden
50477f1f7a1SVarun Wadekar################################################################################
50577f1f7a1SVarun Wadekarifeq (${OVERRIDE_LIBC},0)
50677f1f7a1SVarun Wadekarinclude lib/libc/libc.mk
50777f1f7a1SVarun Wadekarendif
50877f1f7a1SVarun Wadekar
50977f1f7a1SVarun Wadekar################################################################################
510cf2c8a33SAntonio Nino Diaz# Check incompatible options
511cf2c8a33SAntonio Nino Diaz################################################################################
512cf2c8a33SAntonio Nino Diaz
513cf2c8a33SAntonio Nino Diazifdef EL3_PAYLOAD_BASE
51468450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
51568450a6dSAntonio Nino Diaz                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
51668450a6dSAntonio Nino Diaz                incompatible build options. EL3_PAYLOAD_BASE has priority.")
517cf2c8a33SAntonio Nino Diaz        endif
51876580f3dSQixiang Xu        ifneq (${GENERATE_COT},0)
51976580f3dSQixiang Xu                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
52076580f3dSQixiang Xu        endif
52176580f3dSQixiang Xu        ifneq (${TRUSTED_BOARD_BOOT},0)
52276580f3dSQixiang Xu                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
52376580f3dSQixiang Xu        endif
524cf2c8a33SAntonio Nino Diazendif
525cf2c8a33SAntonio Nino Diaz
526cf2c8a33SAntonio Nino Diazifeq (${NEED_BL33},yes)
527cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
528cf2c8a33SAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
529cf2c8a33SAntonio Nino Diaz                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
530cf2c8a33SAntonio Nino Diaz        endif
53168450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
53268450a6dSAntonio Nino Diaz                $(warning "BL33 image is not needed when option \
53368450a6dSAntonio Nino Diaz                PRELOADED_BL33_BASE is used and won't be added to the FIP \
53468450a6dSAntonio Nino Diaz                file.")
535cf2c8a33SAntonio Nino Diaz        endif
536cf2c8a33SAntonio Nino Diazendif
537cf2c8a33SAntonio Nino Diaz
538d4593e47SJeenu Viswambharan# When building for systems with hardware-assisted coherency, there's no need to
539d4593e47SJeenu Viswambharan# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
540d4593e47SJeenu Viswambharanifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
541d4593e47SJeenu Viswambharan$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
542d4593e47SJeenu Viswambharanendif
5431a0a3f06SYatharth Kochar
5447d173fc5SJiafei Pan#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
5457d173fc5SJiafei Panifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
5467d173fc5SJiafei Pan$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
5477d173fc5SJiafei Panendif
5487d173fc5SJiafei Pan
54914c6016aSJeenu Viswambharan# For RAS_EXTENSION, require that EAs are handled in EL3 first
55014c6016aSJeenu Viswambharanifeq ($(RAS_EXTENSION),1)
55114c6016aSJeenu Viswambharan    ifneq ($(HANDLE_EA_EL3_FIRST),1)
55214c6016aSJeenu Viswambharan        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
55314c6016aSJeenu Viswambharan    endif
55414c6016aSJeenu Viswambharanendif
55514c6016aSJeenu Viswambharan
5561a7c1cfeSJeenu Viswambharan# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
5571a7c1cfeSJeenu Viswambharanifeq ($(FAULT_INJECTION_SUPPORT),1)
5581a7c1cfeSJeenu Viswambharan    ifneq ($(RAS_EXTENSION),1)
5591a7c1cfeSJeenu Viswambharan        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
5601a7c1cfeSJeenu Viswambharan    endif
5611a7c1cfeSJeenu Viswambharanendif
5621a7c1cfeSJeenu Viswambharan
563ed51b51fSRoberto Vargas# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
564209a60ccSSoby Mathewifeq ($(DYN_DISABLE_AUTH), 1)
565209a60ccSSoby Mathew    ifeq (${TRUSTED_BOARD_BOOT}, 0)
566209a60ccSSoby Mathew        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
567209a60ccSSoby Mathew    endif
568209a60ccSSoby Mathewendif
569209a60ccSSoby Mathew
570b86048c4SAntonio Nino Diaz# If pointer authentication is used in the firmware, make sure that all the
5719fc59639SAlexei Fedorov# registers associated to it are also saved and restored.
5729fc59639SAlexei Fedorov# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
573b86048c4SAntonio Nino Diazifeq ($(ENABLE_PAUTH),1)
5749fc59639SAlexei Fedorov    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
5759fc59639SAlexei Fedorov        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
57606715f85SAlexei Fedorov    endif
5779fc59639SAlexei Fedorovendif
5789fc59639SAlexei Fedorov
57906715f85SAlexei Fedorovifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
5809fc59639SAlexei Fedorov    ifneq (${ARCH},aarch64)
5819fc59639SAlexei Fedorov        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
582dfc66a17SJohn Tsichritzis    else
58306715f85SAlexei Fedorov        $(info CTX_INCLUDE_PAUTH_REGS is an experimental feature)
584b86048c4SAntonio Nino Diaz    endif
585b86048c4SAntonio Nino Diazendif
5869fc59639SAlexei Fedorov
5879fc59639SAlexei Fedorovifeq ($(ENABLE_PAUTH),1)
5889fc59639SAlexei Fedorov    $(info Pointer Authentication is an experimental feature)
5899fc59639SAlexei Fedorovendif
5909fc59639SAlexei Fedorov
5919fc59639SAlexei Fedorovifeq ($(ENABLE_BTI),1)
5929fc59639SAlexei Fedorov    $(info Branch Protection is an experimental feature)
593dfc66a17SJohn Tsichritzisendif
594b86048c4SAntonio Nino Diaz
5959dd94382SJustin Chadwellifeq ($(CTX_INCLUDE_MTE_REGS),1)
5969dd94382SJustin Chadwell    ifneq (${ARCH},aarch64)
5979dd94382SJustin Chadwell        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
5989dd94382SJustin Chadwell    else
5999dd94382SJustin Chadwell        $(info CTX_INCLUDE_MTE_REGS is an experimental feature)
6009dd94382SJustin Chadwell    endif
6019dd94382SJustin Chadwellendif
6029dd94382SJustin Chadwell
603cf2c8a33SAntonio Nino Diaz################################################################################
60473c99d4eSJuan Castillo# Process platform overrideable behaviour
60573c99d4eSJuan Castillo################################################################################
6064f6ad66aSAchin Gupta
607bd97f83aSJohn Tsichritzis# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
608bd97f83aSJohn Tsichritzis# Certificate generation tools. This flag can be overridden by the platform.
60973c99d4eSJuan Castilloifdef BL2_SOURCES
610cf2c8a33SAntonio Nino Diaz        ifdef EL3_PAYLOAD_BASE
611cf2c8a33SAntonio Nino Diaz                # If booting an EL3 payload there is no need for a BL33 image
612cf2c8a33SAntonio Nino Diaz                # in the FIP file.
6134c117f6cSSandrine Bailleux                NEED_BL33		:=	no
614cf2c8a33SAntonio Nino Diaz        else
61568450a6dSAntonio Nino Diaz                ifdef PRELOADED_BL33_BASE
616cf2c8a33SAntonio Nino Diaz                        # If booting a BL33 preloaded image there is no need of
617cf2c8a33SAntonio Nino Diaz                        # another one in the FIP file.
618cf2c8a33SAntonio Nino Diaz                        NEED_BL33		:=	no
619cf2c8a33SAntonio Nino Diaz                else
620cf2c8a33SAntonio Nino Diaz                        NEED_BL33		?=	yes
621cf2c8a33SAntonio Nino Diaz                endif
6224c117f6cSSandrine Bailleux        endif
62373c99d4eSJuan Castilloendif
6246f971622SJuan Castillo
6254d045d0eSMasahiro Yamada# If SCP_BL2 is given, we always want FIP to include it.
6264d045d0eSMasahiro Yamadaifdef SCP_BL2
6274d045d0eSMasahiro Yamada        NEED_SCP_BL2		:=	yes
6284d045d0eSMasahiro Yamadaendif
6294d045d0eSMasahiro Yamada
6305744e874SSoby Mathew# For AArch32, BL31 is not currently supported.
6315744e874SSoby Mathewifneq (${ARCH},aarch32)
6325744e874SSoby Mathew    ifdef BL31_SOURCES
6335744e874SSoby Mathew        # When booting an EL3 payload, there is no need to compile the BL31 image nor
6345744e874SSoby Mathew        # put it in the FIP.
6355744e874SSoby Mathew        ifndef EL3_PAYLOAD_BASE
6365744e874SSoby Mathew            NEED_BL31 := yes
6375744e874SSoby Mathew        endif
6385744e874SSoby Mathew    endif
6395744e874SSoby Mathewendif
6405744e874SSoby Mathew
64173c99d4eSJuan Castillo# Process TBB related flags
6426f971622SJuan Castilloifneq (${GENERATE_COT},0)
64373c99d4eSJuan Castillo        # Common cert_create options
6446f971622SJuan Castillo        ifneq (${CREATE_KEYS},0)
6456f971622SJuan Castillo                $(eval CRT_ARGS += -n)
6460191262dSYatharth Kochar                $(eval FWU_CRT_ARGS += -n)
647fd34e7baSJuan Castillo                ifneq (${SAVE_KEYS},0)
648fd34e7baSJuan Castillo                        $(eval CRT_ARGS += -k)
6490191262dSYatharth Kochar                        $(eval FWU_CRT_ARGS += -k)
650fd34e7baSJuan Castillo                endif
6516f971622SJuan Castillo        endif
65273c99d4eSJuan Castillo        # Include TBBR makefile (unless the platform indicates otherwise)
65373c99d4eSJuan Castillo        ifeq (${INCLUDE_TBBR_MK},1)
65473c99d4eSJuan Castillo                include make_helpers/tbbr/tbbr_tools.mk
65573c99d4eSJuan Castillo        endif
6566f971622SJuan Castilloendif
6576f971622SJuan Castillo
6581c75d5dfSMasahiro Yamadaifneq (${FIP_ALIGN},0)
6591c75d5dfSMasahiro YamadaFIP_ARGS += --align ${FIP_ALIGN}
6601c75d5dfSMasahiro Yamadaendif
6611c75d5dfSMasahiro Yamada
66273c99d4eSJuan Castillo################################################################################
66346e5e035SMichalis Pappas# Include libraries' Makefile that are used in all BL
66446e5e035SMichalis Pappas################################################################################
66546e5e035SMichalis Pappas
66646e5e035SMichalis Pappasinclude lib/stack_protector/stack_protector.mk
66746e5e035SMichalis Pappas
66846e5e035SMichalis Pappas################################################################################
669819281eeSdp-arm# Auxiliary tools (fiptool, cert_create, etc)
67073c99d4eSJuan Castillo################################################################################
67173c99d4eSJuan Castillo
67273c99d4eSJuan Castillo# Variables for use with Certificate Generation Tool
67373c99d4eSJuan CastilloCRTTOOLPATH		?=	tools/cert_create
67442a45b51SEvan LloydCRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
67573c99d4eSJuan Castillo
67673c99d4eSJuan Castillo# Variables for use with Firmware Image Package
677819281eeSdp-armFIPTOOLPATH		?=	tools/fiptool
678819281eeSdp-armFIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
67973c99d4eSJuan Castillo
68026010da1SAntonio Nino Diaz# Variables for use with sptool
68126010da1SAntonio Nino DiazSPTOOLPATH		?=	tools/sptool
68226010da1SAntonio Nino DiazSPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
68326010da1SAntonio Nino Diaz
6845accce5bSRoberto Vargas# Variables for use with ROMLIB
6855accce5bSRoberto VargasROMLIBPATH		?=	lib/romlib
6865accce5bSRoberto Vargas
687cfe83910SLouis Mayencourt# Variable for use with Python
688cfe83910SLouis MayencourtPYTHON			?=	python3
689cfe83910SLouis Mayencourt
690cfe83910SLouis Mayencourt# Variables for use with PRINT_MEMORY_MAP
691cfe83910SLouis MayencourtPRINT_MEMORY_MAP_PATH		?=	tools/memory
692cfe83910SLouis MayencourtPRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
693cfe83910SLouis Mayencourt
6948a86052dSSoby Mathew################################################################################
6958a86052dSSoby Mathew# Include BL specific makefiles
6968a86052dSSoby Mathew################################################################################
6978a86052dSSoby Mathewifdef BL1_SOURCES
6988a86052dSSoby MathewNEED_BL1 := yes
6998a86052dSSoby Mathewinclude bl1/bl1.mk
7008a86052dSSoby Mathewendif
7018a86052dSSoby Mathew
7028a86052dSSoby Mathewifdef BL2_SOURCES
7038a86052dSSoby MathewNEED_BL2 := yes
7048a86052dSSoby Mathewinclude bl2/bl2.mk
7058a86052dSSoby Mathewendif
7068a86052dSSoby Mathew
7078a86052dSSoby Mathewifdef BL2U_SOURCES
7088a86052dSSoby MathewNEED_BL2U := yes
7098a86052dSSoby Mathewinclude bl2u/bl2u.mk
7108a86052dSSoby Mathewendif
7118a86052dSSoby Mathew
7125744e874SSoby Mathewifeq (${NEED_BL31},yes)
7138a86052dSSoby Mathewifdef BL31_SOURCES
7148a86052dSSoby Mathewinclude bl31/bl31.mk
7158a86052dSSoby Mathewendif
7168a86052dSSoby Mathewendif
7178a86052dSSoby Mathew
71803b397a8SNishanth Menonifdef FDT_SOURCES
71903b397a8SNishanth MenonNEED_FDT := yes
72003b397a8SNishanth Menonendif
72103b397a8SNishanth Menon
72273c99d4eSJuan Castillo################################################################################
72373c99d4eSJuan Castillo# Build options checks
72473c99d4eSJuan Castillo################################################################################
72573c99d4eSJuan Castillo
726a9bec67dSSandrine Bailleux$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
7272fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,CREATE_KEYS))
7282fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
7292fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
7305283962eSAntonio Nino Diaz$(eval $(call assert_boolean,CTX_INCLUDE_PAUTH_REGS))
7319dd94382SJustin Chadwell$(eval $(call assert_boolean,CTX_INCLUDE_MTE_REGS))
7322fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,DEBUG))
733209a60ccSSoby Mathew$(eval $(call assert_boolean,DYN_DISABLE_AUTH))
734c8b55b8fSJeenu Viswambharan$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING))
7350319a977SDimitris Papastamos$(eval $(call assert_boolean,ENABLE_AMU))
736cc8b5632SAntonio Nino Diaz$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
7375f835918SJeenu Viswambharan$(eval $(call assert_boolean,ENABLE_MPAM_FOR_LOWER_ELS))
7383bd17c0fSSoby Mathew$(eval $(call assert_boolean,ENABLE_PIE))
739a31d8983SYatharth Kochar$(eval $(call assert_boolean,ENABLE_PMF))
740170fb93dSYatharth Kochar$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
741872be88aSdp-arm$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
742c1232c31SJeenu Viswambharan$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
7431a853370SDavid Cunado$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
7442fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,ERROR_DEPRECATED))
7451a7c1cfeSJeenu Viswambharan$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT))
7462fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,GENERATE_COT))
74774dce7faSJeenu Viswambharan$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
74876454abfSJeenu Viswambharan$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST))
7493c251af3SJeenu Viswambharan$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
7502fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,NS_TIMER_SWITCH))
75177f1f7a1SVarun Wadekar$(eval $(call assert_boolean,OVERRIDE_LIBC))
7522fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,PL011_GENERIC_UART))
7532fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
7542fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
75514c6016aSJeenu Viswambharan$(eval $(call assert_boolean,RAS_EXTENSION))
7562fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,RESET_TO_BL31))
7572fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,SAVE_KEYS))
7582fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
759f8578e64SSamuel Holland$(eval $(call assert_boolean,SEPARATE_NOBITS_REGION))
7602fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
7618855e52eSAntonio Nino Diaz$(eval $(call assert_boolean,SPM_MM))
7622fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
7632fae4b1eSJeenu Viswambharan$(eval $(call assert_boolean,USE_COHERENT_MEM))
7640ca3913dSOlivier Deprez$(eval $(call assert_boolean,USE_DEBUGFS))
7655accce5bSRoberto Vargas$(eval $(call assert_boolean,USE_ROMLIB))
766bb41eb7aSMasahiro Yamada$(eval $(call assert_boolean,USE_TBBR_DEFS))
767bcc3c49cSSoby Mathew$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
768b1d27b48SRoberto Vargas$(eval $(call assert_boolean,BL2_AT_EL3))
7697d173fc5SJiafei Pan$(eval $(call assert_boolean,BL2_IN_XIP_MEM))
770b90f207aSHadi Asyrafi$(eval $(call assert_boolean,BL2_INV_DCACHE))
771c97cba4eSSoby Mathew$(eval $(call assert_boolean,USE_SPINLOCK_CAS))
77273c99d4eSJuan Castillo
773c877b414SJeenu Viswambharan$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
774c877b414SJeenu Viswambharan$(eval $(call assert_numeric,ARM_ARCH_MINOR))
7759fc59639SAlexei Fedorov$(eval $(call assert_numeric,BRANCH_PROTECTION))
776c877b414SJeenu Viswambharan
777aacff749SJustin Chadwellifdef KEY_SIZE
778aacff749SJustin Chadwell        $(eval $(call assert_numeric,KEY_SIZE))
779aacff749SJustin Chadwellendif
780aacff749SJustin Chadwell
7811f461979SJustin Chadwellifeq ($(filter $(SANITIZE_UB), on off trap),)
7821f461979SJustin Chadwell        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
7831f461979SJustin Chadwellendif
7841f461979SJustin Chadwell
78573c99d4eSJuan Castillo################################################################################
78673c99d4eSJuan Castillo# Add definitions to the cpp preprocessor based on the current build options.
78773c99d4eSJuan Castillo# This is done after including the platform specific makefile to allow the
78873c99d4eSJuan Castillo# platform to overwrite the default options
78973c99d4eSJuan Castillo################################################################################
79073c99d4eSJuan Castillo
791c877b414SJeenu Viswambharan$(eval $(call add_define,ARM_ARCH_MAJOR))
792c877b414SJeenu Viswambharan$(eval $(call add_define,ARM_ARCH_MINOR))
793a9bec67dSSandrine Bailleux$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
7942fae4b1eSJeenu Viswambharan$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
7952fae4b1eSJeenu Viswambharan$(eval $(call add_define,CTX_INCLUDE_FPREGS))
7965283962eSAntonio Nino Diaz$(eval $(call add_define,CTX_INCLUDE_PAUTH_REGS))
797c8b55b8fSJeenu Viswambharan$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
7989dd94382SJustin Chadwell$(eval $(call add_define,CTX_INCLUDE_MTE_REGS))
7990319a977SDimitris Papastamos$(eval $(call add_define,ENABLE_AMU))
800cc8b5632SAntonio Nino Diaz$(eval $(call add_define,ENABLE_ASSERTIONS))
8019fc59639SAlexei Fedorov$(eval $(call add_define,ENABLE_BTI))
8025f835918SJeenu Viswambharan$(eval $(call add_define,ENABLE_MPAM_FOR_LOWER_ELS))
803b86048c4SAntonio Nino Diaz$(eval $(call add_define,ENABLE_PAUTH))
8043bd17c0fSSoby Mathew$(eval $(call add_define,ENABLE_PIE))
805a31d8983SYatharth Kochar$(eval $(call add_define,ENABLE_PMF))
806170fb93dSYatharth Kochar$(eval $(call add_define,ENABLE_PSCI_STAT))
807872be88aSdp-arm$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
808c1232c31SJeenu Viswambharan$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
8091a853370SDavid Cunado$(eval $(call add_define,ENABLE_SVE_FOR_NS))
8102fae4b1eSJeenu Viswambharan$(eval $(call add_define,ERROR_DEPRECATED))
8111a7c1cfeSJeenu Viswambharan$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
81274dce7faSJeenu Viswambharan$(eval $(call add_define,GICV2_G0_FOR_EL3))
81376454abfSJeenu Viswambharan$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
8143c251af3SJeenu Viswambharan$(eval $(call add_define,HW_ASSISTED_COHERENCY))
8152fae4b1eSJeenu Viswambharan$(eval $(call add_define,LOG_LEVEL))
8162fae4b1eSJeenu Viswambharan$(eval $(call add_define,NS_TIMER_SWITCH))
8172fae4b1eSJeenu Viswambharan$(eval $(call add_define,PL011_GENERIC_UART))
8182fae4b1eSJeenu Viswambharan$(eval $(call add_define,PLAT_${PLAT}))
8192fae4b1eSJeenu Viswambharan$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
8202fae4b1eSJeenu Viswambharan$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
82114c6016aSJeenu Viswambharan$(eval $(call add_define,RAS_EXTENSION))
8222fae4b1eSJeenu Viswambharan$(eval $(call add_define,RESET_TO_BL31))
8232fae4b1eSJeenu Viswambharan$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
824f8578e64SSamuel Holland$(eval $(call add_define,SEPARATE_NOBITS_REGION))
8251dcc28cfSDaniel Boulby$(eval $(call add_define,RECLAIM_INIT_CODE))
8262fae4b1eSJeenu Viswambharan$(eval $(call add_define,SPD_${SPD}))
8272fae4b1eSJeenu Viswambharan$(eval $(call add_define,SPIN_ON_BL1_EXIT))
8288855e52eSAntonio Nino Diaz$(eval $(call add_define,SPM_MM))
8292fae4b1eSJeenu Viswambharan$(eval $(call add_define,TRUSTED_BOARD_BOOT))
8302fae4b1eSJeenu Viswambharan$(eval $(call add_define,USE_COHERENT_MEM))
8310ca3913dSOlivier Deprez$(eval $(call add_define,USE_DEBUGFS))
8325accce5bSRoberto Vargas$(eval $(call add_define,USE_ROMLIB))
833bb41eb7aSMasahiro Yamada$(eval $(call add_define,USE_TBBR_DEFS))
834bcc3c49cSSoby Mathew$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
835b1d27b48SRoberto Vargas$(eval $(call add_define,BL2_AT_EL3))
8367d173fc5SJiafei Pan$(eval $(call add_define,BL2_IN_XIP_MEM))
837b90f207aSHadi Asyrafi$(eval $(call add_define,BL2_INV_DCACHE))
838c97cba4eSSoby Mathew$(eval $(call add_define,USE_SPINLOCK_CAS))
8392fae4b1eSJeenu Viswambharan
8401f461979SJustin Chadwellifeq (${SANITIZE_UB},trap)
8411f461979SJustin Chadwell        $(eval $(call add_define,MONITOR_TRAPS))
8421f461979SJustin Chadwellendif
8431f461979SJustin Chadwell
8444c117f6cSSandrine Bailleux# Define the EL3_PAYLOAD_BASE flag only if it is provided.
8454c117f6cSSandrine Bailleuxifdef EL3_PAYLOAD_BASE
8464c117f6cSSandrine Bailleux        $(eval $(call add_define,EL3_PAYLOAD_BASE))
847cf2c8a33SAntonio Nino Diazelse
84868450a6dSAntonio Nino Diaz        # Define the PRELOADED_BL33_BASE flag only if it is provided and
84968450a6dSAntonio Nino Diaz        # EL3_PAYLOAD_BASE is not defined, as it has priority.
85068450a6dSAntonio Nino Diaz        ifdef PRELOADED_BL33_BASE
85168450a6dSAntonio Nino Diaz                $(eval $(call add_define,PRELOADED_BL33_BASE))
8524c117f6cSSandrine Bailleux        endif
853cf2c8a33SAntonio Nino Diazendif
85473c99d4eSJuan Castillo
855209a60ccSSoby Mathew# Define the DYN_DISABLE_AUTH flag only if set.
856209a60ccSSoby Mathewifeq (${DYN_DISABLE_AUTH},1)
857209a60ccSSoby Mathew$(eval $(call add_define,DYN_DISABLE_AUTH))
858209a60ccSSoby Mathewendif
859209a60ccSSoby Mathew
860c2ad38ceSVarun Wadekarifneq ($(findstring armlink,$(notdir $(LD))),)
861c2ad38ceSVarun Wadekar$(eval $(call add_define,USE_ARM_LINK))
862c2ad38ceSVarun Wadekarendif
863c2ad38ceSVarun Wadekar
86473c99d4eSJuan Castillo################################################################################
86573c99d4eSJuan Castillo# Build targets
86673c99d4eSJuan Castillo################################################################################
86773c99d4eSJuan Castillo
868cfe83910SLouis Mayencourt.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip fwu_fip certtool dtbs memmap
86973c99d4eSJuan Castillo.SUFFIXES:
87073c99d4eSJuan Castillo
87173c99d4eSJuan Castilloall: msg_start
87273c99d4eSJuan Castillo
87373c99d4eSJuan Castillomsg_start:
87473c99d4eSJuan Castillo	@echo "Building ${PLAT}"
87573c99d4eSJuan Castillo
8767a24cba5SSoby Mathewifeq (${ERROR_DEPRECATED},0)
877d5dfdeb6SJulius Werner# Check if deprecated declarations and cpp warnings should be treated as error or not.
878c2ad38ceSVarun Wadekarifneq ($(findstring clang,$(notdir $(CC))),)
879c2ad38ceSVarun Wadekar    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
880c2ad38ceSVarun Wadekarelse
881bc1a03c7SDan Handley    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
8827a24cba5SSoby Mathewendif
883d5dfdeb6SJulius Werner# __ASSEMBLY__ is deprecated in favor of the compiler-builtin __ASSEMBLER__.
884d5dfdeb6SJulius WernerASFLAGS	+= -D__ASSEMBLY__
885402b3cf8SJulius Werner# AARCH32/AARCH64 macros are deprecated in favor of the compiler-builtin __aarch64__.
886402b3cf8SJulius Wernerifeq (${ARCH},aarch32)
887402b3cf8SJulius Werner        $(eval $(call add_define,AARCH32))
888402b3cf8SJulius Wernerelse
889402b3cf8SJulius Werner        $(eval $(call add_define,AARCH64))
890402b3cf8SJulius Wernerendif
891d5dfdeb6SJulius Wernerendif # !ERROR_DEPRECATED
8927a24cba5SSoby Mathew
8935accce5bSRoberto Vargas$(eval $(call MAKE_LIB_DIRS))
89461f72a34SRoberto Vargas$(eval $(call MAKE_LIB,c))
8955fee0287SRoberto Vargas
89673c99d4eSJuan Castillo# Expand build macros for the different images
89773c99d4eSJuan Castilloifeq (${NEED_BL1},yes)
89873c99d4eSJuan Castillo$(eval $(call MAKE_BL,1))
89973c99d4eSJuan Castilloendif
90073c99d4eSJuan Castillo
90173c99d4eSJuan Castilloifeq (${NEED_BL2},yes)
902c9b31ae8SRoberto Vargasifeq (${BL2_AT_EL3}, 0)
903c9b31ae8SRoberto VargasFIP_BL2_ARGS := tb-fw
904c9b31ae8SRoberto Vargasendif
905c9b31ae8SRoberto Vargas
90633950dd8SMasahiro Yamada$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
907c9b31ae8SRoberto Vargas	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
90873c99d4eSJuan Castilloendif
90973c99d4eSJuan Castillo
9104d045d0eSMasahiro Yamadaifeq (${NEED_SCP_BL2},yes)
91133950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
9124d045d0eSMasahiro Yamadaendif
9134d045d0eSMasahiro Yamada
91473c99d4eSJuan Castilloifeq (${NEED_BL31},yes)
91573c99d4eSJuan CastilloBL31_SOURCES += ${SPD_SOURCES}
91633950dd8SMasahiro Yamada$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
9178f0617efSJuan Castillo	$(eval $(call MAKE_BL,31,soc-fw)))
91873c99d4eSJuan Castilloendif
91973c99d4eSJuan Castillo
92070d1fc53SJuan Castillo# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
921c939d13aSMasahiro Yamada# build system will call TOOL_ADD_IMG to print a warning message and abort the
92270d1fc53SJuan Castillo# process. Note that the dependency on BL32 applies to the FIP only.
92373c99d4eSJuan Castilloifeq (${NEED_BL32},yes)
9249cd15239SMasahiro Yamada
9259cd15239SMasahiro YamadaBUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
9269cd15239SMasahiro Yamada
9279cd15239SMasahiro Yamada$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
92833950dd8SMasahiro Yamada	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
92973c99d4eSJuan Castilloendif
93073c99d4eSJuan Castillo
93173c99d4eSJuan Castillo# Add the BL33 image if required by the platform
93273c99d4eSJuan Castilloifeq (${NEED_BL33},yes)
93333950dd8SMasahiro Yamada$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
934db6071c9SJuan Castilloendif
935db6071c9SJuan Castillo
9369003fa0bSYatharth Kocharifeq (${NEED_BL2U},yes)
93733950dd8SMasahiro Yamada$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
9381dc0714fSMasahiro Yamada	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
9399003fa0bSYatharth Kocharendif
9409003fa0bSYatharth Kochar
94103b397a8SNishanth Menon# Expand build macros for the different images
94203b397a8SNishanth Menonifeq (${NEED_FDT},yes)
94303b397a8SNishanth Menon    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
94403b397a8SNishanth Menonendif
94503b397a8SNishanth Menon
94636eaaf37SIan Spraylocate-checkpatch:
94736eaaf37SIan Sprayifndef CHECKPATCH
94866079b04SEtienne Carriere	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
94936eaaf37SIan Sprayelse
95036eaaf37SIan Sprayifeq (,$(wildcard ${CHECKPATCH}))
95166079b04SEtienne Carriere	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
95236eaaf37SIan Sprayendif
95336eaaf37SIan Sprayendif
95436eaaf37SIan Spray
9554f6ad66aSAchin Guptaclean:
9564f6ad66aSAchin Gupta	@echo "  CLEAN"
957f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
9582f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
9596f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
9605accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
9614f6ad66aSAchin Gupta
962eaaeece2SJames Morrisseyrealclean distclean:
963eaaeece2SJames Morrissey	@echo "  REALCLEAN"
964f1477d4aSEvan Lloyd	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
965f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
9662f2cef46SJeenu Viswambharan	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
96726010da1SAntonio Nino Diaz	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
9686f971622SJuan Castillo	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
9695accce5bSRoberto Vargas	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
9704f6ad66aSAchin Gupta
97136eaaf37SIan Spraycheckcodebase:		locate-checkpatch
97236eaaf37SIan Spray	@echo "  CHECKING STYLE"
97336eaaf37SIan Spray	@if test -d .git ; then						\
9741ef35512SPaul Beesley		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
9751a41e8c1SDan Handley		while read GIT_FILE ;					\
9761a41e8c1SDan Handley		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
9771a41e8c1SDan Handley		done ;							\
97836eaaf37SIan Spray	else								\
9791a41e8c1SDan Handley		 find . -type f -not -iwholename "*.git*"		\
9801a41e8c1SDan Handley		 -not -iwholename "*build*"				\
9811a41e8c1SDan Handley		 -not -iwholename "*libfdt*"				\
98261f72a34SRoberto Vargas		 -not -iwholename "*libc*"				\
9831a41e8c1SDan Handley		 -not -iwholename "*docs*"				\
9841ef35512SPaul Beesley		 -not -iwholename "*.rst"				\
9851a41e8c1SDan Handley		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
98636eaaf37SIan Spray	fi
98736eaaf37SIan Spray
98836eaaf37SIan Spraycheckpatch:		locate-checkpatch
98936eaaf37SIan Spray	@echo "  CHECKING STYLE"
99002a76d5fSYann Gautier	@if test -n "${CHECKPATCH_OPTS}"; then				\
99102a76d5fSYann Gautier		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
99202a76d5fSYann Gautier	fi
99351d28937SAntonio Nino Diaz	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
99451d28937SAntonio Nino Diaz	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
99551d28937SAntonio Nino Diaz		printf "\n[*] Checking style of '$$commit'\n\n";	\
99651d28937SAntonio Nino Diaz		git log --format=email "$$commit~..$$commit"		\
99702a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
99802a76d5fSYann Gautier			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
99951d28937SAntonio Nino Diaz		git diff --format=email "$$commit~..$$commit"		\
100002a76d5fSYann Gautier			-- ${CHECK_PATHS} |				\
100102a76d5fSYann Gautier			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
100251d28937SAntonio Nino Diaz	done
100336eaaf37SIan Spray
100473c99d4eSJuan Castillocerttool: ${CRTTOOL}
100573c99d4eSJuan Castillo
10066f971622SJuan Castillo.PHONY: ${CRTTOOL}
10076f971622SJuan Castillo${CRTTOOL}:
1008bb41eb7aSMasahiro Yamada	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH}
1009f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
10106f971622SJuan Castillo	@echo "Built $@ successfully"
1011f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
10126f971622SJuan Castillo
10136f971622SJuan Castilloifneq (${GENERATE_COT},0)
101473c99d4eSJuan Castillocertificates: ${CRT_DEPS} ${CRTTOOL}
10156f971622SJuan Castillo	${Q}${CRTTOOL} ${CRT_ARGS}
1016f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
10176f971622SJuan Castillo	@echo "Built $@ successfully"
10186f971622SJuan Castillo	@echo "Certificates can be found in ${BUILD_PLAT}"
1019f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
102073c99d4eSJuan Castilloendif
102127713fb4SSoby Mathew
102273c99d4eSJuan Castillo${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1023819281eeSdp-arm	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1024819281eeSdp-arm	${Q}${FIPTOOL} info $@
1025f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
10262f2cef46SJeenu Viswambharan	@echo "Built $@ successfully"
1027f1477d4aSEvan Lloyd	@${ECHO_BLANK_LINE}
1028f58ad36fSHarry Liebel
10290191262dSYatharth Kocharifneq (${GENERATE_COT},0)
10300191262dSYatharth Kocharfwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
10310191262dSYatharth Kochar	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1032052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
10330191262dSYatharth Kochar	@echo "Built $@ successfully"
10340191262dSYatharth Kochar	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1035052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
10360191262dSYatharth Kocharendif
10370191262dSYatharth Kochar
10380191262dSYatharth Kochar${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1039819281eeSdp-arm	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1040819281eeSdp-arm	${Q}${FIPTOOL} info $@
1041052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
10420191262dSYatharth Kochar	@echo "Built $@ successfully"
1043052ab529SEvan Lloyd	@${ECHO_BLANK_LINE}
10440191262dSYatharth Kochar
104573c99d4eSJuan Castillofiptool: ${FIPTOOL}
104673c99d4eSJuan Castillofip: ${BUILD_PLAT}/${FIP_NAME}
10470191262dSYatharth Kocharfwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
104873c99d4eSJuan Castillo
104973c99d4eSJuan Castillo.PHONY: ${FIPTOOL}
105073c99d4eSJuan Castillo${FIPTOOL}:
1051819281eeSdp-arm	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
1052f58ad36fSHarry Liebel
105326010da1SAntonio Nino Diazsptool: ${SPTOOL}
105426010da1SAntonio Nino Diaz.PHONY: ${SPTOOL}
105526010da1SAntonio Nino Diaz${SPTOOL}:
105626010da1SAntonio Nino Diaz	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${SPTOOLPATH}
105726010da1SAntonio Nino Diaz
10585accce5bSRoberto Vargas.PHONY: libraries
10595accce5bSRoberto Vargasromlib.bin: libraries
1060bbb24f61SJohn 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
10615accce5bSRoberto Vargas
1062cfe83910SLouis Mayencourt# Call print_memory_map tool
1063cfe83910SLouis Mayencourtmemmap: all
1064cfe83910SLouis Mayencourt	${Q}${PYTHON} $(PRINT_MEMORY_MAP) $(BUILD_PLAT)
1065cfe83910SLouis Mayencourt
106635fab8c9SJoakim Bechcscope:
106735fab8c9SJoakim Bech	@echo "  CSCOPE"
106835fab8c9SJoakim Bech	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
106935fab8c9SJoakim Bech	${Q}cscope -b -q -k
107035fab8c9SJoakim Bech
107172ee3314SRyan Harkinhelp:
10727c23126cSJohn Tsichritzis	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
107372ee3314SRyan Harkin	@echo ""
107472ee3314SRyan Harkin	@echo "PLAT is used to specify which platform you wish to build."
107508c7ed0fSSandrine Bailleux	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
107672ee3314SRyan Harkin	@echo ""
10777c23126cSJohn Tsichritzis	@echo "platform = ${PLATFORM_LIST}"
10787c23126cSJohn Tsichritzis	@echo ""
10791b578596SSandrine Bailleux	@echo "Please refer to the User Guide for a list of all supported options."
10801b578596SSandrine Bailleux	@echo "Note that the build system doesn't track dependencies for build "
10811b578596SSandrine Bailleux	@echo "options. Therefore, if any of the build options are changed "
10821b578596SSandrine Bailleux	@echo "from a previous build, a clean build must be performed."
10831b578596SSandrine Bailleux	@echo ""
108472ee3314SRyan Harkin	@echo "Supported Targets:"
10851b578596SSandrine Bailleux	@echo "  all            Build all individual bootloader binaries"
108636eaaf37SIan Spray	@echo "  bl1            Build the BL1 binary"
10878aa559c0SJeenu Viswambharan	@echo "  bl2            Build the BL2 binary"
10889003fa0bSYatharth Kochar	@echo "  bl2u           Build the BL2U binary"
1089d178637dSJuan Castillo	@echo "  bl31           Build the BL31 binary"
10909d29c227SSoby Mathew	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
10919d29c227SSoby Mathew	@echo "                 this builds secure payload specified by AARCH32_SP"
109273c99d4eSJuan Castillo	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
10931b578596SSandrine Bailleux	@echo "  fip            Build the Firmware Image Package (FIP)"
10940191262dSYatharth Kochar	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
109536eaaf37SIan Spray	@echo "  checkcodebase  Check the coding style of the entire source tree"
109636eaaf37SIan Spray	@echo "  checkpatch     Check the coding style on changes in the current"
109736eaaf37SIan Spray	@echo "                 branch against BASE_COMMIT (default origin/master)"
109872ee3314SRyan Harkin	@echo "  clean          Clean the build for the selected platform"
109935fab8c9SJoakim Bech	@echo "  cscope         Generate cscope index"
110072ee3314SRyan Harkin	@echo "  distclean      Remove all build artifacts for all platforms"
11016f971622SJuan Castillo	@echo "  certtool       Build the Certificate generation tool"
1102f58ad36fSHarry Liebel	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
110326010da1SAntonio Nino Diaz	@echo "  sptool         Build the Secure Partition Package creation tool"
110438c14d88SSoby Mathew	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1105cfe83910SLouis Mayencourt	@echo "  memmap         Print the memory map of the built binaries"
110672ee3314SRyan Harkin	@echo ""
11071b578596SSandrine Bailleux	@echo "Note: most build targets require PLAT to be set to a specific platform."
110872ee3314SRyan Harkin	@echo ""
110972ee3314SRyan Harkin	@echo "example: build all targets for the FVP platform:"
111072ee3314SRyan Harkin	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1111