Browse Source

build: permit multiple linker scripts

This change allows platforms to provide more than one linker script to
any image utilizing the `MAKE_BL` build system macro.

This is already done by some MediaTek platforms via the
`EXTRA_LINKERFILE` build system variable, which has now been removed.

In its place, additional linker scripts may be added to the
`<IMAGE>_LINKER_SCRIPT_SOURCES` variable.

BREAKING-CHANGE: The `EXTRA_LINKERFILE` build system variable has been
 replaced with the `<IMAGE>_LINKER_SCRIPT_SOURCES` variable. See the
 commit message for more information.

Change-Id: I3f0b69200d6a4841fd158cd09344ce9e67047271
Signed-off-by: Chris Kay <chris.kay@arm.com>
pull/1994/head
Chris Kay 2 years ago
parent
commit
a6ff0067ab
  1. 20
      make_helpers/build_macros.mk
  2. 25
      plat/mediatek/build_helpers/mtk_build_helpers.mk
  3. 21
      plat/mediatek/build_helpers/mtk_build_helpers_epilogue.mk

20
make_helpers/build_macros.mk

@ -13,6 +13,7 @@ endif
# Some utility macros for manipulating awkward (whitespace) characters. # Some utility macros for manipulating awkward (whitespace) characters.
blank := blank :=
space :=${blank} ${blank} space :=${blank} ${blank}
comma := ,
# A user defined function to recursively search for a filename below a directory # A user defined function to recursively search for a filename below a directory
# $1 is the directory root of the recursive search (blank for current directory). # $1 is the directory root of the recursive search (blank for current directory).
@ -481,9 +482,12 @@ define MAKE_BL
$(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE)) $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE))
$(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE)))
$(eval LINKER_SCRIPT_SOURCES := $($(call uppercase,$(1))_LINKER_SCRIPT_SOURCES))
$(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES)))
# We use sort only to get a list of unique object directory names. # We use sort only to get a list of unique object directory names.
# ordering is not relevant but sort removes duplicates. # ordering is not relevant but sort removes duplicates.
$(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT}))) $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT} ${LINKER_SCRIPTS})))
# The $(dir ) function leaves a trailing / on the directory names # The $(dir ) function leaves a trailing / on the directory names
# Rip off the / to match directory names with make rule targets. # Rip off the / to match directory names with make rule targets.
$(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
@ -502,7 +506,11 @@ $(eval $(foreach objd,${OBJ_DIRS},
${1}_dirs: | ${OBJ_DIRS} ${1}_dirs: | ${OBJ_DIRS}
$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
$(eval $(call MAKE_LD,$(DEFAULT_LINKER_SCRIPT),$(DEFAULT_LINKER_SCRIPT_SOURCE),$(1)))
# Generate targets to preprocess each required linker script
$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \
$(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1))))
$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS)) $(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
ifeq ($(USE_ROMLIB),1) ifeq ($(USE_ROMLIB),1)
@ -513,7 +521,7 @@ endif
# object file path, and prebuilt object file path. # object file path, and prebuilt object file path.
$(eval OBJS += $(MODULE_OBJS)) $(eval OBJS += $(MODULE_OBJS))
$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) | $(1)_dirs libraries $(BL_LIBS) $(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $(1)_dirs libraries $(BL_LIBS)
$$(ECHO) " LD $$@" $$(ECHO) " LD $$@"
ifdef MAKE_BUILD_STRINGS ifdef MAKE_BUILD_STRINGS
$(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
@ -532,11 +540,13 @@ ifneq ($(findstring armlink,$(notdir $(LD))),)
$(BUILD_DIR)/build_message.o $(OBJS) $(BUILD_DIR)/build_message.o $(OBJS)
else ifneq ($(findstring gcc,$(notdir $(LD))),) else ifneq ($(findstring gcc,$(notdir $(LD))),)
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \ $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
$(EXTRA_LINKERFILE) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \ $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \
$(BUILD_DIR)/build_message.o \
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
else else
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \ $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
--script $(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \ $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \
$(BUILD_DIR)/build_message.o \
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
endif endif
ifeq ($(DISABLE_BIN_GENERATION),1) ifeq ($(DISABLE_BIN_GENERATION),1)

25
plat/mediatek/build_helpers/mtk_build_helpers.mk

@ -61,31 +61,6 @@ define MAKE_LOCALS
$(eval $(call uppercase,$(2))_SOURCES += $(1)) $(eval $(call uppercase,$(2))_SOURCES += $(1))
endef endef
# MAKE_LINKERFILE change linker script source file name to
# target linker script
# $(1) = linker script source file
# $(2) = BL stage
define MAKE_LINKERFILE
$(eval EXTRA_GENERATED_LINKER_SCRIPT += $(BUILD_PLAT)/$(2)/$(patsubst %.ld.S,%.ld,$(notdir $(1))))
endef
# MAKE_LINKERFILE_ITER call MAKE_LINKERFILE iteratively
# $(1) = linker script source file
# $(2) = BL stage
define MAKE_LINKERFILE_ITER
$(eval $(foreach link_src,$(1),$(call MAKE_LINKERFILE,$(link_src),$(2))))
endef
# MAKE_LD_ITER generate the linker scripts using the C preprocessor iteratively
# $(1) = output linker script
# $(2) = input template
# $(3) = BL stage (1, 2, 2u, 31, 32)
define MAKE_LD_ITER
$(eval index_list=$(shell seq $(words $(1))))
$(eval $(foreach i, $(index_list), \
$(call MAKE_LD,$(word $(i), $(1)), $(word $(i), $(2)),$(3))))
endef
# MAKE_MODULE reference MAKE_OBJS. # MAKE_MODULE reference MAKE_OBJS.
# Create module folder under out/bl$(BL)/$(module) # Create module folder under out/bl$(BL)/$(module)
# Arguments: # Arguments:

21
plat/mediatek/build_helpers/mtk_build_helpers_epilogue.mk

@ -9,22 +9,7 @@ $(eval $(call INCLUDE_MODULES,$(MODULES-y)))
# Make next section align to page size # Make next section align to page size
ifneq ($(MTK_EXTRA_LINKERFILE),) ifneq ($(MTK_EXTRA_LINKERFILE),)
$(eval $(call MAKE_LINKERFILE_ITER,$(MTK_LINKERFILE_SOURCE),bl31)) # mtk_align.ld MUST BE THE LAST LINKER SCRIPT!
BL31_LINKER_SCRIPT_SOURCES += $(MTK_LINKERFILE_SOURCE)
# EXTRA_GENERATED_LINKER_SCRIPT is a global variable of derived linker BL31_LINKER_SCRIPT_SOURCES += ${MTK_PLAT}/include/mtk_align.ld
# script list(from MTK_LINKERFILE_SOURCE) after MAKE_LINKERFILE_ITER
# function call
EXTRA_LINKERFILE += ${EXTRA_GENERATED_LINKER_SCRIPT}
# Expand derived linker script as build target
$(eval $(call MAKE_LD_ITER, $(EXTRA_GENERATED_LINKER_SCRIPT),$(MTK_LINKERFILE_SOURCE),bl31))
# mtk_align.ld MUST BE THE LAST LINKER SCRIPT!
EXTRA_LINKERFILE += ${MTK_PLAT}/include/mtk_align.ld
# bl31.ld should depend on EXTRA_LINKERFILE
$(eval ${BUILD_PLAT}/bl31/bl31.ld: ${EXTRA_LINKERFILE})
EXTRA_LINKERFILE := $(addprefix -T,$(EXTRA_LINKERFILE))
else
EXTRA_LINKERFILE :=
endif endif

Loading…
Cancel
Save