| Travis Geiselbrecht | 78d0e6c | 2009-11-27 13:37:03 -0800 | [diff] [blame] | 1 | ifeq ($(MAKECMDGOALS),spotless) | 
|  | 2 | spotless: | 
|  | 3 | rm -rf build-* | 
|  | 4 | else | 
|  | 5 |  | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 6 | -include local.mk | 
| Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 7 | include make/macros.mk | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 8 |  | 
| Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 9 | # If one of our goals (from the commandline) happens to have a | 
|  | 10 | # matching project/goal.mk, then we should re-invoke make with | 
|  | 11 | # that project name specified... | 
|  | 12 |  | 
|  | 13 | project-name := $(firstword $(MAKECMDGOALS)) | 
|  | 14 |  | 
|  | 15 | ifneq ($(project-name),) | 
|  | 16 | ifneq ($(wildcard project/$(project-name).mk),) | 
|  | 17 | do-nothing := 1 | 
|  | 18 | $(MAKECMDGOALS) _all: make-make | 
|  | 19 | make-make: | 
|  | 20 | @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS)) | 
|  | 21 | endif | 
|  | 22 | endif | 
|  | 23 |  | 
|  | 24 | ifeq ($(do-nothing),) | 
|  | 25 |  | 
|  | 26 | ifeq ($(PROJECT),) | 
|  | 27 | $(error No project specified.  Use "make projectname" or put "PROJECT := projectname" in local.mk) | 
|  | 28 | endif | 
|  | 29 |  | 
| Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 30 | DEBUG ?= 0 | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 31 |  | 
| Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 32 | ifndef $(BOOTLOADER_OUT) | 
|  | 33 | BOOTLOADER_OUT := . | 
|  | 34 | endif | 
|  | 35 |  | 
| Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 36 | LK_TOP_DIR:= . | 
| Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 37 | BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 38 | OUTBIN := $(BUILDDIR)/lk.bin | 
|  | 39 | OUTELF := $(BUILDDIR)/lk | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 40 | OUTELF_STRIP := $(BUILDDIR)/lk_s.elf | 
|  | 41 |  | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 42 | CONFIGHEADER := $(BUILDDIR)/config.h | 
|  | 43 |  | 
| Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 44 | #Initialize the command-line flag ENABLE_TRUSTZONE. Value for flag passed in at command-line will take precedence | 
|  | 45 | ENABLE_TRUSTZONE := 0 | 
|  | 46 |  | 
|  | 47 | ifeq ($(ENABLE_TRUSTZONE),1) | 
|  | 48 | INPUT_TZ_BIN := tzbsp/tzbsp.bin | 
|  | 49 | OUTPUT_TZ_BIN := $(BUILDDIR)/tzbsp_bin.o | 
|  | 50 | endif | 
|  | 51 |  | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 52 | INCLUDES := -I$(BUILDDIR) -Iinclude | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 53 | CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER) | 
|  | 54 | #CFLAGS += -Werror | 
| David Ng | 025c1d9 | 2009-12-09 23:46:00 -0800 | [diff] [blame] | 55 | ifeq ($(EMMC_BOOT),1) | 
|  | 56 | CFLAGS += -D_EMMC_BOOT=1 | 
|  | 57 | endif | 
| Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 58 |  | 
|  | 59 | ifeq ($(SIGNED_KERNEL),1) | 
|  | 60 | CFLAGS += -D_SIGNED_KERNEL=1 | 
|  | 61 | endif | 
|  | 62 |  | 
| Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 63 | ifeq ($(TARGET_BUILD_VARIANT),user) | 
|  | 64 | CFLAGS += -DDISABLE_FASTBOOT_CMDS=1 | 
|  | 65 | endif | 
|  | 66 |  | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 67 | # setup toolchain prefix | 
|  | 68 | TOOLCHAIN_PREFIX ?= arm-eabi- | 
| Maria Yu | d320051 | 2014-05-28 15:57:51 +0800 | [diff] [blame] | 69 | CFLAGS += -fstack-protector-all | 
| vijay kumar | c2119f1 | 2014-07-22 18:30:11 +0530 | [diff] [blame] | 70 | CFLAGS += -fno-strict-overflow | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 71 | CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics | 
|  | 72 | #CPPFLAGS += -Weffc++ | 
|  | 73 | ASMFLAGS := -DASSEMBLY | 
|  | 74 | LDFLAGS := | 
|  | 75 |  | 
|  | 76 | CFLAGS += -ffunction-sections -fdata-sections | 
|  | 77 | LDFLAGS += -gc-sections | 
|  | 78 |  | 
|  | 79 | # top level rule | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 80 | all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size $(OUTELF_STRIP) APPSBOOTHEADER | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | # the following three object lists are identical except for the ordering | 
|  | 83 | # which is bootobjs, kobjs, objs | 
|  | 84 | BOOTOBJS := | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 85 | OBJS := | 
|  | 86 |  | 
|  | 87 | # a linker script needs to be declared in one of the project/target/platform files | 
|  | 88 | LINKER_SCRIPT := | 
|  | 89 |  | 
|  | 90 | # anything you add here will be deleted in make clean | 
|  | 91 | GENERATED := $(CONFIGHEADER) | 
|  | 92 |  | 
|  | 93 | # anything added to DEFINES will be put into $(BUILDDIR)/config.h | 
|  | 94 | DEFINES := LK=1 | 
|  | 95 |  | 
|  | 96 | # Anything added to SRCDEPS will become a dependency of every source file in the system. | 
|  | 97 | # Useful for header files that may be included by one or more source files. | 
|  | 98 | SRCDEPS := $(CONFIGHEADER) | 
|  | 99 |  | 
| Shashank Mittal | e99a8d3 | 2014-09-11 19:51:06 -0700 | [diff] [blame] | 100 | ifeq ($(VERIFIED_BOOT),1) | 
|  | 101 | DEFINES += VERIFIED_BOOT=1 | 
|  | 102 | DEFINES += _SIGNED_KERNEL=1 | 
|  | 103 | ifeq ($(DEFAULT_UNLOCK),true) | 
|  | 104 | DEFINES += DEFAULT_UNLOCK=1 | 
|  | 105 | endif | 
|  | 106 | endif | 
|  | 107 |  | 
| Channagoud Kadabi | 9071af3 | 2015-03-12 12:39:56 -0700 | [diff] [blame] | 108 | ifeq ($(USER_BUILD_VARIANT),true) | 
|  | 109 | DEFINES += USER_BUILD_VARIANT=1 | 
|  | 110 | endif | 
|  | 111 |  | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 112 | # these need to be filled out by the project/target/platform rules.mk files | 
|  | 113 | TARGET := | 
|  | 114 | PLATFORM := | 
|  | 115 | ARCH := | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 116 | ALLMODULES := | 
|  | 117 | MODULES := | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | # any rules you put here will also be built by the system before considered being complete | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 120 | EXTRA_BUILDDEPS := | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 121 |  | 
|  | 122 | # any rules you put here will be depended on in clean builds | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 123 | EXTRA_CLEANDEPS := | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 124 |  | 
| Travis Geiselbrecht | 577036f | 2009-01-24 21:37:21 -0800 | [diff] [blame] | 125 | include project/$(PROJECT).mk | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 126 | include target/$(TARGET)/rules.mk | 
| Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 127 | include target/$(TARGET)/tools/makefile | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 128 | include platform/$(PLATFORM)/rules.mk | 
|  | 129 | include arch/$(ARCH)/rules.mk | 
|  | 130 | include platform/rules.mk | 
|  | 131 | include target/rules.mk | 
|  | 132 | include kernel/rules.mk | 
|  | 133 | include dev/rules.mk | 
| Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 134 | include app/rules.mk | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 135 |  | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 136 | # recursively include any modules in the MODULE variable, leaving a trail of included | 
|  | 137 | # modules in the ALLMODULES list | 
| Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 138 | include make/module.mk | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 139 |  | 
|  | 140 | # any extra top level build dependencies that someone declared | 
|  | 141 | all:: $(EXTRA_BUILDDEPS) | 
|  | 142 |  | 
|  | 143 | ALLOBJS := \ | 
|  | 144 | $(BOOTOBJS) \ | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 145 | $(OBJS) | 
|  | 146 |  | 
|  | 147 | # add some automatic configuration defines | 
|  | 148 | DEFINES += \ | 
| Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 149 | BOARD=$(PROJECT) \ | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 150 | PROJECT_$(PROJECT)=1 \ | 
|  | 151 | TARGET_$(TARGET)=1 \ | 
|  | 152 | PLATFORM_$(PLATFORM)=1 \ | 
|  | 153 | ARCH_$(ARCH)=1 \ | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 154 | $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES))) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 155 |  | 
|  | 156 | # debug build? | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 157 | ifneq ($(DEBUG),) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 158 | DEFINES += \ | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 159 | DEBUG=$(DEBUG) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 160 | endif | 
|  | 161 |  | 
|  | 162 | ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS)) | 
|  | 163 |  | 
|  | 164 | DEPS := $(ALLOBJS:%o=%d) | 
|  | 165 |  | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 166 | # default to no ccache | 
|  | 167 | CCACHE ?= | 
|  | 168 | CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 169 | ifeq ($(LD),ld) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 170 | LD := $(TOOLCHAIN_PREFIX)ld | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 171 | endif | 
|  | 172 | STRIP := $(TOOLCHAIN_PREFIX)strip | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 173 | OBJDUMP := $(TOOLCHAIN_PREFIX)objdump | 
|  | 174 | OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy | 
|  | 175 | CPPFILT := $(TOOLCHAIN_PREFIX)c++filt | 
|  | 176 | SIZE := $(TOOLCHAIN_PREFIX)size | 
|  | 177 | NM := $(TOOLCHAIN_PREFIX)nm | 
|  | 178 |  | 
| Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 179 | # comment out or override if you want to see the full output of each command | 
|  | 180 | NOECHO ?= @ | 
|  | 181 |  | 
|  | 182 | # the logic to compile and link stuff is in here | 
| Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 183 | include make/build.mk | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 184 |  | 
|  | 185 | clean: $(EXTRA_CLEANDEPS) | 
| Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 186 | rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst $(OUTELF_STRIP) | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 187 |  | 
| Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 188 | install: all | 
|  | 189 | scp $(OUTBIN) 192.168.0.4:/tftproot | 
|  | 190 |  | 
|  | 191 | # generate a config.h file with all of the DEFINES laid out in #define format | 
|  | 192 | configheader: | 
|  | 193 |  | 
|  | 194 | $(CONFIGHEADER): configheader | 
|  | 195 | @$(MKDIR) | 
|  | 196 | @echo generating $@ | 
|  | 197 | @rm -f $(CONFIGHEADER).tmp; \ | 
|  | 198 | echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \ | 
|  | 199 | echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \ | 
|  | 200 | for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \ | 
|  | 201 | echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \ | 
|  | 202 | done; \ | 
|  | 203 | echo \#endif >> $(CONFIGHEADER).tmp; \ | 
|  | 204 | if [ -f "$(CONFIGHEADER)" ]; then \ | 
|  | 205 | if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \ | 
|  | 206 | rm -f $(CONFIGHEADER).tmp; \ | 
|  | 207 | else \ | 
|  | 208 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ | 
|  | 209 | fi \ | 
|  | 210 | else \ | 
|  | 211 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ | 
|  | 212 | fi | 
|  | 213 |  | 
|  | 214 | # Empty rule for the .d files. The above rules will build .d files as a side | 
|  | 215 | # effect. Only works on gcc 3.x and above, however. | 
|  | 216 | %.d: | 
|  | 217 |  | 
|  | 218 | ifeq ($(filter $(MAKECMDGOALS), clean), ) | 
|  | 219 | -include $(DEPS) | 
|  | 220 | endif | 
|  | 221 |  | 
|  | 222 | .PHONY: configheader | 
| Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 223 | endif | 
| Travis Geiselbrecht | 78d0e6c | 2009-11-27 13:37:03 -0800 | [diff] [blame] | 224 |  | 
|  | 225 | endif # make spotless |