xref: /rk3399_ARM-atf/Makefile (revision 7f41bcc76d8857b4678c90796ebd85794ff3ee5f)
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
452################################################################################
453# Common sources and include directories
454################################################################################
455include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
456include lib/compiler-rt/compiler-rt.mk
457
458BL_COMMON_SOURCES	+=	common/bl_common.c			\
459				common/tf_log.c				\
460				common/${ARCH}/debug.S			\
461				drivers/console/multi_console.c		\
462				lib/${ARCH}/cache_helpers.S		\
463				lib/${ARCH}/misc_helpers.S		\
464				plat/common/plat_bl_common.c		\
465				plat/common/plat_log_common.c		\
466				plat/common/${ARCH}/plat_common.c	\
467				plat/common/${ARCH}/platform_helpers.S	\
468				${COMPILER_RT_SRCS}
469
470ifeq ($(notdir $(CC)),armclang)
471BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
472endif
473
474ifeq (${SANITIZE_UB},on)
475BL_COMMON_SOURCES	+=	plat/common/ubsan.c
476endif
477
478INCLUDES		+=	-Iinclude				\
479				-Iinclude/arch/${ARCH}			\
480				-Iinclude/lib/cpus/${ARCH}		\
481				-Iinclude/lib/el3_runtime/${ARCH}	\
482				${PLAT_INCLUDES}			\
483				${SPD_INCLUDES}
484
485include common/backtrace/backtrace.mk
486
487################################################################################
488# Generic definitions
489################################################################################
490
491include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
492
493ifeq (${BUILD_BASE},)
494     BUILD_BASE		:=	./build
495endif
496BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
497
498SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
499
500# Platforms providing their own TBB makefile may override this value
501INCLUDE_TBBR_MK		:=	1
502
503
504################################################################################
505# Include SPD Makefile if one has been specified
506################################################################################
507
508ifneq (${SPD},none)
509    ifeq (${ARCH},aarch32)
510        $(error "Error: SPD is incompatible with AArch32.")
511    endif
512
513    ifdef EL3_PAYLOAD_BASE
514        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
515        $(warning "The SPD and its BL32 companion will be present but ignored.")
516    endif
517
518    ifeq (${SPD},spmd)
519        # SPMD is located in std_svc directory
520        SPD_DIR := std_svc
521
522        ifeq ($(SPMD_SPM_AT_SEL2),1)
523            ifeq ($(CTX_INCLUDE_EL2_REGS),0)
524                $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option)
525            endif
526        endif
527
528        ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
529            DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
530        endif
531
532        ifeq ($(TS_SP_FW_CONFIG),1)
533            DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
534        endif
535
536        ifneq ($(ARM_BL2_SP_LIST_DTS),)
537            DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
538        endif
539
540        ifneq ($(SP_LAYOUT_FILE),)
541            BL2_ENABLE_SP_LOAD := 1
542        endif
543    else
544        # All other SPDs in spd directory
545        SPD_DIR := spd
546    endif
547
548    # We expect to locate an spd.mk under the specified SPD directory
549    SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
550
551    ifeq (${SPD_MAKE},)
552        $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
553    endif
554    $(info Including ${SPD_MAKE})
555    include ${SPD_MAKE}
556
557    # If there's BL32 companion for the chosen SPD, we expect that the SPD's
558    # Makefile would set NEED_BL32 to "yes". In this case, the build system
559    # supports two mutually exclusive options:
560    # * BL32 is built from source: then BL32_SOURCES must contain the list
561    #   of source files to build BL32
562    # * BL32 is a prebuilt binary: then BL32 must point to the image file
563    #   that will be included in the FIP
564    # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
565    # over the sources.
566endif
567
568################################################################################
569# Include rmmd Makefile if RME is enabled
570################################################################################
571
572ifneq (${ENABLE_RME},0)
573ifneq (${ARCH},aarch64)
574	$(error ENABLE_RME requires AArch64)
575endif
576include services/std_svc/rmmd/rmmd.mk
577$(warning "RME is an experimental feature")
578endif
579
580################################################################################
581# Include the platform specific Makefile after the SPD Makefile (the platform
582# makefile may use all previous definitions in this file)
583################################################################################
584
585include ${PLAT_MAKEFILE_FULL}
586
587$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
588
589ifeq (${ARM_ARCH_MAJOR},7)
590include make_helpers/armv7-a-cpus.mk
591endif
592
593PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
594ifneq ($(PIE_FOUND),)
595	TF_CFLAGS	+=	-fno-PIE
596endif
597
598ifneq ($(findstring gcc,$(notdir $(LD))),)
599	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
600else
601	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
602endif
603
604ifeq ($(ENABLE_PIE),1)
605ifeq ($(BL2_AT_EL3),1)
606ifneq ($(BL2_IN_XIP_MEM),1)
607	BL2_CFLAGS	+=	-fpie
608	BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
609endif
610endif
611	BL31_CFLAGS	+=	-fpie
612	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
613	BL32_CFLAGS	+=	-fpie
614	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
615endif
616
617ifeq (${ARCH},aarch64)
618BL1_CPPFLAGS += -DIMAGE_AT_EL3
619ifeq ($(BL2_AT_EL3),1)
620BL2_CPPFLAGS += -DIMAGE_AT_EL3
621else
622BL2_CPPFLAGS += -DIMAGE_AT_EL1
623endif
624BL2U_CPPFLAGS += -DIMAGE_AT_EL1
625BL31_CPPFLAGS += -DIMAGE_AT_EL3
626BL32_CPPFLAGS += -DIMAGE_AT_EL1
627endif
628
629# Include the CPU specific operations makefile, which provides default
630# values for all CPU errata workarounds and CPU specific optimisations.
631# This can be overridden by the platform.
632include lib/cpus/cpu-ops.mk
633
634ifeq (${ARCH},aarch32)
635NEED_BL32 := yes
636
637################################################################################
638# Build `AARCH32_SP` as BL32 image for AArch32
639################################################################################
640ifneq (${AARCH32_SP},none)
641# We expect to locate an sp.mk under the specified AARCH32_SP directory
642AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
643
644ifeq (${AARCH32_SP_MAKE},)
645  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
646endif
647
648$(info Including ${AARCH32_SP_MAKE})
649include ${AARCH32_SP_MAKE}
650endif
651
652endif
653
654################################################################################
655# Include libc if not overridden
656################################################################################
657ifeq (${OVERRIDE_LIBC},0)
658include lib/libc/libc.mk
659endif
660
661################################################################################
662# Check incompatible options
663################################################################################
664
665ifdef EL3_PAYLOAD_BASE
666        ifdef PRELOADED_BL33_BASE
667                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
668                incompatible build options. EL3_PAYLOAD_BASE has priority.")
669        endif
670        ifneq (${GENERATE_COT},0)
671                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
672        endif
673        ifneq (${TRUSTED_BOARD_BOOT},0)
674                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
675        endif
676endif
677
678ifeq (${NEED_BL33},yes)
679        ifdef EL3_PAYLOAD_BASE
680                $(warning "BL33 image is not needed when option \
681                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
682        endif
683        ifdef PRELOADED_BL33_BASE
684                $(warning "BL33 image is not needed when option \
685                PRELOADED_BL33_BASE is used and won't be added to the FIP \
686                file.")
687        endif
688endif
689
690# When building for systems with hardware-assisted coherency, there's no need to
691# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
692ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
693$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
694endif
695
696#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
697ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
698$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
699endif
700
701# For RAS_EXTENSION, require that EAs are handled in EL3 first
702ifeq ($(RAS_EXTENSION),1)
703    ifneq ($(HANDLE_EA_EL3_FIRST),1)
704        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
705    endif
706endif
707
708# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
709ifeq ($(FAULT_INJECTION_SUPPORT),1)
710    ifneq ($(RAS_EXTENSION),1)
711        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
712    endif
713endif
714
715# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
716ifeq ($(DYN_DISABLE_AUTH), 1)
717    ifeq (${TRUSTED_BOARD_BOOT}, 0)
718        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
719    endif
720endif
721
722ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),)
723    CRYPTO_SUPPORT := 1
724else
725    CRYPTO_SUPPORT := 0
726endif
727
728# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
729ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
730$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
731endif
732
733# If pointer authentication is used in the firmware, make sure that all the
734# registers associated to it are also saved and restored.
735# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
736ifeq ($(ENABLE_PAUTH),1)
737    ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
738        $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
739    endif
740endif
741
742ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
743    ifneq (${ARCH},aarch64)
744        $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
745    endif
746endif
747
748ifeq ($(CTX_INCLUDE_MTE_REGS),1)
749    ifneq (${ARCH},aarch64)
750        $(error CTX_INCLUDE_MTE_REGS requires AArch64)
751    endif
752endif
753
754ifeq ($(PSA_FWU_SUPPORT),1)
755    $(info PSA_FWU_SUPPORT is an experimental feature)
756endif
757
758ifeq ($(FEATURE_DETECTION),1)
759    $(info FEATURE_DETECTION is an experimental feature)
760endif
761
762ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
763    ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
764        $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2")
765    endif
766endif
767
768ifneq (${DECRYPTION_SUPPORT},none)
769    ifeq (${TRUSTED_BOARD_BOOT}, 0)
770        $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set)
771    endif
772endif
773
774# SME/SVE only supported on AArch64
775ifeq (${ARCH},aarch32)
776    ifeq (${ENABLE_SME_FOR_NS},1)
777        $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
778    endif
779    ifeq (${ENABLE_SVE_FOR_NS},1)
780        # Warning instead of error due to CI dependency on this
781        $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
782    endif
783endif
784
785# Ensure ENABLE_RME is not used with SME
786ifeq (${ENABLE_RME},1)
787    ifeq (${ENABLE_SME_FOR_NS},1)
788        $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME")
789    endif
790endif
791
792# Secure SME/SVE requires the non-secure component as well
793ifeq (${ENABLE_SME_FOR_SWD},1)
794    ifeq (${ENABLE_SME_FOR_NS},0)
795        $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
796    endif
797endif
798ifeq (${ENABLE_SVE_FOR_SWD},1)
799    ifeq (${ENABLE_SVE_FOR_NS},0)
800        $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
801    endif
802endif
803
804# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
805# its own context management including FPU registers.
806ifeq (${CTX_INCLUDE_FPREGS},1)
807    ifeq (${ENABLE_SME_FOR_NS},1)
808        $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
809    endif
810    ifeq (${ENABLE_SVE_FOR_NS},1)
811        # Warning instead of error due to CI dependency on this
812        $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
813        $(warning "Forced ENABLE_SVE_FOR_NS=0")
814        override ENABLE_SVE_FOR_NS	:= 0
815    endif
816endif
817
818################################################################################
819# Process platform overrideable behaviour
820################################################################################
821
822ifdef BL1_SOURCES
823NEED_BL1 := yes
824endif
825
826ifdef BL2_SOURCES
827	NEED_BL2 := yes
828
829	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
830	# Certificate generation tools. This flag can be overridden by the platform.
831	ifdef EL3_PAYLOAD_BASE
832                # If booting an EL3 payload there is no need for a BL33 image
833                # in the FIP file.
834                NEED_BL33		:=	no
835        else
836                ifdef PRELOADED_BL33_BASE
837                        # If booting a BL33 preloaded image there is no need of
838                        # another one in the FIP file.
839                        NEED_BL33		:=	no
840                else
841                        NEED_BL33		?=	yes
842                endif
843        endif
844endif
845
846ifdef BL2U_SOURCES
847NEED_BL2U := yes
848endif
849
850# If SCP_BL2 is given, we always want FIP to include it.
851ifdef SCP_BL2
852        NEED_SCP_BL2		:=	yes
853endif
854
855# For AArch32, BL31 is not currently supported.
856ifneq (${ARCH},aarch32)
857    ifdef BL31_SOURCES
858        # When booting an EL3 payload, there is no need to compile the BL31 image nor
859        # put it in the FIP.
860        ifndef EL3_PAYLOAD_BASE
861            NEED_BL31 := yes
862        endif
863    endif
864endif
865
866# Process TBB related flags
867ifneq (${GENERATE_COT},0)
868        # Common cert_create options
869        ifneq (${CREATE_KEYS},0)
870                $(eval CRT_ARGS += -n)
871                $(eval FWU_CRT_ARGS += -n)
872                ifneq (${SAVE_KEYS},0)
873                        $(eval CRT_ARGS += -k)
874                        $(eval FWU_CRT_ARGS += -k)
875                endif
876        endif
877        # Include TBBR makefile (unless the platform indicates otherwise)
878        ifeq (${INCLUDE_TBBR_MK},1)
879                include make_helpers/tbbr/tbbr_tools.mk
880        endif
881endif
882
883ifneq (${FIP_ALIGN},0)
884FIP_ARGS += --align ${FIP_ALIGN}
885endif
886
887ifdef FDT_SOURCES
888NEED_FDT := yes
889endif
890
891################################################################################
892# Include libraries' Makefile that are used in all BL
893################################################################################
894
895include lib/stack_protector/stack_protector.mk
896
897################################################################################
898# Auxiliary tools (fiptool, cert_create, etc)
899################################################################################
900
901# Variables for use with Certificate Generation Tool
902CRTTOOLPATH		?=	tools/cert_create
903CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
904
905# Variables for use with Firmware Encryption Tool
906ENCTOOLPATH		?=	tools/encrypt_fw
907ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
908
909# Variables for use with Firmware Image Package
910FIPTOOLPATH		?=	tools/fiptool
911FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
912
913# Variables for use with sptool
914SPTOOLPATH		?=	tools/sptool
915SPTOOL			?=	${SPTOOLPATH}/sptool${BIN_EXT}
916SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
917
918# Variables for use with ROMLIB
919ROMLIBPATH		?=	lib/romlib
920
921# Variable for use with Python
922PYTHON			?=	python3
923
924# Variables for use with PRINT_MEMORY_MAP
925PRINT_MEMORY_MAP_PATH		?=	tools/memory
926PRINT_MEMORY_MAP		?=	${PRINT_MEMORY_MAP_PATH}/print_memory_map.py
927
928# Variables for use with documentation build using Sphinx tool
929DOCS_PATH		?=	docs
930
931# Defination of SIMICS flag
932SIMICS_BUILD	?=	0
933
934################################################################################
935# Include BL specific makefiles
936################################################################################
937
938ifeq (${NEED_BL1},yes)
939include bl1/bl1.mk
940endif
941
942ifeq (${NEED_BL2},yes)
943include bl2/bl2.mk
944endif
945
946ifeq (${NEED_BL2U},yes)
947include bl2u/bl2u.mk
948endif
949
950ifeq (${NEED_BL31},yes)
951include bl31/bl31.mk
952endif
953
954################################################################################
955# Build options checks
956################################################################################
957
958$(eval $(call assert_booleans,\
959    $(sort \
960        ALLOW_RO_XLAT_TABLES \
961        BL2_ENABLE_SP_LOAD \
962        COLD_BOOT_SINGLE_CPU \
963        CREATE_KEYS \
964        CTX_INCLUDE_AARCH32_REGS \
965        CTX_INCLUDE_FPREGS \
966        CTX_INCLUDE_EL2_REGS \
967        DEBUG \
968        DISABLE_MTPMU \
969        DYN_DISABLE_AUTH \
970        EL3_EXCEPTION_HANDLING \
971        ENABLE_AMU \
972        ENABLE_AMU_AUXILIARY_COUNTERS \
973        ENABLE_AMU_FCONF \
974        AMU_RESTRICT_COUNTERS \
975        ENABLE_ASSERTIONS \
976        ENABLE_PIE \
977        ENABLE_PMF \
978        ENABLE_PSCI_STAT \
979        ENABLE_RUNTIME_INSTRUMENTATION \
980        ENABLE_SME_FOR_NS \
981        ENABLE_SME_FOR_SWD \
982        ENABLE_SPE_FOR_LOWER_ELS \
983        ENABLE_SVE_FOR_NS \
984        ENABLE_SVE_FOR_SWD \
985        ERROR_DEPRECATED \
986        FAULT_INJECTION_SUPPORT \
987        GENERATE_COT \
988        GICV2_G0_FOR_EL3 \
989        HANDLE_EA_EL3_FIRST \
990        HW_ASSISTED_COHERENCY \
991        INVERTED_MEMMAP \
992        MEASURED_BOOT \
993        NS_TIMER_SWITCH \
994        OVERRIDE_LIBC \
995        PL011_GENERIC_UART \
996        PROGRAMMABLE_RESET_ADDRESS \
997        PSCI_EXTENDED_STATE_ID \
998        RESET_TO_BL31 \
999        SAVE_KEYS \
1000        SEPARATE_CODE_AND_RODATA \
1001        SEPARATE_BL2_NOLOAD_REGION \
1002        SEPARATE_NOBITS_REGION \
1003        SPIN_ON_BL1_EXIT \
1004        SPM_MM \
1005        SPMD_SPM_AT_SEL2 \
1006        TRUSTED_BOARD_BOOT \
1007        CRYPTO_SUPPORT \
1008        USE_COHERENT_MEM \
1009        USE_DEBUGFS \
1010        ARM_IO_IN_DTB \
1011        SDEI_IN_FCONF \
1012        SEC_INT_DESC_IN_FCONF \
1013        USE_ROMLIB \
1014        USE_TBBR_DEFS \
1015        WARMBOOT_ENABLE_DCACHE_EARLY \
1016        BL2_AT_EL3 \
1017        BL2_IN_XIP_MEM \
1018        BL2_INV_DCACHE \
1019        USE_SPINLOCK_CAS \
1020        ENCRYPT_BL31 \
1021        ENCRYPT_BL32 \
1022        ERRATA_SPECULATIVE_AT \
1023        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1024        COT_DESC_IN_DTB \
1025        USE_SP804_TIMER \
1026        PSA_FWU_SUPPORT \
1027        ENABLE_TRBE_FOR_NS \
1028        ENABLE_SYS_REG_TRACE_FOR_NS \
1029        ENABLE_MPMM \
1030        ENABLE_MPMM_FCONF \
1031        SIMICS_BUILD \
1032        FEATURE_DETECTION \
1033)))
1034
1035$(eval $(call assert_numerics,\
1036    $(sort \
1037        ARM_ARCH_MAJOR \
1038        ARM_ARCH_MINOR \
1039        BRANCH_PROTECTION \
1040        CTX_INCLUDE_PAUTH_REGS \
1041        CTX_INCLUDE_MTE_REGS \
1042        CTX_INCLUDE_NEVE_REGS \
1043        ENABLE_BTI \
1044        ENABLE_PAUTH \
1045        ENABLE_FEAT_AMUv1 \
1046        ENABLE_FEAT_AMUv1p1 \
1047        ENABLE_FEAT_CSV2_2 \
1048        ENABLE_FEAT_DIT \
1049        ENABLE_FEAT_ECV \
1050        ENABLE_FEAT_FGT \
1051        ENABLE_FEAT_HCX \
1052        ENABLE_FEAT_PAN \
1053        ENABLE_FEAT_RNG \
1054        ENABLE_FEAT_SB \
1055        ENABLE_FEAT_SEL2 \
1056        ENABLE_FEAT_VHE \
1057        ENABLE_MPAM_FOR_LOWER_ELS \
1058        ENABLE_RME \
1059        ENABLE_TRF_FOR_NS \
1060        FW_ENC_STATUS \
1061        NR_OF_FW_BANKS \
1062        NR_OF_IMAGES_IN_FW_BANK \
1063        RAS_EXTENSION \
1064)))
1065
1066ifdef KEY_SIZE
1067        $(eval $(call assert_numeric,KEY_SIZE))
1068endif
1069
1070ifeq ($(filter $(SANITIZE_UB), on off trap),)
1071        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1072endif
1073
1074################################################################################
1075# Add definitions to the cpp preprocessor based on the current build options.
1076# This is done after including the platform specific makefile to allow the
1077# platform to overwrite the default options
1078################################################################################
1079
1080$(eval $(call add_defines,\
1081    $(sort \
1082        ALLOW_RO_XLAT_TABLES \
1083        ARM_ARCH_MAJOR \
1084        ARM_ARCH_MINOR \
1085        BL2_ENABLE_SP_LOAD \
1086        COLD_BOOT_SINGLE_CPU \
1087        CTX_INCLUDE_AARCH32_REGS \
1088        CTX_INCLUDE_FPREGS \
1089        CTX_INCLUDE_PAUTH_REGS \
1090        EL3_EXCEPTION_HANDLING \
1091        CTX_INCLUDE_MTE_REGS \
1092        CTX_INCLUDE_EL2_REGS \
1093        CTX_INCLUDE_NEVE_REGS \
1094        DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1095        DISABLE_MTPMU \
1096        ENABLE_AMU \
1097        ENABLE_AMU_AUXILIARY_COUNTERS \
1098        ENABLE_AMU_FCONF \
1099        AMU_RESTRICT_COUNTERS \
1100        ENABLE_ASSERTIONS \
1101        ENABLE_BTI \
1102        ENABLE_MPAM_FOR_LOWER_ELS \
1103        ENABLE_PAUTH \
1104        ENABLE_PIE \
1105        ENABLE_PMF \
1106        ENABLE_PSCI_STAT \
1107        ENABLE_RME \
1108        ENABLE_RUNTIME_INSTRUMENTATION \
1109        ENABLE_SME_FOR_NS \
1110        ENABLE_SME_FOR_SWD \
1111        ENABLE_SPE_FOR_LOWER_ELS \
1112        ENABLE_SVE_FOR_NS \
1113        ENABLE_SVE_FOR_SWD \
1114        ENCRYPT_BL31 \
1115        ENCRYPT_BL32 \
1116        ERROR_DEPRECATED \
1117        FAULT_INJECTION_SUPPORT \
1118        GICV2_G0_FOR_EL3 \
1119        HANDLE_EA_EL3_FIRST \
1120        HW_ASSISTED_COHERENCY \
1121        LOG_LEVEL \
1122        MEASURED_BOOT \
1123        NS_TIMER_SWITCH \
1124        PL011_GENERIC_UART \
1125        PLAT_${PLAT} \
1126        PROGRAMMABLE_RESET_ADDRESS \
1127        PSCI_EXTENDED_STATE_ID \
1128        RAS_EXTENSION \
1129        RESET_TO_BL31 \
1130        SEPARATE_CODE_AND_RODATA \
1131        SEPARATE_BL2_NOLOAD_REGION \
1132        SEPARATE_NOBITS_REGION \
1133        RECLAIM_INIT_CODE \
1134        SPD_${SPD} \
1135        SPIN_ON_BL1_EXIT \
1136        SPM_MM \
1137        SPMD_SPM_AT_SEL2 \
1138        TRUSTED_BOARD_BOOT \
1139        CRYPTO_SUPPORT \
1140        TRNG_SUPPORT \
1141        USE_COHERENT_MEM \
1142        USE_DEBUGFS \
1143        ARM_IO_IN_DTB \
1144        SDEI_IN_FCONF \
1145        SEC_INT_DESC_IN_FCONF \
1146        USE_ROMLIB \
1147        USE_TBBR_DEFS \
1148        WARMBOOT_ENABLE_DCACHE_EARLY \
1149        BL2_AT_EL3 \
1150        BL2_IN_XIP_MEM \
1151        BL2_INV_DCACHE \
1152        USE_SPINLOCK_CAS \
1153        ERRATA_SPECULATIVE_AT \
1154        RAS_TRAP_LOWER_EL_ERR_ACCESS \
1155        COT_DESC_IN_DTB \
1156        USE_SP804_TIMER \
1157        ENABLE_FEAT_RNG \
1158        ENABLE_FEAT_SB \
1159        ENABLE_FEAT_DIT \
1160        NR_OF_FW_BANKS \
1161        NR_OF_IMAGES_IN_FW_BANK \
1162        PSA_FWU_SUPPORT \
1163        ENABLE_TRBE_FOR_NS \
1164        ENABLE_SYS_REG_TRACE_FOR_NS \
1165        ENABLE_TRF_FOR_NS \
1166        ENABLE_FEAT_HCX \
1167        ENABLE_MPMM \
1168        ENABLE_MPMM_FCONF \
1169        ENABLE_FEAT_FGT \
1170        ENABLE_FEAT_AMUv1 \
1171        ENABLE_FEAT_ECV \
1172        SIMICS_BUILD \
1173        ENABLE_FEAT_AMUv1p1 \
1174        ENABLE_FEAT_SEL2 \
1175        ENABLE_FEAT_VHE \
1176        ENABLE_FEAT_CSV2_2 \
1177        ENABLE_FEAT_PAN \
1178        FEATURE_DETECTION \
1179)))
1180
1181ifeq (${SANITIZE_UB},trap)
1182        $(eval $(call add_define,MONITOR_TRAPS))
1183endif
1184
1185# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1186ifdef EL3_PAYLOAD_BASE
1187        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1188else
1189        # Define the PRELOADED_BL33_BASE flag only if it is provided and
1190        # EL3_PAYLOAD_BASE is not defined, as it has priority.
1191        ifdef PRELOADED_BL33_BASE
1192                $(eval $(call add_define,PRELOADED_BL33_BASE))
1193        endif
1194endif
1195
1196# Define the DYN_DISABLE_AUTH flag only if set.
1197ifeq (${DYN_DISABLE_AUTH},1)
1198$(eval $(call add_define,DYN_DISABLE_AUTH))
1199endif
1200
1201ifneq ($(findstring armlink,$(notdir $(LD))),)
1202$(eval $(call add_define,USE_ARM_LINK))
1203endif
1204
1205# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1206ifeq (${SPD},spmd)
1207ifdef SP_LAYOUT_FILE
1208        -include $(BUILD_PLAT)/sp_gen.mk
1209        FIP_DEPS += sp
1210        CRT_DEPS += sp
1211        NEED_SP_PKG := yes
1212else
1213        ifeq (${SPMD_SPM_AT_SEL2},1)
1214            $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1215        endif
1216endif
1217endif
1218
1219################################################################################
1220# Build targets
1221################################################################################
1222
1223.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1224.SUFFIXES:
1225
1226all: msg_start
1227
1228msg_start:
1229	@echo "Building ${PLAT}"
1230
1231ifeq (${ERROR_DEPRECATED},0)
1232# Check if deprecated declarations and cpp warnings should be treated as error or not.
1233ifneq ($(findstring clang,$(notdir $(CC))),)
1234    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1235else
1236    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1237endif
1238endif # !ERROR_DEPRECATED
1239
1240$(eval $(call MAKE_LIB_DIRS))
1241$(eval $(call MAKE_LIB,c))
1242
1243# Expand build macros for the different images
1244ifeq (${NEED_BL1},yes)
1245BL1_SOURCES := $(sort ${BL1_SOURCES})
1246
1247$(eval $(call MAKE_BL,bl1))
1248endif
1249
1250ifeq (${NEED_BL2},yes)
1251ifeq (${BL2_AT_EL3}, 0)
1252FIP_BL2_ARGS := tb-fw
1253endif
1254
1255BL2_SOURCES := $(sort ${BL2_SOURCES})
1256
1257$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1258	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1259endif
1260
1261ifeq (${NEED_SCP_BL2},yes)
1262$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1263endif
1264
1265ifeq (${NEED_BL31},yes)
1266BL31_SOURCES += ${SPD_SOURCES}
1267# Sort BL31 source files to remove duplicates
1268BL31_SOURCES := $(sort ${BL31_SOURCES})
1269ifneq (${DECRYPTION_SUPPORT},none)
1270$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1271	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1272else
1273$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1274	$(eval $(call MAKE_BL,bl31,soc-fw)))
1275endif
1276endif
1277
1278# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1279# build system will call TOOL_ADD_IMG to print a warning message and abort the
1280# process. Note that the dependency on BL32 applies to the FIP only.
1281ifeq (${NEED_BL32},yes)
1282# Sort BL32 source files to remove duplicates
1283BL32_SOURCES := $(sort ${BL32_SOURCES})
1284BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1285
1286ifneq (${DECRYPTION_SUPPORT},none)
1287$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1288	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1289else
1290$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1291	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1292endif
1293endif
1294
1295# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1296# needs to be built from RMM_SOURCES.
1297ifeq (${NEED_RMM},yes)
1298# Sort RMM source files to remove duplicates
1299RMM_SOURCES := $(sort ${RMM_SOURCES})
1300BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1301
1302$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1303         $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1304endif
1305
1306# Add the BL33 image if required by the platform
1307ifeq (${NEED_BL33},yes)
1308$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1309endif
1310
1311ifeq (${NEED_BL2U},yes)
1312$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1313	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1314endif
1315
1316# Expand build macros for the different images
1317ifeq (${NEED_FDT},yes)
1318    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1319endif
1320
1321# Add Secure Partition packages
1322ifeq (${NEED_SP_PKG},yes)
1323$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1324	${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT}
1325sp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk
1326	${Q}$(SPTOOL) $(SPTOOL_ARGS)
1327	@${ECHO_BLANK_LINE}
1328	@echo "Built SP Images successfully"
1329	@${ECHO_BLANK_LINE}
1330endif
1331
1332locate-checkpatch:
1333ifndef CHECKPATCH
1334	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1335else
1336ifeq (,$(wildcard ${CHECKPATCH}))
1337	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1338endif
1339endif
1340
1341clean:
1342	@echo "  CLEAN"
1343	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1344ifdef UNIX_MK
1345	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1346else
1347# Clear the MAKEFLAGS as we do not want
1348# to pass the gnumake flags to nmake.
1349	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1350endif
1351	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1352	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1353	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1354
1355realclean distclean:
1356	@echo "  REALCLEAN"
1357	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1358	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1359ifdef UNIX_MK
1360	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1361else
1362# Clear the MAKEFLAGS as we do not want
1363# to pass the gnumake flags to nmake.
1364	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1365endif
1366	${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean
1367	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1368	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1369	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1370
1371checkcodebase:		locate-checkpatch
1372	@echo "  CHECKING STYLE"
1373	@if test -d .git ; then						\
1374		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1375		while read GIT_FILE ;					\
1376		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1377		done ;							\
1378	else								\
1379		 find . -type f -not -iwholename "*.git*"		\
1380		 -not -iwholename "*build*"				\
1381		 -not -iwholename "*libfdt*"				\
1382		 -not -iwholename "*libc*"				\
1383		 -not -iwholename "*docs*"				\
1384		 -not -iwholename "*.rst"				\
1385		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1386	fi
1387
1388checkpatch:		locate-checkpatch
1389	@echo "  CHECKING STYLE"
1390	@if test -n "${CHECKPATCH_OPTS}"; then				\
1391		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1392	fi
1393	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1394	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1395	do								\
1396		printf "\n[*] Checking style of '$$commit'\n\n";	\
1397		git log --format=email "$$commit~..$$commit"		\
1398			-- ${CHECK_PATHS} |				\
1399			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1400		git diff --format=email "$$commit~..$$commit"		\
1401			-- ${CHECK_PATHS} |				\
1402			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1403	done
1404
1405certtool: ${CRTTOOL}
1406
1407${CRTTOOL}: FORCE
1408	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} --no-print-directory -C ${CRTTOOLPATH}
1409	@${ECHO_BLANK_LINE}
1410	@echo "Built $@ successfully"
1411	@${ECHO_BLANK_LINE}
1412
1413ifneq (${GENERATE_COT},0)
1414certificates: ${CRT_DEPS} ${CRTTOOL}
1415	${Q}${CRTTOOL} ${CRT_ARGS}
1416	@${ECHO_BLANK_LINE}
1417	@echo "Built $@ successfully"
1418	@echo "Certificates can be found in ${BUILD_PLAT}"
1419	@${ECHO_BLANK_LINE}
1420endif
1421
1422${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1423	$(eval ${CHECK_FIP_CMD})
1424	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1425	${Q}${FIPTOOL} info $@
1426	@${ECHO_BLANK_LINE}
1427	@echo "Built $@ successfully"
1428	@${ECHO_BLANK_LINE}
1429
1430ifneq (${GENERATE_COT},0)
1431fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1432	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1433	@${ECHO_BLANK_LINE}
1434	@echo "Built $@ successfully"
1435	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1436	@${ECHO_BLANK_LINE}
1437endif
1438
1439${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1440	$(eval ${CHECK_FWU_FIP_CMD})
1441	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1442	${Q}${FIPTOOL} info $@
1443	@${ECHO_BLANK_LINE}
1444	@echo "Built $@ successfully"
1445	@${ECHO_BLANK_LINE}
1446
1447fiptool: ${FIPTOOL}
1448fip: ${BUILD_PLAT}/${FIP_NAME}
1449fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1450
1451${FIPTOOL}: FORCE
1452ifdef UNIX_MK
1453	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH}
1454else
1455# Clear the MAKEFLAGS as we do not want
1456# to pass the gnumake flags to nmake.
1457	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1458endif
1459
1460sptool: ${SPTOOL}
1461${SPTOOL}: FORCE
1462	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH}
1463
1464romlib.bin: libraries FORCE
1465	${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
1466
1467# Call print_memory_map tool
1468memmap: all
1469	${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP}
1470
1471doc:
1472	@echo "  BUILD DOCUMENTATION"
1473	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1474
1475enctool: ${ENCTOOL}
1476
1477${ENCTOOL}: FORCE
1478	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH}
1479	@${ECHO_BLANK_LINE}
1480	@echo "Built $@ successfully"
1481	@${ECHO_BLANK_LINE}
1482
1483cscope:
1484	@echo "  CSCOPE"
1485	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1486	${Q}cscope -b -q -k
1487
1488help:
1489	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1490	@echo ""
1491	@echo "PLAT is used to specify which platform you wish to build."
1492	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1493	@echo ""
1494	@echo "platform = ${PLATFORM_LIST}"
1495	@echo ""
1496	@echo "Please refer to the User Guide for a list of all supported options."
1497	@echo "Note that the build system doesn't track dependencies for build "
1498	@echo "options. Therefore, if any of the build options are changed "
1499	@echo "from a previous build, a clean build must be performed."
1500	@echo ""
1501	@echo "Supported Targets:"
1502	@echo "  all            Build all individual bootloader binaries"
1503	@echo "  bl1            Build the BL1 binary"
1504	@echo "  bl2            Build the BL2 binary"
1505	@echo "  bl2u           Build the BL2U binary"
1506	@echo "  bl31           Build the BL31 binary"
1507	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1508	@echo "                 this builds secure payload specified by AARCH32_SP"
1509	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1510	@echo "  fip            Build the Firmware Image Package (FIP)"
1511	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1512	@echo "  checkcodebase  Check the coding style of the entire source tree"
1513	@echo "  checkpatch     Check the coding style on changes in the current"
1514	@echo "                 branch against BASE_COMMIT (default origin/master)"
1515	@echo "  clean          Clean the build for the selected platform"
1516	@echo "  cscope         Generate cscope index"
1517	@echo "  distclean      Remove all build artifacts for all platforms"
1518	@echo "  certtool       Build the Certificate generation tool"
1519	@echo "  enctool        Build the Firmware encryption tool"
1520	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1521	@echo "  sp             Build the Secure Partition Packages"
1522	@echo "  sptool         Build the Secure Partition Package creation tool"
1523	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1524	@echo "  memmap         Print the memory map of the built binaries"
1525	@echo "  doc            Build html based documentation using Sphinx tool"
1526	@echo ""
1527	@echo "Note: most build targets require PLAT to be set to a specific platform."
1528	@echo ""
1529	@echo "example: build all targets for the FVP platform:"
1530	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1531
1532.PHONY: FORCE
1533FORCE:;
1534