blob: 58af7966b2a92827a9292e4e4dab8877448b85ec [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Jayanth Dodderi Chidanandce372772023-04-21 11:40:22 +01002# Copyright (c) 2018-2023, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# TFTF Version
8VERSION_MAJOR := 2
Juan Pablo Conde0a0f6742023-05-13 00:20:15 -05009VERSION_MINOR := 9
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
Leonardo Sandoval667fd722020-09-11 12:50:19 -050011MAKE_HELPERS_DIRECTORY := make_helpers/
12include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
13
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020014################################################################################
15# Default values for build configurations, and their dependencies
16################################################################################
17
Leonardo Sandoval667fd722020-09-11 12:50:19 -050018include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20PLAT := ${DEFAULT_PLAT}
21
22# Assertions enabled for DEBUG builds by default
23ENABLE_ASSERTIONS := ${DEBUG}
24
25################################################################################
26# Checkpatch script options
27################################################################################
28
29CHECKCODE_ARGS := --no-patch
30# Do not check the coding style on imported library files or documentation files
31INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Mark Dykese7810b52020-06-03 15:46:55 -050032 include/lib/libfdt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000033 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 $(wildcard include/lib/*)))
35LIB_DIRS_TO_CHECK := $(sort $(filter-out \
36 lib/compiler-rt \
Mark Dykese7810b52020-06-03 15:46:55 -050037 lib/libfdt% \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000038 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020039 $(wildcard lib/*)))
40ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
41 lib \
42 include \
43 docs \
44 %.md \
45 %.rst, \
46 $(wildcard *)))
47CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
48 ${INC_LIB_DIRS_TO_CHECK} \
49 ${LIB_DIRS_TO_CHECK}
50
51ifeq (${V},0)
52 Q=@
53else
54 Q=
55endif
56export Q
57
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010058################################################################################
59# Toolchain configs
60################################################################################
61CC := ${CROSS_COMPILE}gcc
62CPP := ${CROSS_COMPILE}cpp
63AS := ${CROSS_COMPILE}gcc
64AR := ${CROSS_COMPILE}ar
65LD := ${CROSS_COMPILE}ld
66OC := ${CROSS_COMPILE}objcopy
67OD := ${CROSS_COMPILE}objdump
68NM := ${CROSS_COMPILE}nm
69PP := ${CROSS_COMPILE}gcc
70
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071ifneq (${DEBUG}, 0)
72 BUILD_TYPE := debug
73 # Use LOG_LEVEL_INFO by default for debug builds
74 LOG_LEVEL := 40
75else
76 BUILD_TYPE := release
77 # Use LOG_LEVEL_ERROR by default for release builds
78 LOG_LEVEL := 20
79endif
80
81# Default build string (git branch and commit)
82ifeq (${BUILD_STRING},)
Manish V Badarkhece149412022-05-24 22:54:45 +010083 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084endif
85
86VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
87
88BUILD_BASE := ./build
89BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
90
91PLAT_MAKEFILE := platform.mk
92# Generate the platforms list by recursively searching for all directories
93# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
94# char and strip out the final '|'.
95PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
96 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
97 sed -r 's/\|$$//')
98
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020099DOCS_PATH := docs
100
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101ifeq (${PLAT},)
102 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
103endif
104PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
105PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
106ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
107 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
108endif
109
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500110
111EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
112EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
113
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200114.PHONY: all
115all: msg_start
116
117.PHONY: msg_start
118msg_start:
119 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200120 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200121
Shruti Guptac973b2a2023-07-12 12:10:54 +0100122# Set flags for Realm Payload Tests
123ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
Shruti Gupta24597d12023-10-02 10:40:19 +0100124ARM_ARCH_MINOR := 5
Shruti Guptac973b2a2023-07-12 12:10:54 +0100125BRANCH_PROTECTION := 2
126endif
127
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200128# Include test images makefiles.
129include tftf/framework/framework.mk
130include tftf/tests/tests.mk
131include fwu/ns_bl1u/ns_bl1u.mk
132include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100133
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100134# List of secure partitions present.
135SECURE_PARTITIONS :=
136
Olivier Deprez40777f82022-11-09 10:15:28 +0100137# Only platform fvp supports cactus_mm
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100138ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000139include spm/cactus_mm/cactus_mm.mk
nabkah01002e5692022-10-10 12:36:46 +0100140include realm/realm.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100141endif
142
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100143# cactus and ivy are supported on platforms: fvp, tc
144ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100145include spm/cactus/cactus.mk
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100146include spm/ivy/ivy.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100147endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200148
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000149################################################################################
150# Include libc
151################################################################################
152include lib/libc/libc.mk
153
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200154# Include platform specific makefile last because:
155# - the platform makefile may use all previous definitions in this file.
156# - the platform makefile may wish overwriting some of them.
157include ${PLAT_MAKEFILE_FULL}
158
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200159.SUFFIXES:
160
161################################################################################
162# Build options checks
163################################################################################
164$(eval $(call assert_boolean,DEBUG))
165$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
166$(eval $(call assert_boolean,FIRMWARE_UPDATE))
167$(eval $(call assert_boolean,FWU_BL_TEST))
168$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200169$(eval $(call assert_boolean,USE_NVM))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100170$(eval $(call assert_numeric,BRANCH_PROTECTION))
171$(eval $(call assert_boolean,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100172$(eval $(call assert_boolean,TRANSFER_LIST))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200173
174################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100175# Process build options
176################################################################################
177
178# Process BRANCH_PROTECTION value and set
179# Pointer Authentication and Branch Target Identification flags
180include branch_protection.mk
181
182################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200183# Add definitions to the cpp preprocessor based on the current build options.
184# This is done after including the platform specific makefile to allow the
185# platform to overwrite the default options
186################################################################################
187$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
188$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
189$(eval $(call add_define,TFTF_DEFINES,DEBUG))
190$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100191$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000192$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200193$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
194$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
195$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200196$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
Soby Mathew6e5c9962023-10-06 16:38:13 +0100197$(eval $(call add_define,TFTF_DEFINES,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100198$(eval $(call add_define,TFTF_DEFINES,TRANSFER_LIST))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200199
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200200################################################################################
201
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100202################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200203# Assembler, compiler and linker flags shared across all test images.
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100204################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200205COMMON_ASFLAGS :=
206COMMON_CFLAGS :=
207COMMON_LDFLAGS :=
208
209ifeq (${DEBUG},1)
Daniel Boulbyed1f9512022-05-03 16:36:51 +0100210COMMON_CFLAGS += -g -gdwarf-4
211COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200212endif
213
Joel Hutton6a6f4832019-04-08 15:46:36 +0100214# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
215ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000216march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
217march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100218else
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000219march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
220march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100221endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200222
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000223# Get architecture feature modifiers
224arch-features = ${ARM_ARCH_FEATURE}
225
226# Set the compiler's architecture feature modifiers
227ifneq ($(arch-features), none)
228ifeq ($(ARCH), aarch32)
229march32-directive := $(march32-directive)+$(arch-features)
230else
231march64-directive := $(march64-directive)+$(arch-features)
232endif
233# Print features
234$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
235endif # arch-features
236
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100237################################################################################
238# Compiler settings
239################################################################################
240ifneq ($(findstring clang,$(notdir $(CC))),)
241CLANG_CFLAGS_aarch64 := -target aarch64-elf
Joel Hutton6a6f4832019-04-08 15:46:36 +0100242
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100243CPP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
244PP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200245
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100246CLANG_WARNINGS += -nostdinc -ffreestanding -Wall \
247 -Wmissing-include-dirs $(CLANG_CFLAGS_$(ARCH)) \
248 -Wlogical-op-parentheses \
249 -Wno-initializer-overrides \
250 -Wno-sometimes-uninitialized \
251 -Wno-unused-function \
252 -Wno-unused-variable \
253 -Wno-unused-parameter \
254 -Wno-tautological-compare \
255 -Wno-memset-transposed-args \
256 -Wno-parentheses
257
258CLANG_CFLAGS += -Wno-error=deprecated-declarations \
259 -Wno-error=cpp \
260 $(CLANG_WARNINGS)
261endif #(clang)
262
263ifneq ($(findstring gcc,$(notdir $(CC))),)
264GCC_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
265GCC_CFLAGS_aarch64 := -mgeneral-regs-only
266
267GCC_ASFLAGS_aarch32 := ${march32-directive}
268GCC_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
269
270GCC_WARNINGS += -nostdinc -ffreestanding -Wall -Werror \
271 -Wmissing-include-dirs $(GCC_CFLAGS_$(ARCH)) \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200272 -std=gnu99 -Os
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100273
274# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
275GCC_CFLAGS += $(call cc_option, --param=min-pagesize=0)
276GCC_CFLAGS += $(GCC_WARNINGS)
277endif #(gcc)
278
279COMMON_CFLAGS_aarch64 += ${march64-directive} -mstrict-align \
280 $(CLANG_CFLAGS_$(ARCH)) $(GCC_CFLAGS_$(ARCH))
281
282COMMON_CFLAGS += $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200283COMMON_CFLAGS += -ffunction-sections -fdata-sections
284
285# Get the content of CFLAGS user defined value last so they are appended after
286# the options defined in the Makefile
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100287COMMON_CFLAGS += ${CLANG_CFLAGS} ${GCC_CFLAGS} ${INCLUDES}
288
289COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
290 -Werror -Wmissing-include-dirs \
291 -D__ASSEMBLY__ $(GCC_ASFLAGS_$(ARCH)) \
292 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200293
Karl Meakine69d1282023-03-07 17:10:07 +0000294COMMON_LDFLAGS += ${LDFLAGS} --fatal-warnings -O1 --gc-sections --build-id=none
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200295
Soby Mathew25d9e2f2023-05-05 10:51:57 +0100296# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
297# are not loaded by a elf loader.
298COMMON_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
299
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200300################################################################################
301
Mark Dykese7810b52020-06-03 15:46:55 -0500302TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200303TFTF_INCLUDES += ${PLAT_INCLUDES}
304TFTF_CFLAGS += ${COMMON_CFLAGS}
305TFTF_ASFLAGS += ${COMMON_ASFLAGS}
306TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500307TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200308
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100309ifneq (${BP_OPTION},none)
310TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
311NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
312NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
313CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
314CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
315IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
AlexeiFedorov193b3562022-12-22 16:50:08 +0000316REALM_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000317endif
318
Mark Dykese7810b52020-06-03 15:46:55 -0500319ifeq ($(SMC_FUZZING), 1)
320TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
321endif
322
Olivier Deprez231115d2020-02-03 11:27:01 +0100323#####################################################################################
324ifneq ($(findstring gcc,$(notdir $(LD))),)
325 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
326else
327 PIE_LDFLAGS += -pie --no-dynamic-linker
328endif
329
330#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000331NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200332NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
333NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
334NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
335NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
336
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000337NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200338NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
339NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
340NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
341NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
342
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000343CACTUS_MM_SOURCES += ${LIBC_SRCS}
344CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
345CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
346CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
347CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
348
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000349CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200350CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100351CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200352CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100353CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200354
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000355IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000356IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100357IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000358IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100359IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000360
nabkah01002e5692022-10-10 12:36:46 +0100361REALM_SOURCES += ${LIBC_SRCS}
362REALM_CFLAGS += ${COMMON_CFLAGS} -fpie
363REALM_ASFLAGS += ${COMMON_ASFLAGS}
364REALM_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
365
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200366.PHONY: locate-checkpatch
367locate-checkpatch:
368ifndef CHECKPATCH
369 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
370else
371ifeq (,$(wildcard ${CHECKPATCH}))
372 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
373endif
374endif
375
376.PHONY: clean
377clean:
378 @echo " CLEAN"
379 ${Q}rm -rf ${BUILD_PLAT}
Shriram K86879852022-09-15 15:45:05 +0530380ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200381 ${MAKE} -C el3_payload clean
Shriram K86879852022-09-15 15:45:05 +0530382endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200383
384.PHONY: realclean distclean
385realclean distclean:
386 @echo " REALCLEAN"
387 ${Q}rm -rf ${BUILD_BASE}
388 ${Q}rm -f ${CURDIR}/cscope.*
Shriram K86879852022-09-15 15:45:05 +0530389ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200390 ${MAKE} -C el3_payload distclean
Shriram K86879852022-09-15 15:45:05 +0530391endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200392
393.PHONY: checkcodebase
394checkcodebase: locate-checkpatch
395 @echo " CHECKING STYLE"
396 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500397 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200398 while read GIT_FILE ; \
399 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
400 done ; \
401 else \
402 find . -type f -not -iwholename "*.git*" \
403 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500404 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000405 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200406 -not -iwholename "*docs*" \
407 -not -iwholename "*.md" \
408 -not -iwholename "*.rst" \
409 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
410 fi
411
412.PHONY: checkpatch
413checkpatch: locate-checkpatch
414 @echo " CHECKING STYLE"
415 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
416 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
417 printf "\n[*] Checking style of '$$commit'\n\n"; \
418 git log --format=email "$$commit~..$$commit" \
419 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
420 git diff --format=email "$$commit~..$$commit" \
421 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
422 done
423
424ifneq (${FIRMWARE_UPDATE},1)
425.PHONY: ns_bl1u ns_bl2u
426ns_bl1u ns_bl2u:
427 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
428 on this platform."
429 @exit 1
430endif
431
432ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000433.PHONY: cactus_mm
434cactus_mm:
435 @echo "ERROR: $@ is supported only on AArch64 FVP."
436 @exit 1
437
nabkah01002e5692022-10-10 12:36:46 +0100438.PHONY: realm
439realm:
440 @echo "ERROR: $@ is supported only on AArch64 FVP."
441 @exit 1
442
443.PHONY: pack_realm
444pack_realm:
445 @echo "Nothing to be done"
446 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200447endif
448
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100449ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100450.PHONY: cactus
451cactus:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100452 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100453 @exit 1
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100454
455.PHONY: ivy
456ivy:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100457 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100458 @exit 1
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100459endif
460
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200461MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
462
463define MAKE_C
464
465$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
466$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
467
Bence Szépkúti537b3582019-11-29 18:23:56 +0100468$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200469 @echo " CC $$<"
470 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
471
472-include $(DEP)
473endef
474
475
476define MAKE_S
477
478$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
479$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
480
Bence Szépkúti537b3582019-11-29 18:23:56 +0100481$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200482 @echo " AS $$<"
483 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
484
485-include $(DEP)
486endef
487
488
489define MAKE_LD
490
491$(eval DEP := $(1).d)
492
Bence Szépkúti537b3582019-11-29 18:23:56 +0100493$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200494 @echo " PP $$<"
495 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
496
497-include $(DEP)
498endef
499
500
501define MAKE_OBJS
502 $(eval C_OBJS := $(filter %.c,$(2)))
503 $(eval REMAIN := $(filter-out %.c,$(2)))
504 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
505
506 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
507 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
508 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
509
510 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
511endef
512
513
514# NOTE: The line continuation '\' is required in the next define otherwise we
515# end up with a line-feed characer at the end of the last c filename.
516# Also bare this issue in mind if extending the list of supported filetypes.
517define SOURCES_TO_OBJS
518 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
519 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
520endef
521
522define uppercase
523$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
524endef
525
526define MAKE_IMG
527 $(eval IMG_PREFIX := $(call uppercase, $(1)))
528 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
529 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
530 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500531 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200532 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
533 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
534 $(eval ELF := $(BUILD_DIR)/$(1).elf)
535 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
536 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
537
538 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
539 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
540
541$(BUILD_DIR) :
542 $$(Q)mkdir -p "$$@"
543
544$(ELF) : $(OBJS) $(LINKERFILE)
545 @echo " LD $$@"
546 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
547 const char version_string[] = "${VERSION_STRING}";' | \
548 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
549 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
550 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
551
552$(DUMP) : $(ELF)
553 @echo " OD $$@"
554 $${Q}$${OD} -dx $$< > $$@
555
556$(BIN) : $(ELF)
557 @echo " BIN $$@"
558 $$(Q)$$(OC) -O binary $$< $$@
559 @echo
560 @echo "Built $$@ successfully"
561 @echo
562
563.PHONY : $(1)
564$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
565
566all : $(1)
567
568endef
569
Shruti Gupta2eb601b2023-03-29 21:35:17 +0100570ifeq (${ARCH},aarch32)
571 ARCH_TESTS_SKIP_LIST := tftf/tests/aarch32_tests_to_skip.txt
572endif
573
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200574$(AUTOGEN_DIR):
575 $(Q)mkdir -p "$@"
576
Shruti Gupta2eb601b2023-03-29 21:35:17 +0100577$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST} $(ARCH_TESTS_SKIP_LIST)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200578 @echo " AUTOGEN $@"
Jim Ray7ba27bf2023-05-25 14:11:51 -0700579 tools/generate_test_list/generate_test_list.py $(AUTOGEN_DIR)/tests_list.c \
580 $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} \
581 --plat-skip-file=$(PLAT_TESTS_SKIP_LIST) \
582 --arch-skip-file=$(ARCH_TESTS_SKIP_LIST)
Mark Dykese7810b52020-06-03 15:46:55 -0500583ifeq ($(SMC_FUZZING), 1)
584 $(Q)mkdir -p ${BUILD_PLAT}/smcf
585 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
586 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow01d5c79cc2021-06-23 16:10:22 -0500587 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
588 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykese7810b52020-06-03 15:46:55 -0500589endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200590
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200591ifeq ($(FIRMWARE_UPDATE), 1)
592 $(eval $(call MAKE_IMG,ns_bl1u))
593 $(eval $(call MAKE_IMG,ns_bl2u))
594endif
595
596ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000597 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200598 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000599 $(eval $(call MAKE_IMG,ivy))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100600endif
601
602ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
nabkah01002e5692022-10-10 12:36:46 +0100603 $(eval $(call MAKE_IMG,realm))
604endif
605
Shruti Guptac973b2a2023-07-12 12:10:54 +0100606.PHONY : tftf
607 $(eval $(call MAKE_IMG,tftf))
608
609ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
610tftf: realm
611 @echo " PACK REALM PAYLOAD"
612 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
Soby Mathew6e5c9962023-10-06 16:38:13 +0100613 oflag=append conv=notrunc)
Shruti Guptac973b2a2023-07-12 12:10:54 +0100614endif
615
nabkah01002e5692022-10-10 12:36:46 +0100616ifeq (${ARCH}-${PLAT},aarch64-fvp)
617.PHONY : pack_realm
Shruti Guptac973b2a2023-07-12 12:10:54 +0100618$(eval $(call MAKE_IMG,realm))
nabkah01002e5692022-10-10 12:36:46 +0100619pack_realm: realm tftf
620 @echo " PACK REALM PAYLOAD"
621 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
Soby Mathew6e5c9962023-10-06 16:38:13 +0100622 oflag=append conv=notrunc)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200623endif
624
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100625ifeq (${ARCH}-${PLAT},aarch64-tc)
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100626 $(eval $(call MAKE_IMG,cactus))
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100627 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100628endif
629
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100630SP_LAYOUT:
631 ${Q}tools/generate_json/generate_json.sh \
632 $(BUILD_PLAT) $(SECURE_PARTITIONS)
633
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200634# The EL3 test payload is only supported in AArch64. It has an independent build
635# system.
636.PHONY: el3_payload
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100637# TODO: EL3 test payload currently is supported for GCC only. It has an independent
638# build system and support for Clang to be added.
639ifneq ($(findstring gcc,$(notdir $(CC))),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200640ifneq (${ARCH},aarch32)
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500641ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200642el3_payload: $(BUILD_DIR)
643 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
644 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
645
646all: el3_payload
647endif
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500648endif
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100649endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200650
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200651doc:
652 @echo " BUILD DOCUMENTATION"
653 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
654
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200655.PHONY: cscope
656cscope:
657 @echo " CSCOPE"
658 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
659 ${Q}cscope -b -q -k
660
661.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500662.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200663help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500664 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Shruti Guptac973b2a2023-07-12 12:10:54 +0100665<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500666 echo ""
667 echo "PLAT is used to specify which platform you wish to build."
668 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
669 echo ""
670 echo "Supported Targets:"
671 echo " all Build all supported binaries for this platform"
672 echo " (i.e. TFTF and FWU images)"
673 echo " tftf Build the TFTF image"
674 echo " ns_bl1u Build the NS_BL1U image"
675 echo " ns_bl2u Build the NS_BL2U image"
Olivier Deprez40777f82022-11-09 10:15:28 +0100676 echo " cactus Build the Cactus image (FF-A S-EL1 test payload)."
677 echo " cactus_mm Build the Cactus-MM image (SPM-MM S-EL0 test payload)."
678 echo " ivy Build the Ivy image (FF-A S-EL0 test payload)."
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500679 echo " el3_payload Build the EL3 test payload"
680 echo " checkcodebase Check the coding style of the entire source tree"
681 echo " checkpatch Check the coding style on changes in the current"
682 echo " branch against BASE_COMMIT (default origin/master)"
683 echo " doc Build html based documentation using Sphinx tool"
684 echo " clean Clean the build for the selected platform"
685 echo " cscope Generate cscope index"
686 echo " distclean Remove all build artifacts for all platforms"
687 echo " help_tests List all possible sets of tests"
688 echo ""
689 echo "note: most build targets require PLAT to be set to a specific platform."
690 echo ""
691 echo "example: build all targets for the FVP platform:"
692 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"