blob: f809e211b944ab2b54ec0b1062a5013482abd90f [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Alexei Fedorovb61cc152020-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 Pappireddyf5b54742020-04-19 23:58:39 -05009VERSION_MINOR := 3
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},)
70 BUILD_STRING := $(shell git log -n 1 --pretty=format:"%h")
71endif
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
97.PHONY: all
98all: msg_start
99
100.PHONY: msg_start
101msg_start:
102 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200103 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200104
105# Include test images makefiles.
106include tftf/framework/framework.mk
107include tftf/tests/tests.mk
108include fwu/ns_bl1u/ns_bl1u.mk
109include fwu/ns_bl2u/ns_bl2u.mk
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000110include spm/cactus_mm/cactus_mm.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200111include spm/cactus/cactus.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000112include spm/ivy/ivy.mk
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000113include spm/quark/quark.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200114
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000115################################################################################
116# Include libc
117################################################################################
118include lib/libc/libc.mk
119
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200120# Include platform specific makefile last because:
121# - the platform makefile may use all previous definitions in this file.
122# - the platform makefile may wish overwriting some of them.
123include ${PLAT_MAKEFILE_FULL}
124
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200125.SUFFIXES:
126
127################################################################################
128# Build options checks
129################################################################################
130$(eval $(call assert_boolean,DEBUG))
131$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
132$(eval $(call assert_boolean,FIRMWARE_UPDATE))
133$(eval $(call assert_boolean,FWU_BL_TEST))
134$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200135$(eval $(call assert_boolean,USE_NVM))
136
137################################################################################
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100138# Process build options
139################################################################################
140
141# Process BRANCH_PROTECTION value and set
142# Pointer Authentication and Branch Target Identification flags
143include branch_protection.mk
144
145################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200146# Add definitions to the cpp preprocessor based on the current build options.
147# This is done after including the platform specific makefile to allow the
148# platform to overwrite the default options
149################################################################################
150$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
151$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
152$(eval $(call add_define,TFTF_DEFINES,DEBUG))
153$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100154$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000155$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200156$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
157$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
158$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200159$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
160
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200161################################################################################
162
163# Assembler, compiler and linker flags shared across all test images.
164COMMON_ASFLAGS :=
165COMMON_CFLAGS :=
166COMMON_LDFLAGS :=
167
168ifeq (${DEBUG},1)
169COMMON_CFLAGS += -g
170COMMON_ASFLAGS += -g -Wa,--gdwarf-2
171endif
172
Joel Hutton87530242019-04-08 15:46:36 +0100173# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
174ifeq (${ARM_ARCH_MINOR},0)
175march32-directive = -march=armv8-a
176march64-directive = -march=armv8-a
177else
178march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a
179march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a
180endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200181
Joel Hutton87530242019-04-08 15:46:36 +0100182COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
183COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
184
185COMMON_ASFLAGS_aarch32 := ${march32-directive}
186COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200187
188COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
189 -Werror -Wmissing-include-dirs \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000190 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
191 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200192COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
193 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
194 -std=gnu99 -Os
195COMMON_CFLAGS += -ffunction-sections -fdata-sections
196
197# Get the content of CFLAGS user defined value last so they are appended after
198# the options defined in the Makefile
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000199COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200200
201COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
202
203CC := ${CROSS_COMPILE}gcc
204CPP := ${CROSS_COMPILE}cpp
205AS := ${CROSS_COMPILE}gcc
206AR := ${CROSS_COMPILE}ar
207LD := ${CROSS_COMPILE}ld
208OC := ${CROSS_COMPILE}objcopy
209OD := ${CROSS_COMPILE}objdump
210NM := ${CROSS_COMPILE}nm
211PP := ${CROSS_COMPILE}gcc
212
213################################################################################
214
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500215TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200216TFTF_INCLUDES += ${PLAT_INCLUDES}
217TFTF_CFLAGS += ${COMMON_CFLAGS}
218TFTF_ASFLAGS += ${COMMON_ASFLAGS}
219TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500220TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200221
Alexei Fedorovf45484f2020-06-19 14:25:43 +0100222ifneq (${BP_OPTION},none)
223TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
224NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
225NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
226CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
227CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
228IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
229QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz2f13f422019-03-13 13:57:39 +0000230endif
231
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500232ifeq ($(SMC_FUZZING), 1)
233TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
234endif
235
Olivier Deprezdb70c452020-02-03 11:27:01 +0100236#####################################################################################
237ifneq ($(findstring gcc,$(notdir $(LD))),)
238 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
239else
240 PIE_LDFLAGS += -pie --no-dynamic-linker
241endif
242
243#####################################################################################
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000244NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200245NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
246NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
247NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
248NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
249
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000250NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200251NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
252NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
253NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
254NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
255
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000256CACTUS_MM_SOURCES += ${LIBC_SRCS}
257CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
258CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
259CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
260CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
261
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000262CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200263CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100264CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200265CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprezdb70c452020-02-03 11:27:01 +0100266CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200267
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000268IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000269IVY_INCLUDES += ${PLAT_INCLUDES}
270IVY_CFLAGS += ${COMMON_CFLAGS}
271IVY_ASFLAGS += ${COMMON_ASFLAGS}
272IVY_LDFLAGS += ${COMMON_LDFLAGS}
273
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000274QUARK_SOURCES += ${LIBC_SRCS}
275QUARK_INCLUDES += ${PLAT_INCLUDES}
276QUARK_CFLAGS += ${COMMON_CFLAGS}
277QUARK_ASFLAGS += ${COMMON_ASFLAGS}
278QUARK_LDFLAGS += ${COMMON_LDFLAGS}
279
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200280.PHONY: locate-checkpatch
281locate-checkpatch:
282ifndef CHECKPATCH
283 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
284else
285ifeq (,$(wildcard ${CHECKPATCH}))
286 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
287endif
288endif
289
290.PHONY: clean
291clean:
292 @echo " CLEAN"
293 ${Q}rm -rf ${BUILD_PLAT}
294 ${MAKE} -C el3_payload clean
295
296.PHONY: realclean distclean
297realclean distclean:
298 @echo " REALCLEAN"
299 ${Q}rm -rf ${BUILD_BASE}
300 ${Q}rm -f ${CURDIR}/cscope.*
301 ${MAKE} -C el3_payload distclean
302
303.PHONY: checkcodebase
304checkcodebase: locate-checkpatch
305 @echo " CHECKING STYLE"
306 @if test -d .git ; then \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500307 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200308 while read GIT_FILE ; \
309 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
310 done ; \
311 else \
312 find . -type f -not -iwholename "*.git*" \
313 -not -iwholename "*build*" \
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500314 -not -iwholename "*libfdt*" \
Ambroise Vincenta2ede622019-02-11 14:34:26 +0000315 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200316 -not -iwholename "*docs*" \
317 -not -iwholename "*.md" \
318 -not -iwholename "*.rst" \
319 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
320 fi
321
322.PHONY: checkpatch
323checkpatch: locate-checkpatch
324 @echo " CHECKING STYLE"
325 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
326 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
327 printf "\n[*] Checking style of '$$commit'\n\n"; \
328 git log --format=email "$$commit~..$$commit" \
329 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
330 git diff --format=email "$$commit~..$$commit" \
331 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
332 done
333
334ifneq (${FIRMWARE_UPDATE},1)
335.PHONY: ns_bl1u ns_bl2u
336ns_bl1u ns_bl2u:
337 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
338 on this platform."
339 @exit 1
340endif
341
342ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000343.PHONY: cactus_mm
344cactus_mm:
345 @echo "ERROR: $@ is supported only on AArch64 FVP."
346 @exit 1
347
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200348.PHONY: cactus
349cactus:
350 @echo "ERROR: $@ is supported only on AArch64 FVP."
351 @exit 1
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000352
353.PHONY: ivy
354ivy:
355 @echo "ERROR: $@ is supported only on AArch64 FVP."
356 @exit 1
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000357
358.PHONY: quark
359quark:
360 @echo "ERROR: $@ is supported only on AArch64 FVP."
361 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200362endif
363
364MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
365
366define MAKE_C
367
368$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
369$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
370
Bence Szépkúti25671c22019-11-29 18:23:56 +0100371$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200372 @echo " CC $$<"
373 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
374
375-include $(DEP)
376endef
377
378
379define MAKE_S
380
381$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
382$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
383
Bence Szépkúti25671c22019-11-29 18:23:56 +0100384$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200385 @echo " AS $$<"
386 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
387
388-include $(DEP)
389endef
390
391
392define MAKE_LD
393
394$(eval DEP := $(1).d)
395
Bence Szépkúti25671c22019-11-29 18:23:56 +0100396$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200397 @echo " PP $$<"
398 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
399
400-include $(DEP)
401endef
402
403
404define MAKE_OBJS
405 $(eval C_OBJS := $(filter %.c,$(2)))
406 $(eval REMAIN := $(filter-out %.c,$(2)))
407 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
408
409 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
410 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
411 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
412
413 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
414endef
415
416
417# NOTE: The line continuation '\' is required in the next define otherwise we
418# end up with a line-feed characer at the end of the last c filename.
419# Also bare this issue in mind if extending the list of supported filetypes.
420define SOURCES_TO_OBJS
421 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
422 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
423endef
424
425define uppercase
426$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
427endef
428
429define MAKE_IMG
430 $(eval IMG_PREFIX := $(call uppercase, $(1)))
431 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
432 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
433 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykes9f5c50b2020-06-03 15:46:55 -0500434 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200435 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
436 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
437 $(eval ELF := $(BUILD_DIR)/$(1).elf)
438 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
439 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
440
441 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
442 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
443
444$(BUILD_DIR) :
445 $$(Q)mkdir -p "$$@"
446
447$(ELF) : $(OBJS) $(LINKERFILE)
448 @echo " LD $$@"
449 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
450 const char version_string[] = "${VERSION_STRING}";' | \
451 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
452 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
453 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
454
455$(DUMP) : $(ELF)
456 @echo " OD $$@"
457 $${Q}$${OD} -dx $$< > $$@
458
459$(BIN) : $(ELF)
460 @echo " BIN $$@"
461 $$(Q)$$(OC) -O binary $$< $$@
462 @echo
463 @echo "Built $$@ successfully"
464 @echo
465
466.PHONY : $(1)
467$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
468
469all : $(1)
470
471endef
472
473$(AUTOGEN_DIR):
474 $(Q)mkdir -p "$@"
475
476$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
477 @echo " AUTOGEN $@"
478 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 -0500479ifeq ($(SMC_FUZZING), 1)
480 $(Q)mkdir -p ${BUILD_PLAT}/smcf
481 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
482 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
483 --redefine-sym _binary___build_fvp_debug_smcf_dtb_start=_binary___dtb_start \
484 --redefine-sym _binary___build_fvp_debug_smcf_dtb_end=_binary___dtb_end
485endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200486
487$(eval $(call MAKE_IMG,tftf))
488
489ifeq ($(FIRMWARE_UPDATE), 1)
490 $(eval $(call MAKE_IMG,ns_bl1u))
491 $(eval $(call MAKE_IMG,ns_bl2u))
492endif
493
494ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diaz9d7726c2019-03-19 10:59:11 +0000495 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200496 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000497 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diazfee6e7e2019-03-28 13:16:04 +0000498 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200499endif
500
501# The EL3 test payload is only supported in AArch64. It has an independent build
502# system.
503.PHONY: el3_payload
504ifneq (${ARCH},aarch32)
505el3_payload: $(BUILD_DIR)
506 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
507 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
508
509all: el3_payload
510endif
511
Sandrine Bailleux7fb2e0a2020-04-21 14:45:00 +0200512doc:
513 @echo " BUILD DOCUMENTATION"
514 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
515
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200516.PHONY: cscope
517cscope:
518 @echo " CSCOPE"
519 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
520 ${Q}cscope -b -q -k
521
522.PHONY: help
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500523.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200524help:
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500525 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Leonardo Sandoval5c882ba2020-07-14 11:00:31 -0500526<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval2d039ad2020-09-11 14:44:40 -0500527 echo ""
528 echo "PLAT is used to specify which platform you wish to build."
529 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
530 echo ""
531 echo "Supported Targets:"
532 echo " all Build all supported binaries for this platform"
533 echo " (i.e. TFTF and FWU images)"
534 echo " tftf Build the TFTF image"
535 echo " ns_bl1u Build the NS_BL1U image"
536 echo " ns_bl2u Build the NS_BL2U image"
537 echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
538 echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
539 echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
540 echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
541 echo " el3_payload Build the EL3 test payload"
542 echo " checkcodebase Check the coding style of the entire source tree"
543 echo " checkpatch Check the coding style on changes in the current"
544 echo " branch against BASE_COMMIT (default origin/master)"
545 echo " doc Build html based documentation using Sphinx tool"
546 echo " clean Clean the build for the selected platform"
547 echo " cscope Generate cscope index"
548 echo " distclean Remove all build artifacts for all platforms"
549 echo " help_tests List all possible sets of tests"
550 echo ""
551 echo "note: most build targets require PLAT to be set to a specific platform."
552 echo ""
553 echo "example: build all targets for the FVP platform:"
554 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"