From a6632f969a7d294ce4d1a68d8921ee2c01e7f37a Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Wed, 14 Jul 2021 21:07:30 +0200 Subject: [PATCH] boards/xtensa/esp32: Make board level linker script take precedence over the common scripts. This allows having a more costumized linker script per board. Signed-off-by: Abdelatif Guettouche --- .../esp32/esp32-devkitc/scripts/Make.defs | 36 +++++++++++++++---- .../xtensa/esp32/esp32-devkitc/src/Make.defs | 5 ++- .../esp32-ethernet-kit/scripts/Make.defs | 36 +++++++++++++++---- .../esp32/esp32-ethernet-kit/src/Make.defs | 5 ++- .../esp32/esp32-wrover-kit/scripts/Make.defs | 36 +++++++++++++++---- .../esp32/esp32-wrover-kit/src/Make.defs | 7 ++-- 6 files changed, 94 insertions(+), 31 deletions(-) diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs index ced2c519b0..71f2926236 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs @@ -23,16 +23,38 @@ include $(TOPDIR)/tools/Config.mk include $(TOPDIR)/tools/esp32/Config.mk include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs -LDSCRIPT1 = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld -LDSCRIPT2 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld -LDSCRIPT3 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +# Pick the linker scripts from the board level if they exist, if not +# pick the common linker scripts. + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),) + LDSCRIPT_ROM = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +else + LDSCRIPT_ROM = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) + LDSCRIPT_SECT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld +else + LDSCRIPT_SECT = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) + LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +endif + +# This is the generated memory layout linker script. It will always be +# generated at the board level. + +LDSCRIPT_MEMORY = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifeq ($(CONFIG_CYGWIN_WINTOOL),y) - ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT1)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT2)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT3)}" + ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT_MEMORY)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_SECT)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_ROM)}" else - ARCHSCRIPT = -T$(LDSCRIPT1) -T$(LDSCRIPT2) -T$(LDSCRIPT3) + ARCHSCRIPT = -T$(LDSCRIPT_MEMORY) -T$(LDSCRIPT_SECT) -T$(LDSCRIPT_ROM) endif ifeq ($(CONFIG_DEBUG_SYMBOLS),y) diff --git a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs index 6f91478f93..9e6e40ecdc 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs +++ b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs @@ -51,13 +51,12 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += esp32_buttons.c endif -SCRIPTIN = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld .PHONY = context distclean -$(SCRIPTOUT): $(SCRIPTIN) $(CONFIGFILE) - $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(SCRIPTIN) -o $@ +$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE) + $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@ context:: $(SCRIPTOUT) diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs index 155f49e7da..a575f22010 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs @@ -23,16 +23,38 @@ include $(TOPDIR)/tools/Config.mk include $(TOPDIR)/tools/esp32/Config.mk include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs -LDSCRIPT1 = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld -LDSCRIPT2 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld -LDSCRIPT3 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +# Pick the linker scripts from the board level if they exist, if not +# pick the common linker scripts. + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),) + LDSCRIPT_ROM = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +else + LDSCRIPT_ROM = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) + LDSCRIPT_SECT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld +else + LDSCRIPT_SECT = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) + LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +endif + +# This is the generated memory layout linker script. It will always be +# generated at the board level. + +LDSCRIPT_MEMORY = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifeq ($(CONFIG_CYGWIN_WINTOOL),y) - ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT1)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT2)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT3)}" + ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT_MEMORY)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_SECT)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_ROM)}" else - ARCHSCRIPT = -T$(LDSCRIPT1) -T$(LDSCRIPT2) -T$(LDSCRIPT3) + ARCHSCRIPT = -T$(LDSCRIPT_MEMORY) -T$(LDSCRIPT_SECT) -T$(LDSCRIPT_ROM) endif ifeq ($(CONFIG_DEBUG_SYMBOLS),y) diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs index 054bd97a46..6c489fc9c7 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs @@ -43,13 +43,12 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += esp32_buttons.c endif -SCRIPTIN = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld .PHONY = context distclean -$(SCRIPTOUT): $(SCRIPTIN) $(CONFIGFILE) - $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(SCRIPTIN) -o $@ +$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE) + $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@ context:: $(SCRIPTOUT) diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs index 1366c36847..72d2ed8c82 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs @@ -23,16 +23,38 @@ include $(TOPDIR)/tools/Config.mk include $(TOPDIR)/tools/esp32/Config.mk include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs -LDSCRIPT1 = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld -LDSCRIPT2 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld -LDSCRIPT3 = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +# Pick the linker scripts from the board level if they exist, if not +# pick the common linker scripts. + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),) + LDSCRIPT_ROM = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +else + LDSCRIPT_ROM = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) + LDSCRIPT_SECT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld +else + LDSCRIPT_SECT = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld +endif + +ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) + LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld +endif + +# This is the generated memory layout linker script. It will always be +# generated at the board level. + +LDSCRIPT_MEMORY = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifeq ($(CONFIG_CYGWIN_WINTOOL),y) - ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT1)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT2)}" - ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT3)}" + ARCHSCRIPT = -T "${shell cygpath -w $(LDSCRIPT_MEMORY)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_SECT)}" + ARCHSCRIPT += -T "${shell cygpath -w $(LDSCRIPT_ROM)}" else - ARCHSCRIPT = -T$(LDSCRIPT1) -T$(LDSCRIPT2) -T$(LDSCRIPT3) + ARCHSCRIPT = -T$(LDSCRIPT_MEMORY) -T$(LDSCRIPT_SECT) -T$(LDSCRIPT_ROM) endif ifeq ($(CONFIG_DEBUG_SYMBOLS),y) diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs index 2609cb3c1c..90a8e8369b 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs @@ -53,13 +53,12 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += esp32_buttons.c endif -SCRIPTIN = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld -SCRIPTOUT = $(BOARD_DIR)$(DELIM)script$(DELIM)esp32_out.ld +SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld .PHONY = context distclean -$(SCRIPTOUT): $(SCRIPTIN) $(CONFIGFILE) - $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(SCRIPTIN) -o $@ +$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE) + $(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@ context:: $(SCRIPTOUT)