blob: 286a47c7d454f147c0ff8006d81ae1aa15f82f83 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Daniel Boulby9a8c4242022-05-03 16:36:51 +01002# Copyright (c) 2018-2022, 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 Condea3df08d2022-11-16 18:33:40 -05009VERSION_MINOR := 8
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
Leonardo Sandovale1693b42020-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 Sandovale1693b42020-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 Dykes9f5c50b2020-06-03 15:46:55 -050032 include/lib/libfdt \
Ambroise Vincenta2ede622019-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 Dykes9f5c50b2020-06-03 15:46:55 -050037 lib/libfdt% \
Ambroise Vincenta2ede622019-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
58ifneq (${DEBUG}, 0)
59 BUILD_TYPE := debug
60 # Use LOG_LEVEL_INFO by default for debug builds
61 LOG_LEVEL := 40
62else
63 BUILD_TYPE := release
64 # Use LOG_LEVEL_ERROR by default for release builds
65 LOG_LEVEL := 20
66endif
67
68# Default build string (git branch and commit)
69ifeq (${BUILD_STRING},)
Manish V Badarkhef0e77d42022-05-24 22:54:45 +010070 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071endif
72
73VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
74
75BUILD_BASE := ./build
76BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
77
78PLAT_MAKEFILE := platform.mk
79# Generate the platforms list by recursively searching for all directories
80# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
81# char and strip out the final '|'.
82PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
83 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
84 sed -r 's/\|$$//')
85
Sandrine Bailleux7fb2e0a2020-04-21 14:45:00 +020086DOCS_PATH := docs
87
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020088ifeq (${PLAT},)
89 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
90endif
91PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
92PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
93ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
94 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
95endif
96
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -050097
98EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
99EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
100
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101.PHONY: all
102all: msg_start
103
104.PHONY: msg_start
105msg_start:
106 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200107 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200108
109# Include test images makefiles.
110include tftf/framework/framework.mk
111include tftf/tests/tests.mk
112include fwu/ns_bl1u/ns_bl1u.mk
113include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100114
Daniel Boulby7e735ff2022-07-25 14:07:57 +0100115# List of secure partitions present.
116SECURE_PARTITIONS :=
117
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100118# Only platform fvp supports cactus_mm, quark
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100119ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000120include spm/cactus_mm/cactus_mm.mk
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000121include spm/quark/quark.mk
nabkah0114142572022-10-10 12:36:46 +0100122include realm/realm.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100123endif
124
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100125# cactus and ivy are supported on platforms: fvp, tc0
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100126ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
127include spm/cactus/cactus.mk
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100128include spm/ivy/ivy.mk
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100129endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200130
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000131################################################################################
132# Include libc
133################################################################################
134include lib/libc/libc.mk
135
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200136# Include platform specific makefile last because:
137# - the platform makefile may use all previous definitions in this file.
138# - the platform makefile may wish overwriting some of them.
139include ${PLAT_MAKEFILE_FULL}
140
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200141.SUFFIXES:
142
143################################################################################
144# Build options checks
145################################################################################
146$(eval $(call assert_boolean,DEBUG))
147$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
148$(eval $(call assert_boolean,FIRMWARE_UPDATE))
149$(eval $(call assert_boolean,FWU_BL_TEST))
150$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151$(eval $(call assert_boolean,USE_NVM))
152
153################################################################################
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100154# Process build options
155################################################################################
156
157# Process BRANCH_PROTECTION value and set
158# Pointer Authentication and Branch Target Identification flags
159include branch_protection.mk
160
161################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200162# Add definitions to the cpp preprocessor based on the current build options.
163# This is done after including the platform specific makefile to allow the
164# platform to overwrite the default options
165################################################################################
166$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
167$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
168$(eval $(call add_define,TFTF_DEFINES,DEBUG))
169$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100170$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000171$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200172$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
173$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
174$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200175$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
176
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200177################################################################################
178
179# Assembler, compiler and linker flags shared across all test images.
180COMMON_ASFLAGS :=
181COMMON_CFLAGS :=
182COMMON_LDFLAGS :=
183
184ifeq (${DEBUG},1)
Daniel Boulby9a8c4242022-05-03 16:36:51 +0100185COMMON_CFLAGS += -g -gdwarf-4
186COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200187endif
188
Joel Hutton87530242019-04-08 15:46:36 +0100189# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
190ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovfceac732020-12-07 18:13:28 +0000191march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
192march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton87530242019-04-08 15:46:36 +0100193else
Alexei Fedorovfceac732020-12-07 18:13:28 +0000194march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
195march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton87530242019-04-08 15:46:36 +0100196endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200197
Alexei Fedorovfceac732020-12-07 18:13:28 +0000198# Get architecture feature modifiers
199arch-features = ${ARM_ARCH_FEATURE}
200
201# Set the compiler's architecture feature modifiers
202ifneq ($(arch-features), none)
203ifeq ($(ARCH), aarch32)
204march32-directive := $(march32-directive)+$(arch-features)
205else
206march64-directive := $(march64-directive)+$(arch-features)
207endif
208# Print features
209$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
210endif # arch-features
211
Joel Hutton87530242019-04-08 15:46:36 +0100212COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
213COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
214
215COMMON_ASFLAGS_aarch32 := ${march32-directive}
216COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200217
218COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
219 -Werror -Wmissing-include-dirs \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000220 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
221 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200222COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
223 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
224 -std=gnu99 -Os
225COMMON_CFLAGS += -ffunction-sections -fdata-sections
226
227# Get the content of CFLAGS user defined value last so they are appended after
228# the options defined in the Makefile
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000229COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200230
231COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
232
233CC := ${CROSS_COMPILE}gcc
234CPP := ${CROSS_COMPILE}cpp
235AS := ${CROSS_COMPILE}gcc
236AR := ${CROSS_COMPILE}ar
237LD := ${CROSS_COMPILE}ld
238OC := ${CROSS_COMPILE}objcopy
239OD := ${CROSS_COMPILE}objdump
240NM := ${CROSS_COMPILE}nm
241PP := ${CROSS_COMPILE}gcc
242
243################################################################################
244
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500245TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200246TFTF_INCLUDES += ${PLAT_INCLUDES}
247TFTF_CFLAGS += ${COMMON_CFLAGS}
248TFTF_ASFLAGS += ${COMMON_ASFLAGS}
249TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500250TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200251
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100252ifneq (${BP_OPTION},none)
253TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
254NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
255NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
256CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
257CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
258IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
259QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000260endif
261
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500262ifeq ($(SMC_FUZZING), 1)
263TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
264endif
265
Olivier Deprezdb70c452020-02-03 11:27:01 +0100266#####################################################################################
267ifneq ($(findstring gcc,$(notdir $(LD))),)
268 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
269else
270 PIE_LDFLAGS += -pie --no-dynamic-linker
271endif
272
273#####################################################################################
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000274NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200275NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
276NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
277NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
278NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
279
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000280NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200281NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
282NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
283NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
284NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
285
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000286CACTUS_MM_SOURCES += ${LIBC_SRCS}
287CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
288CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
289CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
290CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
291
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000292CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200293CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100294CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200295CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100296CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200297
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000298IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000299IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phippscd924f72020-08-24 11:32:32 +0100300IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000301IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phippscd924f72020-08-24 11:32:32 +0100302IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000303
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000304QUARK_SOURCES += ${LIBC_SRCS}
305QUARK_INCLUDES += ${PLAT_INCLUDES}
306QUARK_CFLAGS += ${COMMON_CFLAGS}
307QUARK_ASFLAGS += ${COMMON_ASFLAGS}
308QUARK_LDFLAGS += ${COMMON_LDFLAGS}
309
nabkah0114142572022-10-10 12:36:46 +0100310REALM_SOURCES += ${LIBC_SRCS}
311REALM_CFLAGS += ${COMMON_CFLAGS} -fpie
312REALM_ASFLAGS += ${COMMON_ASFLAGS}
313REALM_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
314
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200315.PHONY: locate-checkpatch
316locate-checkpatch:
317ifndef CHECKPATCH
318 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
319else
320ifeq (,$(wildcard ${CHECKPATCH}))
321 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
322endif
323endif
324
325.PHONY: clean
326clean:
327 @echo " CLEAN"
328 ${Q}rm -rf ${BUILD_PLAT}
Shriram K593d5822022-09-15 15:45:05 +0530329ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200330 ${MAKE} -C el3_payload clean
Shriram K593d5822022-09-15 15:45:05 +0530331endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200332
333.PHONY: realclean distclean
334realclean distclean:
335 @echo " REALCLEAN"
336 ${Q}rm -rf ${BUILD_BASE}
337 ${Q}rm -f ${CURDIR}/cscope.*
Shriram K593d5822022-09-15 15:45:05 +0530338ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200339 ${MAKE} -C el3_payload distclean
Shriram K593d5822022-09-15 15:45:05 +0530340endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200341
342.PHONY: checkcodebase
343checkcodebase: locate-checkpatch
344 @echo " CHECKING STYLE"
345 @if test -d .git ; then \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500346 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200347 while read GIT_FILE ; \
348 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
349 done ; \
350 else \
351 find . -type f -not -iwholename "*.git*" \
352 -not -iwholename "*build*" \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500353 -not -iwholename "*libfdt*" \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000354 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200355 -not -iwholename "*docs*" \
356 -not -iwholename "*.md" \
357 -not -iwholename "*.rst" \
358 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
359 fi
360
361.PHONY: checkpatch
362checkpatch: locate-checkpatch
363 @echo " CHECKING STYLE"
364 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
365 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
366 printf "\n[*] Checking style of '$$commit'\n\n"; \
367 git log --format=email "$$commit~..$$commit" \
368 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
369 git diff --format=email "$$commit~..$$commit" \
370 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
371 done
372
373ifneq (${FIRMWARE_UPDATE},1)
374.PHONY: ns_bl1u ns_bl2u
375ns_bl1u ns_bl2u:
376 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
377 on this platform."
378 @exit 1
379endif
380
381ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000382.PHONY: cactus_mm
383cactus_mm:
384 @echo "ERROR: $@ is supported only on AArch64 FVP."
385 @exit 1
386
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000387.PHONY: quark
388quark:
389 @echo "ERROR: $@ is supported only on AArch64 FVP."
390 @exit 1
nabkah0114142572022-10-10 12:36:46 +0100391
392.PHONY: realm
393realm:
394 @echo "ERROR: $@ is supported only on AArch64 FVP."
395 @exit 1
396
397.PHONY: pack_realm
398pack_realm:
399 @echo "Nothing to be done"
400 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200401endif
402
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100403ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
404.PHONY: cactus
405cactus:
406 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
407 @exit 1
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100408
409.PHONY: ivy
410ivy:
411 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
412 @exit 1
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100413endif
414
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200415MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
416
417define MAKE_C
418
419$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
420$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
421
Bence Szépkúti25671c22019-11-29 18:23:56 +0100422$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200423 @echo " CC $$<"
424 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
425
426-include $(DEP)
427endef
428
429
430define MAKE_S
431
432$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
433$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
434
Bence Szépkúti25671c22019-11-29 18:23:56 +0100435$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200436 @echo " AS $$<"
437 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
438
439-include $(DEP)
440endef
441
442
443define MAKE_LD
444
445$(eval DEP := $(1).d)
446
Bence Szépkúti25671c22019-11-29 18:23:56 +0100447$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200448 @echo " PP $$<"
449 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
450
451-include $(DEP)
452endef
453
454
455define MAKE_OBJS
456 $(eval C_OBJS := $(filter %.c,$(2)))
457 $(eval REMAIN := $(filter-out %.c,$(2)))
458 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
459
460 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
461 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
462 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
463
464 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
465endef
466
467
468# NOTE: The line continuation '\' is required in the next define otherwise we
469# end up with a line-feed characer at the end of the last c filename.
470# Also bare this issue in mind if extending the list of supported filetypes.
471define SOURCES_TO_OBJS
472 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
473 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
474endef
475
476define uppercase
477$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
478endef
479
480define MAKE_IMG
481 $(eval IMG_PREFIX := $(call uppercase, $(1)))
482 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
483 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
484 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500485 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200486 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
487 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
488 $(eval ELF := $(BUILD_DIR)/$(1).elf)
489 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
490 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
491
492 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
493 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
494
495$(BUILD_DIR) :
496 $$(Q)mkdir -p "$$@"
497
498$(ELF) : $(OBJS) $(LINKERFILE)
499 @echo " LD $$@"
500 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
501 const char version_string[] = "${VERSION_STRING}";' | \
502 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
503 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
504 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
505
506$(DUMP) : $(ELF)
507 @echo " OD $$@"
508 $${Q}$${OD} -dx $$< > $$@
509
510$(BIN) : $(ELF)
511 @echo " BIN $$@"
512 $$(Q)$$(OC) -O binary $$< $$@
513 @echo
514 @echo "Built $$@ successfully"
515 @echo
516
517.PHONY : $(1)
518$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
519
520all : $(1)
521
522endef
523
524$(AUTOGEN_DIR):
525 $(Q)mkdir -p "$@"
526
527$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
528 @echo " AUTOGEN $@"
529 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500530ifeq ($(SMC_FUZZING), 1)
531 $(Q)mkdir -p ${BUILD_PLAT}/smcf
532 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
533 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow0128e1a2b2021-06-23 16:10:22 -0500534 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
535 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500536endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200537
538$(eval $(call MAKE_IMG,tftf))
539
540ifeq ($(FIRMWARE_UPDATE), 1)
541 $(eval $(call MAKE_IMG,ns_bl1u))
542 $(eval $(call MAKE_IMG,ns_bl2u))
543endif
544
545ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000546 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200547 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000548 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000549 $(eval $(call MAKE_IMG,quark))
nabkah0114142572022-10-10 12:36:46 +0100550 $(eval $(call MAKE_IMG,realm))
551endif
552
553ifeq (${ARCH}-${PLAT},aarch64-fvp)
554.PHONY : pack_realm
555pack_realm: realm tftf
556 @echo " PACK REALM PAYLOAD"
557 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
558 seek=$(TFTF_MAX_IMAGE_SIZE))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200559endif
560
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100561ifeq (${ARCH}-${PLAT},aarch64-tc0)
562 $(eval $(call MAKE_IMG,cactus))
Olivier Depreza4a11fe2020-12-16 15:46:14 +0100563 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy3bc8e8d2020-09-22 13:28:29 +0100564endif
565
Daniel Boulby7e735ff2022-07-25 14:07:57 +0100566SP_LAYOUT:
567 ${Q}tools/generate_json/generate_json.sh \
568 $(BUILD_PLAT) $(SECURE_PARTITIONS)
569
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200570# The EL3 test payload is only supported in AArch64. It has an independent build
571# system.
572.PHONY: el3_payload
573ifneq (${ARCH},aarch32)
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -0500574ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200575el3_payload: $(BUILD_DIR)
576 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
577 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
578
579all: el3_payload
580endif
Arvind Ram Prakashb3d71492022-05-20 12:27:40 -0500581endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200582
Sandrine Bailleux7fb2e0a2020-04-21 14:45:00 +0200583doc:
584 @echo " BUILD DOCUMENTATION"
585 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
586
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200587.PHONY: cscope
588cscope:
589 @echo " CSCOPE"
590 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
591 ${Q}cscope -b -q -k
592
593.PHONY: help
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500594.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200595help:
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500596 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
nabkah0114142572022-10-10 12:36:46 +0100597<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|realm|pack_realm|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500598 echo ""
599 echo "PLAT is used to specify which platform you wish to build."
600 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
601 echo ""
602 echo "Supported Targets:"
603 echo " all Build all supported binaries for this platform"
604 echo " (i.e. TFTF and FWU images)"
605 echo " tftf Build the TFTF image"
606 echo " ns_bl1u Build the NS_BL1U image"
607 echo " ns_bl2u Build the NS_BL2U image"
608 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
nabkah0114142572022-10-10 12:36:46 +0100609 echo " realm Build the Realm image (Test R-EL1 payload)."
610 echo " pack_realm Pack the realm image to tftf.bin."
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500611 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
612 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
613 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
614 echo " el3_payload Build the EL3 test payload"
615 echo " checkcodebase Check the coding style of the entire source tree"
616 echo " checkpatch Check the coding style on changes in the current"
617 echo " branch against BASE_COMMIT (default origin/master)"
618 echo " doc Build html based documentation using Sphinx tool"
619 echo " clean Clean the build for the selected platform"
620 echo " cscope Generate cscope index"
621 echo " distclean Remove all build artifacts for all platforms"
622 echo " help_tests List all possible sets of tests"
623 echo ""
624 echo "note: most build targets require PLAT to be set to a specific platform."
625 echo ""
626 echo "example: build all targets for the FVP platform:"
627 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"