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