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