From a6ff0067ab57d848d3fb28a3eb2b47e6cf2a6092 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Mon, 16 Jan 2023 18:57:26 +0000 Subject: 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 `_LINKER_SCRIPT_SOURCES` variable. BREAKING-CHANGE: The `EXTRA_LINKERFILE` build system variable has been replaced with the `_LINKER_SCRIPT_SOURCES` variable. See the commit message for more information. Change-Id: I3f0b69200d6a4841fd158cd09344ce9e67047271 Signed-off-by: Chris Kay --- make_helpers/build_macros.mk | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'make_helpers') diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index d86720e61..a6b1d528b 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -13,6 +13,7 @@ endif # Some utility macros for manipulating awkward (whitespace) characters. blank := space :=${blank} ${blank} +comma := , # 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). @@ -481,9 +482,12 @@ define MAKE_BL $(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 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. # 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 # Rip off the / to match directory names with make rule targets. $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) @@ -502,7 +506,11 @@ $(eval $(foreach objd,${OBJ_DIRS}, ${1}_dirs: | ${OBJ_DIRS} $(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)) ifeq ($(USE_ROMLIB),1) @@ -513,7 +521,7 @@ endif # object file path, and prebuilt object file path. $(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 $$@" ifdef MAKE_BUILD_STRINGS $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) @@ -532,11 +540,13 @@ ifneq ($(findstring armlink,$(notdir $(LD))),) $(BUILD_DIR)/build_message.o $(OBJS) else ifneq ($(findstring gcc,$(notdir $(LD))),) $$(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) else $$(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) endif ifeq ($(DISABLE_BIN_GENERATION),1) -- cgit v1.2.1