xref: /rk3399_ARM-atf/Makefile (revision cf953bca5c01245fd5473c5785a0dc307c55e18d)
1#
2# Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7#
8# Trusted Firmware Version
9#
10VERSION_MAJOR			:= 2
11VERSION_MINOR			:= 9
12VERSION_PATCH			:= 0
13VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
14
15# Default goal is build all images
16.DEFAULT_GOAL			:= all
17
18# Avoid any implicit propagation of command line variable definitions to
19# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
20# usage. Other command line options like "-s" are still propagated as usual.
21MAKEOVERRIDES =
22
23MAKE_HELPERS_DIRECTORY := make_helpers/
24include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
25include ${MAKE_HELPERS_DIRECTORY}build_env.mk
26
27################################################################################
28# Default values for build configurations, and their dependencies
29################################################################################
30
31include ${MAKE_HELPERS_DIRECTORY}defaults.mk
32
33# Assertions enabled for DEBUG builds by default
34ENABLE_ASSERTIONS		:= ${DEBUG}
35ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
36PLAT				:= ${DEFAULT_PLAT}
37
38################################################################################
39# Checkpatch script options
40################################################################################
41
42CHECKCODE_ARGS		:=	--no-patch
43# Do not check the coding style on imported library files or documentation files
44INC_ARM_DIRS_TO_CHECK	:=	$(sort $(filter-out                     \
45					include/drivers/arm/cryptocell,	\
46					$(wildcard include/drivers/arm/*)))
47INC_ARM_DIRS_TO_CHECK	+=	include/drivers/arm/cryptocell/*.h
48INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
49					include/drivers/arm,		\
50					$(wildcard include/drivers/*)))
51INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
52					include/lib/libfdt		\
53					include/lib/libc,		\
54					$(wildcard include/lib/*)))
55INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
56					include/lib			\
57					include/drivers,		\
58					$(wildcard include/*)))
59LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
60					lib/compiler-rt			\
61					lib/libfdt%			\
62					lib/libc,			\
63					lib/zlib			\
64					$(wildcard lib/*)))
65ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
66					lib				\
67					include				\
68					docs				\
69					%.rst,				\
70					$(wildcard *)))
71CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
72				${INC_DIRS_TO_CHECK}			\
73				${INC_LIB_DIRS_TO_CHECK}		\
74				${LIB_DIRS_TO_CHECK}			\
75				${INC_DRV_DIRS_TO_CHECK}		\
76				${INC_ARM_DIRS_TO_CHECK}
77
78################################################################################
79# Process build options
80################################################################################
81
82# Verbose flag
83ifeq (${V},0)
84	Q:=@
85	ECHO:=@echo
86	CHECKCODE_ARGS	+=	--no-summary --terse
87else
88	Q:=
89	ECHO:=$(ECHO_QUIET)
90endif
91
92ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
93	Q:=@
94	ECHO:=$(ECHO_QUIET)
95endif
96
97export Q ECHO
98
99################################################################################
100# Toolchain
101################################################################################
102
103HOSTCC			:=	gcc
104export HOSTCC
105
106CC			:=	${CROSS_COMPILE}gcc
107CPP			:=	${CROSS_COMPILE}cpp
108AS			:=	${CROSS_COMPILE}gcc
109AR			:=	${CROSS_COMPILE}ar
110LINKER			:=	${CROSS_COMPILE}ld
111OC			:=	${CROSS_COMPILE}objcopy
112OD			:=	${CROSS_COMPILE}objdump
113NM			:=	${CROSS_COMPILE}nm
114PP			:=	${CROSS_COMPILE}gcc -E
115DTC			:=	dtc
116
117# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
118ifneq ($(strip $(wildcard ${LD}.bfd) \
119	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
120LINKER			:=	${LINKER}.bfd
121endif
122
123################################################################################
124# Auxiliary tools (fiptool, cert_create, etc)
125################################################################################
126
127# Variables for use with Certificate Generation Tool
128CRTTOOLPATH		?=	tools/cert_create
129CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
130
131# Variables for use with Firmware Encryption Tool
132ENCTOOLPATH		?=	tools/encrypt_fw
133ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
134
135# Variables for use with Firmware Image Package
136FIPTOOLPATH		?=	tools/fiptool
137FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
138
139# Variables for use with sptool
140SPTOOLPATH		?=	tools/sptool
141SPTOOL			?=	${SPTOOLPATH}/sptool.py
142SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
143SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
144
145# Variables for use with ROMLIB
146ROMLIBPATH		?=	lib/romlib
147
148# Variable for use with Python
149PYTHON			?=	python3
150
151# Variables for use with documentation build using Sphinx tool
152DOCS_PATH		?=	docs
153
154################################################################################
155# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
156################################################################################
157ifeq (${ARM_ARCH_MAJOR},7)
158	target32-directive	= 	-target arm-none-eabi
159# Will set march-directive from platform configuration
160else
161	target32-directive	= 	-target armv8a-none-eabi
162endif #(ARM_ARCH_MAJOR)
163
164################################################################################
165# Get Architecture Feature Modifiers
166################################################################################
167arch-features		=	${ARM_ARCH_FEATURE}
168
169# Set the compiler's architecture feature modifiers
170ifneq ($(arch-features), none)
171	# Strip "none+" from arch-features
172	arch-features	:=	$(subst none+,,$(arch-features))
173	march-directive	:=	$(march-directive)+$(arch-features)
174# Print features
175        $(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
176endif #(arch-features)
177
178ifneq ($(findstring clang,$(notdir $(CC))),)
179	ifneq ($(findstring armclang,$(notdir $(CC))),)
180		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
181		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
182		LD			:=	$(LINKER)
183	else
184		TF_CFLAGS_aarch32	=	$(target32-directive)
185		TF_CFLAGS_aarch64	:=	-target aarch64-elf
186		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
187
188		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
189		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
190		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
191	endif
192
193	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
194	PP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
195	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
196else ifneq ($(findstring gcc,$(notdir $(CC))),)
197	ifeq ($(ENABLE_LTO),1)
198		# Enable LTO only for aarch64
199		ifeq (${ARCH},aarch64)
200			LTO_CFLAGS	=	-flto
201			# Use gcc as a wrapper for the ld, recommended for LTO
202			LINKER		:=	${CROSS_COMPILE}gcc
203		endif
204	endif
205	LD			=	$(LINKER)
206else
207	LD			=	$(LINKER)
208endif #(clang)
209
210# Process Debug flag
211$(eval $(call add_define,DEBUG))
212ifneq (${DEBUG}, 0)
213	BUILD_TYPE	:=	debug
214	TF_CFLAGS	+=	-g -gdwarf-4
215	ASFLAGS		+=	-g -Wa,-gdwarf-4
216
217	# Use LOG_LEVEL_INFO by default for debug builds
218	LOG_LEVEL	:=	40
219else
220	BUILD_TYPE	:=	release
221	# Use LOG_LEVEL_NOTICE by default for release builds
222	LOG_LEVEL	:=	20
223endif #(Debug)
224
225# Default build string (git branch and commit)
226ifeq (${BUILD_STRING},)
227	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
228endif
229VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
230
231ifeq (${AARCH32_INSTRUCTION_SET},A32)
232	TF_CFLAGS_aarch32	+=	-marm
233else ifeq (${AARCH32_INSTRUCTION_SET},T32)
234	TF_CFLAGS_aarch32	+=	-mthumb
235else
236        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
237endif #(AARCH32_INSTRUCTION_SET)
238
239TF_CFLAGS_aarch32	+=	-mno-unaligned-access
240TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
241
242ASFLAGS		+=	$(march-directive)
243
244##############################################################################
245# WARNINGS Configuration
246###############################################################################
247# General warnings
248WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
249				-Wdisabled-optimization -Wvla -Wshadow	\
250				-Wredundant-decls
251# stricter warnings
252WARNINGS		+=	-Wextra -Wno-trigraphs
253# too verbose for generic build
254WARNINGS		+=	-Wno-missing-field-initializers \
255				-Wno-type-limits -Wno-sign-compare \
256# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
257WARNINGS		+=	-Wno-unused-parameter
258
259# Additional warnings
260# Level 1 - infrequent warnings we should have none of
261# full -Wextra
262WARNING1 += -Wsign-compare
263WARNING1 += -Wtype-limits
264WARNING1 += -Wmissing-field-initializers
265
266# Level 2 - problematic warnings that we want
267# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
268# TODO: disable just for them and move into default build
269WARNING2 += -Wold-style-definition
270WARNING2 += -Wmissing-prototypes
271WARNING2 += -Wmissing-format-attribute
272# TF-A aims to comply with this eventually. Effort too large at present
273WARNING2 += -Wundef
274# currently very involved and many platforms set this off
275WARNING2 += -Wunused-const-variable=2
276
277# Level 3 - very pedantic, frequently ignored
278WARNING3 := -Wbad-function-cast
279WARNING3 += -Waggregate-return
280WARNING3 += -Wnested-externs
281WARNING3 += -Wcast-align
282WARNING3 += -Wcast-qual
283WARNING3 += -Wconversion
284WARNING3 += -Wpacked
285WARNING3 += -Wpointer-arith
286WARNING3 += -Wswitch-default
287
288# Setting W is quite verbose and most warnings will be pre-existing issues
289# outside of the contributor's control. Don't fail the build on them so warnings
290# can be seen and hopefully addressed
291ifdef W
292	ifneq (${W},0)
293		E	 ?= 0
294	endif
295endif
296
297ifeq (${W},1)
298	WARNINGS += $(WARNING1)
299else ifeq (${W},2)
300	WARNINGS += $(WARNING1) $(WARNING2)
301else ifeq (${W},3)
302	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
303endif #(W)
304
305# Compiler specific warnings
306ifeq ($(findstring clang,$(notdir $(CC))),)
307# not using clang
308WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
309				-Wpacked-bitfield-compat -Wshift-overflow=2 \
310				-Wlogical-op
311
312# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
313TF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
314
315else
316# using clang
317WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
318				-Wlogical-op-parentheses
319endif #(Clang Warning)
320
321ifneq (${E},0)
322	ERRORS := -Werror
323endif #(E)
324
325################################################################################
326# Compiler and Linker Directives
327################################################################################
328CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
329				$(ERRORS) $(WARNINGS)
330ASFLAGS			+=	$(CPPFLAGS)                 			\
331				-ffreestanding -Wa,--fatal-warnings
332TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
333				-ffunction-sections -fdata-sections		\
334				-ffreestanding -fno-builtin -fno-common		\
335				-Os -std=gnu99
336
337ifeq (${SANITIZE_UB},on)
338	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
339endif #(${SANITIZE_UB},on)
340
341ifeq (${SANITIZE_UB},trap)
342	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
343				-fsanitize-undefined-trap-on-error
344endif #(${SANITIZE_UB},trap)
345
346GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
347
348TF_LDFLAGS		+=	-z noexecstack
349
350# LD = armlink
351ifneq ($(findstring armlink,$(notdir $(LD))),)
352	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
353	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
354	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
355
356# LD = gcc (used when GCC LTO is enabled)
357else ifneq ($(findstring gcc,$(notdir $(LD))),)
358	# Pass ld options with Wl or Xlinker switches
359	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
360	TF_LDFLAGS		+=	-Wl,--gc-sections
361
362	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
363	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
364
365	ifeq ($(ENABLE_LTO),1)
366		ifeq (${ARCH},aarch64)
367			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
368		endif
369	endif #(ENABLE_LTO)
370
371# GCC automatically adds fix-cortex-a53-843419 flag when used to link
372# which breaks some builds, so disable if errata fix is not explicitly enabled
373	ifeq (${ARCH},aarch64)
374		ifneq (${ERRATA_A53_843419},1)
375			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
376		endif
377	endif
378	TF_LDFLAGS		+= 	-nostdlib
379	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
380
381# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
382else
383# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
384# are not loaded by a elf loader.
385	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
386	TF_LDFLAGS		+=	-O1
387	TF_LDFLAGS		+=	--gc-sections
388
389	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
390	TF_LDFLAGS		+=	-z max-page-size=4096
391
392# ld.lld doesn't recognize the errata flags,
393# therefore don't add those in that case.
394# ld.lld reports section type mismatch warnings,
395# therefore don't add --fatal-warnings to it.
396	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
397		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
398	endif
399
400endif #(LD = armlink)
401
402DTC_FLAGS		+=	-I dts -O dtb
403DTC_CPPFLAGS		+=	-P -nostdinc -Iinclude -Ifdts -undef \
404				-x assembler-with-cpp $(DEFINES)
405
406################################################################################
407# Setup ARCH_MAJOR/MINOR before parsing arch_features.
408################################################################################
409ifeq (${ENABLE_RME},1)
410	ARM_ARCH_MAJOR := 8
411	ARM_ARCH_MINOR := 6
412endif
413
414################################################################################
415# Common sources and include directories
416################################################################################
417include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
418include lib/compiler-rt/compiler-rt.mk
419
420BL_COMMON_SOURCES	+=	common/bl_common.c			\
421				common/tf_log.c				\
422				common/${ARCH}/debug.S			\
423				drivers/console/multi_console.c		\
424				lib/${ARCH}/cache_helpers.S		\
425				lib/${ARCH}/misc_helpers.S		\
426				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
427				plat/common/plat_bl_common.c		\
428				plat/common/plat_log_common.c		\
429				plat/common/${ARCH}/plat_common.c	\
430				plat/common/${ARCH}/platform_helpers.S	\
431				${COMPILER_RT_SRCS}
432
433ifeq ($(notdir $(CC)),armclang)
434	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
435endif
436
437ifeq (${SANITIZE_UB},on)
438	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
439endif
440
441INCLUDES		+=	-Iinclude				\
442				-Iinclude/arch/${ARCH}			\
443				-Iinclude/lib/cpus/${ARCH}		\
444				-Iinclude/lib/el3_runtime/${ARCH}	\
445				${PLAT_INCLUDES}			\
446				${SPD_INCLUDES}
447
448include common/backtrace/backtrace.mk
449
450################################################################################
451# Generic definitions
452################################################################################
453include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
454
455ifeq (${BUILD_BASE},)
456     BUILD_BASE		:=	./build
457endif
458BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
459
460SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
461
462# Platforms providing their own TBB makefile may override this value
463INCLUDE_TBBR_MK		:=	1
464
465################################################################################
466# Include SPD Makefile if one has been specified
467################################################################################
468
469ifneq (${SPD},none)
470	ifeq (${ARCH},aarch32)
471                $(error "Error: SPD is incompatible with AArch32.")
472	endif
473
474	ifdef EL3_PAYLOAD_BASE
475                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
476                $(warning "The SPD and its BL32 companion will be present but \
477                ignored.")
478	endif
479
480	ifeq (${SPD},spmd)
481	# SPMD is located in std_svc directory
482		SPD_DIR := std_svc
483
484		ifeq ($(SPMD_SPM_AT_SEL2),1)
485			CTX_INCLUDE_EL2_REGS := 1
486			ifeq ($(SPMC_AT_EL3),1)
487                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
488			endif
489		endif
490
491		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
492			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
493		endif
494
495		ifeq ($(TS_SP_FW_CONFIG),1)
496		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
497		endif
498
499		ifneq ($(ARM_BL2_SP_LIST_DTS),)
500		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
501		endif
502
503		ifneq ($(SP_LAYOUT_FILE),)
504		BL2_ENABLE_SP_LOAD := 1
505		endif
506	else
507		# All other SPDs in spd directory
508		SPD_DIR := spd
509	endif #(SPD)
510
511	# We expect to locate an spd.mk under the specified SPD directory
512	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
513
514	ifeq (${SPD_MAKE},)
515                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
516	endif
517        $(info Including ${SPD_MAKE})
518        include ${SPD_MAKE}
519
520	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
521	# Makefile would set NEED_BL32 to "yes". In this case, the build system
522	# supports two mutually exclusive options:
523	# * BL32 is built from source: then BL32_SOURCES must contain the list
524	#   of source files to build BL32
525	# * BL32 is a prebuilt binary: then BL32 must point to the image file
526	#   that will be included in the FIP
527	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
528	# over the sources.
529endif #(SPD=none)
530
531ifeq (${ENABLE_SPMD_LP}, 1)
532ifneq (${SPD},spmd)
533        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
534endif
535ifeq ($(SPMC_AT_EL3),1)
536        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
537endif
538endif
539
540################################################################################
541# Process BRANCH_PROTECTION value and set
542# Pointer Authentication and Branch Target Identification flags
543################################################################################
544ifeq (${BRANCH_PROTECTION},0)
545	# Default value turns off all types of branch protection
546	BP_OPTION := none
547else ifneq (${ARCH},aarch64)
548        $(error BRANCH_PROTECTION requires AArch64)
549else ifeq (${BRANCH_PROTECTION},1)
550	# Enables all types of branch protection features
551	BP_OPTION := standard
552	ENABLE_BTI := 1
553	ENABLE_PAUTH := 1
554else ifeq (${BRANCH_PROTECTION},2)
555	# Return address signing to its standard level
556	BP_OPTION := pac-ret
557	ENABLE_PAUTH := 1
558else ifeq (${BRANCH_PROTECTION},3)
559	# Extend the signing to include leaf functions
560	BP_OPTION := pac-ret+leaf
561	ENABLE_PAUTH := 1
562else ifeq (${BRANCH_PROTECTION},4)
563	# Turn on branch target identification mechanism
564	BP_OPTION := bti
565	ENABLE_BTI := 1
566else
567        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
568endif #(BRANCH_PROTECTION)
569
570ifeq ($(ENABLE_PAUTH),1)
571	CTX_INCLUDE_PAUTH_REGS := 1
572endif
573ifneq (${BP_OPTION},none)
574	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
575endif #(BP_OPTION)
576
577# Pointer Authentication sources
578ifeq (${ENABLE_PAUTH}, 1)
579# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
580# Pauth support. As it's not secure, it must be reimplemented for real platforms
581	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
582endif
583
584################################################################################
585# Include the platform specific Makefile after the SPD Makefile (the platform
586# makefile may use all previous definitions in this file)
587################################################################################
588include ${PLAT_MAKEFILE_FULL}
589
590################################################################################
591# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
592# platform.
593################################################################################
594include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
595
596####################################################
597# Enable required options for Memory Stack Tagging.
598####################################################
599
600# Currently, these options are enabled only for clang and armclang compiler.
601ifeq (${SUPPORT_STACK_MEMTAG},yes)
602    ifdef mem_tag_arch_support
603        # Check for armclang and clang compilers
604        ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
605        # Add "memtag" architecture feature modifier if not specified
606            ifeq ( ,$(findstring memtag,$(arch-features)))
607                arch-features	:=	$(arch-features)+memtag
608            endif	# memtag
609            ifeq ($(notdir $(CC)),armclang)
610                TF_CFLAGS	+=	-mmemtag-stack
611            else ifeq ($(notdir $(CC)),clang)
612                TF_CFLAGS	+=	-fsanitize=memtag
613            endif	# armclang
614        endif
615    else
616        $(error "Error: stack memory tagging is not supported for  \
617        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
618	endif #(mem_tag_arch_support)
619endif #(SUPPORT_STACK_MEMTAG)
620
621################################################################################
622# RME dependent flags configuration, Enable optional features for RME.
623################################################################################
624# FEAT_RME
625ifeq (${ENABLE_RME},1)
626	# RME doesn't support PIE
627	ifneq (${ENABLE_PIE},0)
628                $(error ENABLE_RME does not support PIE)
629	endif
630
631	# RME doesn't support BRBE
632	ifneq (${ENABLE_BRBE_FOR_NS},0)
633                $(error ENABLE_RME does not support BRBE.)
634	endif
635
636	# RME requires AARCH64
637	ifneq (${ARCH},aarch64)
638                $(error ENABLE_RME requires AArch64)
639	endif
640
641	# RME requires el2 context to be saved for now.
642	CTX_INCLUDE_EL2_REGS := 1
643	CTX_INCLUDE_AARCH32_REGS := 0
644	CTX_INCLUDE_PAUTH_REGS := 1
645
646	# RME enables CSV2_2 extension by default.
647	ENABLE_FEAT_CSV2_2 = 1
648endif #(FEAT_RME)
649
650################################################################################
651# Generic definitions
652################################################################################
653include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
654
655ifeq (${BUILD_BASE},)
656     BUILD_BASE		:=	./build
657endif
658BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
659
660SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
661
662# Platforms providing their own TBB makefile may override this value
663INCLUDE_TBBR_MK		:=	1
664
665################################################################################
666# Include SPD Makefile if one has been specified
667################################################################################
668
669ifneq (${SPD},none)
670	ifeq (${ARCH},aarch32)
671                $(error "Error: SPD is incompatible with AArch32.")
672	endif
673
674	ifdef EL3_PAYLOAD_BASE
675                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
676                $(warning "The SPD and its BL32 companion will be present but \
677                ignored.")
678	endif
679
680	ifeq (${SPD},spmd)
681	# SPMD is located in std_svc directory
682		SPD_DIR := std_svc
683
684		ifeq ($(SPMD_SPM_AT_SEL2),1)
685			CTX_INCLUDE_EL2_REGS := 1
686			ifeq ($(SPMC_AT_EL3),1)
687                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
688			endif
689		endif
690
691		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
692			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
693		endif
694
695		ifeq ($(TS_SP_FW_CONFIG),1)
696		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
697		endif
698
699		ifneq ($(ARM_BL2_SP_LIST_DTS),)
700		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
701		endif
702
703		ifneq ($(SP_LAYOUT_FILE),)
704		BL2_ENABLE_SP_LOAD := 1
705		endif
706
707		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
708			ifneq ($(SPMC_AT_EL3),1)
709			$(error SEL0 SP cannot be enabled without SPMC at EL3)
710			endif
711		endif
712	else
713		# All other SPDs in spd directory
714		SPD_DIR := spd
715	endif #(SPD)
716
717	# We expect to locate an spd.mk under the specified SPD directory
718	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
719
720	ifeq (${SPD_MAKE},)
721                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
722	endif
723        $(info Including ${SPD_MAKE})
724        include ${SPD_MAKE}
725
726	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
727	# Makefile would set NEED_BL32 to "yes". In this case, the build system
728	# supports two mutually exclusive options:
729	# * BL32 is built from source: then BL32_SOURCES must contain the list
730	#   of source files to build BL32
731	# * BL32 is a prebuilt binary: then BL32 must point to the image file
732	#   that will be included in the FIP
733	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
734	# over the sources.
735endif #(SPD=none)
736
737ifeq (${ENABLE_SPMD_LP}, 1)
738ifneq (${SPD},spmd)
739        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
740endif
741ifeq ($(SPMC_AT_EL3),1)
742        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
743endif
744endif
745
746ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
747	ifeq (${SPD},none)
748		ifeq (${ENABLE_RME},0)
749                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
750                        or RME is enabled)
751		endif
752	endif
753endif
754
755################################################################################
756# Include rmmd Makefile if RME is enabled
757################################################################################
758ifneq (${ENABLE_RME},0)
759	ifneq (${ARCH},aarch64)
760                $(error ENABLE_RME requires AArch64)
761	endif
762	ifeq ($(SPMC_AT_EL3),1)
763                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
764	endif
765
766	ifneq (${SPD}, none)
767		ifneq (${SPD}, spmd)
768                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
769		endif
770	endif
771include services/std_svc/rmmd/rmmd.mk
772$(warning "RME is an experimental feature")
773endif
774
775ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
776	ifeq (${SPD},none)
777		ifeq (${ENABLE_RME},0)
778                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
779                        or RME is enabled)
780		endif
781	endif
782endif
783
784################################################################################
785# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
786# up with appropriate march values for compiler.
787################################################################################
788include ${MAKE_HELPERS_DIRECTORY}march.mk
789
790TF_CFLAGS   +=	$(march-directive)
791
792# This internal flag is common option which is set to 1 for scenarios
793# when the BL2 is running in EL3 level. This occurs in two scenarios -
794# 4 world system running BL2 at EL3 and two world system without BL1 running
795# BL2 in EL3
796
797ifeq (${RESET_TO_BL2},1)
798	BL2_RUNS_AT_EL3	:=	1
799	ifeq (${ENABLE_RME},1)
800                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
801                supported at the moment.)
802	endif
803else ifeq (${ENABLE_RME},1)
804	BL2_RUNS_AT_EL3	:=	1
805else
806	BL2_RUNS_AT_EL3	:=	0
807endif
808
809$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
810
811ifeq (${ARM_ARCH_MAJOR},7)
812include make_helpers/armv7-a-cpus.mk
813endif
814
815PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
816ifneq ($(PIE_FOUND),)
817	TF_CFLAGS	+=	-fno-PIE
818ifneq ($(findstring gcc,$(notdir $(LD))),)
819	TF_LDFLAGS	+=	-no-pie
820endif
821endif #(PIE_FOUND)
822
823ifneq ($(findstring gcc,$(notdir $(LD))),)
824	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
825else
826	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
827endif
828
829ifeq ($(ENABLE_PIE),1)
830	ifeq ($(RESET_TO_BL2),1)
831		ifneq ($(BL2_IN_XIP_MEM),1)
832			BL2_CPPFLAGS	+=	-fpie
833			BL2_CFLAGS	+=	-fpie
834			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
835		endif #(BL2_IN_XIP_MEM)
836	endif #(RESET_TO_BL2)
837	BL31_CPPFLAGS	+=	-fpie
838	BL31_CFLAGS 	+=	-fpie
839	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
840
841	BL32_CPPFLAGS	+=	-fpie
842	BL32_CFLAGS	+=	-fpie
843	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
844endif #(ENABLE_PIE)
845
846BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
847BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
848BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
849
850BL1_CPPFLAGS += -DIMAGE_AT_EL3
851ifeq ($(RESET_TO_BL2),1)
852	BL2_CPPFLAGS += -DIMAGE_AT_EL3
853else
854	BL2_CPPFLAGS += -DIMAGE_AT_EL1
855endif #(RESET_TO_BL2)
856
857ifeq (${ARCH},aarch64)
858	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
859	BL31_CPPFLAGS += -DIMAGE_AT_EL3
860	BL32_CPPFLAGS += -DIMAGE_AT_EL1
861else
862	BL32_CPPFLAGS += -DIMAGE_AT_EL3
863endif
864
865# Include the CPU specific operations makefile, which provides default
866# values for all CPU errata workarounds and CPU specific optimisations.
867# This can be overridden by the platform.
868include lib/cpus/cpu-ops.mk
869
870################################################################################
871# Build `AARCH32_SP` as BL32 image for AArch32
872################################################################################
873ifeq (${ARCH},aarch32)
874        NEED_BL32 := yes
875
876        ifneq (${AARCH32_SP},none)
877        # We expect to locate an sp.mk under the specified AARCH32_SP directory
878		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
879
880                ifeq (${AARCH32_SP_MAKE},)
881                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
882                endif
883                $(info Including ${AARCH32_SP_MAKE})
884                include ${AARCH32_SP_MAKE}
885        endif
886endif #(ARCH=aarch32)
887
888################################################################################
889# Include libc if not overridden
890################################################################################
891ifeq (${OVERRIDE_LIBC},0)
892include lib/libc/libc.mk
893endif
894
895################################################################################
896# Check incompatible options and dependencies
897################################################################################
898
899# USE_DEBUGFS experimental feature recommended only in debug builds
900ifeq (${USE_DEBUGFS},1)
901        ifeq (${DEBUG},1)
902                $(warning DEBUGFS experimental feature is enabled.)
903        else
904                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
905        endif
906endif #(USE_DEBUGFS)
907
908# USE_SPINLOCK_CAS requires AArch64 build
909ifeq (${USE_SPINLOCK_CAS},1)
910        ifneq (${ARCH},aarch64)
911               $(error USE_SPINLOCK_CAS requires AArch64)
912        endif
913endif #(USE_SPINLOCK_CAS)
914
915# The cert_create tool cannot generate certificates individually, so we use the
916# target 'certificates' to create them all
917ifneq (${GENERATE_COT},0)
918        FIP_DEPS += certificates
919        FWU_FIP_DEPS += fwu_certificates
920endif
921
922ifneq (${DECRYPTION_SUPPORT},none)
923	ENC_ARGS += -f ${FW_ENC_STATUS}
924	ENC_ARGS += -k ${ENC_KEY}
925	ENC_ARGS += -n ${ENC_NONCE}
926	FIP_DEPS += enctool
927	FWU_FIP_DEPS += enctool
928endif #(DECRYPTION_SUPPORT)
929
930ifdef EL3_PAYLOAD_BASE
931	ifdef PRELOADED_BL33_BASE
932                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
933		incompatible build options. EL3_PAYLOAD_BASE has priority.")
934	endif
935	ifneq (${GENERATE_COT},0)
936                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
937                build options.")
938	endif
939	ifneq (${TRUSTED_BOARD_BOOT},0)
940                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
941                incompatible \ build options.")
942	endif
943endif #(EL3_PAYLOAD_BASE)
944
945ifeq (${NEED_BL33},yes)
946	ifdef EL3_PAYLOAD_BASE
947                $(warning "BL33 image is not needed when option \
948                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
949	endif
950	ifdef PRELOADED_BL33_BASE
951                $(warning "BL33 image is not needed when option \
952                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
953	endif
954endif #(NEED_BL33)
955
956# When building for systems with hardware-assisted coherency, there's no need to
957# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
958ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
959        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
960endif
961
962#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
963ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
964        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
965endif
966
967# RAS_EXTENSION is deprecated, provide alternate build options
968ifeq ($(RAS_EXTENSION),1)
969        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
970        and RAS_FFH_SUPPORT instead")
971endif
972
973# RAS firmware first handling requires that EAs are handled in EL3 first
974ifeq ($(RAS_FFH_SUPPORT),1)
975	ifneq ($(ENABLE_FEAT_RAS),1)
976                $(error For RAS_FFH_SUPPORT, ENABLE_FEAT_RAS must also be 1)
977	endif
978	ifneq ($(HANDLE_EA_EL3_FIRST_NS),1)
979                $(error For RAS_FFH_SUPPORT, HANDLE_EA_EL3_FIRST_NS must also be 1)
980	endif
981endif #(RAS_FFH_SUPPORT)
982
983# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
984ifeq ($(FAULT_INJECTION_SUPPORT),1)
985	ifeq ($(ENABLE_FEAT_RAS),0)
986                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
987	endif
988endif #(FAULT_INJECTION_SUPPORT)
989
990# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
991ifeq ($(DYN_DISABLE_AUTH), 1)
992	ifeq (${TRUSTED_BOARD_BOOT}, 0)
993                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
994                to be set.")
995	endif
996endif #(DYN_DISABLE_AUTH)
997
998ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
999# Support authentication verification and hash calculation
1000	CRYPTO_SUPPORT := 3
1001else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
1002# Support authentication verification and hash calculation
1003	CRYPTO_SUPPORT := 3
1004else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
1005# Support hash calculation only
1006	CRYPTO_SUPPORT := 2
1007else ifeq (${TRUSTED_BOARD_BOOT},1)
1008# Support authentication verification only
1009	CRYPTO_SUPPORT := 1
1010else
1011	CRYPTO_SUPPORT := 0
1012endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
1013
1014# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
1015ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
1016        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
1017endif
1018
1019# If pointer authentication is used in the firmware, make sure that all the
1020# registers associated to it are also saved and restored.
1021# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
1022ifeq ($(ENABLE_PAUTH),1)
1023	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
1024                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
1025	endif
1026endif #(ENABLE_PAUTH)
1027
1028ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
1029	ifneq (${ARCH},aarch64)
1030                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
1031	endif
1032endif #(CTX_INCLUDE_PAUTH_REGS)
1033
1034ifeq ($(CTX_INCLUDE_MTE_REGS),1)
1035	ifneq (${ARCH},aarch64)
1036                $(error CTX_INCLUDE_MTE_REGS requires AArch64)
1037	endif
1038endif #(CTX_INCLUDE_MTE_REGS)
1039
1040ifeq ($(PSA_FWU_SUPPORT),1)
1041        $(info PSA_FWU_SUPPORT is an experimental feature)
1042endif #(PSA_FWU_SUPPORT)
1043
1044ifeq ($(FEATURE_DETECTION),1)
1045        $(info FEATURE_DETECTION is an experimental feature)
1046endif #(FEATURE_DETECTION)
1047
1048ifneq ($(ENABLE_SME2_FOR_NS), 0)
1049	ifeq (${ENABLE_SME_FOR_NS}, 0)
1050                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
1051                to be set")
1052                $(warning "Forced ENABLE_SME_FOR_NS=1")
1053		override ENABLE_SME_FOR_NS	:= 1
1054	endif
1055endif #(ENABLE_SME2_FOR_NS)
1056
1057ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
1058	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
1059                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
1060                library v2")
1061	endif
1062endif #(ARM_XLAT_TABLES_LIB_V1)
1063
1064ifneq (${DECRYPTION_SUPPORT},none)
1065	ifeq (${TRUSTED_BOARD_BOOT}, 0)
1066                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
1067                to be set)
1068	endif
1069endif #(DECRYPTION_SUPPORT)
1070
1071# Ensure that no Aarch64-only features are enabled in Aarch32 build
1072ifeq (${ARCH},aarch32)
1073
1074	# SME/SVE only supported on AArch64
1075	ifneq (${ENABLE_SME_FOR_NS},0)
1076                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
1077	endif
1078
1079	ifeq (${ENABLE_SVE_FOR_NS},1)
1080		# Warning instead of error due to CI dependency on this
1081                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
1082	endif
1083
1084	# BRBE is not supported in AArch32
1085	ifeq (${ENABLE_BRBE_FOR_NS},1)
1086                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
1087	endif
1088
1089	# FEAT_RNG_TRAP is not supported in AArch32
1090	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
1091                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
1092	endif
1093endif #(ARCH=aarch32)
1094
1095ifneq (${ENABLE_SME_FOR_NS},0)
1096	ifeq (${ENABLE_SVE_FOR_NS},0)
1097                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
1098	endif
1099endif #(ENABLE_SME_FOR_NS)
1100
1101# Secure SME/SVE requires the non-secure component as well
1102ifeq (${ENABLE_SME_FOR_SWD},1)
1103	ifeq (${ENABLE_SME_FOR_NS},0)
1104                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
1105	endif
1106	ifeq (${ENABLE_SVE_FOR_SWD},0)
1107                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
1108	endif
1109endif #(ENABLE_SME_FOR_SWD)
1110
1111ifeq (${ENABLE_SVE_FOR_SWD},1)
1112	ifeq (${ENABLE_SVE_FOR_NS},0)
1113                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1114	endif
1115endif #(ENABLE_SVE_FOR_SWD)
1116
1117# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1118# its own context management including FPU registers.
1119ifeq (${CTX_INCLUDE_FPREGS},1)
1120	ifneq (${ENABLE_SME_FOR_NS},0)
1121                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1122	endif
1123
1124	ifeq (${ENABLE_SVE_FOR_NS},1)
1125		# Warning instead of error due to CI dependency on this
1126                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1127                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1128		override ENABLE_SVE_FOR_NS	:= 0
1129	endif
1130endif #(CTX_INCLUDE_FPREGS)
1131
1132ifeq ($(DRTM_SUPPORT),1)
1133        $(info DRTM_SUPPORT is an experimental feature)
1134endif
1135
1136ifeq (${TRANSFER_LIST},1)
1137        $(info TRANSFER_LIST is an experimental feature)
1138endif
1139
1140ifeq (${ENABLE_RME},1)
1141	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1142                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1143	endif
1144endif
1145
1146# Determine if FEAT_RNG is supported
1147ENABLE_FEAT_RNG		=	$(if $(findstring rng,${arch-features}),1,0)
1148
1149# Determine if FEAT_SB is supported
1150ENABLE_FEAT_SB		=	$(if $(findstring sb,${arch-features}),1,0)
1151
1152ifeq ($(PSA_CRYPTO),1)
1153        $(info PSA_CRYPTO is an experimental feature)
1154endif
1155
1156################################################################################
1157# Process platform overrideable behaviour
1158################################################################################
1159
1160ifdef BL1_SOURCES
1161	NEED_BL1 := yes
1162endif #(BL1_SOURCES)
1163
1164ifdef BL2_SOURCES
1165	NEED_BL2 := yes
1166
1167	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1168	# Certificate generation tools. This flag can be overridden by the platform.
1169	ifdef EL3_PAYLOAD_BASE
1170		# If booting an EL3 payload there is no need for a BL33 image
1171		# in the FIP file.
1172		NEED_BL33		:=	no
1173	else
1174		ifdef PRELOADED_BL33_BASE
1175			# If booting a BL33 preloaded image there is no need of
1176			# another one in the FIP file.
1177			NEED_BL33		:=	no
1178		else
1179			NEED_BL33		?=	yes
1180		endif
1181	endif
1182endif #(BL2_SOURCES)
1183
1184ifdef BL2U_SOURCES
1185	NEED_BL2U := yes
1186endif #(BL2U_SOURCES)
1187
1188# If SCP_BL2 is given, we always want FIP to include it.
1189ifdef SCP_BL2
1190	NEED_SCP_BL2		:=	yes
1191endif #(SCP_BL2)
1192
1193# For AArch32, BL31 is not currently supported.
1194ifneq (${ARCH},aarch32)
1195	ifdef BL31_SOURCES
1196	# When booting an EL3 payload, there is no need to compile the BL31
1197	# image nor put it in the FIP.
1198		ifndef EL3_PAYLOAD_BASE
1199			NEED_BL31 := yes
1200		endif
1201	endif
1202endif #(ARCH=aarch64)
1203
1204# Process TBB related flags
1205ifneq (${GENERATE_COT},0)
1206	# Common cert_create options
1207	ifneq (${CREATE_KEYS},0)
1208                $(eval CRT_ARGS += -n)
1209                $(eval FWU_CRT_ARGS += -n)
1210		ifneq (${SAVE_KEYS},0)
1211                        $(eval CRT_ARGS += -k)
1212                        $(eval FWU_CRT_ARGS += -k)
1213		endif
1214	endif
1215	# Include TBBR makefile (unless the platform indicates otherwise)
1216	ifeq (${INCLUDE_TBBR_MK},1)
1217                include make_helpers/tbbr/tbbr_tools.mk
1218	endif
1219endif #(GENERATE_COT)
1220
1221ifneq (${FIP_ALIGN},0)
1222	FIP_ARGS += --align ${FIP_ALIGN}
1223endif #(FIP_ALIGN)
1224
1225ifdef FDT_SOURCES
1226	NEED_FDT := yes
1227endif #(FDT_SOURCES)
1228
1229################################################################################
1230# Include libraries' Makefile that are used in all BL
1231################################################################################
1232
1233include lib/stack_protector/stack_protector.mk
1234
1235################################################################################
1236# Include BL specific makefiles
1237################################################################################
1238
1239ifeq (${NEED_BL1},yes)
1240include bl1/bl1.mk
1241endif
1242
1243ifeq (${NEED_BL2},yes)
1244include bl2/bl2.mk
1245endif
1246
1247ifeq (${NEED_BL2U},yes)
1248include bl2u/bl2u.mk
1249endif
1250
1251ifeq (${NEED_BL31},yes)
1252include bl31/bl31.mk
1253endif
1254
1255################################################################################
1256# Build options checks
1257################################################################################
1258
1259# Boolean_Flags
1260$(eval $(call assert_booleans,\
1261    $(sort \
1262	ALLOW_RO_XLAT_TABLES \
1263	BL2_ENABLE_SP_LOAD \
1264	COLD_BOOT_SINGLE_CPU \
1265	CREATE_KEYS \
1266	CTX_INCLUDE_AARCH32_REGS \
1267	CTX_INCLUDE_FPREGS \
1268	CTX_INCLUDE_EL2_REGS \
1269	DEBUG \
1270	DYN_DISABLE_AUTH \
1271	EL3_EXCEPTION_HANDLING \
1272	ENABLE_AMU_AUXILIARY_COUNTERS \
1273	ENABLE_AMU_FCONF \
1274	AMU_RESTRICT_COUNTERS \
1275	ENABLE_ASSERTIONS \
1276	ENABLE_FEAT_SB \
1277	ENABLE_PIE \
1278	ENABLE_PMF \
1279	ENABLE_PSCI_STAT \
1280	ENABLE_RUNTIME_INSTRUMENTATION \
1281	ENABLE_SME_FOR_SWD \
1282	ENABLE_SVE_FOR_SWD \
1283	ERROR_DEPRECATED \
1284	FAULT_INJECTION_SUPPORT \
1285	GENERATE_COT \
1286	GICV2_G0_FOR_EL3 \
1287	HANDLE_EA_EL3_FIRST_NS \
1288	HW_ASSISTED_COHERENCY \
1289	MEASURED_BOOT \
1290	DRTM_SUPPORT \
1291	NS_TIMER_SWITCH \
1292	OVERRIDE_LIBC \
1293	PL011_GENERIC_UART \
1294	PLAT_RSS_NOT_SUPPORTED \
1295	PROGRAMMABLE_RESET_ADDRESS \
1296	PSCI_EXTENDED_STATE_ID \
1297	PSCI_OS_INIT_MODE \
1298	RESET_TO_BL31 \
1299	SAVE_KEYS \
1300	SEPARATE_CODE_AND_RODATA \
1301	SEPARATE_BL2_NOLOAD_REGION \
1302	SEPARATE_NOBITS_REGION \
1303	SPIN_ON_BL1_EXIT \
1304	SPM_MM \
1305	SPMC_AT_EL3 \
1306	SPMC_AT_EL3_SEL0_SP \
1307	SPMD_SPM_AT_SEL2 \
1308	ENABLE_SPMD_LP \
1309	TRANSFER_LIST \
1310	TRUSTED_BOARD_BOOT \
1311	USE_COHERENT_MEM \
1312	USE_DEBUGFS \
1313	ARM_IO_IN_DTB \
1314	SDEI_IN_FCONF \
1315	SEC_INT_DESC_IN_FCONF \
1316	USE_ROMLIB \
1317	USE_TBBR_DEFS \
1318	WARMBOOT_ENABLE_DCACHE_EARLY \
1319	RESET_TO_BL2 \
1320	BL2_IN_XIP_MEM \
1321	BL2_INV_DCACHE \
1322	USE_SPINLOCK_CAS \
1323	ENCRYPT_BL31 \
1324	ENCRYPT_BL32 \
1325	ERRATA_SPECULATIVE_AT \
1326	RAS_TRAP_NS_ERR_REC_ACCESS \
1327	COT_DESC_IN_DTB \
1328	USE_SP804_TIMER \
1329	PSA_FWU_SUPPORT \
1330	ENABLE_MPMM \
1331	ENABLE_MPMM_FCONF \
1332	FEATURE_DETECTION \
1333	TRNG_SUPPORT \
1334	ERRATA_ABI_SUPPORT \
1335	ERRATA_NON_ARM_INTERCONNECT \
1336	CONDITIONAL_CMO \
1337	RAS_FFH_SUPPORT \
1338	PSA_CRYPTO	\
1339	ENABLE_CONSOLE_GETC \
1340)))
1341
1342# Numeric_Flags
1343$(eval $(call assert_numerics,\
1344    $(sort \
1345	ARM_ARCH_MAJOR \
1346	ARM_ARCH_MINOR \
1347	BRANCH_PROTECTION \
1348	CTX_INCLUDE_PAUTH_REGS \
1349	CTX_INCLUDE_MTE_REGS \
1350	CTX_INCLUDE_NEVE_REGS \
1351	CRYPTO_SUPPORT \
1352	DISABLE_MTPMU \
1353	ENABLE_BRBE_FOR_NS \
1354	ENABLE_TRBE_FOR_NS \
1355	ENABLE_BTI \
1356	ENABLE_PAUTH \
1357	ENABLE_FEAT_AMU \
1358	ENABLE_FEAT_AMUv1p1 \
1359	ENABLE_FEAT_CSV2_2 \
1360	ENABLE_FEAT_RAS	\
1361	ENABLE_FEAT_DIT \
1362	ENABLE_FEAT_ECV \
1363	ENABLE_FEAT_FGT \
1364	ENABLE_FEAT_HCX \
1365	ENABLE_FEAT_PAN \
1366	ENABLE_FEAT_RNG \
1367	ENABLE_FEAT_RNG_TRAP \
1368	ENABLE_FEAT_SEL2 \
1369	ENABLE_FEAT_TCR2 \
1370	ENABLE_FEAT_S2PIE \
1371	ENABLE_FEAT_S1PIE \
1372	ENABLE_FEAT_S2POE \
1373	ENABLE_FEAT_S1POE \
1374	ENABLE_FEAT_GCS \
1375	ENABLE_FEAT_VHE \
1376	ENABLE_FEAT_MTE_PERM \
1377	ENABLE_FEAT_MPAM \
1378	ENABLE_RME \
1379	ENABLE_SPE_FOR_NS \
1380	ENABLE_SYS_REG_TRACE_FOR_NS \
1381	ENABLE_SME_FOR_NS \
1382	ENABLE_SME2_FOR_NS \
1383	ENABLE_SVE_FOR_NS \
1384	ENABLE_TRF_FOR_NS \
1385	FW_ENC_STATUS \
1386	NR_OF_FW_BANKS \
1387	NR_OF_IMAGES_IN_FW_BANK \
1388	TWED_DELAY \
1389	ENABLE_FEAT_TWED \
1390	SVE_VECTOR_LEN \
1391	IMPDEF_SYSREG_TRAP \
1392)))
1393
1394ifdef KEY_SIZE
1395        $(eval $(call assert_numeric,KEY_SIZE))
1396endif
1397
1398ifeq ($(filter $(SANITIZE_UB), on off trap),)
1399        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1400endif
1401
1402################################################################################
1403# Add definitions to the cpp preprocessor based on the current build options.
1404# This is done after including the platform specific makefile to allow the
1405# platform to overwrite the default options
1406################################################################################
1407
1408$(eval $(call add_defines,\
1409    $(sort \
1410	ALLOW_RO_XLAT_TABLES \
1411	ARM_ARCH_MAJOR \
1412	ARM_ARCH_MINOR \
1413	BL2_ENABLE_SP_LOAD \
1414	COLD_BOOT_SINGLE_CPU \
1415	CTX_INCLUDE_AARCH32_REGS \
1416	CTX_INCLUDE_FPREGS \
1417	CTX_INCLUDE_PAUTH_REGS \
1418	EL3_EXCEPTION_HANDLING \
1419	CTX_INCLUDE_MTE_REGS \
1420	CTX_INCLUDE_EL2_REGS \
1421	CTX_INCLUDE_NEVE_REGS \
1422	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1423	DISABLE_MTPMU \
1424	ENABLE_FEAT_AMU \
1425	ENABLE_AMU_AUXILIARY_COUNTERS \
1426	ENABLE_AMU_FCONF \
1427	AMU_RESTRICT_COUNTERS \
1428	ENABLE_ASSERTIONS \
1429	ENABLE_BTI \
1430	ENABLE_FEAT_MPAM \
1431	ENABLE_PAUTH \
1432	ENABLE_PIE \
1433	ENABLE_PMF \
1434	ENABLE_PSCI_STAT \
1435	ENABLE_RME \
1436	ENABLE_RUNTIME_INSTRUMENTATION \
1437	ENABLE_SME_FOR_NS \
1438	ENABLE_SME2_FOR_NS \
1439	ENABLE_SME_FOR_SWD \
1440	ENABLE_SPE_FOR_NS \
1441	ENABLE_SVE_FOR_NS \
1442	ENABLE_SVE_FOR_SWD \
1443	ENCRYPT_BL31 \
1444	ENCRYPT_BL32 \
1445	ERROR_DEPRECATED \
1446	FAULT_INJECTION_SUPPORT \
1447	GICV2_G0_FOR_EL3 \
1448	HANDLE_EA_EL3_FIRST_NS \
1449	HW_ASSISTED_COHERENCY \
1450	LOG_LEVEL \
1451	MEASURED_BOOT \
1452	DRTM_SUPPORT \
1453	NS_TIMER_SWITCH \
1454	PL011_GENERIC_UART \
1455	PLAT_${PLAT} \
1456	PLAT_RSS_NOT_SUPPORTED \
1457	PROGRAMMABLE_RESET_ADDRESS \
1458	PSCI_EXTENDED_STATE_ID \
1459	PSCI_OS_INIT_MODE \
1460	ENABLE_FEAT_RAS \
1461	RAS_FFH_SUPPORT \
1462	RESET_TO_BL31 \
1463	SEPARATE_CODE_AND_RODATA \
1464	SEPARATE_BL2_NOLOAD_REGION \
1465	SEPARATE_NOBITS_REGION \
1466	RECLAIM_INIT_CODE \
1467	SPD_${SPD} \
1468	SPIN_ON_BL1_EXIT \
1469	SPM_MM \
1470	SPMC_AT_EL3 \
1471	SPMC_AT_EL3_SEL0_SP \
1472	SPMD_SPM_AT_SEL2 \
1473	TRANSFER_LIST \
1474	TRUSTED_BOARD_BOOT \
1475	CRYPTO_SUPPORT \
1476	TRNG_SUPPORT \
1477	ERRATA_ABI_SUPPORT \
1478	ERRATA_NON_ARM_INTERCONNECT \
1479	USE_COHERENT_MEM \
1480	USE_DEBUGFS \
1481	ARM_IO_IN_DTB \
1482	SDEI_IN_FCONF \
1483	SEC_INT_DESC_IN_FCONF \
1484	USE_ROMLIB \
1485	USE_TBBR_DEFS \
1486	WARMBOOT_ENABLE_DCACHE_EARLY \
1487	RESET_TO_BL2 \
1488	BL2_RUNS_AT_EL3	\
1489	BL2_IN_XIP_MEM \
1490	BL2_INV_DCACHE \
1491	USE_SPINLOCK_CAS \
1492	ERRATA_SPECULATIVE_AT \
1493	RAS_TRAP_NS_ERR_REC_ACCESS \
1494	COT_DESC_IN_DTB \
1495	USE_SP804_TIMER \
1496	ENABLE_FEAT_RNG \
1497	ENABLE_FEAT_RNG_TRAP \
1498	ENABLE_FEAT_SB \
1499	ENABLE_FEAT_DIT \
1500	NR_OF_FW_BANKS \
1501	NR_OF_IMAGES_IN_FW_BANK \
1502	PSA_FWU_SUPPORT \
1503	ENABLE_BRBE_FOR_NS \
1504	ENABLE_TRBE_FOR_NS \
1505	ENABLE_SYS_REG_TRACE_FOR_NS \
1506	ENABLE_TRF_FOR_NS \
1507	ENABLE_FEAT_HCX \
1508	ENABLE_MPMM \
1509	ENABLE_MPMM_FCONF \
1510	ENABLE_FEAT_FGT \
1511	ENABLE_FEAT_ECV \
1512	ENABLE_FEAT_AMUv1p1 \
1513	ENABLE_FEAT_SEL2 \
1514	ENABLE_FEAT_VHE \
1515	ENABLE_FEAT_CSV2_2 \
1516	ENABLE_FEAT_PAN \
1517	ENABLE_FEAT_TCR2 \
1518	ENABLE_FEAT_S2PIE \
1519	ENABLE_FEAT_S1PIE \
1520	ENABLE_FEAT_S2POE \
1521	ENABLE_FEAT_S1POE \
1522	ENABLE_FEAT_GCS \
1523	ENABLE_FEAT_MTE_PERM \
1524	FEATURE_DETECTION \
1525	TWED_DELAY \
1526	ENABLE_FEAT_TWED \
1527	CONDITIONAL_CMO \
1528	IMPDEF_SYSREG_TRAP \
1529	SVE_VECTOR_LEN \
1530	ENABLE_SPMD_LP \
1531	PSA_CRYPTO	\
1532	ENABLE_CONSOLE_GETC \
1533)))
1534
1535ifeq (${SANITIZE_UB},trap)
1536        $(eval $(call add_define,MONITOR_TRAPS))
1537endif #(SANITIZE_UB)
1538
1539# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1540ifdef EL3_PAYLOAD_BASE
1541        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1542else
1543# Define the PRELOADED_BL33_BASE flag only if it is provided and
1544# EL3_PAYLOAD_BASE is not defined, as it has priority.
1545	ifdef PRELOADED_BL33_BASE
1546                $(eval $(call add_define,PRELOADED_BL33_BASE))
1547	endif
1548endif #(EL3_PAYLOAD_BASE)
1549
1550# Define the DYN_DISABLE_AUTH flag only if set.
1551ifeq (${DYN_DISABLE_AUTH},1)
1552        $(eval $(call add_define,DYN_DISABLE_AUTH))
1553endif
1554
1555ifneq ($(findstring armlink,$(notdir $(LD))),)
1556        $(eval $(call add_define,USE_ARM_LINK))
1557endif
1558
1559# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1560ifeq (${SPD},spmd)
1561ifdef SP_LAYOUT_FILE
1562	-include $(BUILD_PLAT)/sp_gen.mk
1563	FIP_DEPS += sp
1564	CRT_DEPS += sp
1565	NEED_SP_PKG := yes
1566else
1567	ifeq (${SPMD_SPM_AT_SEL2},1)
1568                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1569	endif
1570endif #(SP_LAYOUT_FILE)
1571endif #(SPD)
1572
1573################################################################################
1574# Build targets
1575################################################################################
1576
1577.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1578.SUFFIXES:
1579
1580all: msg_start
1581
1582msg_start:
1583	@echo "Building ${PLAT}"
1584
1585ifeq (${ERROR_DEPRECATED},0)
1586# Check if deprecated declarations and cpp warnings should be treated as error or not.
1587ifneq ($(findstring clang,$(notdir $(CC))),)
1588    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1589else
1590    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1591endif
1592endif #(!ERROR_DEPRECATED)
1593
1594$(eval $(call MAKE_LIB_DIRS))
1595$(eval $(call MAKE_LIB,c))
1596
1597# Expand build macros for the different images
1598ifeq (${NEED_BL1},yes)
1599BL1_SOURCES := $(sort ${BL1_SOURCES})
1600$(eval $(call MAKE_BL,bl1))
1601endif #(NEED_BL1)
1602
1603ifeq (${NEED_BL2},yes)
1604
1605ifeq (${RESET_TO_BL2}, 0)
1606FIP_BL2_ARGS := tb-fw
1607endif
1608
1609BL2_SOURCES := $(sort ${BL2_SOURCES})
1610
1611$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1612	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1613
1614endif #(NEED_BL2)
1615
1616ifeq (${NEED_SCP_BL2},yes)
1617$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1618endif #(NEED_SCP_BL2)
1619
1620ifeq (${NEED_BL31},yes)
1621BL31_SOURCES += ${SPD_SOURCES}
1622# Sort BL31 source files to remove duplicates
1623BL31_SOURCES := $(sort ${BL31_SOURCES})
1624ifneq (${DECRYPTION_SUPPORT},none)
1625$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1626	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1627else
1628$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1629	$(eval $(call MAKE_BL,bl31,soc-fw)))
1630endif #(DECRYPTION_SUPPORT)
1631endif #(NEED_BL31)
1632
1633# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1634# build system will call TOOL_ADD_IMG to print a warning message and abort the
1635# process. Note that the dependency on BL32 applies to the FIP only.
1636ifeq (${NEED_BL32},yes)
1637# Sort BL32 source files to remove duplicates
1638BL32_SOURCES := $(sort ${BL32_SOURCES})
1639BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1640
1641ifneq (${DECRYPTION_SUPPORT},none)
1642$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1643	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1644else
1645$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1646	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1647endif #(DECRYPTION_SUPPORT)
1648endif #(NEED_BL32)
1649
1650# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1651# needs to be built from RMM_SOURCES.
1652ifeq (${NEED_RMM},yes)
1653# Sort RMM source files to remove duplicates
1654RMM_SOURCES := $(sort ${RMM_SOURCES})
1655BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1656
1657$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1658	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1659endif #(NEED_RMM)
1660
1661# Add the BL33 image if required by the platform
1662ifeq (${NEED_BL33},yes)
1663$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1664endif #(NEED_BL33)
1665
1666ifeq (${NEED_BL2U},yes)
1667$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1668	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1669endif #(NEED_BL2U)
1670
1671# Expand build macros for the different images
1672ifeq (${NEED_FDT},yes)
1673    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1674endif #(NEED_FDT)
1675
1676# Add Secure Partition packages
1677ifeq (${NEED_SP_PKG},yes)
1678$(BUILD_PLAT)/sp_gen.mk : ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1679	${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1680sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1681	@${ECHO_BLANK_LINE}
1682	@echo "Built SP Images successfully"
1683	@${ECHO_BLANK_LINE}
1684endif #(NEED_SP_PKG)
1685
1686locate-checkpatch:
1687ifndef CHECKPATCH
1688	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1689else
1690ifeq (,$(wildcard ${CHECKPATCH}))
1691	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1692endif
1693endif #(CHECKPATCH)
1694
1695clean:
1696	@echo "  CLEAN"
1697	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1698ifdef UNIX_MK
1699	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1700else
1701# Clear the MAKEFLAGS as we do not want
1702# to pass the gnumake flags to nmake.
1703	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1704endif #(UNIX_MK)
1705	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1706	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1707	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1708
1709realclean distclean:
1710	@echo "  REALCLEAN"
1711	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1712	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1713ifdef UNIX_MK
1714	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1715else
1716# Clear the MAKEFLAGS as we do not want
1717# to pass the gnumake flags to nmake.
1718	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1719endif #(UNIX_MK)
1720	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1721	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1722	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1723
1724checkcodebase:		locate-checkpatch
1725	@echo "  CHECKING STYLE"
1726	@if test -d .git ; then						\
1727		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1728		while read GIT_FILE ;					\
1729		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1730		done ;							\
1731	else								\
1732		 find . -type f -not -iwholename "*.git*"		\
1733		 -not -iwholename "*build*"				\
1734		 -not -iwholename "*libfdt*"				\
1735		 -not -iwholename "*libc*"				\
1736		 -not -iwholename "*docs*"				\
1737		 -not -iwholename "*.rst"				\
1738		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1739	fi
1740
1741checkpatch:		locate-checkpatch
1742	@echo "  CHECKING STYLE"
1743	@if test -n "${CHECKPATCH_OPTS}"; then				\
1744		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1745	fi
1746	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1747	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1748	do								\
1749		printf "\n[*] Checking style of '$$commit'\n\n";	\
1750		git log --format=email "$$commit~..$$commit"		\
1751			-- ${CHECK_PATHS} |				\
1752			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1753		git diff --format=email "$$commit~..$$commit"		\
1754			-- ${CHECK_PATHS} |				\
1755			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1756	done
1757
1758certtool: ${CRTTOOL}
1759
1760${CRTTOOL}: FORCE
1761	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${CRTTOOLPATH} all
1762	@${ECHO_BLANK_LINE}
1763	@echo "Built $@ successfully"
1764	@${ECHO_BLANK_LINE}
1765
1766ifneq (${GENERATE_COT},0)
1767certificates: ${CRT_DEPS} ${CRTTOOL}
1768	${Q}${CRTTOOL} ${CRT_ARGS}
1769	@${ECHO_BLANK_LINE}
1770	@echo "Built $@ successfully"
1771	@echo "Certificates can be found in ${BUILD_PLAT}"
1772	@${ECHO_BLANK_LINE}
1773endif #(GENERATE_COT)
1774
1775${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1776	$(eval ${CHECK_FIP_CMD})
1777	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1778	${Q}${FIPTOOL} info $@
1779	@${ECHO_BLANK_LINE}
1780	@echo "Built $@ successfully"
1781	@${ECHO_BLANK_LINE}
1782
1783ifneq (${GENERATE_COT},0)
1784fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1785	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1786	@${ECHO_BLANK_LINE}
1787	@echo "Built $@ successfully"
1788	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1789	@${ECHO_BLANK_LINE}
1790endif #(GENERATE_COT)
1791
1792${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1793	$(eval ${CHECK_FWU_FIP_CMD})
1794	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1795	${Q}${FIPTOOL} info $@
1796	@${ECHO_BLANK_LINE}
1797	@echo "Built $@ successfully"
1798	@${ECHO_BLANK_LINE}
1799
1800fiptool: ${FIPTOOL}
1801fip: ${BUILD_PLAT}/${FIP_NAME}
1802fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1803
1804${FIPTOOL}: FORCE
1805ifdef UNIX_MK
1806	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
1807else
1808# Clear the MAKEFLAGS as we do not want
1809# to pass the gnumake flags to nmake.
1810	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1811endif #(UNIX_MK)
1812
1813romlib.bin: libraries FORCE
1814	${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
1815
1816memmap: all
1817ifdef UNIX_MK
1818	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1819		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1820else
1821	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1822		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1823endif
1824
1825doc:
1826	@echo "  BUILD DOCUMENTATION"
1827	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1828
1829enctool: ${ENCTOOL}
1830
1831${ENCTOOL}: FORCE
1832	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
1833	@${ECHO_BLANK_LINE}
1834	@echo "Built $@ successfully"
1835	@${ECHO_BLANK_LINE}
1836
1837cscope:
1838	@echo "  CSCOPE"
1839	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1840	${Q}cscope -b -q -k
1841
1842help:
1843	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1844	@echo ""
1845	@echo "PLAT is used to specify which platform you wish to build."
1846	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1847	@echo ""
1848	@echo "platform = ${PLATFORM_LIST}"
1849	@echo ""
1850	@echo "Please refer to the User Guide for a list of all supported options."
1851	@echo "Note that the build system doesn't track dependencies for build "
1852	@echo "options. Therefore, if any of the build options are changed "
1853	@echo "from a previous build, a clean build must be performed."
1854	@echo ""
1855	@echo "Supported Targets:"
1856	@echo "  all            Build all individual bootloader binaries"
1857	@echo "  bl1            Build the BL1 binary"
1858	@echo "  bl2            Build the BL2 binary"
1859	@echo "  bl2u           Build the BL2U binary"
1860	@echo "  bl31           Build the BL31 binary"
1861	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1862	@echo "                 this builds secure payload specified by AARCH32_SP"
1863	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1864	@echo "  fip            Build the Firmware Image Package (FIP)"
1865	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1866	@echo "  checkcodebase  Check the coding style of the entire source tree"
1867	@echo "  checkpatch     Check the coding style on changes in the current"
1868	@echo "                 branch against BASE_COMMIT (default origin/master)"
1869	@echo "  clean          Clean the build for the selected platform"
1870	@echo "  cscope         Generate cscope index"
1871	@echo "  distclean      Remove all build artifacts for all platforms"
1872	@echo "  certtool       Build the Certificate generation tool"
1873	@echo "  enctool        Build the Firmware encryption tool"
1874	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1875	@echo "  sp             Build the Secure Partition Packages"
1876	@echo "  sptool         Build the Secure Partition Package creation tool"
1877	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1878	@echo "  memmap         Print the memory map of the built binaries"
1879	@echo "  doc            Build html based documentation using Sphinx tool"
1880	@echo ""
1881	@echo "Note: most build targets require PLAT to be set to a specific platform."
1882	@echo ""
1883	@echo "example: build all targets for the FVP platform:"
1884	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1885
1886.PHONY: FORCE
1887FORCE:;
1888