From f1070229f845d3214a3fb092acf4221d78c2ddc0 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 1 Dec 2022 15:28:26 +0800 Subject: [PATCH] system: fixed USE_FIXED_STATIC_RAM_SIZE option The USE_FIXED_STATIC_RAM_SIZE was not actually causing the heap to start at a fixed address. Closes https://github.com/espressif/esp-idf/issues/10270 Closes https://github.com/espressif/esp-idf/issues/10271 --- components/esp_system/ld/esp32/memory.ld.in | 4 ++-- components/esp_system/ld/esp32/sections.ld.in | 5 +++-- components/esp_system/ld/esp32c2/memory.ld.in | 13 +----------- components/esp_system/ld/esp32c3/memory.ld.in | 13 +----------- components/esp_system/ld/esp32s2/memory.ld.in | 21 +++++++------------ .../esp_system/ld/esp32s2/sections.ld.in | 5 +++-- components/esp_system/ld/esp32s3/memory.ld.in | 4 ++-- .../esp_system/ld/esp32s3/sections.ld.in | 5 +++-- .../port/soc/esp32s2/Kconfig.memory | 5 ++++- .../port/soc/esp32s3/Kconfig.memory | 5 ++++- 10 files changed, 31 insertions(+), 49 deletions(-) diff --git a/components/esp_system/ld/esp32/memory.ld.in b/components/esp_system/ld/esp32/memory.ld.in index d231a25db38..4fe39c7843f 100644 --- a/components/esp_system/ld/esp32/memory.ld.in +++ b/components/esp_system/ld/esp32/memory.ld.in @@ -114,9 +114,9 @@ MEMORY #if defined(CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE) /* static data ends at defined address */ -_static_data_end = 0x3FFB0000 + DRAM0_0_SEG_LEN; +_heap_start = 0x3FFB0000 + DRAM0_0_SEG_LEN; #else -_static_data_end = _bss_end; +_heap_start = _heap_low_start; #endif /* Heap ends at top of dram0_0_seg */ diff --git a/components/esp_system/ld/esp32/sections.ld.in b/components/esp_system/ld/esp32/sections.ld.in index 5dffe85b097..9f6e1fe8733 100644 --- a/components/esp_system/ld/esp32/sections.ld.in +++ b/components/esp_system/ld/esp32/sections.ld.in @@ -396,7 +396,8 @@ SECTIONS .dram0.heap_start (NOLOAD) : { . = ALIGN (8); - _heap_start = ABSOLUTE(.); + /* Lowest possible start address for the heap */ + _heap_low_start = ABSOLUTE(.); } > dram0_0_seg /** This section will be used by the debugger and disassembler to get more information @@ -422,5 +423,5 @@ SECTIONS ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), "IRAM0 segment data does not fit.") -ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), +ASSERT(((_heap_low_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.") diff --git a/components/esp_system/ld/esp32c2/memory.ld.in b/components/esp_system/ld/esp32c2/memory.ld.in index 9a91b24f3d1..ec02e05b65b 100644 --- a/components/esp_system/ld/esp32c2/memory.ld.in +++ b/components/esp_system/ld/esp32c2/memory.ld.in @@ -20,12 +20,8 @@ #define I_D_SRAM_SIZE SRAM_DRAM_END - SRAM_DRAM_ORG -#if CONFIG_ESP32C2_USE_FIXED_STATIC_RAM_SIZE -ASSERT((CONFIG_ESP32C2_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.") -#define DRAM0_0_SEG_LEN CONFIG_ESP32C2_FIXED_STATIC_RAM_SIZE -#else #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE -#endif // CONFIG_ESP32C2_USE_FIXED_STATIC_RAM_SIZE + MEMORY { /** @@ -65,13 +61,6 @@ MEMORY } -#if CONFIG_ESP32C2_USE_FIXED_STATIC_RAM_SIZE -/* static data ends at defined address */ -_static_data_end = 0x3FCA0000 + DRAM0_0_SEG_LEN; -#else -_static_data_end = _bss_end; -#endif // CONFIG_ESP32C2_USE_FIXED_STATIC_RAM_SIZE - /* Heap ends at top of dram0_0_seg */ _heap_end = 0x40000000; diff --git a/components/esp_system/ld/esp32c3/memory.ld.in b/components/esp_system/ld/esp32c3/memory.ld.in index b16f855b1f3..aa8aabd5f8f 100644 --- a/components/esp_system/ld/esp32c3/memory.ld.in +++ b/components/esp_system/ld/esp32c3/memory.ld.in @@ -38,12 +38,8 @@ #define I_D_SRAM_SIZE SRAM_DRAM_END - SRAM_DRAM_ORG -#if CONFIG_ESP32C3_USE_FIXED_STATIC_RAM_SIZE -ASSERT((CONFIG_ESP32C3_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.") -#define DRAM0_0_SEG_LEN CONFIG_ESP3C3_FIXED_STATIC_RAM_SIZE -#else #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE -#endif // CONFIG_ESP32C3_USE_FIXED_STATIC_RAM_SIZE + MEMORY { /** @@ -87,13 +83,6 @@ MEMORY rtc_iram_seg(RWX) : org = 0x50000000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC } -#if CONFIG_ESP32C3_USE_FIXED_STATIC_RAM_SIZE -/* static data ends at defined address */ -_static_data_end = 0x3FCA0000 + DRAM0_0_SEG_LEN; -#else -_static_data_end = _bss_end; -#endif // CONFIG_ESP32C3_USE_FIXED_STATIC_RAM_SIZE - /* Heap ends at top of dram0_0_seg */ _heap_end = 0x40000000; diff --git a/components/esp_system/ld/esp32s2/memory.ld.in b/components/esp_system/ld/esp32s2/memory.ld.in index 68c3a70e0bd..3297c8e3c8e 100644 --- a/components/esp_system/ld/esp32s2/memory.ld.in +++ b/components/esp_system/ld/esp32s2/memory.ld.in @@ -50,17 +50,12 @@ #define I_D_RAM_SIZE DATA_RAM_END - DRAM_ORG -#if defined(CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE) - -ASSERT((CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE <= I_D_RAM_SIZE), - "Fixed static ram data does not fit.") - -#define STATIC_RAM_SIZE CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE - +#if CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE +ASSERT((CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE <= I_D_RAM_SIZE), "Fixed static ram data does not fit.") +#define DRAM0_0_SEG_LEN CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE #else -#define STATIC_RAM_SIZE 0 -#endif - +#define DRAM0_0_SEG_LEN I_D_RAM_SIZE +#endif // CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE MEMORY { /* All these values assume the flash cache is on, and have the blocks this uses subtracted from the length @@ -86,7 +81,7 @@ MEMORY /* Shared data RAM, excluding memory reserved for bootloader and ROM bss/data/stack. */ - dram0_0_seg (RW) : org = DRAM_ORG, len = I_D_RAM_SIZE - STATIC_RAM_SIZE + dram0_0_seg (RW) : org = DRAM_ORG, len = DRAM0_0_SEG_LEN #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS /* Flash mapped constant data */ @@ -120,9 +115,9 @@ MEMORY #if defined(CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE) /* static data ends at defined address */ -_static_data_end = DRAM_ORG + STATIC_RAM_SIZE; +_heap_start = DRAM_ORG + DRAM0_0_SEG_LEN; #else -_static_data_end = _bss_end; +_heap_start = _heap_low_start; #endif _heap_end = 0x40000000; diff --git a/components/esp_system/ld/esp32s2/sections.ld.in b/components/esp_system/ld/esp32s2/sections.ld.in index 899bca0af6b..9acdda8f7ab 100644 --- a/components/esp_system/ld/esp32s2/sections.ld.in +++ b/components/esp_system/ld/esp32s2/sections.ld.in @@ -390,7 +390,8 @@ SECTIONS .dram0.heap_start (NOLOAD) : { . = ALIGN (8); - _heap_start = ABSOLUTE(.); + /* Lowest possible start address for the heap */ + _heap_low_start = ABSOLUTE(.); } > dram0_0_seg /** This section will be used by the debugger and disassembler to get more information @@ -416,5 +417,5 @@ SECTIONS ASSERT(((_iram_text_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), "IRAM0 segment data does not fit.") -ASSERT(((_heap_start - _data_start) <= LENGTH(dram0_0_seg)), +ASSERT(((_heap_low_start - _data_start) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.") diff --git a/components/esp_system/ld/esp32s3/memory.ld.in b/components/esp_system/ld/esp32s3/memory.ld.in index 4607b371d16..5435434763d 100644 --- a/components/esp_system/ld/esp32s3/memory.ld.in +++ b/components/esp_system/ld/esp32s3/memory.ld.in @@ -119,9 +119,9 @@ MEMORY #if CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE /* static data ends at defined address */ -_static_data_end = 0x3FCA0000 + DRAM0_0_SEG_LEN; +_heap_start = SRAM_DRAM_ORG + DRAM0_0_SEG_LEN; #else -_static_data_end = _bss_end; +_heap_start = _heap_low_start; #endif // CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE /* Heap ends at top of dram0_0_seg */ diff --git a/components/esp_system/ld/esp32s3/sections.ld.in b/components/esp_system/ld/esp32s3/sections.ld.in index ab48772187a..ed49afc2ccb 100644 --- a/components/esp_system/ld/esp32s3/sections.ld.in +++ b/components/esp_system/ld/esp32s3/sections.ld.in @@ -429,7 +429,8 @@ SECTIONS .dram0.heap_start (NOLOAD) : { . = ALIGN (8); - _heap_start = ABSOLUTE(.); + /* Lowest possible start address for the heap */ + _heap_low_start = ABSOLUTE(.); } > dram0_0_seg /** This section will be used by the debugger and disassembler to get more information @@ -455,5 +456,5 @@ SECTIONS ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), "IRAM0 segment data does not fit.") -ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), +ASSERT(((_heap_low_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.") diff --git a/components/esp_system/port/soc/esp32s2/Kconfig.memory b/components/esp_system/port/soc/esp32s2/Kconfig.memory index aa7a64bae3c..255845f7c81 100644 --- a/components/esp_system/port/soc/esp32s2/Kconfig.memory +++ b/components/esp_system/port/soc/esp32s2/Kconfig.memory @@ -21,9 +21,12 @@ menu "Memory" config ESP32S2_FIXED_STATIC_RAM_SIZE hex "Fixed Static RAM size" default 0x10000 - range 0 0x34000 + range 0 0x34000 # Equal to I_D_SRAM_SIZE in linkerscript depends on ESP32S2_USE_FIXED_STATIC_RAM_SIZE help RAM size dedicated for static variables (.data & .bss sections). + This value is less than the chips total memory, as not all of it can be used for this purpose. + E.g. parts are used by the software bootloader, and will only be available + as heap memory after app startup. endmenu # Memory diff --git a/components/esp_system/port/soc/esp32s3/Kconfig.memory b/components/esp_system/port/soc/esp32s3/Kconfig.memory index 5a1076647f0..13ade9943ad 100644 --- a/components/esp_system/port/soc/esp32s3/Kconfig.memory +++ b/components/esp_system/port/soc/esp32s3/Kconfig.memory @@ -21,9 +21,12 @@ menu "Memory" config ESP32S3_FIXED_STATIC_RAM_SIZE hex "Fixed Static RAM size" default 0x10000 - range 0 0x34000 + range 0 0x54700 # Equal to I_D_SRAM_SIZE in linkerscript depends on ESP32S3_USE_FIXED_STATIC_RAM_SIZE help RAM size dedicated for static variables (.data & .bss sections). + This value is less than the chips total memory, as not all of it can be used for this purpose. + E.g. parts are used by the software bootloader, and will only be available + as heap memory after app startup. endmenu # Memory