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