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