blob: 8247bd90afb7241b925e6c1e03b7cf062161a3e3 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Alexei Fedorov52fd7332020-01-08 14:02:18 +00002# Copyright (c) 2018-2020, 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
Madhukar Pappireddy0ab15ae2020-04-19 23:58:39 -05009VERSION_MINOR := 3
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
11################################################################################
12# Default values for build configurations, and their dependencies
13################################################################################
14
15include defaults.mk
16
17PLAT := ${DEFAULT_PLAT}
18
19# Assertions enabled for DEBUG builds by default
20ENABLE_ASSERTIONS := ${DEBUG}
21
22################################################################################
23# Checkpatch script options
24################################################################################
25
26CHECKCODE_ARGS := --no-patch
27# Do not check the coding style on imported library files or documentation files
28INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000029 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030 $(wildcard include/lib/*)))
31LIB_DIRS_TO_CHECK := $(sort $(filter-out \
32 lib/compiler-rt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000033 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 $(wildcard lib/*)))
35ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
36 lib \
37 include \
38 docs \
39 %.md \
40 %.rst, \
41 $(wildcard *)))
42CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
43 ${INC_LIB_DIRS_TO_CHECK} \
44 ${LIB_DIRS_TO_CHECK}
45
46ifeq (${V},0)
47 Q=@
48else
49 Q=
50endif
51export Q
52
53ifneq (${DEBUG}, 0)
54 BUILD_TYPE := debug
55 # Use LOG_LEVEL_INFO by default for debug builds
56 LOG_LEVEL := 40
57else
58 BUILD_TYPE := release
59 # Use LOG_LEVEL_ERROR by default for release builds
60 LOG_LEVEL := 20
61endif
62
63# Default build string (git branch and commit)
64ifeq (${BUILD_STRING},)
65 BUILD_STRING := $(shell git log -n 1 --pretty=format:"%h")
66endif
67
68VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
69
70BUILD_BASE := ./build
71BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
72
73PLAT_MAKEFILE := platform.mk
74# Generate the platforms list by recursively searching for all directories
75# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
76# char and strip out the final '|'.
77PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
78 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
79 sed -r 's/\|$$//')
80
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020081DOCS_PATH := docs
82
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020083# Convenience function for adding build definitions
84# $(eval $(call add_define,BAR_DEFINES,FOO)) will have:
85# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
86# inside the BAR_DEFINES variable.
87define add_define
88$(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),)
89endef
90
91# Convenience function for verifying option has a boolean value
92# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
93define assert_boolean
94$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
95endef
96
Alexei Fedorov7cc25872020-06-02 16:35:36 +010097# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
98# $(2) and assign the sequence to $(1)
99define CREATE_SEQ
100$(if $(word $(2), $($(1))),\
101 $(eval $(1) += $(words $($(1))))\
102 $(eval $(1) := $(filter-out 0,$($(1)))),\
103 $(eval $(1) += $(words $($(1))))\
104 $(call CREATE_SEQ,$(1),$(2))\
105)
106endef
107
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200108ifeq (${PLAT},)
109 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
110endif
111PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
112PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
113ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
114 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
115endif
116
117.PHONY: all
118all: msg_start
119
120.PHONY: msg_start
121msg_start:
122 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200123 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200124
125# Include test images makefiles.
126include tftf/framework/framework.mk
127include tftf/tests/tests.mk
128include fwu/ns_bl1u/ns_bl1u.mk
129include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100130
131# Only platform fvp supports cactus_mm, ivy, quark
132ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000133include spm/cactus_mm/cactus_mm.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000134include spm/ivy/ivy.mk
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000135include spm/quark/quark.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100136endif
137
138# cactus is supported on platforms: fvp, tc0
139ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
140include spm/cactus/cactus.mk
141endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200142
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000143################################################################################
144# Include libc
145################################################################################
146include lib/libc/libc.mk
147
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200148# Include platform specific makefile last because:
149# - the platform makefile may use all previous definitions in this file.
150# - the platform makefile may wish overwriting some of them.
151include ${PLAT_MAKEFILE_FULL}
152
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200153.SUFFIXES:
154
155################################################################################
156# Build options checks
157################################################################################
158$(eval $(call assert_boolean,DEBUG))
159$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
160$(eval $(call assert_boolean,FIRMWARE_UPDATE))
161$(eval $(call assert_boolean,FWU_BL_TEST))
162$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200163$(eval $(call assert_boolean,USE_NVM))
164
165################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100166# Process build options
167################################################################################
168
169# Process BRANCH_PROTECTION value and set
170# Pointer Authentication and Branch Target Identification flags
171include branch_protection.mk
172
173################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200174# Add definitions to the cpp preprocessor based on the current build options.
175# This is done after including the platform specific makefile to allow the
176# platform to overwrite the default options
177################################################################################
178$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
179$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
180$(eval $(call add_define,TFTF_DEFINES,DEBUG))
181$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100182$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000183$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200184$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
185$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
186$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200187$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
188
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200189################################################################################
190
191# Assembler, compiler and linker flags shared across all test images.
192COMMON_ASFLAGS :=
193COMMON_CFLAGS :=
194COMMON_LDFLAGS :=
195
196ifeq (${DEBUG},1)
197COMMON_CFLAGS += -g
198COMMON_ASFLAGS += -g -Wa,--gdwarf-2
199endif
200
Joel Hutton6a6f4832019-04-08 15:46:36 +0100201# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
202ifeq (${ARM_ARCH_MINOR},0)
203march32-directive = -march=armv8-a
204march64-directive = -march=armv8-a
205else
206march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a
207march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a
208endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200209
Joel Hutton6a6f4832019-04-08 15:46:36 +0100210COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
211COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
212
213COMMON_ASFLAGS_aarch32 := ${march32-directive}
214COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200215
216COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
217 -Werror -Wmissing-include-dirs \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000218 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
219 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200220COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
221 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
222 -std=gnu99 -Os
223COMMON_CFLAGS += -ffunction-sections -fdata-sections
224
225# Get the content of CFLAGS user defined value last so they are appended after
226# the options defined in the Makefile
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000227COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200228
229COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
230
231CC := ${CROSS_COMPILE}gcc
232CPP := ${CROSS_COMPILE}cpp
233AS := ${CROSS_COMPILE}gcc
234AR := ${CROSS_COMPILE}ar
235LD := ${CROSS_COMPILE}ld
236OC := ${CROSS_COMPILE}objcopy
237OD := ${CROSS_COMPILE}objdump
238NM := ${CROSS_COMPILE}nm
239PP := ${CROSS_COMPILE}gcc
240
241################################################################################
242
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000243TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200244TFTF_INCLUDES += ${PLAT_INCLUDES}
245TFTF_CFLAGS += ${COMMON_CFLAGS}
246TFTF_ASFLAGS += ${COMMON_ASFLAGS}
247TFTF_LDFLAGS += ${COMMON_LDFLAGS}
248
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100249ifneq (${BP_OPTION},none)
250TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
251NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
252NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
253CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
254CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
255IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
256QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000257endif
258
Olivier Deprez231115d2020-02-03 11:27:01 +0100259#####################################################################################
260ifneq ($(findstring gcc,$(notdir $(LD))),)
261 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
262else
263 PIE_LDFLAGS += -pie --no-dynamic-linker
264endif
265
266#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000267NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200268NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
269NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
270NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
271NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
272
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000273NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200274NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
275NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
276NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
277NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
278
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000279CACTUS_MM_SOURCES += ${LIBC_SRCS}
280CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
281CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
282CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
283CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
284
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000285CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200286CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100287CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200288CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100289CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200290
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000291IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000292IVY_INCLUDES += ${PLAT_INCLUDES}
293IVY_CFLAGS += ${COMMON_CFLAGS}
294IVY_ASFLAGS += ${COMMON_ASFLAGS}
295IVY_LDFLAGS += ${COMMON_LDFLAGS}
296
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000297QUARK_SOURCES += ${LIBC_SRCS}
298QUARK_INCLUDES += ${PLAT_INCLUDES}
299QUARK_CFLAGS += ${COMMON_CFLAGS}
300QUARK_ASFLAGS += ${COMMON_ASFLAGS}
301QUARK_LDFLAGS += ${COMMON_LDFLAGS}
302
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200303.PHONY: locate-checkpatch
304locate-checkpatch:
305ifndef CHECKPATCH
306 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
307else
308ifeq (,$(wildcard ${CHECKPATCH}))
309 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
310endif
311endif
312
313.PHONY: clean
314clean:
315 @echo " CLEAN"
316 ${Q}rm -rf ${BUILD_PLAT}
317 ${MAKE} -C el3_payload clean
318
319.PHONY: realclean distclean
320realclean distclean:
321 @echo " REALCLEAN"
322 ${Q}rm -rf ${BUILD_BASE}
323 ${Q}rm -f ${CURDIR}/cscope.*
324 ${MAKE} -C el3_payload distclean
325
326.PHONY: checkcodebase
327checkcodebase: locate-checkpatch
328 @echo " CHECKING STYLE"
329 @if test -d .git ; then \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000330 git ls-files | grep -E -v 'libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200331 while read GIT_FILE ; \
332 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
333 done ; \
334 else \
335 find . -type f -not -iwholename "*.git*" \
336 -not -iwholename "*build*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000337 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200338 -not -iwholename "*docs*" \
339 -not -iwholename "*.md" \
340 -not -iwholename "*.rst" \
341 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
342 fi
343
344.PHONY: checkpatch
345checkpatch: locate-checkpatch
346 @echo " CHECKING STYLE"
347 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
348 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
349 printf "\n[*] Checking style of '$$commit'\n\n"; \
350 git log --format=email "$$commit~..$$commit" \
351 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
352 git diff --format=email "$$commit~..$$commit" \
353 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
354 done
355
356ifneq (${FIRMWARE_UPDATE},1)
357.PHONY: ns_bl1u ns_bl2u
358ns_bl1u ns_bl2u:
359 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
360 on this platform."
361 @exit 1
362endif
363
364ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000365.PHONY: cactus_mm
366cactus_mm:
367 @echo "ERROR: $@ is supported only on AArch64 FVP."
368 @exit 1
369
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000370.PHONY: ivy
371ivy:
372 @echo "ERROR: $@ is supported only on AArch64 FVP."
373 @exit 1
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000374
375.PHONY: quark
376quark:
377 @echo "ERROR: $@ is supported only on AArch64 FVP."
378 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200379endif
380
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100381ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
382.PHONY: cactus
383cactus:
384 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
385 @exit 1
386endif
387
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200388MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
389
390define MAKE_C
391
392$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
393$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
394
Bence Szépkúti537b3582019-11-29 18:23:56 +0100395$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200396 @echo " CC $$<"
397 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
398
399-include $(DEP)
400endef
401
402
403define MAKE_S
404
405$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
406$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
407
Bence Szépkúti537b3582019-11-29 18:23:56 +0100408$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200409 @echo " AS $$<"
410 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
411
412-include $(DEP)
413endef
414
415
416define MAKE_LD
417
418$(eval DEP := $(1).d)
419
Bence Szépkúti537b3582019-11-29 18:23:56 +0100420$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200421 @echo " PP $$<"
422 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
423
424-include $(DEP)
425endef
426
427
428define MAKE_OBJS
429 $(eval C_OBJS := $(filter %.c,$(2)))
430 $(eval REMAIN := $(filter-out %.c,$(2)))
431 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
432
433 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
434 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
435 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
436
437 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
438endef
439
440
441# NOTE: The line continuation '\' is required in the next define otherwise we
442# end up with a line-feed characer at the end of the last c filename.
443# Also bare this issue in mind if extending the list of supported filetypes.
444define SOURCES_TO_OBJS
445 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
446 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
447endef
448
449define uppercase
450$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
451endef
452
453define MAKE_IMG
454 $(eval IMG_PREFIX := $(call uppercase, $(1)))
455 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
456 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
457 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
458 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
459 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
460 $(eval ELF := $(BUILD_DIR)/$(1).elf)
461 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
462 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
463
464 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
465 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
466
467$(BUILD_DIR) :
468 $$(Q)mkdir -p "$$@"
469
470$(ELF) : $(OBJS) $(LINKERFILE)
471 @echo " LD $$@"
472 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
473 const char version_string[] = "${VERSION_STRING}";' | \
474 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
475 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
476 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
477
478$(DUMP) : $(ELF)
479 @echo " OD $$@"
480 $${Q}$${OD} -dx $$< > $$@
481
482$(BIN) : $(ELF)
483 @echo " BIN $$@"
484 $$(Q)$$(OC) -O binary $$< $$@
485 @echo
486 @echo "Built $$@ successfully"
487 @echo
488
489.PHONY : $(1)
490$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
491
492all : $(1)
493
494endef
495
496$(AUTOGEN_DIR):
497 $(Q)mkdir -p "$@"
498
499$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
500 @echo " AUTOGEN $@"
501 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
502
503$(eval $(call MAKE_IMG,tftf))
504
505ifeq ($(FIRMWARE_UPDATE), 1)
506 $(eval $(call MAKE_IMG,ns_bl1u))
507 $(eval $(call MAKE_IMG,ns_bl2u))
508endif
509
510ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000511 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200512 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000513 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000514 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200515endif
516
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100517ifeq (${ARCH}-${PLAT},aarch64-tc0)
518 $(eval $(call MAKE_IMG,cactus))
519endif
520
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200521# The EL3 test payload is only supported in AArch64. It has an independent build
522# system.
523.PHONY: el3_payload
524ifneq (${ARCH},aarch32)
525el3_payload: $(BUILD_DIR)
526 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
527 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
528
529all: el3_payload
530endif
531
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200532doc:
533 @echo " BUILD DOCUMENTATION"
534 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
535
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200536.PHONY: cscope
537cscope:
538 @echo " CSCOPE"
539 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
540 ${Q}cscope -b -q -k
541
542.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500543.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200544help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500545 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandovald8711ca2020-07-14 11:00:31 -0500546<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500547 echo ""
548 echo "PLAT is used to specify which platform you wish to build."
549 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
550 echo ""
551 echo "Supported Targets:"
552 echo " all Build all supported binaries for this platform"
553 echo " (i.e. TFTF and FWU images)"
554 echo " tftf Build the TFTF image"
555 echo " ns_bl1u Build the NS_BL1U image"
556 echo " ns_bl2u Build the NS_BL2U image"
557 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
558 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
559 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
560 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
561 echo " el3_payload Build the EL3 test payload"
562 echo " checkcodebase Check the coding style of the entire source tree"
563 echo " checkpatch Check the coding style on changes in the current"
564 echo " branch against BASE_COMMIT (default origin/master)"
565 echo " doc Build html based documentation using Sphinx tool"
566 echo " clean Clean the build for the selected platform"
567 echo " cscope Generate cscope index"
568 echo " distclean Remove all build artifacts for all platforms"
569 echo " help_tests List all possible sets of tests"
570 echo ""
571 echo "note: most build targets require PLAT to be set to a specific platform."
572 echo ""
573 echo "example: build all targets for the FVP platform:"
574 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"