From 4c3033e8161e85cc58afc1f86fdc992cb88a6bdc Mon Sep 17 00:00:00 2001 From: Marek Matej Date: Wed, 11 Dec 2024 20:55:38 +0100 Subject: [PATCH 1/3] soc: esp32: Fix WiFi allocations to SPIRAM Fix allocations of large buffers if SPIRAM and WiFi alloc to SPIRAM are both enabled. Signed-off-by: Marek Matej --- soc/espressif/esp32/default.ld | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/soc/espressif/esp32/default.ld b/soc/espressif/esp32/default.ld index d084228f1aa7c4..4c18043ca33f23 100644 --- a/soc/espressif/esp32/default.ld +++ b/soc/espressif/esp32/default.ld @@ -680,10 +680,27 @@ SECTIONS .dram0.noinit (NOLOAD) : { - . = ALIGN (8); + . = ALIGN (4); + __dram_noinit_start = ABSOLUTE(.); +#ifdef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM + *(EXCLUDE_FILE( + *libdrivers__wifi.a:* + *libsubsys__net__l2__ethernet.a:* + *libsubsys__net__lib__config.a:* + *libsubsys__net__ip.a:* + *libsubsys__net.a:* ) .noinit) + *(EXCLUDE_FILE( + *libdrivers__wifi.a:* + *libsubsys__net__l2__ethernet.a:* + *libsubsys__net__lib__config.a:* + *libsubsys__net__ip.a:* + *libsubsys__net.a:* ) .noinit.*) +#else *(.noinit) *(.noinit.*) - . = ALIGN (8); +#endif /* CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM */ + __dram_noinit_end = ABSOLUTE(.); + . = ALIGN (4); } GROUP_LINK_IN(RAMABLE_REGION) /* Provide total SRAM usage, including IRAM and DRAM */ @@ -700,7 +717,8 @@ SECTIONS #ifdef CONFIG_ESP_SPIRAM .ext_ram.bss (NOLOAD): { - _ext_ram_data_start = ABSOLUTE(.); + _ext_ram_start = ABSOLUTE(.); + _ext_ram_noinit_start = ABSOLUTE(.); #ifdef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM *libdrivers__wifi.a:(.noinit .noinit.*) @@ -709,14 +727,19 @@ SECTIONS *libsubsys__net__ip.a:(.noinit .noinit.*) *libsubsys__net.a:(.noinit .noinit.*) #endif /* CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM */ + . = ALIGN(16); + _ext_ram_noinit_end = ABSOLUTE(.); _ext_ram_bss_start = ABSOLUTE(.); *(.ext_ram.bss*) + . = ALIGN(16); _ext_ram_bss_end = ABSOLUTE(.); + _spiram_heap_start = ABSOLUTE(.); . = . + CONFIG_ESP_SPIRAM_HEAP_SIZE; + . = ALIGN(4); - _ext_ram_data_end = ABSOLUTE(.); + _ext_ram_end = ABSOLUTE(.); } GROUP_LINK_IN(ext_ram_seg) #endif /* CONFIG_ESP_SPIRAM */ @@ -900,6 +923,6 @@ SECTIONS /* --- XTENSA GLUE AND DEBUG END --- */ #ifdef CONFIG_ESP_SPIRAM -ASSERT(((_ext_ram_data_end - _ext_ram_data_start) <= CONFIG_ESP_SPIRAM_SIZE), +ASSERT(((_ext_ram_end - _ext_ram_start) <= CONFIG_ESP_SPIRAM_SIZE), "External SPIRAM overflowed.") #endif /* CONFIG_ESP_SPIRAM */ From f434bf55349c335f63490fe7024e78782d211a86 Mon Sep 17 00:00:00 2001 From: Marek Matej Date: Fri, 21 Jun 2024 14:12:28 +0200 Subject: [PATCH 2/3] soc: esp32s3: Fix WiFi allocation to SPIRAM Fix the allocations if the SPIRAM and WiFi alloc to SPIRAM are both enabled. Signed-off-by: Marek Matej --- soc/espressif/esp32s3/default.ld | 74 +++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/soc/espressif/esp32s3/default.ld b/soc/espressif/esp32s3/default.ld index a57a18fb386b78..5a193ba11e0d05 100644 --- a/soc/espressif/esp32s3/default.ld +++ b/soc/espressif/esp32s3/default.ld @@ -68,7 +68,10 @@ MEMORY * A dummy section is used to avoid overlap. See `.ext_ram.dummy` in `sections.ld.in` */ #if defined(CONFIG_ESP_SPIRAM) - ext_ram_seg(RWX): org = DROM_SEG_ORG, len = CONFIG_ESP_SPIRAM_SIZE - 0x40 + /* `ext_[id]ram_seg` and `drom0_0_seg` share the same bus and the address region. + * A dummy section is used to avoid overlap. See `.ext_ram.dummy` */ + ext_dram_seg(RW): org = DROM_SEG_ORG, len = (CONFIG_ESP_SPIRAM_SIZE) + ext_iram_seg(RX): org = IROM_SEG_ORG, len = (CONFIG_ESP_SPIRAM_SIZE) #endif /* RTC fast memory (executable). Persists over deep sleep. @@ -702,6 +705,31 @@ SECTIONS _data_end = ABSOLUTE(.); } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + .dram0.noinit (NOLOAD): + { + . = ALIGN(4); + __dram_noinit_start = ABSOLUTE(.); +#ifdef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM + *(EXCLUDE_FILE( + *libdrivers__wifi.a:* + *libsubsys__net__l2__ethernet.a:* + *libsubsys__net__lib__config.a:* + *libsubsys__net__ip.a:* + *libsubsys__net.a:* ) .noinit) + *(EXCLUDE_FILE( + *libdrivers__wifi.a:* + *libsubsys__net__l2__ethernet.a:* + *libsubsys__net__lib__config.a:* + *libsubsys__net__ip.a:* + *libsubsys__net.a:* ) .noinit.*) +#else + *(.noinit) + *(.noinit.*) +#endif /* CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM */ + __dram_noinit_end = ABSOLUTE(.); + . = ALIGN(4) ; + } GROUP_LINK_IN(RAMABLE_REGION) + /* Shared RAM */ .dram0.bss (NOLOAD) : { @@ -734,14 +762,6 @@ SECTIONS __bss_end = ABSOLUTE(.); } GROUP_LINK_IN(RAMABLE_REGION) - .dram0.noinit (NOLOAD): - { - . = ALIGN(4); - *(.noinit) - *(.noinit.*) - . = ALIGN(4) ; - } GROUP_LINK_IN(RAMABLE_REGION) - /* Provide total SRAM usage, including IRAM and DRAM */ _image_ram_start = _init_start - IRAM_DRAM_OFFSET; #include @@ -823,7 +843,7 @@ SECTIONS .flash.rodata : ALIGN(CACHE_ALIGN) { - _flash_rodata_start = ABSOLUTE(.); + _image_rodata_start = ABSOLUTE(.); _rodata_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.rodata start, this can be used for mmu driver to maintain virtual address */ _rodata_start = ABSOLUTE(.); __rodata_region_start = ABSOLUTE(.); @@ -898,25 +918,41 @@ SECTIONS */ #if defined(CONFIG_ESP_SPIRAM) + /* This section is required to skip flash rodata sections, because `ext_[id]ram_seg` + * and `drom0_0_seg` are on the same bus */ .ext_ram.dummy (NOLOAD): { - . = ORIGIN(ext_ram_seg) + (_rodata_reserved_end - _flash_rodata_dummy_start); + . = ADDR(.flash.rodata_end) - ORIGIN(ext_dram_seg); . = ALIGN (CACHE_ALIGN); - } GROUP_LINK_IN(ext_ram_seg) + } GROUP_LINK_IN(ext_dram_seg) /* This section holds .ext_ram.bss data, and will be put in PSRAM */ .ext_ram.bss (NOLOAD) : { + _ext_ram_start = ABSOLUTE(.); + _ext_ram_noinit_start = ABSOLUTE(.); + +#ifdef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM + *libdrivers__wifi.a:(.noinit .noinit.*) + *libsubsys__net__l2__ethernet.a:(.noinit .noinit.*) + *libsubsys__net__lib__config.a:(.noinit .noinit.*) + *libsubsys__net__ip.a:(.noinit .noinit.*) + *libsubsys__net.a:(.noinit .noinit.*) +#endif /* CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM */ + . = ALIGN(16); + _ext_ram_noinit_end = ABSOLUTE(.); + _ext_ram_bss_start = ABSOLUTE(.); *(.ext_ram.bss*) - . = ALIGN(4); + . = ALIGN(16); + _ext_ram_bss_end = ABSOLUTE(.); _spiram_heap_start = ABSOLUTE(.); . = . + CONFIG_ESP_SPIRAM_HEAP_SIZE - (_spiram_heap_start - _ext_ram_bss_start); . = ALIGN(4); - _ext_ram_bss_end = ABSOLUTE(.); - } GROUP_LINK_IN(ext_ram_seg) + _ext_ram_end = ABSOLUTE(.); + } GROUP_LINK_IN(ext_dram_seg) #endif /* CONFIG_ESP_SPIRAM */ @@ -967,7 +1003,13 @@ SECTIONS /* --- XTENSA GLUE AND DEBUG END --- */ +ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), + "IRAM0 segment data does not fit.") + +ASSERT(((_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), + "DRAM segment data does not fit.") + #if defined(CONFIG_ESP_SPIRAM) -ASSERT(((_ext_ram_bss_end - _ext_ram_bss_start) <= CONFIG_ESP_SPIRAM_SIZE), +ASSERT(((_ext_ram_end - _ext_ram_start) <= CONFIG_ESP_SPIRAM_SIZE), "External SPIRAM overflowed.") #endif From fa551406deba4ac612e1727b8463c19eabe37554 Mon Sep 17 00:00:00 2001 From: Marek Matej Date: Tue, 10 Dec 2024 14:39:56 +0100 Subject: [PATCH 3/3] soc: espressif: Rename common/psram.c Rename psram.c -> esp_psram.c to align with the naming conventions. Signed-off-by: Marek Matej --- soc/espressif/common/CMakeLists.txt | 2 +- soc/espressif/common/{psram.c => esp_psram.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename soc/espressif/common/{psram.c => esp_psram.c} (100%) diff --git a/soc/espressif/common/CMakeLists.txt b/soc/espressif/common/CMakeLists.txt index d5e0a563412bc4..4cd6217126aa9f 100644 --- a/soc/espressif/common/CMakeLists.txt +++ b/soc/espressif/common/CMakeLists.txt @@ -4,6 +4,6 @@ zephyr_include_directories(include) if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU) - zephyr_sources_ifdef(CONFIG_ESP_SPIRAM psram.c) zephyr_sources_ifdef(CONFIG_ESP_HEAP_RUNTIME esp_heap_runtime.c) + zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c) endif() diff --git a/soc/espressif/common/psram.c b/soc/espressif/common/esp_psram.c similarity index 100% rename from soc/espressif/common/psram.c rename to soc/espressif/common/esp_psram.c