Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32[-S2/-S3]: Refactor and rename linker scripts #7822

Merged
merged 4 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/xtensa/src/esp32/esp32_allocateheap.c
Expand Up @@ -121,7 +121,7 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
void up_allocate_kheap(void **heap_start, size_t *heap_size)
{
/* These values come from the linker scripts (kernel-space.ld and
* protected.template.ld).
* protected_memory.ld).
* Check boards/xtensa/esp32.
*/

Expand Down
12 changes: 8 additions & 4 deletions boards/xtensa/esp32/common/kernel/Makefile
Expand Up @@ -29,12 +29,12 @@ ENTRYPT = $(patsubst "%",%,$(CONFIG_INIT_ENTRYPOINT))
# is appropriate for the host OS

USER_LIBPATHS = $(addprefix -L,$(call CONVERT_PATH,$(addprefix $(TOPDIR)$(DELIM),$(dir $(USERLIBS)))))
USER_LDSCRIPT = -T $(call CONVERT_PATH,$(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld)
USER_LDSCRIPT += -T $(call CONVERT_PATH,$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)user-space.ld)
USER_LDSCRIPT = $(call CONVERT_PATH,$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected_memory.ld)
USER_LDSCRIPT += $(call CONVERT_PATH,$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)user-space.ld)
USER_HEXFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.hex)
USER_BINFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.bin)

USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(USER_LDSCRIPT)
USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(addprefix -T,$(addsuffix .tmp,$(USER_LDSCRIPT)))

ifeq ($(CONFIG_DEBUG_LINK_MAP),y)
USER_LDFLAGS += --cref -Map="$(TOPDIR)$(DELIM)User.map"
Expand Down Expand Up @@ -67,9 +67,12 @@ all: $(TOPDIR)$(DELIM)nuttx_user.elf
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)

$(addsuffix .tmp,$(USER_LDSCRIPT)): $(USER_LDSCRIPT)
$(call PREPROCESS,$(patsubst %.tmp,%,$@),$@)

# Create the nuttx_user.elf file containing all of the user-mode code

nuttx_user.elf: $(OBJS)
nuttx_user.elf: $(OBJS) $(addsuffix .tmp,$(USER_LDSCRIPT))
$(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) $(LDSTARTGROUP) $(USER_LDLIBS) $(LDENDGROUP) $(USER_LIBGCC)

$(TOPDIR)$(DELIM)nuttx_user.elf: nuttx_user.elf
Expand All @@ -83,6 +86,7 @@ ifeq ($(CONFIG_RAW_BINARY),y)
$(Q) echo "CP: nuttx_user.bin"
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx_user.elf $(USER_BINFILE)
endif
$(Q) $(call DELFILE,$(addsuffix .tmp,$(USER_LDSCRIPT)))

.depend:

Expand Down
1 change: 1 addition & 0 deletions boards/xtensa/esp32/common/scripts/.gitignore
@@ -0,0 +1 @@
/*.ld.tmp
@@ -1,5 +1,5 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/flat.template.ld
* boards/xtensa/esp32/common/scripts/flat_memory.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -24,16 +24,13 @@
* This file describes the memory layout (memory blocks) as virtual
* memory addresses.
*
* esp32.ld contains output sections to link compiler output into these
* memory blocks.
*
* NOTE: That this is not the actual linker script but rather a "template"
* for the esp32_out.ld script. This template script is passed through
* the C preprocessor to include selected configuration options.
* <legacy/mcuboot>_sections.ld contains output sections to link compiler
* output into these memory blocks.
*
****************************************************************************/

#include <nuttx/config.h>

#include "esp32_aliases.ld"

#ifdef CONFIG_ESP32_FLASH_2M
Expand All @@ -59,8 +56,8 @@ MEMORY
*/

metadata (RX) : org = CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE, len = 0x20
ROM (RX) : org = CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE + 0x20,
len = FLASH_SIZE - (CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE + 0x20)
ROM (RX) : org = ORIGIN(metadata) + LENGTH(metadata),
len = FLASH_SIZE - ORIGIN(ROM)
#endif

/* Below values assume the flash cache is on, and have the blocks this
Expand Down Expand Up @@ -117,8 +114,8 @@ MEMORY
* be equal.
*/

drom0_0_seg (R) : org = 0x3f400000 + (CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE + 0x20),
len = FLASH_SIZE - (CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE + 0x20)
drom0_0_seg (R) : org = 0x3f400000 + ORIGIN(ROM),
len = FLASH_SIZE - ORIGIN(ROM)
#else
/* The 0x20 offset is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
Expand Down
@@ -1,5 +1,5 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32.ld
* boards/xtensa/esp32/common/scripts/legacy_sections.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down
@@ -1,5 +1,5 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32_mcuboot.ld
* boards/xtensa/esp32/common/scripts/mcuboot_sections.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down
@@ -1,5 +1,5 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/protected.template.ld
* boards/xtensa/esp32/common/scripts/protected_memory.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -19,7 +19,7 @@
****************************************************************************/

