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