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