blob: b48fbf55fbeefdaef428785309b8cc87de0df160 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001#
Dan Handleye83b0ca2014-01-14 18:17:09 +00002# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003#
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
James Morrisseyeaaeece2013-11-01 13:56:59 +000034 KBUILD_VERBOSE = ${V}
Achin Gupta4f6ad662013-10-25 09:08:21 +010035else
36 KBUILD_VERBOSE = 0
37endif
38
Ian Spray36eaaf32014-01-30 17:25:28 +000039CHECKPATCH_ARGS = --no-tree --no-signoff
40CHECKCODE_ARGS = --no-patch --no-tree --no-signoff
41
James Morrisseyeaaeece2013-11-01 13:56:59 +000042ifeq "${KBUILD_VERBOSE}" "0"
Achin Gupta4f6ad662013-10-25 09:08:21 +010043 Q=@
Ian Spray36eaaf32014-01-30 17:25:28 +000044 CHECKCODE_ARGS += --no-summary --terse
Achin Gupta4f6ad662013-10-25 09:08:21 +010045else
46 Q=
47endif
48
49DEBUG ?= 0
James Morrisseyeaaeece2013-11-01 13:56:59 +000050
51ifneq (${DEBUG}, 0)
52 BUILD_TYPE := debug
53else
54 BUILD_TYPE := release
55endif
56
Ryan Harkind7a6b0f2014-01-13 14:40:13 +000057BL_COMMON_OBJS := misc_helpers.o \
58 cache_helpers.o \
59 tlb_helpers.o \
60 std.o \
61 bl_common.o \
62 platform_helpers.o
63
Ryan Harkin25cff832014-01-13 12:37:03 +000064ARCH ?= aarch64
Achin Gupta4f6ad662013-10-25 09:08:21 +010065
Ryan Harkin25cff832014-01-13 12:37:03 +000066# By default, build all platforms available
67PLAT ?= all
Achin Gupta4f6ad662013-10-25 09:08:21 +010068
Ryan Harkin25cff832014-01-13 12:37:03 +000069BUILD_BASE := ./build
70BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
71BUILD_BL1 := ${BUILD_PLAT}/bl1
72BUILD_BL2 := ${BUILD_PLAT}/bl2
73BUILD_BL31 := ${BUILD_PLAT}/bl31
74BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31}
Achin Gupta4f6ad662013-10-25 09:08:21 +010075
Ryan Harkin25cff832014-01-13 12:37:03 +000076PLATFORMS := $(shell ls -I common plat/)
Ryan Harkin72ee3312014-01-15 16:55:07 +000077HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g')
78
Ryan Harkin25cff832014-01-13 12:37:03 +000079ifeq (${PLAT},)
80 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
81endif
82ifeq ($(findstring ${PLAT},${PLATFORMS} all),)
83 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
84endif
85
86ifeq (${PLAT},all)
87all: ${PLATFORMS}
88else
89all: msg_start bl1 bl2 bl31
90endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010091
Ryan Harkin25cff832014-01-13 12:37:03 +000092msg_start:
93 @echo "Building ${PLAT}"
Achin Gupta4f6ad662013-10-25 09:08:21 +010094
Ryan Harkin25cff832014-01-13 12:37:03 +000095${PLATFORMS}:
96 ${MAKE} PLAT=$@ all
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
Ryan Harkin25cff832014-01-13 12:37:03 +000098ifneq (${PLAT},all)
99 $(info Including ${PLAT}/platform.mk)
100 include plat/${PLAT}/platform.mk
101 $(info Including bl1.mk)
102 include bl1/bl1.mk
103 $(info Including bl2.mk)
104 include bl2/bl2.mk
105 $(info Including bl31.mk)
106 include bl31/bl31.mk
107endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
Ian Spray36eaaf32014-01-30 17:25:28 +0000109.PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31 cscope locate-checkpatch checkcodebase checkpatch
James Morrisseyeaaeece2013-11-01 13:56:59 +0000110.SUFFIXES:
111
112
Ryan Harkin25cff832014-01-13 12:37:03 +0000113BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
114BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
115BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
James Morrisseyeaaeece2013-11-01 13:56:59 +0000116BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE})
117BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE})
118BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE})
119BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE})
120BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE})
121BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE})
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000123INCLUDES += -Ilib/include/ \
124 -Iinclude/${ARCH}/ \
125 -Iinclude/ \
126 -Iarch/system/gic \
127 -Icommon/psci \
128 -Iinclude/stdlib \
129 -Iinclude/stdlib/sys \
130 -Iplat/${PLAT} \
131 ${PLAT_INCLUDES}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132
Harry Liebel0af6d642013-12-20 18:51:12 +0000133ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
Harry Liebel4f603682014-01-14 18:11:48 +0000134 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES}
135CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \
136 -Werror -mgeneral-regs-only -std=c99 -c -Os \
137 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
Sandrine Bailleux3e850a82013-11-20 11:50:48 +0000139LDFLAGS += --fatal-warnings -O1
James Morrisseyeaaeece2013-11-01 13:56:59 +0000140BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT}
141BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT}
142BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100143
144
145vpath %.ld.S bl1:bl2:bl31
146vpath %.c bl1:bl2:bl31
147vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
148vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
149
150
James Morrisseyeaaeece2013-11-01 13:56:59 +0000151ifneq (${DEBUG}, 0)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152#CFLAGS += -g -O0
153CFLAGS += -g
154# -save-temps -fverbose-asm
155ASFLAGS += -g -Wa,--gdwarf-2
156endif
157
158
James Morrisseyeaaeece2013-11-01 13:56:59 +0000159CC := ${CROSS_COMPILE}gcc
160CPP := ${CROSS_COMPILE}cpp
161AS := ${CROSS_COMPILE}gcc
162AR := ${CROSS_COMPILE}ar
163LD := ${CROSS_COMPILE}ld
164OC := ${CROSS_COMPILE}objcopy
165OD := ${CROSS_COMPILE}objdump
166NM := ${CROSS_COMPILE}nm
167PP := ${CROSS_COMPILE}gcc -E ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100168
169
Ryan Harkin25cff832014-01-13 12:37:03 +0000170bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin
171bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin
172bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin
Achin Gupta4f6ad662013-10-25 09:08:21 +0100173
Ian Spray36eaaf32014-01-30 17:25:28 +0000174BASE_COMMIT ?= origin/master
175
Ryan Harkin25cff832014-01-13 12:37:03 +0000176ifeq (${PLAT},all)
177 ifeq (${MAKECMDGOALS},clean)
178 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
179 endif
180endif
Ian Spray36eaaf32014-01-30 17:25:28 +0000181
182locate-checkpatch:
183ifndef CHECKPATCH
184 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
185else
186ifeq (,$(wildcard ${CHECKPATCH}))
187 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
188endif
189endif
190
Achin Gupta4f6ad662013-10-25 09:08:21 +0100191clean:
192 @echo " CLEAN"
Ryan Harkin25cff832014-01-13 12:37:03 +0000193 ${Q}rm -rf ${BUILD_PLAT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100194
James Morrisseyeaaeece2013-11-01 13:56:59 +0000195realclean distclean:
196 @echo " REALCLEAN"
197 ${Q}rm -rf ${BUILD_BASE}
Joakim Bech35fab8c2014-01-23 14:51:49 +0100198 ${Q}rm -f ${CURDIR}/cscope.*
Achin Gupta4f6ad662013-10-25 09:08:21 +0100199
200dump:
201 @echo " OBJDUMP"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000202 ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump
203 ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump
204 ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump
205
Ian Spray36eaaf32014-01-30 17:25:28 +0000206checkcodebase: locate-checkpatch
207 @echo " CHECKING STYLE"
208 @if test -d .git ; then \
209 git ls-files | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ; \
210 else \
211 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
212 fi
213
214checkpatch: locate-checkpatch
215 @echo " CHECKING STYLE"
216 @git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true
217
James Morrisseyeaaeece2013-11-01 13:56:59 +0000218${BUILD_DIRS}:
219 ${Q}mkdir -p "$@"
Achin Gupta4f6ad662013-10-25 09:08:21 +0100220
James Morrisseyeaaeece2013-11-01 13:56:59 +0000221
222${BUILD_BL1}/%.o: %.S
223 @echo " AS $<"
224 ${Q}${AS} ${ASFLAGS} -c $< -o $@
225
226${BUILD_BL2}/%.o: %.S
227 @echo " AS $<"
228 ${Q}${AS} ${ASFLAGS} -c $< -o $@
229
230${BUILD_BL31}/%.o: %.S
Achin Gupta4f6ad662013-10-25 09:08:21 +0100231 @echo " AS $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000232 ${Q}${AS} ${ASFLAGS} -c $< -o $@
233
234${BUILD_BL1}/%.o: %.c
235 @echo " CC $<"
236 ${Q}${CC} ${CFLAGS} -c $< -o $@
237
238${BUILD_BL2}/%.o: %.c
239 @echo " CC $<"
240 ${Q}${CC} ${CFLAGS} -c $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100241
James Morrisseyeaaeece2013-11-01 13:56:59 +0000242${BUILD_BL31}/%.o: %.c
Achin Gupta4f6ad662013-10-25 09:08:21 +0100243 @echo " CC $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000244 ${Q}${CC} ${CFLAGS} -c $< -o $@
245
246${BUILD_BL1}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000247 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000248 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
249
250${BUILD_BL2}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000251 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000252 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100253
James Morrisseyeaaeece2013-11-01 13:56:59 +0000254${BUILD_BL31}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000255 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000256 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100257
258
James Morrisseyeaaeece2013-11-01 13:56:59 +0000259${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100260 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000261 ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS}
262
263${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE}
264 @echo " LD $@"
265 ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100266
James Morrisseyeaaeece2013-11-01 13:56:59 +0000267${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000269 ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS}
270
Ryan Harkin25cff832014-01-13 12:37:03 +0000271${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf
272 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000273 ${Q}${OC} -O binary $< $@
274 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100275 @echo "Built $@ successfully"
276 @echo
277
Ryan Harkin25cff832014-01-13 12:37:03 +0000278${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf
279 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000280 ${Q}${OC} -O binary $< $@
281 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100282 @echo "Built $@ successfully"
283 @echo
284
Ryan Harkin25cff832014-01-13 12:37:03 +0000285${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf
286 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000287 ${Q}${OC} -O binary $< $@
288 @echo
289 @echo "Built $@ successfully"
290 @echo
Ryan Harkin72ee3312014-01-15 16:55:07 +0000291
Joakim Bech35fab8c2014-01-23 14:51:49 +0100292cscope:
293 @echo " CSCOPE"
294 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
295 ${Q}cscope -b -q -k
296
Ryan Harkin72ee3312014-01-15 16:55:07 +0000297help:
Ian Spray36eaaf32014-01-30 17:25:28 +0000298 @echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch|dump>"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000299 @echo ""
300 @echo "PLAT is used to specify which platform you wish to build."
301 @echo ""
302 @echo "Supported Targets:"
Ian Spray36eaaf32014-01-30 17:25:28 +0000303 @echo " all Build the BL1, BL2 and BL31 binaries"
304 @echo " bl1 Build the BL1 binary"
305 @echo " bl2 Build the BL2 binary"
306 @echo " bl31 Build the BL31 binary"
307 @echo " checkcodebase Check the coding style of the entire source tree"
308 @echo " checkpatch Check the coding style on changes in the current"
309 @echo " branch against BASE_COMMIT (default origin/master)"
310 @echo " clean Clean the build for the selected platform"
Joakim Bech35fab8c2014-01-23 14:51:49 +0100311 @echo " cscope Generate cscope index"
Ian Spray36eaaf32014-01-30 17:25:28 +0000312 @echo " distclean Remove all build artifacts for all platforms"
313 @echo " dump Generate object file dumps"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000314 @echo ""
315 @echo "note: most build targets require PLAT to be set to a specific platform."
316 @echo ""
317 @echo "example: build all targets for the FVP platform:"
318 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"