xref: /rk3399_ARM-atf/Makefile (revision 9f98aa1a7e33dd55851fd4feec0de9b40b6d9f10)
1#
2# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# Redistributions of source code must retain the above copyright notice, this
8# list of conditions and the following disclaimer.
9#
10# Redistributions in binary form must reproduce the above copyright notice,
11# this list of conditions and the following disclaimer in the documentation
12# and/or other materials provided with the distribution.
13#
14# Neither the name of ARM nor the names of its contributors may be used
15# to endorse or promote products derived from this software without specific
16# prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31# Decrease the verbosity of the make script
32# can be made verbose by passing V=1 at the make command line
33ifdef V
34  KBUILD_VERBOSE = ${V}
35else
36  KBUILD_VERBOSE = 0
37endif
38
39# Checkpatch ignores
40CHECK_IGNORE		=	--ignore COMPLEX_MACRO
41
42CHECKPATCH_ARGS		=	--no-tree --no-signoff ${CHECK_IGNORE}
43CHECKCODE_ARGS		=	--no-patch --no-tree --no-signoff ${CHECK_IGNORE}
44
45ifeq "${KBUILD_VERBOSE}" "0"
46	Q=@
47	CHECKCODE_ARGS	+=	--no-summary --terse
48else
49	Q=
50endif
51
52export Q
53
54DEBUG	?= 0
55
56ifneq (${DEBUG}, 0)
57	BUILD_TYPE	:=	debug
58else
59	BUILD_TYPE	:=	release
60endif
61
62BL_COMMON_SOURCES	:=	misc_helpers.S		\
63				cache_helpers.S		\
64				tlb_helpers.S		\
65				xlat_helpers.c		\
66				std.c			\
67				bl_common.c		\
68				platform_helpers.S	\
69				io_storage.c
70
71ARCH 			?=	aarch64
72
73# By default, build all platforms available
74PLAT			?=	fvp
75# By default, build no SPD component
76SPD			?=	none
77
78BUILD_BASE		:=	./build
79BUILD_PLAT		:=	${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
80
81PLATFORMS		:=	$(shell ls -I common plat/)
82SPDS			:=	$(shell ls -I none services/spd)
83HELP_PLATFORMS		:=	$(shell echo ${PLATFORMS} | sed 's/ /|/g')
84
85ifeq (${PLAT},)
86  $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
87endif
88ifeq ($(findstring ${PLAT},${PLATFORMS}),)
89  $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
90endif
91
92all: msg_start
93
94msg_start:
95	@echo "Building ${PLAT}"
96
97include plat/${PLAT}/platform.mk
98
99ifdef BL1_SOURCES
100NEED_BL1 := yes
101include bl1/bl1.mk
102endif
103
104ifdef BL2_SOURCES
105NEED_BL2 := yes
106include bl2/bl2.mk
107endif
108
109ifdef BL31_SOURCES
110NEED_BL31 := yes
111include bl31/bl31.mk
112endif
113
114# Include SPD Makefile if one has been specified
115ifneq (${SPD},none)
116  # We expect to locate an spd.mk under the specified SPD directory
117  SPD_MAKE		:=	$(shell m="services/spd/${SPD}/${SPD}.mk"; [ -f "$$m" ] && echo "$$m")
118
119  ifeq (${SPD_MAKE},)
120    $(error Error: No services/spd/${SPD}/${SPD}.mk located)
121  endif
122  $(info Including ${SPD_MAKE})
123  include ${SPD_MAKE}
124
125  # If there's BL32 companion for the chosen SPD, and the SPD wants to build the
126  # BL2 from source, we expect that the SPD's Makefile would set NEED_BL32
127  # variable to "yes"
128endif
129
130.PHONY:			all msg_start ${PLATFORMS} clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip
131.SUFFIXES:
132
133
134INCLUDES		+=	-Ilib/include/			\
135				-Idrivers/io			\
136				-Iinclude/${ARCH}/		\
137				-Iinclude/			\
138				-Iarch/system/gic		\
139				-Iservices/std_svc/psci		\
140				-Iinclude/stdlib		\
141				-Iinclude/stdlib/sys		\
142				-Iplat/${PLAT}			\
143				${PLAT_INCLUDES}		\
144				${SPD_INCLUDES}
145
146ASFLAGS			+= 	-nostdinc -ffreestanding -Wa,--fatal-warnings	\
147				-mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES}	\
148				-DDEBUG=${DEBUG}
149CFLAGS			:= 	-nostdinc -pedantic -ffreestanding -Wall	\
150				-Werror -mgeneral-regs-only -std=c99 -c -Os	\
151				-DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
152
153LDFLAGS			+=	--fatal-warnings -O1
154
155
156vpath %.ld.S bl1:bl2:bl31
157vpath %.c bl1:bl2:bl31
158vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
159vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
160vpath %.c lib/arch/${ARCH} # One of the missing paths needed for BL_COMMON_SOURCES
161
162
163ifneq (${DEBUG}, 0)
164#CFLAGS			+= 	-g -O0
165CFLAGS			+= 	-g
166# -save-temps -fverbose-asm
167ASFLAGS			+= 	-g -Wa,--gdwarf-2
168else
169CFLAGS			+=	-DNDEBUG=1
170endif
171
172
173CC			:=	${CROSS_COMPILE}gcc
174CPP			:=	${CROSS_COMPILE}cpp
175AS			:=	${CROSS_COMPILE}gcc
176AR			:=	${CROSS_COMPILE}ar
177LD			:=	${CROSS_COMPILE}ld
178OC			:=	${CROSS_COMPILE}objcopy
179OD			:=	${CROSS_COMPILE}objdump
180NM			:=	${CROSS_COMPILE}nm
181PP			:=	${CROSS_COMPILE}gcc -E ${CFLAGS}
182
183BASE_COMMIT		?=	origin/master
184
185# Variables for use with Firmware Image Package
186FIPTOOLPATH		?=	tools/fip_create
187FIPTOOL			?=	${FIPTOOLPATH}/fip_create
188fiptool:		${FIPTOOL}
189fip:			${BUILD_PLAT}/fip.bin
190
191ifeq (${PLAT},all)
192  ifeq (${MAKECMDGOALS},clean)
193    $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
194  endif
195endif
196
197locate-checkpatch:
198ifndef CHECKPATCH
199	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
200else
201ifeq (,$(wildcard ${CHECKPATCH}))
202	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
203endif
204endif
205
206clean:
207			@echo "  CLEAN"
208			${Q}rm -rf ${BUILD_PLAT}
209			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
210
211realclean distclean:
212			@echo "  REALCLEAN"
213			${Q}rm -rf ${BUILD_BASE}
214			${Q}rm -f ${CURDIR}/cscope.*
215			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
216
217checkcodebase:		locate-checkpatch
218			@echo "  CHECKING STYLE"
219			@if test -d .git ; then	\
220				git ls-files | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ;	\
221			 else			\
222				 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
223			 fi
224
225checkpatch:		locate-checkpatch
226			@echo "  CHECKING STYLE"
227			@git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true
228
229${FIPTOOL}:
230			${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH}
231			@echo
232			@echo "Built $@ successfully"
233			@echo
234
235define match_goals
236$(strip $(foreach goal,$(1),$(filter $(goal),$(MAKECMDGOALS))))
237endef
238
239
240CLEANING := $(call match_goals,clean realclean distclean)
241
242
243define MAKE_C
244
245$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
246$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ)))
247
248$(OBJ) : $(2)
249	@echo "  CC      $$<"
250	$$(Q)$$(CC) $$(CFLAGS) -c $$< -o $$@
251
252
253$(PREREQUISITES) : $(2)
254	@echo "  DEPS    $$@"
255	@mkdir -p $(1)
256	$$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$<
257
258ifeq "$(CLEANING)" ""
259-include $(PREREQUISITES)
260endif
261
262endef
263
264
265define MAKE_S
266
267$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
268$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ)))
269
270$(OBJ) : $(2)
271	@echo "  AS      $$<"
272	$$(Q)$$(AS) $$(ASFLAGS) -c $$< -o $$@
273
274$(PREREQUISITES) : $(2)
275	@echo "  DEPS    $$@"
276	@mkdir -p $(1)
277	$$(Q)$$(AS) $$(ASFLAGS) -M -MT $(OBJ) -MF $$@ $$<
278
279ifeq "$(CLEANING)" ""
280-include $(PREREQUISITES)
281endif
282
283endef
284
285
286define MAKE_LD
287
288$(eval PREREQUISITES := $(1).d)
289
290$(1) : $(2)
291	@echo "  PP      $$<"
292	$$(Q)$$(AS) $$(ASFLAGS) -P -E -o $$@ $$<
293
294$(PREREQUISITES) : $(2)
295	@echo "  DEPS    $$@"
296	@mkdir -p $$(dir $$@)
297	$$(Q)$$(AS) $$(ASFLAGS) -M -MT $(1) -MF $$@ $$<
298
299ifeq "$(CLEANING)" ""
300-include $(PREREQUISITES)
301endif
302
303endef
304
305
306define MAKE_OBJS
307	$(eval C_OBJS := $(filter %.c,$(2)))
308	$(eval REMAIN := $(filter-out %.c,$(2)))
309	$(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj))))
310
311	$(eval S_OBJS := $(filter %.S,$(REMAIN)))
312	$(eval REMAIN := $(filter-out %.S,$(REMAIN)))
313	$(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj))))
314
315	$(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
316endef
317
318
319# NOTE: The line continuation '\' is required in the next define otherwise we
320# end up with a line-feed characer at the end of the last c filename.
321# Also bare this issue in mind if extending the list of supported filetypes.
322define SOURCES_TO_OBJS
323	$(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
324	$(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
325endef
326
327define MAKE_BL
328	$(eval BUILD_DIR  := ${BUILD_PLAT}/bl$(1))
329	$(eval SOURCES    := $(BL$(1)_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
330	$(eval OBJS       := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
331	$(eval LINKERFILE := $(BUILD_DIR)/bl$(1).ld)
332	$(eval MAPFILE    := $(BUILD_DIR)/bl$(1).map)
333	$(eval ELF        := $(BUILD_DIR)/bl$(1).elf)
334	$(eval DUMP       := $(BUILD_DIR)/bl$(1).dump)
335	$(eval BIN        := $(BUILD_PLAT)/bl$(1).bin)
336
337	$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES)))
338	$(eval $(call MAKE_LD,$(LINKERFILE),$(BL$(1)_LINKERFILE)))
339
340$(BUILD_DIR) :
341	$$(Q)mkdir -p "$$@"
342
343$(ELF) : $(OBJS) $(LINKERFILE)
344	@echo "  LD      $$@"
345	@echo 'const char build_message[] = "Built : "__TIME__", "__DATE__;' | \
346		$$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o
347	$$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \
348					$(BUILD_DIR)/build_message.o $(OBJS)
349
350$(DUMP) : $(ELF)
351	@echo "  OD      $$@"
352	$${Q}$${OD} -dx $$< > $$@
353
354$(BIN) : $(ELF)
355	@echo "  BIN     $$@"
356	$$(Q)$$(OC) -O binary $$< $$@
357	@echo
358	@echo "Built $$@ successfully"
359	@echo
360
361.PHONY : bl$(1)
362bl$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
363
364all : bl$(1)
365
366$(eval FIP_DEPS += $(if $2,$(BIN),))
367$(eval FIP_ARGS += $(if $2,--bl$(1) $(BIN),))
368
369endef
370
371
372ifeq (${NEED_BL1},yes)
373$(eval $(call MAKE_BL,1))
374endif
375
376ifeq (${NEED_BL2},yes)
377$(eval $(call MAKE_BL,2,in_fip))
378endif
379
380ifeq (${NEED_BL31},yes)
381BL31_SOURCES += ${SPD_SOURCES}
382$(eval $(call MAKE_BL,31,in_fip))
383endif
384
385ifeq (${NEED_BL32},yes)
386$(eval $(call MAKE_BL,32,in_fip))
387endif
388
389${BUILD_PLAT}/fip.bin:	${FIP_DEPS} ${BL33} ${FIPTOOL}
390			$(if ${BL33},,$(error "To build a FIP, please set BL33 to point to the Normal World binary, eg: BL33=../uefi/FVP_AARCH64_EFI.fd"))
391			${Q}${FIPTOOL} --dump \
392				${FIP_ARGS} \
393				--bl33 ${BL33} \
394				$@
395			@echo
396			@echo "Built $@ successfully"
397			@echo
398
399
400cscope:
401	@echo "  CSCOPE"
402	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
403	${Q}cscope -b -q -k
404
405help:
406	@echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch>"
407	@echo ""
408	@echo "PLAT is used to specify which platform you wish to build."
409	@echo ""
410	@echo "Supported Targets:"
411	@echo "  all            Build the BL1, BL2 and BL31 binaries"
412	@echo "  bl1            Build the BL1 binary"
413	@echo "  bl2            Build the BL2 binary"
414	@echo "  bl31           Build the BL31 binary"
415	@echo "  checkcodebase  Check the coding style of the entire source tree"
416	@echo "  checkpatch     Check the coding style on changes in the current"
417	@echo "                 branch against BASE_COMMIT (default origin/master)"
418	@echo "  clean          Clean the build for the selected platform"
419	@echo "  cscope         Generate cscope index"
420	@echo "  distclean      Remove all build artifacts for all platforms"
421	@echo "  fiptool        Build the Firmware Image Package(FIP) creation tool"
422	@echo ""
423	@echo "note: most build targets require PLAT to be set to a specific platform."
424	@echo ""
425	@echo "example: build all targets for the FVP platform:"
426	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
427