blob: 197e01bea5bd75198c2567ca60277a214b0f64a8 [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
James Morrisseyeaaeece2013-11-01 13:56:59 +000039ifeq "${KBUILD_VERBOSE}" "0"
Achin Gupta4f6ad662013-10-25 09:08:21 +010040 Q=@
41else
42 Q=
43endif
44
45DEBUG ?= 0
James Morrisseyeaaeece2013-11-01 13:56:59 +000046
47ifneq (${DEBUG}, 0)
48 BUILD_TYPE := debug
49else
50 BUILD_TYPE := release
51endif
52
Ryan Harkind7a6b0f2014-01-13 14:40:13 +000053BL_COMMON_OBJS := misc_helpers.o \
54 cache_helpers.o \
55 tlb_helpers.o \
56 std.o \
57 bl_common.o \
58 platform_helpers.o
59
Ryan Harkin25cff832014-01-13 12:37:03 +000060ARCH ?= aarch64
Achin Gupta4f6ad662013-10-25 09:08:21 +010061
Ryan Harkin25cff832014-01-13 12:37:03 +000062# By default, build all platforms available
63PLAT ?= all
Achin Gupta4f6ad662013-10-25 09:08:21 +010064
Ryan Harkin25cff832014-01-13 12:37:03 +000065BUILD_BASE := ./build
66BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
67BUILD_BL1 := ${BUILD_PLAT}/bl1
68BUILD_BL2 := ${BUILD_PLAT}/bl2
69BUILD_BL31 := ${BUILD_PLAT}/bl31
70BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31}
Achin Gupta4f6ad662013-10-25 09:08:21 +010071
Ryan Harkin25cff832014-01-13 12:37:03 +000072PLATFORMS := $(shell ls -I common plat/)
Ryan Harkin72ee3312014-01-15 16:55:07 +000073HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g')
74
Ryan Harkin25cff832014-01-13 12:37:03 +000075ifeq (${PLAT},)
76 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.")
77endif
78ifeq ($(findstring ${PLAT},${PLATFORMS} all),)
79 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
80endif
81
82ifeq (${PLAT},all)
83all: ${PLATFORMS}
84else
85all: msg_start bl1 bl2 bl31
86endif
Achin Gupta4f6ad662013-10-25 09:08:21 +010087
Ryan Harkin25cff832014-01-13 12:37:03 +000088msg_start:
89 @echo "Building ${PLAT}"
Achin Gupta4f6ad662013-10-25 09:08:21 +010090
Ryan Harkin25cff832014-01-13 12:37:03 +000091${PLATFORMS}:
92 ${MAKE} PLAT=$@ all
Achin Gupta4f6ad662013-10-25 09:08:21 +010093
Ryan Harkin25cff832014-01-13 12:37:03 +000094ifneq (${PLAT},all)
95 $(info Including ${PLAT}/platform.mk)
96 include plat/${PLAT}/platform.mk
97 $(info Including bl1.mk)
98 include bl1/bl1.mk
99 $(info Including bl2.mk)
100 include bl2/bl2.mk
101 $(info Including bl31.mk)
102 include bl31/bl31.mk
103endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100104
Joakim Bech35fab8c2014-01-23 14:51:49 +0100105.PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31 cscope
James Morrisseyeaaeece2013-11-01 13:56:59 +0000106.SUFFIXES:
107
108
Ryan Harkin25cff832014-01-13 12:37:03 +0000109BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
110BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
111BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS})
James Morrisseyeaaeece2013-11-01 13:56:59 +0000112BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE})
113BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE})
114BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE})
115BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE})
116BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE})
117BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE})
Achin Gupta4f6ad662013-10-25 09:08:21 +0100118
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000119INCLUDES += -Ilib/include/ \
120 -Iinclude/${ARCH}/ \
121 -Iinclude/ \
122 -Iarch/system/gic \
123 -Icommon/psci \
124 -Iinclude/stdlib \
125 -Iinclude/stdlib/sys \
126 -Iplat/${PLAT} \
127 ${PLAT_INCLUDES}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128
Harry Liebel0af6d642013-12-20 18:51:12 +0000129ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
Harry Liebel4f603682014-01-14 18:11:48 +0000130 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES}
131CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \
132 -Werror -mgeneral-regs-only -std=c99 -c -Os \
133 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
Sandrine Bailleux3e850a82013-11-20 11:50:48 +0000135LDFLAGS += --fatal-warnings -O1
James Morrisseyeaaeece2013-11-01 13:56:59 +0000136BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT}
137BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT}
138BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
140
141vpath %.ld.S bl1:bl2:bl31
142vpath %.c bl1:bl2:bl31
143vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
144vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH}
145
146
James Morrisseyeaaeece2013-11-01 13:56:59 +0000147ifneq (${DEBUG}, 0)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100148#CFLAGS += -g -O0
149CFLAGS += -g
150# -save-temps -fverbose-asm
151ASFLAGS += -g -Wa,--gdwarf-2
152endif
153
154
James Morrisseyeaaeece2013-11-01 13:56:59 +0000155CC := ${CROSS_COMPILE}gcc
156CPP := ${CROSS_COMPILE}cpp
157AS := ${CROSS_COMPILE}gcc
158AR := ${CROSS_COMPILE}ar
159LD := ${CROSS_COMPILE}ld
160OC := ${CROSS_COMPILE}objcopy
161OD := ${CROSS_COMPILE}objdump
162NM := ${CROSS_COMPILE}nm
163PP := ${CROSS_COMPILE}gcc -E ${CFLAGS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164
165
Ryan Harkin25cff832014-01-13 12:37:03 +0000166bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin
167bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin
168bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin
Achin Gupta4f6ad662013-10-25 09:08:21 +0100169
Ryan Harkin25cff832014-01-13 12:37:03 +0000170ifeq (${PLAT},all)
171 ifeq (${MAKECMDGOALS},clean)
172 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds")
173 endif
174endif
Achin Gupta4f6ad662013-10-25 09:08:21 +0100175clean:
176 @echo " CLEAN"
Ryan Harkin25cff832014-01-13 12:37:03 +0000177 ${Q}rm -rf ${BUILD_PLAT}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100178
James Morrisseyeaaeece2013-11-01 13:56:59 +0000179realclean distclean:
180 @echo " REALCLEAN"
181 ${Q}rm -rf ${BUILD_BASE}
Joakim Bech35fab8c2014-01-23 14:51:49 +0100182 ${Q}rm -f ${CURDIR}/cscope.*
Achin Gupta4f6ad662013-10-25 09:08:21 +0100183
184dump:
185 @echo " OBJDUMP"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000186 ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump
187 ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump
188 ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump
189
190${BUILD_DIRS}:
191 ${Q}mkdir -p "$@"
Achin Gupta4f6ad662013-10-25 09:08:21 +0100192
James Morrisseyeaaeece2013-11-01 13:56:59 +0000193
194${BUILD_BL1}/%.o: %.S
195 @echo " AS $<"
196 ${Q}${AS} ${ASFLAGS} -c $< -o $@
197
198${BUILD_BL2}/%.o: %.S
199 @echo " AS $<"
200 ${Q}${AS} ${ASFLAGS} -c $< -o $@
201
202${BUILD_BL31}/%.o: %.S
Achin Gupta4f6ad662013-10-25 09:08:21 +0100203 @echo " AS $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000204 ${Q}${AS} ${ASFLAGS} -c $< -o $@
205
206${BUILD_BL1}/%.o: %.c
207 @echo " CC $<"
208 ${Q}${CC} ${CFLAGS} -c $< -o $@
209
210${BUILD_BL2}/%.o: %.c
211 @echo " CC $<"
212 ${Q}${CC} ${CFLAGS} -c $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100213
James Morrisseyeaaeece2013-11-01 13:56:59 +0000214${BUILD_BL31}/%.o: %.c
Achin Gupta4f6ad662013-10-25 09:08:21 +0100215 @echo " CC $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000216 ${Q}${CC} ${CFLAGS} -c $< -o $@
217
218${BUILD_BL1}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000219 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000220 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
221
222${BUILD_BL2}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000223 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000224 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225
James Morrisseyeaaeece2013-11-01 13:56:59 +0000226${BUILD_BL31}/%.ld: %.ld.S
Ryan Harkin25cff832014-01-13 12:37:03 +0000227 @echo " PP $<"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000228 ${Q}${AS} ${ASFLAGS} -P -E $< -o $@
Achin Gupta4f6ad662013-10-25 09:08:21 +0100229
230
James Morrisseyeaaeece2013-11-01 13:56:59 +0000231${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100232 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000233 ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS}
234
235${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE}
236 @echo " LD $@"
237 ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100238
James Morrisseyeaaeece2013-11-01 13:56:59 +0000239${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE}
Achin Gupta4f6ad662013-10-25 09:08:21 +0100240 @echo " LD $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000241 ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS}
242
Ryan Harkin25cff832014-01-13 12:37:03 +0000243${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf
244 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000245 ${Q}${OC} -O binary $< $@
246 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100247 @echo "Built $@ successfully"
248 @echo
249
Ryan Harkin25cff832014-01-13 12:37:03 +0000250${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf
251 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000252 ${Q}${OC} -O binary $< $@
253 @echo
Achin Gupta4f6ad662013-10-25 09:08:21 +0100254 @echo "Built $@ successfully"
255 @echo
256
Ryan Harkin25cff832014-01-13 12:37:03 +0000257${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf
258 @echo " BIN $@"
James Morrisseyeaaeece2013-11-01 13:56:59 +0000259 ${Q}${OC} -O binary $< $@
260 @echo
261 @echo "Built $@ successfully"
262 @echo
Ryan Harkin72ee3312014-01-15 16:55:07 +0000263
Joakim Bech35fab8c2014-01-23 14:51:49 +0100264cscope:
265 @echo " CSCOPE"
266 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
267 ${Q}cscope -b -q -k
268
Ryan Harkin72ee3312014-01-15 16:55:07 +0000269help:
270 @echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|dump>"
271 @echo ""
272 @echo "PLAT is used to specify which platform you wish to build."
273 @echo ""
274 @echo "Supported Targets:"
275 @echo " all build the BL1, BL2 and BL31 binaries"
276 @echo " bl1 build the BL1 binary"
277 @echo " bl2 build the BL2 binary"
278 @echo " bl31 build the BL31 binary"
279 @echo " clean Clean the build for the selected platform"
Joakim Bech35fab8c2014-01-23 14:51:49 +0100280 @echo " cscope Generate cscope index"
Ryan Harkin72ee3312014-01-15 16:55:07 +0000281 @echo " distclean Remove all build artifacts for all platforms"
282 @echo " dump Generate object file dumps"
283 @echo ""
284 @echo "note: most build targets require PLAT to be set to a specific platform."
285 @echo ""
286 @echo "example: build all targets for the FVP platform:"
287 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"