linker: prefer board specific linker file

First look for a custom linker file defined by a config variable, if
not defined, look in the board directory. Finally look in the SoC
directory.

This adds flexibility and enhances modularity allowing a board to define
the linker the script instead of the SoC specific one.

Change-Id: Id44aa7d0e93d97234163ec858e2cfefe09768a08
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2016-01-05 08:42:23 -05:00
commit 6c5509f34f

View file

@ -707,7 +707,19 @@ LDFLAGS_zephyr += $(call ld-option,--build-id=none)
LD_TOOLCHAIN ?= -D__GCC_LINKER_CMD__
export LD_TOOLCHAIN
ifdef CONFIG_HAVE_CUSTOM_LINKER_SCRIPT
KBUILD_LDS := $(subst $(DQUOTE),,$(CONFIG_CUSTOM_LINKER_SCRIPT))
else
# Try a board specific linker file
KBUILD_LDS := $(srctree)/boards/$(BOARD_NAME)/linker.cmd
# If not available, try an SoC specific linker file
ifeq ($(wildcard $(KBUILD_LDS)),)
KBUILD_LDS := $(srctree)/arch/$(ARCH)/soc/$(SOC_NAME)/linker.cmd
endif
endif
export LD_TOOLCHAIN KBUILD_LDS
# Default kernel image to build when no specific target is given.
# KBUILD_IMAGE may be overruled on the command line or
@ -732,14 +744,8 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y := $(libs-y1) $(libs-y2)
# Externally visible symbols (used by link-zephyr.sh)
export KBUILD_ZEPHYR_MAIN := $(drivers-y) $(core-y) $(libs-y) $(app-y)
ifdef CONFIG_HAVE_CUSTOM_LINKER_SCRIPT
export KBUILD_LDS := $(subst $(DQUOTE),,$(CONFIG_CUSTOM_LINKER_SCRIPT))
else
export KBUILD_LDS := $(srctree)/arch/$(ARCH)/soc/$(SOC_NAME)/linker.cmd
endif
export LDFLAGS_zephyr
# used by scripts/pacmage/Makefile
export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(zephyr-alldirs)) arch include samples scripts)