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# Load generated board configuration 53ifeq ($(CONFIG_TPL_BUILD),y) 54# Include TPL autoconf 55sinclude $(OBJTREE)/include/tpl-autoconf.mk 56else 57ifeq ($(CONFIG_SPL_BUILD),y) 58# Include SPL autoconf 59sinclude $(OBJTREE)/include/spl-autoconf.mk 60else 61# Include normal autoconf 62sinclude $(OBJTREE)/include/autoconf.mk 63endif 64endif 65sinclude $(OBJTREE)/include/config.mk 66 67# Some architecture config.mk files need to know what CPUDIR is set to, 68# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files. 69# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains 70# CPU-specific code. 71CPUDIR=arch/$(ARCH)/cpu/$(CPU) 72ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR))) 73CPUDIR=arch/$(ARCH)/cpu 74endif 75 76sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules 77sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules 78 79ifdef SOC 80sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules 81endif 82ifdef VENDOR 83BOARDDIR = $(VENDOR)/$(BOARD) 84else 85BOARDDIR = $(BOARD) 86endif 87ifdef BOARD 88sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules 89endif 90 91######################################################################### 92 93# We don't actually use $(ARFLAGS) anywhere anymore, so catch people 94# who are porting old code to latest mainline but not updating $(AR). 95ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR) 96RELFLAGS= $(PLATFORM_RELFLAGS) 97DBGFLAGS= -g # -DDEBUG 98OPTFLAGS= -Os #-fomit-frame-pointer 99 100OBJCFLAGS += --gap-fill=0xff 101 102gccincdir := $(shell $(CC) -print-file-name=include) 103 104CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ 105 -D__KERNEL__ 106 107# Enable garbage collection of un-used sections for SPL 108ifeq ($(CONFIG_SPL_BUILD),y) 109CPPFLAGS += -ffunction-sections -fdata-sections 110LDFLAGS_FINAL += --gc-sections 111endif 112 113ifneq ($(CONFIG_SYS_TEXT_BASE),) 114CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) 115endif 116 117ifeq ($(CONFIG_SPL_BUILD),y) 118CPPFLAGS += -DCONFIG_SPL_BUILD 119ifeq ($(CONFIG_TPL_BUILD),y) 120CPPFLAGS += -DCONFIG_TPL_BUILD 121endif 122endif 123 124# Does this architecture support generic board init? 125ifeq ($(__HAVE_ARCH_GENERIC_BOARD),) 126ifneq ($(CONFIG_SYS_GENERIC_BOARD),) 127CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \ 128Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file) 129endif 130endif 131 132ifneq ($(OBJTREE),$(SRCTREE)) 133CPPFLAGS += -I$(OBJTREE)/include 134endif 135 136CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include 137CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ 138 -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) 139 140CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes 141 142ifdef BUILD_TAG 143CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"' 144endif 145 146CFLAGS_SSP := $(call cc-option,-fno-stack-protector) 147CFLAGS += $(CFLAGS_SSP) 148# Some toolchains enable security related warning flags by default, 149# but they don't make much sense in the u-boot world, so disable them. 150CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ 151 $(call cc-option,-Wno-format-security) 152CFLAGS += $(CFLAGS_WARN) 153 154# Report stack usage if supported 155CFLAGS_STACK := $(call cc-option,-fstack-usage) 156CFLAGS += $(CFLAGS_STACK) 157 158BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) 159 160ifeq ($(findstring examples/,$(BCURDIR)),) 161ifeq ($(CONFIG_SPL_BUILD),) 162ifdef FTRACE 163CFLAGS += -finstrument-functions -DFTRACE 164endif 165endif 166endif 167 168# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> 169# option to the assembler. 170AFLAGS_DEBUG := 171 172# turn jbsr into jsr for m68k 173ifeq ($(ARCH),m68k) 174ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) 175AFLAGS_DEBUG := -Wa,-gstabs,-S 176endif 177endif 178 179AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) 180 181LDFLAGS += $(PLATFORM_LDFLAGS) 182LDFLAGS_FINAL += -Bstatic 183 184LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL) 185ifneq ($(CONFIG_SYS_TEXT_BASE),) 186LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) 187endif 188 189LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) 190ifneq ($(CONFIG_SPL_TEXT_BASE),) 191LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) 192endif 193 194######################################################################### 195 196export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS 197