diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 6de6e8cf477..d6267035a14 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -131,6 +131,13 @@ config XTENSA_IMEM_REGION_SIZE depends on XTENSA_IMEM_USE_SEPARATE_HEAP default 0x18000 +config XTENSA_EXTMEM_BSS + bool "Allow BSS section in external memory" + default n + help + Adds a section and an attribute that allows to force variables into + the external memory. + source arch/xtensa/src/lx6/Kconfig if ARCH_CHIP_ESP32 source arch/xtensa/src/esp32/Kconfig diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h index 88e70eb8fb0..eca3dbdfebb 100644 --- a/arch/xtensa/src/common/xtensa.h +++ b/arch/xtensa/src/common/xtensa.h @@ -216,6 +216,8 @@ extern uint32_t _sbss; /* Start of .bss */ extern uint32_t _ebss; /* End+1 of .bss */ extern uint32_t _sheap; /* Start of heap */ extern uint32_t _eheap; /* End+1 of heap */ +extern uint32_t _sbss_extmem; /* start of external memory bss */ +extern uint32_t _ebss_extmem; /* End+1 of external memory bss */ /**************************************************************************** * Inline Functions diff --git a/arch/xtensa/src/common/xtensa_attr.h b/arch/xtensa/src/common/xtensa_attr.h index b7f218c2fba..fa67cbb0c70 100644 --- a/arch/xtensa/src/common/xtensa_attr.h +++ b/arch/xtensa/src/common/xtensa_attr.h @@ -27,6 +27,12 @@ #ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_ATTR_H #define __ARCH_XTENSA_SRC_COMMON_XTENSA_ATTR_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -63,4 +69,10 @@ #define RTC_RODATA_ATTR __attribute__((section(".rtc.rodata"))) +/* Forces bss variable into external memory. */ + +#ifdef CONFIG_XTENSA_EXTMEM_BSS +# define EXT_RAM_ATTR __attribute__((section(".extmem.bss"))) +#endif + #endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_ATTR_H */ diff --git a/arch/xtensa/src/esp32/esp32_start.c b/arch/xtensa/src/esp32/esp32_start.c index f00e1092bc1..1115cf39a71 100644 --- a/arch/xtensa/src/esp32/esp32_start.c +++ b/arch/xtensa/src/esp32/esp32_start.c @@ -157,6 +157,14 @@ void IRAM_ATTR __start(void) PANIC(); # endif } + + /* Set external memory bss section to zero */ + +# ifdef CONFIG_XTENSA_EXTMEM_BSS + memset(&_sbss_extmem, 0, + (&_ebss_extmem - &_sbss_extmem) * sizeof(_sbss_extmem)); +# endif + #endif /* Initialize onboard resources */ diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld index 199380e93ab..22d8226865d 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld @@ -68,6 +68,10 @@ MEMORY rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ESP32_ULP_COPROC_RESERVE_MEM, len = 0x1000 - CONFIG_ESP32_ULP_COPROC_RESERVE_MEM + + /* External memory, including data and text */ + + extmem_seg(RWX) : org = 0x3f800000, len = 0x400000 } /* Heap ends at top of dram0_0_seg */ diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld index 31dd3fadeb5..e4fffeee63f 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld @@ -123,6 +123,16 @@ SECTIONS _sheap = ABSOLUTE(.); } >dram0_0_seg + /* External memory bss, from any global variable with EXT_RAM_ATTR attribute */ + + .extmem.bss (NOLOAD) : + { + _sbss_extmem = ABSOLUTE(.); + *(.extmem.bss .extmem.bss.*) + . = ALIGN(4); + _ebss_extmem = ABSOLUTE(.); + } > extmem_seg + .flash.rodata : { _srodata = ABSOLUTE(.); diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld index e02992564f0..63024c07baf 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld @@ -68,6 +68,10 @@ MEMORY rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ESP32_ULP_COPROC_RESERVE_MEM, len = 0x1000 - CONFIG_ESP32_ULP_COPROC_RESERVE_MEM + + /* External memory, including data and text */ + + extmem_seg(RWX) : org = 0x3f800000, len = 0x400000 } /* Heap ends at top of dram0_0_seg */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld index 1e3ccda352c..8e4cd2e8e8a 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld @@ -125,6 +125,16 @@ SECTIONS _sheap = ABSOLUTE(.); } >dram0_0_seg + /* External memory bss, from any global variable with EXT_RAM_ATTR attribute */ + + .extmem.bss (NOLOAD) : + { + _sbss_extmem = ABSOLUTE(.); + *(.extmem.bss .extmem.bss.*) + . = ALIGN(4); + _ebss_extmem = ABSOLUTE(.); + } > extmem_seg + .flash.rodata : { _srodata = ABSOLUTE(.); diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld index 4a7204ad52c..f5ea00b00cb 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld @@ -68,6 +68,10 @@ MEMORY rtc_slow_seg(RW) : org = 0x50000000 + CONFIG_ESP32_ULP_COPROC_RESERVE_MEM, len = 0x1000 - CONFIG_ESP32_ULP_COPROC_RESERVE_MEM + + /* External memory, including data and text */ + + extmem_seg(RWX) : org = 0x3f800000, len = 0x400000 } /* Heap ends at top of dram0_0_seg */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld index 8103d22d43f..b62887b3ec9 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld @@ -125,6 +125,16 @@ SECTIONS _sheap = ABSOLUTE(.); } >dram0_0_seg + /* External memory bss, from any global variable with EXT_RAM_ATTR attribute */ + + .extmem.bss (NOLOAD) : + { + _sbss_extmem = ABSOLUTE(.); + *(.extmem.bss .extmem.bss.*) + . = ALIGN(4); + _ebss_extmem = ABSOLUTE(.); + } > extmem_seg + .flash.rodata : { _srodata = ABSOLUTE(.);