1# 2# (C) Copyright 2000-2013 3# Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4# 5# SPDX-License-Identifier: GPL-2.0+ 6# 7######################################################################### 8 9ifeq ($(CURDIR),$(SRCTREE)) 10dir := 11else 12dir := $(subst $(SRCTREE)/,,$(CURDIR)) 13endif 14 15ifneq ($(OBJTREE),$(SRCTREE)) 16# Create object files for SPL in a separate directory 17ifeq ($(CONFIG_SPL_BUILD),y) 18ifeq ($(CONFIG_TPL_BUILD),y) 19obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) 20else 21obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) 22endif 23else 24obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) 25endif 26src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) 27 28$(shell mkdir -p $(obj)) 29else 30# Create object files for SPL in a separate directory 31ifeq ($(CONFIG_SPL_BUILD),y) 32ifeq ($(CONFIG_TPL_BUILD),y) 33obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/) 34else 35obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) 36 37endif 38$(shell mkdir -p $(obj)) 39else 40obj := 41endif 42src := 43endif 44 45# clean the slate ... 46PLATFORM_RELFLAGS = 47PLATFORM_CPPFLAGS = 48PLATFORM_LDFLAGS = 49 50######################################################################### 51# 52# Option checker, gcc version (courtesy linux kernel) to ensure 53# only supported compiler options are used 54# 55CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk 56CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o 57 58-include $(CC_OPTIONS_CACHE_FILE) 59 60cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \ 61 if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \ 62 > /dev/null 2>&1; then \ 63 echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \ 64 echo "$(1)"; fi) 65 66ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y) 67cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2)) 68else 69cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\ 70 $(if $(call cc-option-sys,$1),$1,$2))) 71endif 72 73# cc-version 74# Usage gcc-ver := $(call cc-version) 75cc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC)) 76binutils-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS)) 77dtc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC)) 78 79######################################################################### 80 81# Load generated board configuration 82ifeq ($(CONFIG_TPL_BUILD),y) 83# Include TPL autoconf 84sinclude $(OBJTREE)/include/tpl-autoconf.mk 85else 86ifeq ($(CONFIG_SPL_BUILD),y) 87# Include SPL autoconf 88sinclude $(OBJTREE)/include/spl-autoconf.mk 89else 90# Include normal autoconf 91sinclude $(OBJTREE)/include/autoconf.mk 92endif 93endif 94sinclude $(OBJTREE)/include/config.mk 95 96# Some architecture config.mk files need to know what CPUDIR is set to, 97# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files. 98# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains 99# CPU-specific code. 100CPUDIR=arch/$(ARCH)/cpu/$(CPU) 101ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR))) 102CPUDIR=arch/$(ARCH)/cpu 103endif 104 105sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules 106sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules 107 108ifdef SOC 109sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules 110endif 111ifdef VENDOR 112BOARDDIR = $(VENDOR)/$(BOARD) 113else 114BOARDDIR = $(BOARD) 115endif 116ifdef BOARD 117sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules 118endif 119 120######################################################################### 121 122# We don't actually use $(ARFLAGS) anywhere anymore, so catch people 123# who are porting old code to latest mainline but not updating $(AR). 124ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR) 125RELFLAGS= $(PLATFORM_RELFLAGS) 126DBGFLAGS= -g # -DDEBUG 127OPTFLAGS= -Os #-fomit-frame-pointer 128 129OBJCFLAGS += --gap-fill=0xff 130 131gccincdir := $(shell $(CC) -print-file-name=include) 132 133CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ 134 -D__KERNEL__ 135 136# Enable garbage collection of un-used sections for SPL 137ifeq ($(CONFIG_SPL_BUILD),y) 138CPPFLAGS += -ffunction-sections -fdata-sections 139LDFLAGS_FINAL += --gc-sections 140endif 141 142ifneq ($(CONFIG_SYS_TEXT_BASE),) 143CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) 144endif 145 146ifeq ($(CONFIG_SPL_BUILD),y) 147CPPFLAGS += -DCONFIG_SPL_BUILD 148ifeq ($(CONFIG_TPL_BUILD),y) 149CPPFLAGS += -DCONFIG_TPL_BUILD 150endif 151endif 152 153# Does this architecture support generic board init? 154ifeq ($(__HAVE_ARCH_GENERIC_BOARD),) 155ifneq ($(CONFIG_SYS_GENERIC_BOARD),) 156CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \ 157Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file) 158endif 159endif 160 161ifneq ($(OBJTREE),$(SRCTREE)) 162CPPFLAGS += -I$(OBJTREE)/include 163endif 164 165CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include 166CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ 167 -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) 168 169CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes 170 171ifdef BUILD_TAG 172CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"' 173endif 174 175CFLAGS_SSP := $(call cc-option,-fno-stack-protector) 176CFLAGS += $(CFLAGS_SSP) 177# Some toolchains enable security related warning flags by default, 178# but they don't make much sense in the u-boot world, so disable them. 179CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ 180 $(call cc-option,-Wno-format-security) 181CFLAGS += $(CFLAGS_WARN) 182 183# Report stack usage if supported 184CFLAGS_STACK := $(call cc-option,-fstack-usage) 185CFLAGS += $(CFLAGS_STACK) 186 187BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) 188 189ifeq ($(findstring examples/,$(BCURDIR)),) 190ifeq ($(CONFIG_SPL_BUILD),) 191ifdef FTRACE 192CFLAGS += -finstrument-functions -DFTRACE 193endif 194endif 195endif 196 197# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> 198# option to the assembler. 199AFLAGS_DEBUG := 200 201# turn jbsr into jsr for m68k 202ifeq ($(ARCH),m68k) 203ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) 204AFLAGS_DEBUG := -Wa,-gstabs,-S 205endif 206endif 207 208AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) 209 210LDFLAGS += $(PLATFORM_LDFLAGS) 211LDFLAGS_FINAL += -Bstatic 212 213LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL) 214ifneq ($(CONFIG_SYS_TEXT_BASE),) 215LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) 216endif 217 218LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) 219ifneq ($(CONFIG_SPL_TEXT_BASE),) 220LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) 221endif 222 223######################################################################### 224 225export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS 226