Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | # |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | # Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 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 |
| 33 | ifdef V |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 34 | KBUILD_VERBOSE = ${V} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | else |
| 36 | KBUILD_VERBOSE = 0 |
| 37 | endif |
| 38 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 39 | ifeq "${KBUILD_VERBOSE}" "0" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | Q=@ |
| 41 | else |
| 42 | Q= |
| 43 | endif |
| 44 | |
| 45 | DEBUG ?= 0 |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 46 | |
| 47 | ifneq (${DEBUG}, 0) |
| 48 | BUILD_TYPE := debug |
| 49 | else |
| 50 | BUILD_TYPE := release |
| 51 | endif |
| 52 | |
Ryan Harkin | d7a6b0f | 2014-01-13 14:40:13 +0000 | [diff] [blame^] | 53 | BL_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 Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 60 | ARCH ?= aarch64 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 61 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 62 | # By default, build all platforms available |
| 63 | PLAT ?= all |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 64 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 65 | BUILD_BASE := ./build |
| 66 | BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE} |
| 67 | BUILD_BL1 := ${BUILD_PLAT}/bl1 |
| 68 | BUILD_BL2 := ${BUILD_PLAT}/bl2 |
| 69 | BUILD_BL31 := ${BUILD_PLAT}/bl31 |
| 70 | BUILD_DIRS := ${BUILD_BL1} ${BUILD_BL2} ${BUILD_BL31} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 71 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 72 | PLATFORMS := $(shell ls -I common plat/) |
| 73 | ifeq (${PLAT},) |
| 74 | $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.") |
| 75 | endif |
| 76 | ifeq ($(findstring ${PLAT},${PLATFORMS} all),) |
| 77 | $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}") |
| 78 | endif |
| 79 | |
| 80 | ifeq (${PLAT},all) |
| 81 | all: ${PLATFORMS} |
| 82 | else |
| 83 | all: msg_start bl1 bl2 bl31 |
| 84 | endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 85 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 86 | msg_start: |
| 87 | @echo "Building ${PLAT}" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 89 | ${PLATFORMS}: |
| 90 | ${MAKE} PLAT=$@ all |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 91 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 92 | ifneq (${PLAT},all) |
| 93 | $(info Including ${PLAT}/platform.mk) |
| 94 | include plat/${PLAT}/platform.mk |
| 95 | $(info Including bl1.mk) |
| 96 | include bl1/bl1.mk |
| 97 | $(info Including bl2.mk) |
| 98 | include bl2/bl2.mk |
| 99 | $(info Including bl31.mk) |
| 100 | include bl31/bl31.mk |
| 101 | endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 102 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 103 | .PHONY: all msg_start ${PLATFORMS} dump clean realclean distclean bl1 bl2 bl31 |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 104 | .SUFFIXES: |
| 105 | |
| 106 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 107 | BL1_OBJS := $(addprefix ${BUILD_BL1}/,${BL1_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS}) |
| 108 | BL2_OBJS := $(addprefix ${BUILD_BL2}/,${BL2_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS}) |
| 109 | BL31_OBJS := $(addprefix ${BUILD_BL31}/,${BL31_OBJS} ${BL_COMMON_OBJS} ${PLAT_BL_COMMON_OBJS}) |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 110 | BL1_MAPFILE := $(addprefix ${BUILD_BL1}/,${BL1_MAPFILE}) |
| 111 | BL2_MAPFILE := $(addprefix ${BUILD_BL2}/,${BL2_MAPFILE}) |
| 112 | BL31_MAPFILE := $(addprefix ${BUILD_BL31}/,${BL31_MAPFILE}) |
| 113 | BL1_LINKERFILE := $(addprefix ${BUILD_BL1}/,${BL1_LINKERFILE}) |
| 114 | BL2_LINKERFILE := $(addprefix ${BUILD_BL2}/,${BL2_LINKERFILE}) |
| 115 | BL31_LINKERFILE := $(addprefix ${BUILD_BL31}/,${BL31_LINKERFILE}) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 116 | |
Ryan Harkin | d7a6b0f | 2014-01-13 14:40:13 +0000 | [diff] [blame^] | 117 | INCLUDES += -Ilib/include/ \ |
| 118 | -Iinclude/${ARCH}/ \ |
| 119 | -Iinclude/ \ |
| 120 | -Iarch/system/gic \ |
| 121 | -Icommon/psci \ |
| 122 | -Iinclude/stdlib \ |
| 123 | -Iinclude/stdlib/sys \ |
| 124 | -Iplat/${PLAT} \ |
| 125 | ${PLAT_INCLUDES} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 126 | |
Harry Liebel | 0af6d64 | 2013-12-20 18:51:12 +0000 | [diff] [blame] | 127 | ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ |
Harry Liebel | 4f60368 | 2014-01-14 18:11:48 +0000 | [diff] [blame] | 128 | -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES} |
| 129 | CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \ |
| 130 | -Werror -mgeneral-regs-only -std=c99 -c -Os \ |
| 131 | -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 132 | |
Sandrine Bailleux | 3e850a8 | 2013-11-20 11:50:48 +0000 | [diff] [blame] | 133 | LDFLAGS += --fatal-warnings -O1 |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 134 | BL1_LDFLAGS := -Map=${BL1_MAPFILE} --script ${BL1_LINKERFILE} --entry=${BL1_ENTRY_POINT} |
| 135 | BL2_LDFLAGS := -Map=${BL2_MAPFILE} --script ${BL2_LINKERFILE} --entry=${BL2_ENTRY_POINT} |
| 136 | BL31_LDFLAGS := -Map=${BL31_MAPFILE} --script ${BL31_LINKERFILE} --entry=${BL31_ENTRY_POINT} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 137 | |
| 138 | |
| 139 | vpath %.ld.S bl1:bl2:bl31 |
| 140 | vpath %.c bl1:bl2:bl31 |
| 141 | vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH} |
| 142 | vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH} |
| 143 | |
| 144 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 145 | ifneq (${DEBUG}, 0) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 146 | #CFLAGS += -g -O0 |
| 147 | CFLAGS += -g |
| 148 | # -save-temps -fverbose-asm |
| 149 | ASFLAGS += -g -Wa,--gdwarf-2 |
| 150 | endif |
| 151 | |
| 152 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 153 | CC := ${CROSS_COMPILE}gcc |
| 154 | CPP := ${CROSS_COMPILE}cpp |
| 155 | AS := ${CROSS_COMPILE}gcc |
| 156 | AR := ${CROSS_COMPILE}ar |
| 157 | LD := ${CROSS_COMPILE}ld |
| 158 | OC := ${CROSS_COMPILE}objcopy |
| 159 | OD := ${CROSS_COMPILE}objdump |
| 160 | NM := ${CROSS_COMPILE}nm |
| 161 | PP := ${CROSS_COMPILE}gcc -E ${CFLAGS} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 162 | |
| 163 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 164 | bl1: ${BUILD_BL1} ${BUILD_PLAT}/bl1.bin |
| 165 | bl2: ${BUILD_BL2} ${BUILD_PLAT}/bl2.bin |
| 166 | bl31: ${BUILD_BL31} ${BUILD_PLAT}/bl31.bin |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 167 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 168 | ifeq (${PLAT},all) |
| 169 | ifeq (${MAKECMDGOALS},clean) |
| 170 | $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds") |
| 171 | endif |
| 172 | endif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 173 | clean: |
| 174 | @echo " CLEAN" |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 175 | ${Q}rm -rf ${BUILD_PLAT} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 176 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 177 | realclean distclean: |
| 178 | @echo " REALCLEAN" |
| 179 | ${Q}rm -rf ${BUILD_BASE} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 180 | |
| 181 | dump: |
| 182 | @echo " OBJDUMP" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 183 | ${Q}${OD} -d ${BUILD_BL1}/bl1.elf > ${BUILD_BL1}/bl1.dump |
| 184 | ${Q}${OD} -d ${BUILD_BL2}/bl2.elf > ${BUILD_BL2}/bl2.dump |
| 185 | ${Q}${OD} -d ${BUILD_BL31}/bl31.elf > ${BUILD_BL31}/bl31.dump |
| 186 | |
| 187 | ${BUILD_DIRS}: |
| 188 | ${Q}mkdir -p "$@" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 189 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 190 | |
| 191 | ${BUILD_BL1}/%.o: %.S |
| 192 | @echo " AS $<" |
| 193 | ${Q}${AS} ${ASFLAGS} -c $< -o $@ |
| 194 | |
| 195 | ${BUILD_BL2}/%.o: %.S |
| 196 | @echo " AS $<" |
| 197 | ${Q}${AS} ${ASFLAGS} -c $< -o $@ |
| 198 | |
| 199 | ${BUILD_BL31}/%.o: %.S |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 200 | @echo " AS $<" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 201 | ${Q}${AS} ${ASFLAGS} -c $< -o $@ |
| 202 | |
| 203 | ${BUILD_BL1}/%.o: %.c |
| 204 | @echo " CC $<" |
| 205 | ${Q}${CC} ${CFLAGS} -c $< -o $@ |
| 206 | |
| 207 | ${BUILD_BL2}/%.o: %.c |
| 208 | @echo " CC $<" |
| 209 | ${Q}${CC} ${CFLAGS} -c $< -o $@ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 210 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 211 | ${BUILD_BL31}/%.o: %.c |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 212 | @echo " CC $<" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 213 | ${Q}${CC} ${CFLAGS} -c $< -o $@ |
| 214 | |
| 215 | ${BUILD_BL1}/%.ld: %.ld.S |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 216 | @echo " PP $<" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 217 | ${Q}${AS} ${ASFLAGS} -P -E $< -o $@ |
| 218 | |
| 219 | ${BUILD_BL2}/%.ld: %.ld.S |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 220 | @echo " PP $<" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 221 | ${Q}${AS} ${ASFLAGS} -P -E $< -o $@ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 222 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 223 | ${BUILD_BL31}/%.ld: %.ld.S |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 224 | @echo " PP $<" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 225 | ${Q}${AS} ${ASFLAGS} -P -E $< -o $@ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 226 | |
| 227 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 228 | ${BUILD_BL1}/bl1.elf: ${BL1_OBJS} ${BL1_LINKERFILE} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 229 | @echo " LD $@" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 230 | ${Q}${LD} -o $@ ${LDFLAGS} ${BL1_LDFLAGS} ${BL1_OBJS} |
| 231 | |
| 232 | ${BUILD_BL2}/bl2.elf: ${BL2_OBJS} ${BL2_LINKERFILE} |
| 233 | @echo " LD $@" |
| 234 | ${Q}${LD} -o $@ ${LDFLAGS} ${BL2_LDFLAGS} ${BL2_OBJS} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 235 | |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 236 | ${BUILD_BL31}/bl31.elf: ${BL31_OBJS} ${BL31_LINKERFILE} |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 237 | @echo " LD $@" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 238 | ${Q}${LD} -o $@ ${LDFLAGS} ${BL31_LDFLAGS} ${BL31_OBJS} |
| 239 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 240 | ${BUILD_PLAT}/bl1.bin: ${BUILD_BL1}/bl1.elf |
| 241 | @echo " BIN $@" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 242 | ${Q}${OC} -O binary $< $@ |
| 243 | @echo |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 244 | @echo "Built $@ successfully" |
| 245 | @echo |
| 246 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 247 | ${BUILD_PLAT}/bl2.bin: ${BUILD_BL2}/bl2.elf |
| 248 | @echo " BIN $@" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 249 | ${Q}${OC} -O binary $< $@ |
| 250 | @echo |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 251 | @echo "Built $@ successfully" |
| 252 | @echo |
| 253 | |
Ryan Harkin | 25cff83 | 2014-01-13 12:37:03 +0000 | [diff] [blame] | 254 | ${BUILD_PLAT}/bl31.bin: ${BUILD_BL31}/bl31.elf |
| 255 | @echo " BIN $@" |
James Morrissey | eaaeece | 2013-11-01 13:56:59 +0000 | [diff] [blame] | 256 | ${Q}${OC} -O binary $< $@ |
| 257 | @echo |
| 258 | @echo "Built $@ successfully" |
| 259 | @echo |