#
# (C) Copyright 2000-2006
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
# project.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#########################################################################
i f e q ( $( CURDIR ) , $( SRCTREE ) )
dir :=
e l s e
dir := $( subst $( SRCTREE) /,,$( CURDIR) )
e n d i f
i f n e q ( $( OBJTREE ) , $( SRCTREE ) )
# Create object files for SPL in a separate directory
i f e q ( $( CONFIG_SPL_BUILD ) , y )
obj := $( if $( dir) ,$( SPLTREE) /$( dir) /,$( SPLTREE) /)
e l s e
obj := $( if $( dir) ,$( OBJTREE) /$( dir) /,$( OBJTREE) /)
e n d i f
src := $( if $( dir) ,$( SRCTREE) /$( dir) /,$( SRCTREE) /)
$( shell mkdir -p $ ( obj ) )
e l s e
# Create object files for SPL in a separate directory
i f e q ( $( CONFIG_SPL_BUILD ) , y )
obj := $( if $( dir) ,$( SPLTREE) /$( dir) /,$( SPLTREE) /)
$( shell mkdir -p $ ( obj ) )
e l s e
obj :=
e n d i f
src :=
e n d i f
# clean the slate ...
PLATFORM_RELFLAGS =
PLATFORM_CPPFLAGS =
PLATFORM_LDFLAGS =
#########################################################################
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
$( HOSTCPPFLAGS)
HOSTSTRIP = strip
#
# Mac OS X / Darwin's C preprocessor is Apple specific. It
# generates numerous errors and warnings. We want to bypass it
# and use GNU C's cpp. To do this we pass the -traditional-cpp
# option to the compiler. Note that the -traditional-cpp flag
# DOES NOT have the same semantics as GNU C's flag, all it does
# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
#
# Apple's linker is similar, thanks to the new 2 stage linking
# multiple symbol definitions are treated as errors, hence the
# -multiply_defined suppress option to turn off this error.
#
i f e q ( $( HOSTOS ) , d a r w i n )
# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
DARWIN_MAJOR_VERSION = $( shell sw_vers -productVersion | cut -f 1 -d '.' )
DARWIN_MINOR_VERSION = $( shell sw_vers -productVersion | cut -f 2 -d '.' )
os_x_before = $( shell if [ $( DARWIN_MAJOR_VERSION) -le $( 1) -a \
$( DARWIN_MINOR_VERSION) -le $( 2) ] ; then echo " $( 3) " ; else echo " $( 4) " ; fi ; )
# Snow Leopards build environment has no longer restrictions as described above
HOSTCC = $( call os_x_before, 10, 5, "cc" , "gcc" )
HOSTCFLAGS += $( call os_x_before, 10, 4, "-traditional-cpp" )
HOSTLDFLAGS += $( call os_x_before, 10, 5, "-multiply_defined suppress" )
e l s e
HOSTCC = gcc
e n d i f
i f e q ( $( HOSTOS ) , c y g w i n )
HOSTCFLAGS += -ansi
e n d i f
# We build some files with extra pedantic flags to try to minimize things
# that won't build on some weird host compiler -- though there are lots of
# exceptions for files that aren't complaint.
HOSTCFLAGS_NOPED = $( filter-out -pedantic,$( HOSTCFLAGS) )
HOSTCFLAGS += -pedantic
#########################################################################
#
# Option checker (courtesy linux kernel) to ensure
# only supported compiler options are used
#
CC_OPTIONS_CACHE_FILE := $( OBJTREE) /include/generated/cc_options.mk
$( if $ ( wildcard $ ( CC_OPTIONS_CACHE_FILE ) ) ,,\
$( shell mkdir -p $( dir $( CC_OPTIONS_CACHE_FILE) ) ) )
- i n c l u d e $( CC_OPTIONS_CACHE_FILE )
cc-option-sys = $( shell if $( CC) $( CFLAGS) $( 1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>& 1; then \
echo 'CC_OPTIONS += $(strip $1)' >> $( CC_OPTIONS_CACHE_FILE) ; \
echo " $( 1) " ; fi )
i f e q ( $( CONFIG_CC_OPT_CACHE_DISABLE ) , y )
cc-option = $( strip $( if $( call cc-option-sys,$1 ) ,$1 ,$2 ) )
e l s e
cc-option = $( strip $( if $( findstring $1 ,$( CC_OPTIONS) ) ,$1 ,\
$( if $( call cc-option-sys,$1 ) ,$1 ,$2 ) ) )
e n d i f
#
# Include the make variables (CC, etc...)
#
AS = $( CROSS_COMPILE) as
LD = $( CROSS_COMPILE) ld
CC = $( CROSS_COMPILE) gcc
CPP = $( CC) -E
AR = $( CROSS_COMPILE) ar
NM = $( CROSS_COMPILE) nm
LDR = $( CROSS_COMPILE) ldr
STRIP = $( CROSS_COMPILE) strip
OBJCOPY = $( CROSS_COMPILE) objcopy
OBJDUMP = $( CROSS_COMPILE) objdump
RANLIB = $( CROSS_COMPILE) RANLIB
DTC = dtc
#########################################################################
# Load generated board configuration
s i n c l u d e $( OBJTREE ) / i n c l u d e / a u t o c o n f . m k
s i n c l u d e $( OBJTREE ) / i n c l u d e / c o n f i g . m k
# Some architecture config.mk files need to know what CPUDIR is set to,
# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
# CPU-specific code.
CPUDIR = arch/$( ARCH) /cpu/$( CPU)
i f n e q ( $( SRCTREE ) / $( CPUDIR ) , $( wildcard $ ( SRCTREE ) /$ ( CPUDIR ) ) )
CPUDIR = arch/$( ARCH) /cpu
e n d i f
s i n c l u d e $( TOPDIR ) / a r c h / $( ARCH ) / c o n f i g . m k # include architecture dependend rules
s i n c l u d e $( TOPDIR ) / $( CPUDIR ) / c o n f i g . m k # include CPU specific rules
i f d e f S O C
s i n c l u d e $( TOPDIR ) / $( CPUDIR ) / $( SOC ) / c o n f i g . m k # include SoC specific rules
e n d i f
i f d e f V E N D O R
BOARDDIR = $( VENDOR) /$( BOARD)
e l s e
BOARDDIR = $( BOARD)
e n d i f
i f d e f B O A R D
s i n c l u d e $( TOPDIR ) / b o a r d / $( BOARDDIR ) / c o n f i g . m k # include board specific rules
e n d i f
#########################################################################
# We don't actually use $(ARFLAGS) anywhere anymore, so catch people
# who are porting old code to latest mainline but not updating $(AR).
ARFLAGS = $( error update your Makefile to use cmd_link_o_target and not AR)
RELFLAGS = $( PLATFORM_RELFLAGS)
DBGFLAGS = -g # -DDEBUG
OPTFLAGS = -Os #-fomit-frame-pointer
Handle most LDSCRIPT setting centrally
Currently, some linker scripts are found by common code in config.mk.
Some are found using CONFIG_SYS_LDSCRIPT, but the code for that is
sometimes in arch config.mk and sometimes in board config.mk. Some
are found using an arch-specific rule for looking in CPUDIR, etc.
Further, the powerpc config.mk rule relied on CONFIG_NAND_SPL
when it really wanted CONFIG_NAND_U_BOOT -- which covered up the fact
that not all NAND_U_BOOT builds actually wanted CPUDIR/u-boot-nand.lds.
Replace all of this -- except for a handful of boards that are actually
selecting a linker script in a unique way -- with centralized ldscript
finding.
If board code specifies LDSCRIPT, that will be used.
Otherwise, if CONFIG_SYS_LDSCRIPT is specified, that will be used.
If neither of these are specified, then the central config.mk will
check for the existence of the following, in order:
$(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds (only if CONFIG_NAND_U_BOOT)
$(TOPDIR)/$(CPUDIR)/u-boot-nand.lds (only if CONFIG_NAND_U_BOOT)
$(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
$(TOPDIR)/$(CPUDIR)/u-boot.lds
Some boards (sc3, cm5200, munices) provided their own u-boot.lds that
were dead code, because they were overridden by a CPUDIR u-boot.lds under
the old powerpc rules. These boards' own u-boot.lds have bitrotted and
no longer work -- these lds files have been removed.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Tested-by: Graeme Russ <graeme.russ@gmail.com>
14 years ago
OBJCFLAGS += --gap-fill= 0xff
gccincdir := $( shell $( CC) -print-file-name= include)
CPPFLAGS := $( DBGFLAGS) $( OPTFLAGS) $( RELFLAGS) \
-D__KERNEL__
# Enable garbage collection of un-used sections for SPL
i f e q ( $( CONFIG_SPL_BUILD ) , y )
CPPFLAGS += -ffunction-sections -fdata-sections
LDFLAGS_FINAL += --gc-sections
e n d i f
i f n e q ( $( CONFIG_SYS_TEXT_BASE ) , )
CPPFLAGS += -DCONFIG_SYS_TEXT_BASE= $( CONFIG_SYS_TEXT_BASE)
e n d i f
i f n e q ( $( CONFIG_SPL_TEXT_BASE ) , )
CPPFLAGS += -DCONFIG_SPL_TEXT_BASE= $( CONFIG_SPL_TEXT_BASE)
e n d i f
i f e q ( $( CONFIG_SPL_BUILD ) , y )
CPPFLAGS += -DCONFIG_SPL_BUILD
e n d i f
i f n e q ( $( RESET_VECTOR_ADDRESS ) , )
CPPFLAGS += -DRESET_VECTOR_ADDRESS= $( RESET_VECTOR_ADDRESS)
e n d i f
i f n e q ( $( OBJTREE ) , $( SRCTREE ) )
CPPFLAGS += -I$( OBJTREE) /include2 -I$( OBJTREE) /include
e n d i f
CPPFLAGS += -I$( TOPDIR) /include
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
-isystem $( gccincdir) -pipe $( PLATFORM_CPPFLAGS)
i f d e f B U I L D _ T A G
CFLAGS := $( CPPFLAGS) -Wall -Wstrict-prototypes \
-DBUILD_TAG= '"$(BUILD_TAG)"'
e l s e
CFLAGS := $( CPPFLAGS) -Wall -Wstrict-prototypes
e n d i f
CFLAGS_SSP := $( call cc-option,-fno-stack-protector)
CFLAGS += $( CFLAGS_SSP)
# Some toolchains enable security related warning flags by default,
# but they don't make much sense in the u-boot world, so disable them.
CFLAGS_WARN := $( call cc-option,-Wno-format-nonliteral) \
$( call cc-option,-Wno-format-security)
CFLAGS += $( CFLAGS_WARN)
# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
# option to the assembler.
AFLAGS_DEBUG :=
# turn jbsr into jsr for m68k
i f e q ( $( ARCH ) , m 6 8 k )
i f e q ( $( findstring 3.4,$ ( shell $ ( CC ) --version ) ) , 3 . 4 )
AFLAGS_DEBUG := -Wa,-gstabs,-S
e n d i f
e n d i f
AFLAGS := $( AFLAGS_DEBUG) -D__ASSEMBLY__ $( CPPFLAGS)
LDFLAGS += $( PLATFORM_LDFLAGS)
LDFLAGS_FINAL += -Bstatic
LDFLAGS_u-boot += -T $( obj) u-boot.lds $( LDFLAGS_FINAL)
i f n e q ( $( CONFIG_SYS_TEXT_BASE ) , )
LDFLAGS_u-boot += -Ttext $( CONFIG_SYS_TEXT_BASE)
e n d i f
LDFLAGS_u-boot-spl += -T $( obj) u-boot-spl.lds $( LDFLAGS_FINAL)
i f n e q ( $( CONFIG_SPL_TEXT_BASE ) , )
LDFLAGS_u-boot-spl += -Ttext $( CONFIG_SPL_TEXT_BASE)
e n d i f
# Location of a usable BFD library, where we define "usable" as
# "built for ${HOST}, supports ${TARGET}". Sensible values are
# - When cross-compiling: the root of the cross-environment
# - Linux/ppc (native): /usr
# - NetBSD/ppc (native): you lose ... (must extract these from the
# binutils build directory, plus the native and U-Boot include
# files don't like each other)
#
# So far, this is used only by tools/gdb/Makefile.
i f e q ( $( HOSTOS ) , d a r w i n )
BFD_ROOT_DIR = /usr/local/tools
e l s e
i f e q ( $( HOSTARCH ) , $( ARCH ) )
# native
BFD_ROOT_DIR = /usr
e l s e
#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
BFD_ROOT_DIR = /opt/powerpc
e n d i f
e n d i f
#########################################################################
export H O S T C C H O S T C F L A G S H O S T L D F L A G S P E D C F L A G S H O S T S T R I P C R O S S _ C O M P I L E \
AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
#########################################################################
# Allow boards to use custom optimize flags on a per dir/file basis
BCURDIR = $( subst $( SRCTREE) /,,$( CURDIR:$( obj) %= %) )
ALL_AFLAGS = $( AFLAGS) $( AFLAGS_$( BCURDIR) /$( @F) ) $( AFLAGS_$( BCURDIR) )
ALL_CFLAGS = $( CFLAGS) $( CFLAGS_$( BCURDIR) /$( @F) ) $( CFLAGS_$( BCURDIR) )
EXTRA_CPPFLAGS = $( CPPFLAGS_$( BCURDIR) /$( @F) ) $( CPPFLAGS_$( BCURDIR) )
ALL_CFLAGS += $( EXTRA_CPPFLAGS)
# The _DEP version uses the $< file target (for dependency generation)
# See rules.mk
EXTRA_CPPFLAGS_DEP = $( CPPFLAGS_$( BCURDIR) /$( addsuffix .o,$( basename $<) ) ) \
$( CPPFLAGS_$( BCURDIR) )
$(obj)%.s : %.S
$( CPP) $( ALL_AFLAGS) -o $@ $<
$(obj)%.o : %.S
$( CC) $( ALL_AFLAGS) -o $@ $< -c
$(obj)%.o : %.c
$( CC) $( ALL_CFLAGS) -o $@ $< -c
$(obj)%.i : %.c
$( CPP) $( ALL_CFLAGS) -o $@ $< -c
$(obj)%.s : %.c
$( CC) $( ALL_CFLAGS) -o $@ $< -c -S
#########################################################################
# If the list of objects to link is empty, just create an empty built-in.o
cmd_link_o_target = $( if $( strip $1 ) ,\
$( LD) $( LDFLAGS) -r -o $@ $1 ,\
rm -f $@ ; $( AR) rcs $@ )
#########################################################################