xref: /rk3399_ARM-atf/Makefile (revision 0e6ddc1d876737713913123a33d97fa7920693ab)
1#
2# Copyright (c) 2013-2025, 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			:= 14
12# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH			:= 0
14VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15
16# Default goal is build all images
17.DEFAULT_GOAL			:= all
18
19# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
24MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
27include ${MAKE_HELPERS_DIRECTORY}common.mk
28
29################################################################################
30# Default values for build configurations, and their dependencies
31################################################################################
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34# Include the CPU specific operations makefile, which provides default
35# values for all CPU errata workarounds and CPU specific optimisations.
36# This can be overridden by the platform.
37include lib/cpus/cpu-ops.mk
38
39PLAT				:= ${DEFAULT_PLAT}
40include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
41
42# To be able to set platform specific defaults
43ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
44include ${PLAT_DEFAULTS_MAKEFILE_FULL}
45endif
46
47################################################################################
48# Configure the toolchains used to build TF-A and its tools
49################################################################################
50
51include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
52
53# Assertions enabled for DEBUG builds by default
54ENABLE_ASSERTIONS		:= ${DEBUG}
55ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
56
57################################################################################
58# Checkpatch script options
59################################################################################
60
61CHECKCODE_ARGS		:=	--no-patch
62# Do not check the coding style on imported library files or documentation files
63INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
64					include/drivers/arm,		\
65					$(wildcard include/drivers/*)))
66INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
67					lib/libfdt		\
68					include/lib/libc,		\
69					$(wildcard include/lib/*)))
70INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
71					include/lib			\
72					include/drivers,		\
73					$(wildcard include/*)))
74LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
75					lib/compiler-rt			\
76					lib/libfdt%			\
77					lib/libc,			\
78					lib/zlib			\
79					$(wildcard lib/*)))
80ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
81					lib				\
82					include				\
83					docs				\
84					%.rst,				\
85					$(wildcard *)))
86CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
87				${INC_DIRS_TO_CHECK}			\
88				${INC_LIB_DIRS_TO_CHECK}		\
89				${LIB_DIRS_TO_CHECK}			\
90				${INC_DRV_DIRS_TO_CHECK}		\
91				${INC_ARM_DIRS_TO_CHECK}
92
93################################################################################
94# Process build options
95################################################################################
96
97ifeq ($(verbose),)
98	CHECKCODE_ARGS	+=	--no-summary --terse
99endif
100
101################################################################################
102# Auxiliary tools (fiptool, cert_create, etc)
103################################################################################
104
105# Variables for use with Certificate Generation Tool
106CRTTOOLPATH		?=	tools/cert_create
107CRTTOOL			?=	${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
108
109# Variables for use with Firmware Encryption Tool
110ENCTOOLPATH		?=	tools/encrypt_fw
111ENCTOOL			?=	${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
112
113# Variables for use with Firmware Image Package
114FIPTOOLPATH		?=	tools/fiptool
115FIPTOOL			?=	${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
116
117# Variables for use with sptool
118SPTOOLPATH		?=	tools/sptool
119SPTOOL			?=	${SPTOOLPATH}/sptool.py
120SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
121SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
122
123# Variables for use with sptool
124TLCTOOL 		?=	poetry run tlc
125
126# Variables for use with ROMLIB
127ROMLIBPATH		?=	lib/romlib
128
129# Variable for use with Python
130PYTHON			?=	python3
131
132# Variables for use with documentation build using Sphinx tool
133DOCS_PATH		?=	docs
134
135# Process Debug flag
136ifneq (${DEBUG}, 0)
137	BUILD_TYPE	:=	debug
138	# Use LOG_LEVEL_INFO by default for debug builds
139	LOG_LEVEL	:=	40
140else
141	BUILD_TYPE	:=	release
142	# Use LOG_LEVEL_NOTICE by default for release builds
143	LOG_LEVEL	:=	20
144        # Enable link-time optimization (AKA "inter-procedural optimization")
145        ifeq (${ARCH},aarch64)
146                ifeq ($($(ARCH)-ld-id),$($(ARCH)-cc-id))
147                        ENABLE_LTO :=	1
148                endif
149        endif
150endif #(Debug)
151
152# Default build string (git branch and commit)
153ifeq (${BUILD_STRING},)
154	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
155endif
156VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
157
158# Setting W is quite verbose and most warnings will be pre-existing issues
159# outside of the contributor's control. Don't fail the build on them so warnings
160# can be seen and hopefully addressed
161ifdef W
162	ifneq (${W},0)
163		E	 ?= 0
164	endif
165endif
166
167################################################################################
168# Setup ARCH_MAJOR/MINOR before parsing arch_features.
169################################################################################
170ifeq (${ENABLE_RME},1)
171	ARM_ARCH_MAJOR := 9
172	ARM_ARCH_MINOR := 2
173endif
174
175################################################################################
176# Common sources and include directories
177################################################################################
178include lib/compiler-rt/compiler-rt.mk
179
180# Allow overriding the timestamp, for example for reproducible builds, or to
181# synchronize timestamps across multiple projects.
182# This must be set to a C string (including quotes where applicable).
183BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
184
185DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
186DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
187DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
188
189BL_COMMON_SOURCES	+=	common/bl_common.c			\
190				common/tf_log.c				\
191				common/${ARCH}/debug.S			\
192				drivers/console/multi_console.c		\
193				lib/${ARCH}/cache_helpers.S		\
194				lib/${ARCH}/misc_helpers.S		\
195				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
196				plat/common/plat_bl_common.c		\
197				plat/common/plat_log_common.c		\
198				plat/common/${ARCH}/plat_common.c	\
199				plat/common/${ARCH}/platform_helpers.S	\
200				${COMPILER_RT_SRCS}
201
202ifeq ($($(ARCH)-cc-id),arm-clang)
203	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
204endif
205
206ifeq (${SANITIZE_UB},on)
207	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
208endif
209
210INCLUDES		+=	-Iinclude				\
211				-Iinclude/arch/${ARCH}			\
212				-Iinclude/lib/cpus/${ARCH}		\
213				-Iinclude/lib/el3_runtime/${ARCH}	\
214				${PLAT_INCLUDES}			\
215				${SPD_INCLUDES}
216
217include common/backtrace/backtrace.mk
218
219################################################################################
220# Generic definitions
221################################################################################
222
223ifeq (${BUILD_BASE},)
224     BUILD_BASE		:=	./build
225endif
226BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
227
228SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
229
230# Platforms providing their own TBB makefile may override this value
231INCLUDE_TBBR_MK		:=	1
232
233################################################################################
234# Include SPD Makefile if one has been specified
235################################################################################
236
237ifneq (${SPD},none)
238	ifeq (${SPD},spmd)
239	# SPMD is located in std_svc directory
240		SPD_DIR := std_svc
241
242		ifeq ($(SPMD_SPM_AT_SEL2),1)
243			CTX_INCLUDE_EL2_REGS := 1
244		endif
245
246		ifneq ($(SP_LAYOUT_FILE),)
247		BL2_ENABLE_SP_LOAD := 1
248		endif
249	else
250		# All other SPDs in spd directory
251		SPD_DIR := spd
252	endif #(SPD)
253
254	# We expect to locate an spd.mk under the specified SPD directory
255	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
256
257	ifeq (${SPD_MAKE},)
258                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
259	endif
260        $(info Including ${SPD_MAKE})
261        include ${SPD_MAKE}
262
263	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
264	# Makefile would set NEED_BL32 to "yes". In this case, the build system
265	# supports two mutually exclusive options:
266	# * BL32 is built from source: then BL32_SOURCES must contain the list
267	#   of source files to build BL32
268	# * BL32 is a prebuilt binary: then BL32 must point to the image file
269	#   that will be included in the FIP
270	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
271	# over the sources.
272endif #(SPD=none)
273
274################################################################################
275# Include the platform specific Makefile after the SPD Makefile (the platform
276# makefile may use all previous definitions in this file)
277################################################################################
278include ${PLAT_MAKEFILE_FULL}
279
280################################################################################
281# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
282# platform.
283################################################################################
284
285include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
286################################################################################
287# Process BRANCH_PROTECTION value and set
288# Pointer Authentication and Branch Target Identification flags
289################################################################################
290ifeq (${BRANCH_PROTECTION},0)
291	# Default value turns off all types of branch protection
292	BP_OPTION := none
293else ifneq (${ARCH},aarch64)
294        $(error BRANCH_PROTECTION requires AArch64)
295else ifeq (${BRANCH_PROTECTION},1)
296	# Enables all types of branch protection features
297	BP_OPTION := standard
298	ENABLE_BTI := 1
299	ENABLE_PAUTH := 1
300else ifeq (${BRANCH_PROTECTION},2)
301	# Return address signing to its standard level
302	BP_OPTION := pac-ret
303	ENABLE_PAUTH := 1
304else ifeq (${BRANCH_PROTECTION},3)
305	# Extend the signing to include leaf functions
306	BP_OPTION := pac-ret+leaf
307	ENABLE_PAUTH := 1
308else ifeq (${BRANCH_PROTECTION},4)
309	# Turn on branch target identification mechanism
310	BP_OPTION := bti
311	ENABLE_BTI := 1
312else ifeq (${BRANCH_PROTECTION},5)
313	# Turn on branch target identification mechanism
314	BP_OPTION := standard
315	ENABLE_BTI := 2
316	ENABLE_PAUTH := 2
317else
318        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
319endif #(BRANCH_PROTECTION)
320
321ifneq ($(ENABLE_PAUTH),0)
322	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
323endif
324
325# Pointer Authentication sources
326ifneq (${ENABLE_PAUTH},0)
327# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
328# Pauth support. As it's not secure, it must be reimplemented for real platforms
329	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
330endif
331
332################################################################################
333# RME dependent flags configuration, Enable optional features for RME.
334################################################################################
335# FEAT_RME
336ifeq (${ENABLE_RME},1)
337	# RMM relies on SMCCC_ARCH_FEATURE_AVAILABILITY to discover EL3 enablement
338	ARCH_FEATURE_AVAILABILITY := 1
339
340	# RME requires el2 context to be saved for now.
341	CTX_INCLUDE_EL2_REGS := 1
342	CTX_INCLUDE_AARCH32_REGS := 0
343	CTX_INCLUDE_PAUTH_REGS := 1
344
345	ifneq ($(ENABLE_FEAT_MPAM), 0)
346		CTX_INCLUDE_MPAM_REGS := 1
347	endif
348
349	# RME enables CSV2_2 extension by default.
350	ENABLE_FEAT_CSV2_2 = 1
351endif #(FEAT_RME)
352
353################################################################################
354# Include rmmd Makefile if RME is enabled
355################################################################################
356ifneq (${ENABLE_RME},0)
357include services/std_svc/rmmd/rmmd.mk
358$(warning "RME is an experimental feature")
359endif
360
361################################################################################
362# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
363################################################################################
364ifneq (${ENABLE_FEAT_D128}, 0)
365        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
366endif
367
368# This internal flag is common option which is set to 1 for scenarios
369# when the BL2 is running in EL3 level. This occurs in two scenarios -
370# 4 world system running BL2 at EL3 and two world system without BL1 running
371# BL2 in EL3
372
373ifeq (${RESET_TO_BL2},1)
374	BL2_RUNS_AT_EL3	:=	1
375	ifeq (${ENABLE_RME},1)
376                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
377                supported at the moment.)
378	endif
379else ifeq (${ENABLE_RME},1)
380	BL2_RUNS_AT_EL3	:=	1
381else
382	BL2_RUNS_AT_EL3	:=	0
383endif
384
385# This internal flag is set to 1 when Firmware First handling of External aborts
386# is required by lowe ELs. Currently only NS requires this support.
387ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
388	FFH_SUPPORT := 1
389else
390	FFH_SUPPORT := 0
391endif
392
393ifneq ($(filter 1,${ERRATA_A53_1530924} ${ERRATA_A55_1530923}	\
394        ${ERRATA_A57_1319537} ${ERRATA_A72_1319367} ${ERRATA_A76_1165522}),)
395ERRATA_SPECULATIVE_AT	:= 1
396else
397ERRATA_SPECULATIVE_AT	:= 0
398endif
399
400################################################################################
401# Build `AARCH32_SP` as BL32 image for AArch32
402################################################################################
403ifeq (${ARCH},aarch32)
404        NEED_BL32 := yes
405
406        ifneq (${AARCH32_SP},none)
407        # We expect to locate an sp.mk under the specified AARCH32_SP directory
408		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
409
410                ifeq (${AARCH32_SP_MAKE},)
411                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
412                endif
413                $(info Including ${AARCH32_SP_MAKE})
414                include ${AARCH32_SP_MAKE}
415        endif
416endif #(ARCH=aarch32)
417
418################################################################################
419# Include libc if not overridden
420################################################################################
421ifeq (${OVERRIDE_LIBC},0)
422include lib/libc/libc.mk
423endif
424
425ifneq (${USE_GIC_DRIVER},0)
426include drivers/arm/gic/gic.mk
427endif
428
429################################################################################
430# Check incompatible options and dependencies
431################################################################################
432include ${MAKE_HELPERS_DIRECTORY}constraints.mk
433
434# The cert_create tool cannot generate certificates individually, so we use the
435# target 'certificates' to create them all
436ifneq (${GENERATE_COT},0)
437    FIP_DEPS += certificates
438    FWU_FIP_DEPS += fwu_certificates
439    BL2_FIP_DEPS += bl2_certificates
440endif
441
442ifneq (${DECRYPTION_SUPPORT},none)
443	ENC_ARGS += -f ${FW_ENC_STATUS}
444	ENC_ARGS += -k ${ENC_KEY}
445	ENC_ARGS += -n ${ENC_NONCE}
446	FIP_DEPS += enctool
447	FWU_FIP_DEPS += enctool
448	BL2_FIP_DEPS += enctool
449endif #(DECRYPTION_SUPPORT)
450
451################################################################################
452# Process platform overrideable behaviour
453################################################################################
454
455ifdef BL1_SOURCES
456	NEED_BL1 := yes
457endif #(BL1_SOURCES)
458
459ifdef BL2_SOURCES
460	NEED_BL2 := yes
461
462	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
463	# Certificate generation tools. This flag can be overridden by the platform.
464	ifdef EL3_PAYLOAD_BASE
465		# If booting an EL3 payload there is no need for a BL33 image
466		# in the FIP file.
467		NEED_BL33		:=	no
468	else
469		ifdef PRELOADED_BL33_BASE
470			# If booting a BL33 preloaded image there is no need of
471			# another one in the FIP file.
472			NEED_BL33		:=	no
473		else
474			NEED_BL33		?=	yes
475		endif
476	endif
477endif #(BL2_SOURCES)
478
479ifdef BL2U_SOURCES
480	NEED_BL2U := yes
481endif #(BL2U_SOURCES)
482
483# If SCP_BL2 is given, we always want FIP to include it.
484ifdef SCP_BL2
485	NEED_SCP_BL2		:=	yes
486endif #(SCP_BL2)
487
488# For AArch32, BL31 is not currently supported.
489ifneq (${ARCH},aarch32)
490	ifdef BL31_SOURCES
491	# When booting an EL3 payload, there is no need to compile the BL31
492	# image nor put it in the FIP.
493		ifndef EL3_PAYLOAD_BASE
494			NEED_BL31 := yes
495		endif
496	endif
497endif #(ARCH=aarch64)
498
499# Process TBB related flags
500ifneq (${GENERATE_COT},0)
501    # Common cert_create options
502    ifneq (${CREATE_KEYS},0)
503        $(eval CRT_ARGS += -n)
504        $(eval FWU_CRT_ARGS += -n)
505        $(eval BL2_CRT_ARGS += -n)
506        ifneq (${SAVE_KEYS},0)
507            $(eval CRT_ARGS += -k)
508            $(eval FWU_CRT_ARGS += -k)
509            $(eval BL2_CRT_ARGS += -k)
510        endif
511    endif
512    # Include TBBR makefile (unless the platform indicates otherwise)
513    ifeq (${INCLUDE_TBBR_MK},1)
514        include make_helpers/tbbr/tbbr_tools.mk
515    endif
516endif #(GENERATE_COT)
517
518ifneq (${FIP_ALIGN},0)
519	FIP_ARGS += --align ${FIP_ALIGN}
520endif #(FIP_ALIGN)
521
522ifdef FDT_SOURCES
523	NEED_FDT := yes
524endif #(FDT_SOURCES)
525
526################################################################################
527# Include libraries' Makefile that are used in all BL
528################################################################################
529
530include lib/stack_protector/stack_protector.mk
531
532################################################################################
533# Include BL specific makefiles
534################################################################################
535
536ifeq (${NEED_BL1},yes)
537include bl1/bl1.mk
538endif
539
540ifeq (${NEED_BL2},yes)
541include bl2/bl2.mk
542endif
543
544ifeq (${NEED_BL2U},yes)
545include bl2u/bl2u.mk
546endif
547
548ifeq (${NEED_BL31},yes)
549include bl31/bl31.mk
550endif
551
552################################################################################
553# Build options checks
554################################################################################
555
556# Boolean_Flags
557$(eval $(call assert_booleans,\
558    $(sort \
559	ALLOW_RO_XLAT_TABLES \
560	BL2_ENABLE_SP_LOAD \
561	COLD_BOOT_SINGLE_CPU \
562	$(CPU_FLAG_LIST) \
563	CREATE_KEYS \
564	CTX_INCLUDE_AARCH32_REGS \
565	CTX_INCLUDE_FPREGS \
566	CTX_INCLUDE_SVE_REGS \
567	CTX_INCLUDE_EL2_REGS \
568	CTX_INCLUDE_MPAM_REGS \
569	DEBUG \
570	DYN_DISABLE_AUTH \
571	EL3_EXCEPTION_HANDLING \
572	ENABLE_AMU_AUXILIARY_COUNTERS \
573	AMU_RESTRICT_COUNTERS \
574	ENABLE_ASSERTIONS \
575	ENABLE_PIE \
576	ENABLE_PMF \
577	ENABLE_PSCI_STAT \
578	ENABLE_RUNTIME_INSTRUMENTATION \
579	ENABLE_SME_FOR_SWD \
580	ENABLE_SVE_FOR_SWD \
581	ENABLE_FEAT_GCIE \
582	ENABLE_FEAT_RAS	\
583	FFH_SUPPORT	\
584	ERROR_DEPRECATED \
585	FAULT_INJECTION_SUPPORT \
586	GENERATE_COT \
587	GICV2_G0_FOR_EL3 \
588	HANDLE_EA_EL3_FIRST_NS \
589	HARDEN_SLS \
590	HW_ASSISTED_COHERENCY \
591	MEASURED_BOOT \
592	DISCRETE_TPM \
593	DICE_PROTECTION_ENVIRONMENT \
594	RMMD_ENABLE_EL3_TOKEN_SIGN \
595	RMMD_ENABLE_IDE_KEY_PROG \
596	DRTM_SUPPORT \
597	NS_TIMER_SWITCH \
598	OVERRIDE_LIBC \
599	PL011_GENERIC_UART \
600	PLAT_EXTRA_LD_SCRIPT \
601	PROGRAMMABLE_RESET_ADDRESS \
602	PSCI_EXTENDED_STATE_ID \
603	PSCI_OS_INIT_MODE \
604	ARCH_FEATURE_AVAILABILITY \
605	RESET_TO_BL31 \
606	SAVE_KEYS \
607	SEPARATE_CODE_AND_RODATA \
608	SEPARATE_BL2_NOLOAD_REGION \
609	SEPARATE_NOBITS_REGION \
610	SEPARATE_RWDATA_REGION \
611	SEPARATE_SIMD_SECTION \
612	SPIN_ON_BL1_EXIT \
613	SPM_MM \
614	SPMC_AT_EL3 \
615	SPMC_AT_EL3_SEL0_SP \
616	SPMD_SPM_AT_SEL2 \
617	ENABLE_SPMD_LP \
618	TRANSFER_LIST \
619	TRUSTED_BOARD_BOOT \
620	USE_COHERENT_MEM \
621	USE_DEBUGFS \
622	USE_KERNEL_DT_CONVENTION \
623	ARM_IO_IN_DTB \
624	SDEI_IN_FCONF \
625	SEC_INT_DESC_IN_FCONF \
626	USE_ROMLIB \
627	USE_TBBR_DEFS \
628	WARMBOOT_ENABLE_DCACHE_EARLY \
629	RESET_TO_BL2 \
630	BL2_IN_XIP_MEM \
631	BL2_INV_DCACHE \
632	USE_SPINLOCK_CAS \
633	ENCRYPT_BL31 \
634	ENCRYPT_BL32 \
635	ERRATA_SPECULATIVE_AT \
636	ERRATA_SME_POWER_DOWN \
637	RAS_TRAP_NS_ERR_REC_ACCESS \
638	COT_DESC_IN_DTB \
639	USE_SP804_TIMER \
640	PSA_FWU_SUPPORT \
641	PSA_FWU_METADATA_FW_STORE_DESC \
642	ENABLE_MPMM \
643	FEATURE_DETECTION \
644	TRNG_SUPPORT \
645	ENABLE_ERRATA_ALL \
646	ERRATA_ABI_SUPPORT \
647	ERRATA_NON_ARM_INTERCONNECT \
648	CONDITIONAL_CMO \
649	PSA_CRYPTO	\
650	ENABLE_CONSOLE_GETC \
651	INIT_UNUSED_NS_EL2	\
652	PLATFORM_REPORT_CTX_MEM_USE \
653	EARLY_CONSOLE \
654	PRESERVE_DSU_PMU_REGS \
655	HOB_LIST \
656	LFA_SUPPORT \
657)))
658
659# Numeric_Flags
660$(eval $(call assert_numerics,\
661    $(sort \
662	ARM_ARCH_MAJOR \
663	ARM_ARCH_MINOR \
664	BRANCH_PROTECTION \
665	CTX_INCLUDE_PAUTH_REGS \
666	CTX_INCLUDE_NEVE_REGS \
667	DISABLE_MTPMU \
668	ENABLE_BRBE_FOR_NS \
669	ENABLE_TRBE_FOR_NS \
670	ENABLE_BTI \
671	ENABLE_PAUTH \
672	ENABLE_FEAT_PAUTH_LR \
673	ENABLE_FEAT_AIE \
674	ENABLE_FEAT_AMU \
675	ENABLE_FEAT_AMUv1p1 \
676	ENABLE_FEAT_CLRBHB \
677	ENABLE_FEAT_CPA2 \
678	ENABLE_FEAT_CSV2_2 \
679	ENABLE_FEAT_CSV2_3 \
680	ENABLE_FEAT_DEBUGV8P9 \
681	ENABLE_FEAT_DIT \
682	ENABLE_FEAT_ECV \
683	ENABLE_FEAT_EBEP \
684	ENABLE_FEAT_FGT \
685	ENABLE_FEAT_FGT2 \
686	ENABLE_FEAT_FGWTE3 \
687	ENABLE_FEAT_FPMR \
688	ENABLE_FEAT_HCX \
689	ENABLE_FEAT_IDTE3 \
690	ENABLE_FEAT_LS64_ACCDATA \
691	ENABLE_FEAT_MEC \
692	ENABLE_FEAT_MOPS \
693	ENABLE_FEAT_MTE2 \
694	ENABLE_FEAT_PAN \
695	ENABLE_FEAT_PFAR \
696	ENABLE_FEAT_RNG \
697	ENABLE_FEAT_RNG_TRAP \
698	ENABLE_FEAT_SEL2 \
699	ENABLE_FEAT_TCR2 \
700	ENABLE_FEAT_THE \
701	ENABLE_FEAT_SB \
702	ENABLE_FEAT_S2PIE \
703	ENABLE_FEAT_S1PIE \
704	ENABLE_FEAT_S2POE \
705	ENABLE_FEAT_S1POE \
706	ENABLE_FEAT_SCTLR2 \
707	ENABLE_FEAT_D128 \
708	ENABLE_FEAT_RME_GDI \
709	ENABLE_FEAT_GCS \
710	ENABLE_FEAT_VHE \
711	ENABLE_FEAT_MPAM \
712	ENABLE_FEAT_MPAM_PE_BW_CTRL \
713	ENABLE_RME \
714	ENABLE_SPE_FOR_NS \
715	ENABLE_SYS_REG_TRACE_FOR_NS \
716	ENABLE_SME_FOR_NS \
717	ENABLE_SME2_FOR_NS \
718	ENABLE_SVE_FOR_NS \
719	ENABLE_TRF_FOR_NS \
720	FW_ENC_STATUS \
721	NR_OF_FW_BANKS \
722	NR_OF_IMAGES_IN_FW_BANK \
723	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
724	TWED_DELAY \
725	ENABLE_FEAT_TWED \
726	SVE_VECTOR_LEN \
727	IMPDEF_SYSREG_TRAP \
728	W \
729)))
730
731ifdef KEY_SIZE
732        $(eval $(call assert_numeric,KEY_SIZE))
733endif
734
735ifeq ($(filter $(SANITIZE_UB), on off trap),)
736        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
737endif
738
739################################################################################
740# Add definitions to the cpp preprocessor based on the current build options.
741# This is done after including the platform specific makefile to allow the
742# platform to overwrite the default options
743################################################################################
744
745$(eval $(call add_defines,\
746    $(sort \
747	ALLOW_RO_XLAT_TABLES \
748	ARM_ARCH_MAJOR \
749	ARM_ARCH_MINOR \
750	BL2_ENABLE_SP_LOAD \
751	COLD_BOOT_SINGLE_CPU \
752	$(CPU_FLAG_LIST) \
753	CTX_INCLUDE_AARCH32_REGS \
754	CTX_INCLUDE_FPREGS \
755	CTX_INCLUDE_SVE_REGS \
756	CTX_INCLUDE_PAUTH_REGS \
757	CTX_INCLUDE_MPAM_REGS \
758	EL3_EXCEPTION_HANDLING \
759	CTX_INCLUDE_EL2_REGS \
760	CTX_INCLUDE_NEVE_REGS \
761	DEBUG \
762	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
763	DISABLE_MTPMU \
764	ENABLE_FEAT_AMU \
765	ENABLE_AMU_AUXILIARY_COUNTERS \
766	AMU_RESTRICT_COUNTERS \
767	ENABLE_ASSERTIONS \
768	ENABLE_BTI \
769	ENABLE_FEAT_DEBUGV8P9 \
770	ENABLE_FEAT_IDTE3 \
771	ENABLE_FEAT_MPAM \
772	ENABLE_FEAT_MPAM_PE_BW_CTRL \
773	ENABLE_PAUTH \
774	ENABLE_FEAT_PAUTH_LR \
775	ENABLE_PIE \
776	ENABLE_PMF \
777	ENABLE_PSCI_STAT \
778	ENABLE_RME \
779	RMMD_ENABLE_EL3_TOKEN_SIGN \
780	RMMD_ENABLE_IDE_KEY_PROG \
781	ENABLE_RUNTIME_INSTRUMENTATION \
782	ENABLE_SME_FOR_NS \
783	ENABLE_SME2_FOR_NS \
784	ENABLE_SME_FOR_SWD \
785	ENABLE_SPE_FOR_NS \
786	ENABLE_SVE_FOR_NS \
787	ENABLE_SVE_FOR_SWD \
788	ENABLE_FEAT_RAS \
789	FFH_SUPPORT \
790	ENCRYPT_BL31 \
791	ENCRYPT_BL32 \
792	ERROR_DEPRECATED \
793	FAULT_INJECTION_SUPPORT \
794	GICV2_G0_FOR_EL3 \
795	HANDLE_EA_EL3_FIRST_NS \
796	HW_ASSISTED_COHERENCY \
797	LOG_LEVEL \
798	MEASURED_BOOT \
799	DISCRETE_TPM \
800	DICE_PROTECTION_ENVIRONMENT \
801	DRTM_SUPPORT \
802	NS_TIMER_SWITCH \
803	PLATFORM_NODE_COUNT \
804	PL011_GENERIC_UART \
805	PLAT_EXTRA_LD_SCRIPT \
806	PLAT_${PLAT} \
807	PROGRAMMABLE_RESET_ADDRESS \
808	PSCI_EXTENDED_STATE_ID \
809	PSCI_OS_INIT_MODE \
810	ARCH_FEATURE_AVAILABILITY \
811	RESET_TO_BL31 \
812	RME_GPT_BITLOCK_BLOCK \
813	RME_GPT_MAX_BLOCK \
814	SEPARATE_CODE_AND_RODATA \
815	SEPARATE_BL2_FIP \
816	SEPARATE_BL2_NOLOAD_REGION \
817	SEPARATE_NOBITS_REGION \
818	SEPARATE_RWDATA_REGION \
819	SEPARATE_SIMD_SECTION \
820	RECLAIM_INIT_CODE \
821	SPD_${SPD} \
822	SPIN_ON_BL1_EXIT \
823	SPM_MM \
824	SPMC_AT_EL3 \
825	SPMC_AT_EL3_PARTITION_MAX_UUIDS \
826	SPMC_AT_EL3_SEL0_SP \
827	SPMD_SPM_AT_SEL2 \
828	TRANSFER_LIST \
829	TRUSTED_BOARD_BOOT \
830	TRNG_SUPPORT \
831	ERRATA_ABI_SUPPORT \
832	ERRATA_NON_ARM_INTERCONNECT \
833	USE_COHERENT_MEM \
834	USE_DEBUGFS \
835	ARM_IO_IN_DTB \
836	SDEI_IN_FCONF \
837	SEC_INT_DESC_IN_FCONF \
838	USE_ROMLIB \
839	USE_TBBR_DEFS \
840	USE_KERNEL_DT_CONVENTION \
841	WARMBOOT_ENABLE_DCACHE_EARLY \
842	RESET_TO_BL2 \
843	BL2_RUNS_AT_EL3	\
844	BL2_IN_XIP_MEM \
845	BL2_INV_DCACHE \
846	USE_SPINLOCK_CAS \
847	ERRATA_SPECULATIVE_AT \
848	ERRATA_SME_POWER_DOWN \
849	RAS_TRAP_NS_ERR_REC_ACCESS \
850	COT_DESC_IN_DTB \
851	USE_SP804_TIMER \
852	ENABLE_FEAT_RNG \
853	ENABLE_FEAT_RNG_TRAP \
854	ENABLE_FEAT_SB \
855	ENABLE_FEAT_DIT \
856	NR_OF_FW_BANKS \
857	NR_OF_IMAGES_IN_FW_BANK \
858	PSA_FWU_SUPPORT \
859	PSA_FWU_METADATA_FW_STORE_DESC \
860	ENABLE_BRBE_FOR_NS \
861	ENABLE_TRBE_FOR_NS \
862	ENABLE_SYS_REG_TRACE_FOR_NS \
863	ENABLE_TRF_FOR_NS \
864	ENABLE_FEAT_AIE \
865	ENABLE_FEAT_HCX \
866	ENABLE_MPMM \
867	ENABLE_FEAT_FGT \
868	ENABLE_FEAT_FGT2 \
869	ENABLE_FEAT_FGWTE3 \
870	ENABLE_FEAT_FPMR \
871	ENABLE_FEAT_ECV \
872	ENABLE_FEAT_EBEP \
873	ENABLE_FEAT_AMUv1p1 \
874	ENABLE_FEAT_SEL2 \
875	ENABLE_FEAT_VHE \
876	ENABLE_FEAT_CLRBHB \
877	ENABLE_FEAT_CPA2 \
878	ENABLE_FEAT_CSV2_2 \
879	ENABLE_FEAT_CSV2_3 \
880	ENABLE_FEAT_LS64_ACCDATA \
881	ENABLE_FEAT_MEC \
882	ENABLE_FEAT_PAN \
883	ENABLE_FEAT_TCR2 \
884	ENABLE_FEAT_THE \
885	ENABLE_FEAT_S2PIE \
886	ENABLE_FEAT_S1PIE \
887	ENABLE_FEAT_S2POE \
888	ENABLE_FEAT_S1POE \
889	ENABLE_FEAT_SCTLR2 \
890	ENABLE_FEAT_D128 \
891	ENABLE_FEAT_RME_GDI \
892	ENABLE_FEAT_GCS \
893	ENABLE_FEAT_MOPS \
894	ENABLE_FEAT_GCIE \
895	ENABLE_FEAT_MTE2 \
896	ENABLE_FEAT_PFAR \
897	FEATURE_DETECTION \
898	TWED_DELAY \
899	ENABLE_FEAT_TWED \
900	CONDITIONAL_CMO \
901	IMPDEF_SYSREG_TRAP \
902	SVE_VECTOR_LEN \
903	ENABLE_SPMD_LP \
904	PSA_CRYPTO	\
905	ENABLE_CONSOLE_GETC \
906	INIT_UNUSED_NS_EL2	\
907	PLATFORM_REPORT_CTX_MEM_USE \
908	EARLY_CONSOLE \
909	PRESERVE_DSU_PMU_REGS \
910	HOB_LIST \
911	HW_CONFIG_BASE \
912	LFA_SUPPORT \
913)))
914
915ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
916ifeq (${DEBUG}, 0)
917        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
918        override PLATFORM_REPORT_CTX_MEM_USE := 0
919endif
920endif
921
922ifeq (${SANITIZE_UB},trap)
923        $(eval $(call add_define,MONITOR_TRAPS))
924endif #(SANITIZE_UB)
925
926# Define the EL3_PAYLOAD_BASE flag only if it is provided.
927ifdef EL3_PAYLOAD_BASE
928        $(eval $(call add_define,EL3_PAYLOAD_BASE))
929else
930# Define the PRELOADED_BL33_BASE flag only if it is provided and
931# EL3_PAYLOAD_BASE is not defined, as it has priority.
932	ifdef PRELOADED_BL33_BASE
933                $(eval $(call add_define,PRELOADED_BL33_BASE))
934	endif
935endif #(EL3_PAYLOAD_BASE)
936
937# Define the DYN_DISABLE_AUTH flag only if set.
938ifeq (${DYN_DISABLE_AUTH},1)
939        $(eval $(call add_define,DYN_DISABLE_AUTH))
940endif
941
942ifeq ($($(ARCH)-ld-id),arm-link)
943        $(eval $(call add_define,USE_ARM_LINK))
944endif
945
946# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
947ifeq (${SPD},spmd)
948ifdef SP_LAYOUT_FILE
949	-include $(BUILD_PLAT)/sp_gen.mk
950	FIP_DEPS += sp
951	CRT_DEPS += sp
952	NEED_SP_PKG := yes
953else
954	ifeq (${SPMD_SPM_AT_SEL2},1)
955                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
956	endif
957endif #(SP_LAYOUT_FILE)
958endif #(SPD)
959
960################################################################################
961# Configure the flags for the specified compiler and linker
962################################################################################
963include ${MAKE_HELPERS_DIRECTORY}cflags.mk
964
965################################################################################
966# Build targets
967################################################################################
968
969.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
970
971all: msg_start
972
973msg_start:
974	$(s)echo "Building ${PLAT}"
975
976$(eval $(call MAKE_LIB,c))
977
978# Expand build macros for the different images
979ifeq (${NEED_BL1},yes)
980BL1_SOURCES := $(sort ${BL1_SOURCES})
981$(eval $(call MAKE_BL,bl1))
982endif #(NEED_BL1)
983
984ifeq (${NEED_BL2},yes)
985
986ifeq (${RESET_TO_BL2}, 0)
987FIP_BL2_ARGS := tb-fw
988endif
989
990BL2_SOURCES := $(sort ${BL2_SOURCES})
991
992ifeq (${SEPARATE_BL2_FIP},1)
993$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS},BL2_)), \
994	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS},BL2_)))
995else
996$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})), \
997	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
998endif #(SEPARATE_BL2_FIP)
999
1000endif #(NEED_BL2)
1001
1002ifeq (${NEED_SCP_BL2},yes)
1003$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1004endif #(NEED_SCP_BL2)
1005
1006ifeq (${NEED_BL31},yes)
1007BL31_SOURCES += ${SPD_SOURCES}
1008# Sort BL31 source files to remove duplicates
1009BL31_SOURCES := $(sort ${BL31_SOURCES})
1010ifneq (${DECRYPTION_SUPPORT},none)
1011$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1012	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1013else
1014$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1015	$(eval $(call MAKE_BL,bl31,soc-fw)))
1016endif #(DECRYPTION_SUPPORT)
1017endif #(NEED_BL31)
1018
1019# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1020# build system will call TOOL_ADD_IMG to print a warning message and abort the
1021# process. Note that the dependency on BL32 applies to the FIP only.
1022ifeq (${NEED_BL32},yes)
1023# Sort BL32 source files to remove duplicates
1024BL32_SOURCES := $(sort ${BL32_SOURCES})
1025BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1026
1027ifneq (${DECRYPTION_SUPPORT},none)
1028$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1029	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1030else
1031$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1032	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1033endif #(DECRYPTION_SUPPORT)
1034endif #(NEED_BL32)
1035
1036# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1037# needs to be built from RMM_SOURCES.
1038ifeq (${NEED_RMM},yes)
1039# Sort RMM source files to remove duplicates
1040RMM_SOURCES := $(sort ${RMM_SOURCES})
1041BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1042
1043$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1044	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1045endif #(NEED_RMM)
1046
1047# Add the BL33 image if required by the platform
1048ifeq (${NEED_BL33},yes)
1049$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1050endif #(NEED_BL33)
1051
1052ifeq (${NEED_BL2U},yes)
1053$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1054	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1055endif #(NEED_BL2U)
1056
1057# Expand build macros for the different images
1058ifeq (${NEED_FDT},yes)
1059    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1060
1061    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1062        ifndef INITRD_BASE
1063            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1064        endif
1065
1066        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1067        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1068
1069        define $(HW_CONFIG)-after +=
1070            $(s)echo "  INITRD  $(HW_CONFIG)"
1071            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1072            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1073        endef
1074    endif
1075endif #(NEED_FDT)
1076
1077# Add Secure Partition packages
1078ifeq (${NEED_SP_PKG},yes)
1079$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1080	$(if $(host-poetry),$(q)poetry -q install --no-root)
1081	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1082sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1083	$(s)echo
1084	$(s)echo "Built SP Images successfully"
1085	$(s)echo
1086endif #(NEED_SP_PKG)
1087
1088locate-checkpatch:
1089ifndef CHECKPATCH
1090	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1091else
1092ifeq (,$(wildcard ${CHECKPATCH}))
1093	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1094endif
1095endif #(CHECKPATCH)
1096
1097clean:
1098	$(s)echo "  CLEAN"
1099	$(q)rm -rf $(BUILD_PLAT)
1100	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1101	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1102	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1103	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1104	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1105	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1106
1107realclean distclean:
1108	$(s)echo "  REALCLEAN"
1109	$(q)rm -rf $(BUILD_BASE)
1110	$(q)rm -rf $(CURDIR)/cscope.*
1111	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1112	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1113	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1114	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1115	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1116	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1117
1118checkcodebase:		locate-checkpatch
1119	$(s)echo "  CHECKING STYLE"
1120	$(q)if test -d .git ; then						\
1121		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1122		while read GIT_FILE ;					\
1123		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1124		done ;							\
1125	else								\
1126		 find . -type f -not -iwholename "*.git*"		\
1127		 -not -iwholename "*build*"				\
1128		 -not -iwholename "*libfdt*"				\
1129		 -not -iwholename "*libc*"				\
1130		 -not -iwholename "*docs*"				\
1131		 -not -iwholename "*.rst"				\
1132		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1133	fi
1134
1135checkpatch:		locate-checkpatch
1136	$(s)echo "  CHECKING STYLE"
1137	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1138		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1139	fi
1140	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1141	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1142	do								\
1143		printf "\n[*] Checking style of '$$commit'\n\n";	\
1144		( git log --format=email "$$commit~..$$commit"		\
1145			-- ${CHECK_PATHS} ;				\
1146		  git diff --format=email "$$commit~..$$commit"		\
1147			-- ${CHECK_PATHS}; ) |				\
1148			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1149	done
1150
1151certtool: ${CRTTOOL}
1152
1153${CRTTOOL}: FORCE | $$(@D)/
1154	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1155	$(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
1156	$(s)echo
1157	$(s)echo "Built $@ successfully"
1158	$(s)echo
1159
1160ifneq (${GENERATE_COT},0)
1161certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1162	$(q)${CRTTOOL} ${CRT_ARGS}
1163	$(s)echo
1164	$(s)echo "Built $@ successfully"
1165	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1166	$(s)echo
1167endif #(GENERATE_COT)
1168
1169ifeq (${SEPARATE_BL2_FIP},1)
1170${BUILD_PLAT}/${BL2_FIP_NAME}: ${BL2_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1171	$(eval ${CHECK_BL2_FIP_CMD})
1172	$(q)${FIPTOOL} create ${BL2_FIP_ARGS} $@
1173	$(q)${FIPTOOL} info $@
1174	$(s)echo
1175	$(s)echo "Built $@ successfully"
1176	$(s)echo
1177endif #(SEPARATE_BL2_FIP)
1178
1179${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} | $$(@D)/
1180	$(eval ${CHECK_FIP_CMD})
1181	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1182	$(q)${FIPTOOL} info $@
1183	$(s)echo
1184	$(s)echo "Built $@ successfully"
1185	$(s)echo
1186
1187ifneq (${GENERATE_COT},0)
1188fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1189	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1190	$(s)echo
1191	$(s)echo "Built $@ successfully"
1192	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1193	$(s)echo
1194endif #(GENERATE_COT)
1195
1196ifneq (${GENERATE_COT},0)
1197bl2_certificates: ${BUILD_PLAT}/${FIP_NAME} ${BL2_CRT_DEPS} ${CRTTOOL} | ${BUILD_PLAT}/
1198	$(q)${CRTTOOL} ${BL2_CRT_ARGS}
1199	$(s)echo
1200	$(s)echo "Built $@ successfully"
1201	$(s)echo "BL2 certificates can be found in ${BUILD_PLAT}"
1202	$(s)echo
1203endif #(GENERATE_COT)
1204
1205${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1206	$(eval ${CHECK_FWU_FIP_CMD})
1207	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1208	$(q)${FIPTOOL} info $@
1209	$(s)echo
1210	$(s)echo "Built $@ successfully"
1211	$(s)echo
1212
1213fiptool: ${FIPTOOL}
1214ifeq (${SEPARATE_BL2_FIP},1)
1215bl2_fip: ${BUILD_PLAT}/${BL2_FIP_NAME}
1216fip: bl2_fip
1217else
1218fip: ${BUILD_PLAT}/${FIP_NAME}
1219endif #(SEPARATE_BL2_FIP)
1220fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1221
1222# symlink for compatibility before tools were in the build directory
1223${FIPTOOL}: FORCE | $$(@D)/
1224	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1225	$(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
1226
1227$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB) | $$(@D)/
1228	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_LIB=$(CRYPTO_LIB) ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1229
1230memmap: all
1231	$(if $(host-poetry),$(q)poetry -q install --no-root)
1232	$(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
1233
1234tl: ${BUILD_PLAT}/tl.bin
1235${BUILD_PLAT}/tl.bin: ${HW_CONFIG} | $$(@D)/
1236	$(if $(host-poetry),$(q)poetry -q install --no-root)
1237	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1238
1239doc:
1240	$(s)echo "  BUILD DOCUMENTATION"
1241	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1242	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} BUILDDIR=$(abspath ${BUILD_BASE}/docs) html
1243
1244enctool: ${ENCTOOL}
1245
1246${ENCTOOL}: FORCE | $$(@D)/
1247	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1248	$(s)echo
1249	$(s)echo "Built $@ successfully"
1250	$(s)echo
1251
1252cscope:
1253	$(s)echo "  CSCOPE"
1254	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1255	$(q)cscope -b -q -k
1256
1257help:
1258	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1259	$(s)echo ""
1260	$(s)echo "PLAT is used to specify which platform you wish to build."
1261	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1262	$(s)echo ""
1263	$(s)echo "platform = ${PLATFORM_LIST}"
1264	$(s)echo ""
1265	$(s)echo "Please refer to the User Guide for a list of all supported options."
1266	$(s)echo "Note that the build system doesn't track dependencies for build "
1267	$(s)echo "options. Therefore, if any of the build options are changed "
1268	$(s)echo "from a previous build, a clean build must be performed."
1269	$(s)echo ""
1270	$(s)echo "Supported Targets:"
1271	$(s)echo "  all            Build all individual bootloader binaries"
1272	$(s)echo "  bl1            Build the BL1 binary"
1273	$(s)echo "  bl2            Build the BL2 binary"
1274	$(s)echo "  bl2u           Build the BL2U binary"
1275	$(s)echo "  bl31           Build the BL31 binary"
1276	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1277	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1278	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1279	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1280	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1281	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1282	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1283	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1284	$(s)echo "  clean          Clean the build for the selected platform"
1285	$(s)echo "  cscope         Generate cscope index"
1286	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1287	$(s)echo "  certtool       Build the Certificate generation tool"
1288	$(s)echo "  enctool        Build the Firmware encryption tool"
1289	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1290	$(s)echo "  sp             Build the Secure Partition Packages"
1291	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1292	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1293	$(s)echo "  memmap         Print the memory map of the built binaries"
1294	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1295	$(s)echo ""
1296	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1297	$(s)echo ""
1298	$(s)echo "example: build all targets for the FVP platform:"
1299	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1300
1301.PHONY: FORCE
1302FORCE:;
1303