xref: /rk3399_ARM-atf/Makefile (revision 1684b8733d2423032552c8148a24d8e274f51d71)
1#
2# Copyright (c) 2013-2018, 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			:= 1
11VERSION_MINOR			:= 5
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
29ifdef ASM_ASSERTION
30        $(warning ASM_ASSERTION is removed, use ENABLE_ASSERTIONS instead.)
31endif
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34
35# Assertions enabled for DEBUG builds by default
36ENABLE_ASSERTIONS		:= ${DEBUG}
37ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
38PLAT				:= ${DEFAULT_PLAT}
39
40################################################################################
41# Checkpatch script options
42################################################################################
43
44CHECKCODE_ARGS		:=	--no-patch
45# Do not check the coding style on imported library files or documentation files
46INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
47					include/lib/libfdt		\
48					include/lib/stdlib,		\
49					$(wildcard include/lib/*)))
50INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
51					include/lib,			\
52					$(wildcard include/*)))
53LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
54					lib/compiler-rt			\
55					lib/libfdt%			\
56					lib/stdlib,			\
57					$(wildcard lib/*)))
58ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					lib				\
60					include				\
61					docs				\
62					%.md,				\
63					$(wildcard *)))
64CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
65				${INC_DIRS_TO_CHECK}			\
66				${INC_LIB_DIRS_TO_CHECK}		\
67				${LIB_DIRS_TO_CHECK}
68
69
70################################################################################
71# Process build options
72################################################################################
73
74# Verbose flag
75ifeq (${V},0)
76        Q:=@
77        CHECKCODE_ARGS	+=	--no-summary --terse
78else
79        Q:=
80endif
81export Q
82
83# Process Debug flag
84$(eval $(call add_define,DEBUG))
85ifneq (${DEBUG}, 0)
86        BUILD_TYPE	:=	debug
87        TF_CFLAGS	+= 	-g
88
89        ifneq ($(findstring clang,$(notdir $(CC))),)
90             ASFLAGS		+= 	-g
91        else
92             ASFLAGS		+= 	-g -Wa,--gdwarf-2
93        endif
94
95        # Use LOG_LEVEL_INFO by default for debug builds
96        LOG_LEVEL	:=	40
97else
98        BUILD_TYPE	:=	release
99        # Use LOG_LEVEL_NOTICE by default for release builds
100        LOG_LEVEL	:=	20
101endif
102
103# Default build string (git branch and commit)
104ifeq (${BUILD_STRING},)
105        BUILD_STRING	:=	$(shell git describe --always --dirty --tags 2> /dev/null)
106endif
107VERSION_STRING		:=	v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING}
108
109# The cert_create tool cannot generate certificates individually, so we use the
110# target 'certificates' to create them all
111ifneq (${GENERATE_COT},0)
112        FIP_DEPS += certificates
113        FWU_FIP_DEPS += fwu_certificates
114endif
115
116
117################################################################################
118# Toolchain
119################################################################################
120
121HOSTCC			:=	gcc
122export HOSTCC
123
124CC			:=	${CROSS_COMPILE}gcc
125CPP			:=	${CROSS_COMPILE}cpp
126AS			:=	${CROSS_COMPILE}gcc
127AR			:=	${CROSS_COMPILE}ar
128LINKER			:=	${CROSS_COMPILE}ld
129OC			:=	${CROSS_COMPILE}objcopy
130OD			:=	${CROSS_COMPILE}objdump
131NM			:=	${CROSS_COMPILE}nm
132PP			:=	${CROSS_COMPILE}gcc -E
133DTC			:=	dtc
134
135# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
136ifneq ($(strip $(wildcard ${LD}.bfd) \
137	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
138LINKER			:=	${LINKER}.bfd
139endif
140
141ifeq (${ARM_ARCH_MAJOR},7)
142target32-directive	= 	-target arm-none-eabi
143# Will set march32-directive from platform configuration
144else
145target32-directive	= 	-target armv8a-none-eabi
146march32-directive	= 	-march=armv8-a
147endif
148
149ifeq ($(notdir $(CC)),armclang)
150TF_CFLAGS_aarch32	=	-target arm-arm-none-eabi $(march32-directive)
151TF_CFLAGS_aarch64	=	-target aarch64-arm-none-eabi -march=armv8-a
152LD			=	$(LINKER)
153AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
154else ifneq ($(findstring clang,$(notdir $(CC))),)
155TF_CFLAGS_aarch32	=	$(target32-directive)
156TF_CFLAGS_aarch64	=	-target aarch64-elf
157LD			=	$(LINKER)
158AS			=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
159else
160TF_CFLAGS_aarch32	=	$(march32-directive)
161TF_CFLAGS_aarch64	=	-march=armv8-a
162LD			=	$(LINKER)
163endif
164
165TF_CFLAGS_aarch32	+=	-mno-unaligned-access
166TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
167
168ASFLAGS_aarch32		=	$(march32-directive)
169ASFLAGS_aarch64		=	-march=armv8-a
170
171CPPFLAGS		=	${DEFINES} ${INCLUDES} -nostdinc		\
172				-Wmissing-include-dirs -Werror
173ASFLAGS			+=	$(CPPFLAGS) $(ASFLAGS_$(ARCH))			\
174				-D__ASSEMBLY__ -ffreestanding 			\
175				-Wa,--fatal-warnings
176TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
177				-ffreestanding -fno-builtin -Wall -std=gnu99	\
178				-Os -ffunction-sections -fdata-sections
179
180GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
181PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
182
183ifneq ($(PIE_FOUND),)
184TF_CFLAGS		+=	-fno-PIE
185endif
186
187TF_LDFLAGS		+=	--fatal-warnings -O1
188TF_LDFLAGS		+=	--gc-sections
189TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
190
191DTC_FLAGS		+=	-I dts -O dtb
192
193################################################################################
194# Common sources and include directories
195################################################################################
196include lib/compiler-rt/compiler-rt.mk
197include lib/stdlib/stdlib.mk
198
199BL_COMMON_SOURCES	+=	common/bl_common.c			\
200				common/tf_log.c				\
201				common/tf_printf.c			\
202				common/tf_snprintf.c			\
203				common/${ARCH}/debug.S			\
204				lib/${ARCH}/cache_helpers.S		\
205				lib/${ARCH}/misc_helpers.S		\
206				plat/common/plat_bl_common.c		\
207				plat/common/plat_log_common.c		\
208				plat/common/${ARCH}/plat_common.c	\
209				plat/common/${ARCH}/platform_helpers.S	\
210				${COMPILER_RT_SRCS}			\
211				${STDLIB_SRCS}
212
213INCLUDES		+=	-Iinclude				\
214				-Iinclude/bl1				\
215				-Iinclude/bl2				\
216				-Iinclude/bl2u				\
217				-Iinclude/bl31				\
218				-Iinclude/common			\
219				-Iinclude/common/${ARCH}		\
220				-Iinclude/drivers			\
221				-Iinclude/drivers/arm			\
222				-Iinclude/drivers/auth			\
223				-Iinclude/drivers/io			\
224				-Iinclude/drivers/ti/uart		\
225				-Iinclude/lib				\
226				-Iinclude/lib/${ARCH}			\
227				-Iinclude/lib/cpus			\
228				-Iinclude/lib/cpus/${ARCH}		\
229				-Iinclude/lib/el3_runtime		\
230				-Iinclude/lib/el3_runtime/${ARCH}	\
231				-Iinclude/lib/extensions		\
232				-Iinclude/lib/pmf			\
233				-Iinclude/lib/psci			\
234				-Iinclude/lib/xlat_tables		\
235				-Iinclude/plat/common			\
236				-Iinclude/services			\
237				${PLAT_INCLUDES}			\
238				${SPD_INCLUDES}				\
239				-Iinclude/tools_share
240
241
242################################################################################
243# Generic definitions
244################################################################################
245
246include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
247
248BUILD_BASE		:=	./build
249BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
250
251SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
252
253# Platforms providing their own TBB makefile may override this value
254INCLUDE_TBBR_MK		:=	1
255
256
257################################################################################
258# Include SPD Makefile if one has been specified
259################################################################################
260
261ifneq (${SPD},none)
262ifeq (${ARCH},aarch32)
263	$(error "Error: SPD is incompatible with AArch32.")
264endif
265ifdef EL3_PAYLOAD_BASE
266        $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
267        $(warning "The SPD and its BL32 companion will be present but ignored.")
268endif
269        # We expect to locate an spd.mk under the specified SPD directory
270        SPD_MAKE	:=	$(wildcard services/spd/${SPD}/${SPD}.mk)
271
272        ifeq (${SPD_MAKE},)
273                $(error Error: No services/spd/${SPD}/${SPD}.mk located)
274        endif
275        $(info Including ${SPD_MAKE})
276        include ${SPD_MAKE}
277
278        # If there's BL32 companion for the chosen SPD, we expect that the SPD's
279        # Makefile would set NEED_BL32 to "yes". In this case, the build system
280        # supports two mutually exclusive options:
281        # * BL32 is built from source: then BL32_SOURCES must contain the list
282        #   of source files to build BL32
283        # * BL32 is a prebuilt binary: then BL32 must point to the image file
284        #   that will be included in the FIP
285        # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
286        # over the sources.
287endif
288
289################################################################################
290# Include the platform specific Makefile after the SPD Makefile (the platform
291# makefile may use all previous definitions in this file)
292################################################################################
293
294include ${PLAT_MAKEFILE_FULL}
295
296$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
297
298ifeq (${ARM_ARCH_MAJOR},7)
299include make_helpers/armv7-a-cpus.mk
300endif
301
302# Platform compatibility is not supported in AArch32
303ifneq (${ARCH},aarch32)
304# If the platform has not defined ENABLE_PLAT_COMPAT, then enable it by default
305ifndef ENABLE_PLAT_COMPAT
306ENABLE_PLAT_COMPAT := 1
307endif
308
309# Include the platform compatibility helpers for PSCI
310ifneq (${ENABLE_PLAT_COMPAT}, 0)
311include plat/compat/plat_compat.mk
312endif
313endif
314
315# Include the CPU specific operations makefile, which provides default
316# values for all CPU errata workarounds and CPU specific optimisations.
317# This can be overridden by the platform.
318include lib/cpus/cpu-ops.mk
319
320ifeq (${ARCH},aarch32)
321NEED_BL32 := yes
322
323################################################################################
324# Build `AARCH32_SP` as BL32 image for AArch32
325################################################################################
326ifneq (${AARCH32_SP},none)
327# We expect to locate an sp.mk under the specified AARCH32_SP directory
328AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
329
330ifeq (${AARCH32_SP_MAKE},)
331  $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
332endif
333
334$(info Including ${AARCH32_SP_MAKE})
335include ${AARCH32_SP_MAKE}
336endif
337
338endif
339
340################################################################################
341# Check incompatible options
342################################################################################
343
344ifdef EL3_PAYLOAD_BASE
345        ifdef PRELOADED_BL33_BASE
346                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
347                incompatible build options. EL3_PAYLOAD_BASE has priority.")
348        endif
349        ifneq (${GENERATE_COT},0)
350                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.")
351        endif
352        ifneq (${TRUSTED_BOARD_BOOT},0)
353                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.")
354        endif
355endif
356
357ifeq (${NEED_BL33},yes)
358        ifdef EL3_PAYLOAD_BASE
359                $(warning "BL33 image is not needed when option \
360                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
361        endif
362        ifdef PRELOADED_BL33_BASE
363                $(warning "BL33 image is not needed when option \
364                PRELOADED_BL33_BASE is used and won't be added to the FIP \
365                file.")
366        endif
367endif
368
369# For AArch32, LOAD_IMAGE_V2 must be enabled.
370ifeq (${ARCH},aarch32)
371    ifeq (${LOAD_IMAGE_V2}, 0)
372        $(error "For AArch32, LOAD_IMAGE_V2 must be enabled.")
373    endif
374endif
375
376# When building for systems with hardware-assisted coherency, there's no need to
377# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
378ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
379$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
380endif
381
382ifneq ($(MULTI_CONSOLE_API), 0)
383    ifeq (${ARCH},aarch32)
384        $(error "Error: MULTI_CONSOLE_API is not supported for AArch32")
385    endif
386endif
387
388#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1.
389ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1)
390$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled")
391endif
392
393# SMC Calling Convention checks
394ifneq (${SMCCC_MAJOR_VERSION},1)
395    ifneq (${SPD},none)
396        $(error "SMC Calling Convention 1.X must be used with SPDs")
397    endif
398    ifeq (${ARCH},aarch32)
399        $(error "Only SMCCC 1.X is supported in AArch32 mode.")
400    endif
401endif
402
403# For RAS_EXTENSION, require that EAs are handled in EL3 first
404ifeq ($(RAS_EXTENSION),1)
405    ifneq ($(HANDLE_EA_EL3_FIRST),1)
406        $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1)
407    endif
408endif
409
410# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled
411ifeq ($(FAULT_INJECTION_SUPPORT),1)
412    ifneq ($(RAS_EXTENSION),1)
413        $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1)
414    endif
415endif
416
417# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1 and LOAD_IMAGE_V2=1
418ifeq ($(DYN_DISABLE_AUTH), 1)
419    ifeq (${TRUSTED_BOARD_BOOT}, 0)
420        $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.")
421    endif
422    ifeq (${LOAD_IMAGE_V2}, 0)
423        $(error "DYN_DISABLE_AUTH is only supported for LOAD_IMAGE_V2.")
424    endif
425endif
426
427################################################################################
428# Process platform overrideable behaviour
429################################################################################
430
431# Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
432# supplied for the FIP and Certificate generation tools. This flag can be
433# overridden by the platform.
434ifdef BL2_SOURCES
435        ifdef EL3_PAYLOAD_BASE
436                # If booting an EL3 payload there is no need for a BL33 image
437                # in the FIP file.
438                NEED_BL33		:=	no
439        else
440                ifdef PRELOADED_BL33_BASE
441                        # If booting a BL33 preloaded image there is no need of
442                        # another one in the FIP file.
443                        NEED_BL33		:=	no
444                else
445                        NEED_BL33		?=	yes
446                endif
447        endif
448endif
449
450# If SCP_BL2 is given, we always want FIP to include it.
451ifdef SCP_BL2
452        NEED_SCP_BL2		:=	yes
453endif
454
455# For AArch32, BL31 is not currently supported.
456ifneq (${ARCH},aarch32)
457    ifdef BL31_SOURCES
458        # When booting an EL3 payload, there is no need to compile the BL31 image nor
459        # put it in the FIP.
460        ifndef EL3_PAYLOAD_BASE
461            NEED_BL31 := yes
462        endif
463    endif
464endif
465
466# Process TBB related flags
467ifneq (${GENERATE_COT},0)
468        # Common cert_create options
469        ifneq (${CREATE_KEYS},0)
470                $(eval CRT_ARGS += -n)
471                $(eval FWU_CRT_ARGS += -n)
472                ifneq (${SAVE_KEYS},0)
473                        $(eval CRT_ARGS += -k)
474                        $(eval FWU_CRT_ARGS += -k)
475                endif
476        endif
477        # Include TBBR makefile (unless the platform indicates otherwise)
478        ifeq (${INCLUDE_TBBR_MK},1)
479                include make_helpers/tbbr/tbbr_tools.mk
480        endif
481endif
482
483ifneq (${FIP_ALIGN},0)
484FIP_ARGS += --align ${FIP_ALIGN}
485endif
486
487################################################################################
488# Include libraries' Makefile that are used in all BL
489################################################################################
490
491include lib/stack_protector/stack_protector.mk
492
493################################################################################
494# Auxiliary tools (fiptool, cert_create, etc)
495################################################################################
496
497# Variables for use with Certificate Generation Tool
498CRTTOOLPATH		?=	tools/cert_create
499CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
500
501# Variables for use with Firmware Image Package
502FIPTOOLPATH		?=	tools/fiptool
503FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
504
505################################################################################
506# Include BL specific makefiles
507################################################################################
508ifdef BL1_SOURCES
509NEED_BL1 := yes
510include bl1/bl1.mk
511endif
512
513ifdef BL2_SOURCES
514NEED_BL2 := yes
515include bl2/bl2.mk
516endif
517
518ifdef BL2U_SOURCES
519NEED_BL2U := yes
520include bl2u/bl2u.mk
521endif
522
523ifeq (${NEED_BL31},yes)
524ifdef BL31_SOURCES
525include bl31/bl31.mk
526endif
527endif
528
529ifdef FDT_SOURCES
530NEED_FDT := yes
531endif
532
533################################################################################
534# Build options checks
535################################################################################
536
537$(eval $(call assert_boolean,COLD_BOOT_SINGLE_CPU))
538$(eval $(call assert_boolean,CREATE_KEYS))
539$(eval $(call assert_boolean,CTX_INCLUDE_AARCH32_REGS))
540$(eval $(call assert_boolean,CTX_INCLUDE_FPREGS))
541$(eval $(call assert_boolean,DEBUG))
542$(eval $(call assert_boolean,DISABLE_PEDANTIC))
543$(eval $(call assert_boolean,DYN_DISABLE_AUTH))
544$(eval $(call assert_boolean,EL3_EXCEPTION_HANDLING))
545$(eval $(call assert_boolean,ENABLE_AMU))
546$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
547$(eval $(call assert_boolean,ENABLE_PLAT_COMPAT))
548$(eval $(call assert_boolean,ENABLE_PMF))
549$(eval $(call assert_boolean,ENABLE_PSCI_STAT))
550$(eval $(call assert_boolean,ENABLE_RUNTIME_INSTRUMENTATION))
551$(eval $(call assert_boolean,ENABLE_SPE_FOR_LOWER_ELS))
552$(eval $(call assert_boolean,ENABLE_SPM))
553$(eval $(call assert_boolean,ENABLE_SVE_FOR_NS))
554$(eval $(call assert_boolean,ERROR_DEPRECATED))
555$(eval $(call assert_boolean,FAULT_INJECTION_SUPPORT))
556$(eval $(call assert_boolean,GENERATE_COT))
557$(eval $(call assert_boolean,GICV2_G0_FOR_EL3))
558$(eval $(call assert_boolean,HANDLE_EA_EL3_FIRST))
559$(eval $(call assert_boolean,HW_ASSISTED_COHERENCY))
560$(eval $(call assert_boolean,LOAD_IMAGE_V2))
561$(eval $(call assert_boolean,MULTI_CONSOLE_API))
562$(eval $(call assert_boolean,NS_TIMER_SWITCH))
563$(eval $(call assert_boolean,PL011_GENERIC_UART))
564$(eval $(call assert_boolean,PROGRAMMABLE_RESET_ADDRESS))
565$(eval $(call assert_boolean,PSCI_EXTENDED_STATE_ID))
566$(eval $(call assert_boolean,RAS_EXTENSION))
567$(eval $(call assert_boolean,RESET_TO_BL31))
568$(eval $(call assert_boolean,SAVE_KEYS))
569$(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA))
570$(eval $(call assert_boolean,SPIN_ON_BL1_EXIT))
571$(eval $(call assert_boolean,TRUSTED_BOARD_BOOT))
572$(eval $(call assert_boolean,USE_COHERENT_MEM))
573$(eval $(call assert_boolean,USE_TBBR_DEFS))
574$(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY))
575$(eval $(call assert_boolean,BL2_AT_EL3))
576$(eval $(call assert_boolean,BL2_IN_XIP_MEM))
577
578$(eval $(call assert_numeric,ARM_ARCH_MAJOR))
579$(eval $(call assert_numeric,ARM_ARCH_MINOR))
580$(eval $(call assert_numeric,SMCCC_MAJOR_VERSION))
581
582################################################################################
583# Add definitions to the cpp preprocessor based on the current build options.
584# This is done after including the platform specific makefile to allow the
585# platform to overwrite the default options
586################################################################################
587
588$(eval $(call add_define,ARM_ARCH_MAJOR))
589$(eval $(call add_define,ARM_ARCH_MINOR))
590$(eval $(call add_define,ARM_GIC_ARCH))
591$(eval $(call add_define,COLD_BOOT_SINGLE_CPU))
592$(eval $(call add_define,CTX_INCLUDE_AARCH32_REGS))
593$(eval $(call add_define,CTX_INCLUDE_FPREGS))
594$(eval $(call add_define,EL3_EXCEPTION_HANDLING))
595$(eval $(call add_define,ENABLE_AMU))
596$(eval $(call add_define,ENABLE_ASSERTIONS))
597$(eval $(call add_define,ENABLE_PLAT_COMPAT))
598$(eval $(call add_define,ENABLE_PMF))
599$(eval $(call add_define,ENABLE_PSCI_STAT))
600$(eval $(call add_define,ENABLE_RUNTIME_INSTRUMENTATION))
601$(eval $(call add_define,ENABLE_SPE_FOR_LOWER_ELS))
602$(eval $(call add_define,ENABLE_SPM))
603$(eval $(call add_define,ENABLE_SVE_FOR_NS))
604$(eval $(call add_define,ERROR_DEPRECATED))
605$(eval $(call add_define,FAULT_INJECTION_SUPPORT))
606$(eval $(call add_define,GICV2_G0_FOR_EL3))
607$(eval $(call add_define,HANDLE_EA_EL3_FIRST))
608$(eval $(call add_define,HW_ASSISTED_COHERENCY))
609$(eval $(call add_define,LOAD_IMAGE_V2))
610$(eval $(call add_define,LOG_LEVEL))
611$(eval $(call add_define,MULTI_CONSOLE_API))
612$(eval $(call add_define,NS_TIMER_SWITCH))
613$(eval $(call add_define,PL011_GENERIC_UART))
614$(eval $(call add_define,PLAT_${PLAT}))
615$(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
616$(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
617$(eval $(call add_define,RAS_EXTENSION))
618$(eval $(call add_define,RESET_TO_BL31))
619$(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
620$(eval $(call add_define,SMCCC_MAJOR_VERSION))
621$(eval $(call add_define,SPD_${SPD}))
622$(eval $(call add_define,SPIN_ON_BL1_EXIT))
623$(eval $(call add_define,TRUSTED_BOARD_BOOT))
624$(eval $(call add_define,USE_COHERENT_MEM))
625$(eval $(call add_define,USE_TBBR_DEFS))
626$(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY))
627$(eval $(call add_define,BL2_AT_EL3))
628$(eval $(call add_define,BL2_IN_XIP_MEM))
629
630# Define the EL3_PAYLOAD_BASE flag only if it is provided.
631ifdef EL3_PAYLOAD_BASE
632        $(eval $(call add_define,EL3_PAYLOAD_BASE))
633else
634        # Define the PRELOADED_BL33_BASE flag only if it is provided and
635        # EL3_PAYLOAD_BASE is not defined, as it has priority.
636        ifdef PRELOADED_BL33_BASE
637                $(eval $(call add_define,PRELOADED_BL33_BASE))
638        endif
639endif
640# Define the AARCH32/AARCH64 flag based on the ARCH flag
641ifeq (${ARCH},aarch32)
642        $(eval $(call add_define,AARCH32))
643else
644        $(eval $(call add_define,AARCH64))
645endif
646
647# Define the DYN_DISABLE_AUTH flag only if set.
648ifeq (${DYN_DISABLE_AUTH},1)
649$(eval $(call add_define,DYN_DISABLE_AUTH))
650endif
651
652################################################################################
653# Build targets
654################################################################################
655
656.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip fwu_fip certtool dtbs
657.SUFFIXES:
658
659all: msg_start
660
661msg_start:
662	@echo "Building ${PLAT}"
663
664# Check if deprecated declarations and cpp warnings should be treated as error or not.
665ifeq (${ERROR_DEPRECATED},0)
666    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
667endif
668
669# Expand build macros for the different images
670ifeq (${NEED_BL1},yes)
671$(eval $(call MAKE_BL,1))
672endif
673
674ifeq (${NEED_BL2},yes)
675ifeq (${BL2_AT_EL3}, 0)
676FIP_BL2_ARGS := tb-fw
677endif
678
679$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
680	$(eval $(call MAKE_BL,2,${FIP_BL2_ARGS})))
681endif
682
683ifeq (${NEED_SCP_BL2},yes)
684$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
685endif
686
687ifeq (${NEED_BL31},yes)
688BL31_SOURCES += ${SPD_SOURCES}
689$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
690	$(eval $(call MAKE_BL,31,soc-fw)))
691endif
692
693# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
694# build system will call TOOL_ADD_IMG to print a warning message and abort the
695# process. Note that the dependency on BL32 applies to the FIP only.
696ifeq (${NEED_BL32},yes)
697
698BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
699
700$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,32,tos-fw)),\
701	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
702endif
703
704# Add the BL33 image if required by the platform
705ifeq (${NEED_BL33},yes)
706$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
707endif
708
709ifeq (${NEED_BL2U},yes)
710$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
711	$(eval $(call MAKE_BL,2u,ap-fwu-cfg,FWU_)))
712endif
713
714# Expand build macros for the different images
715ifeq (${NEED_FDT},yes)
716    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
717endif
718
719locate-checkpatch:
720ifndef CHECKPATCH
721	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
722else
723ifeq (,$(wildcard ${CHECKPATCH}))
724	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
725endif
726endif
727
728clean:
729	@echo "  CLEAN"
730	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
731	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
732	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
733
734realclean distclean:
735	@echo "  REALCLEAN"
736	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
737	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
738	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
739	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
740
741checkcodebase:		locate-checkpatch
742	@echo "  CHECKING STYLE"
743	@if test -d .git ; then						\
744		git ls-files | grep -E -v 'libfdt|stdlib|docs|\.md' |	\
745		while read GIT_FILE ;					\
746		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
747		done ;							\
748	else								\
749		 find . -type f -not -iwholename "*.git*"		\
750		 -not -iwholename "*build*"				\
751		 -not -iwholename "*libfdt*"				\
752		 -not -iwholename "*stdlib*"				\
753		 -not -iwholename "*docs*"				\
754		 -not -iwholename "*.md"				\
755		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
756	fi
757
758checkpatch:		locate-checkpatch
759	@echo "  CHECKING STYLE"
760	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
761	for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do		\
762		printf "\n[*] Checking style of '$$commit'\n\n";	\
763		git log --format=email "$$commit~..$$commit"		\
764			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
765		git diff --format=email "$$commit~..$$commit"		\
766			-- ${CHECK_PATHS} | ${CHECKPATCH} - || true;	\
767	done
768
769certtool: ${CRTTOOL}
770
771.PHONY: ${CRTTOOL}
772${CRTTOOL}:
773	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} --no-print-directory -C ${CRTTOOLPATH}
774	@${ECHO_BLANK_LINE}
775	@echo "Built $@ successfully"
776	@${ECHO_BLANK_LINE}
777
778ifneq (${GENERATE_COT},0)
779certificates: ${CRT_DEPS} ${CRTTOOL}
780	${Q}${CRTTOOL} ${CRT_ARGS}
781	@${ECHO_BLANK_LINE}
782	@echo "Built $@ successfully"
783	@echo "Certificates can be found in ${BUILD_PLAT}"
784	@${ECHO_BLANK_LINE}
785endif
786
787${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
788	${Q}${FIPTOOL} create ${FIP_ARGS} $@
789	${Q}${FIPTOOL} info $@
790	@${ECHO_BLANK_LINE}
791	@echo "Built $@ successfully"
792	@${ECHO_BLANK_LINE}
793
794ifneq (${GENERATE_COT},0)
795fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
796	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
797	@${ECHO_BLANK_LINE}
798	@echo "Built $@ successfully"
799	@echo "FWU certificates can be found in ${BUILD_PLAT}"
800	@${ECHO_BLANK_LINE}
801endif
802
803${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
804	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
805	${Q}${FIPTOOL} info $@
806	@${ECHO_BLANK_LINE}
807	@echo "Built $@ successfully"
808	@${ECHO_BLANK_LINE}
809
810fiptool: ${FIPTOOL}
811fip: ${BUILD_PLAT}/${FIP_NAME}
812fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
813
814.PHONY: ${FIPTOOL}
815${FIPTOOL}:
816	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH}
817
818cscope:
819	@echo "  CSCOPE"
820	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
821	${Q}cscope -b -q -k
822
823help:
824	@echo "usage: ${MAKE} PLAT=<${PLATFORM_LIST}> [OPTIONS] [TARGET]"
825	@echo ""
826	@echo "PLAT is used to specify which platform you wish to build."
827	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
828	@echo ""
829	@echo "Please refer to the User Guide for a list of all supported options."
830	@echo "Note that the build system doesn't track dependencies for build "
831	@echo "options. Therefore, if any of the build options are changed "
832	@echo "from a previous build, a clean build must be performed."
833	@echo ""
834	@echo "Supported Targets:"
835	@echo "  all            Build all individual bootloader binaries"
836	@echo "  bl1            Build the BL1 binary"
837	@echo "  bl2            Build the BL2 binary"
838	@echo "  bl2u           Build the BL2U binary"
839	@echo "  bl31           Build the BL31 binary"
840	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
841	@echo "                 this builds secure payload specified by AARCH32_SP"
842	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
843	@echo "  fip            Build the Firmware Image Package (FIP)"
844	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
845	@echo "  checkcodebase  Check the coding style of the entire source tree"
846	@echo "  checkpatch     Check the coding style on changes in the current"
847	@echo "                 branch against BASE_COMMIT (default origin/master)"
848	@echo "  clean          Clean the build for the selected platform"
849	@echo "  cscope         Generate cscope index"
850	@echo "  distclean      Remove all build artifacts for all platforms"
851	@echo "  certtool       Build the Certificate generation tool"
852	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
853	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
854	@echo ""
855	@echo "Note: most build targets require PLAT to be set to a specific platform."
856	@echo ""
857	@echo "example: build all targets for the FVP platform:"
858	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
859