/****************************************************************************
* ESP32 Linker Script Memory Layout
* ESP32 Linker Script Memory Layout for Protected Mode
*
* This file describes the memory layout (memory blocks) as virtual
* memory addresses.
Expand All @@ -28,10 +28,6 @@
* output into these memory blocks for the Kernel and User images,
* respectively.
*
* NOTE: That this is not the actual linker script but rather a "template"
* for the esp32_out.ld script. This template script is passed through
* the C preprocessor to include selected configuration options.
*
****************************************************************************/

#include <nuttx/config.h>
Expand All @@ -40,9 +36,9 @@

MEMORY
{

metadata (RX) : org = 0x0, len = 0x18
ROM (RX) : org = 0x18, len = 0x100000
ROM (RX) : org = ORIGIN(metadata) + LENGTH(metadata),
len = 0x100000 - ORIGIN(ROM)

/* Below values assume the flash cache is on, and have the blocks this
* uses subtracted from the length of the various regions. The 'data access
Expand Down Expand Up @@ -105,5 +101,5 @@ MEMORY
*/

KDROM (R) : org = 0x3f400020, len = 0x80000 - 0x20
UDROM (R) : org = 0x3f480018, len = 0x80000 - 0x18
UDROM (R) : org = 0x3f480018, len = 0x80000 - ORIGIN(ROM)
}
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-devkitc/scripts/.gitignore

This file was deleted.

40 changes: 10 additions & 30 deletions boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs
Expand Up @@ -23,42 +23,22 @@ include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/tools/esp32/Config.mk
include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs

# This is the generated memory layout linker script. It will always be
# generated at the board level.

ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld
ARCHSCRIPT += $(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.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
else
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld
endif
endif
endif

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld)
ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld)
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
endif
ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),)
LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld
else
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld
endif
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld)
else
ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld)
endif
endif

ARCHPICFLAGS = -fpic
Expand Down
12 changes: 0 additions & 12 deletions boards/xtensa/esp32/esp32-devkitc/src/Make.defs
Expand Up @@ -59,18 +59,6 @@ ifeq ($(CONFIG_NET_W5500),y)
CSRCS += esp32_w5500.c
endif

SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld

.PHONY = context distclean

$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE)
$(Q) $(CC) -isystem $(TOPDIR)/include -I $(BOARD_COMMON_DIR)$(DELIM)scripts -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@

context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))

DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-ethernet-kit/scripts/.gitignore

This file was deleted.

40 changes: 10 additions & 30 deletions boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs
Expand Up @@ -23,42 +23,22 @@ include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/tools/esp32/Config.mk
include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs

# This is the generated memory layout linker script. It will always be
# generated at the board level.

ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld
ARCHSCRIPT += $(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.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
else
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld
endif
endif
endif

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld)
ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld)
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
endif
ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),)
LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld
else
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld
endif
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld)
else
ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld)
endif
endif

ARCHPICFLAGS = -fpic
Expand Down
12 changes: 0 additions & 12 deletions boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs
Expand Up @@ -39,18 +39,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += esp32_buttons.c
endif

SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld

.PHONY = context distclean

$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE)
$(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@

context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))

DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-lyrat/scripts/.gitignore

This file was deleted.

40 changes: 10 additions & 30 deletions boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs
Expand Up @@ -23,42 +23,22 @@ include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/tools/esp32/Config.mk
include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs

# This is the generated memory layout linker script. It will always be
# generated at the board level.

ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld
ARCHSCRIPT += $(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.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
else
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld
endif
endif
endif

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld),)
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld)
ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld)
else
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
endif
ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)

ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),)
LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld
else
ifeq ($(CONFIG_BUILD_PROTECTED),y)
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld
else
LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld
endif
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld)
else
ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld)
endif
endif

ARCHPICFLAGS = -fpic
Expand Down
12 changes: 0 additions & 12 deletions boards/xtensa/esp32/esp32-lyrat/src/Make.defs
Expand Up @@ -47,18 +47,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += esp32_buttons.c
endif

SCRIPTOUT = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld

.PHONY = context distclean

$(SCRIPTOUT): $(LDSCRIPT_TEMPLATE) $(CONFIGFILE)
$(Q) $(CC) -isystem $(TOPDIR)/include -C -P -x c -E $(LDSCRIPT_TEMPLATE) -o $@

context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))

DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-sparrow-kit/scripts/.gitignore

This file was deleted.