From 585f05596bc88262564499feda485dfe5464d242 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/esp32c6/memory.ld.in | 13 +----------- components/esp_system/ld/esp32h2/memory.ld.in | 13 +----------- components/esp_system/ld/esp32h4/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 ++++- 13 files changed, 34 insertions(+), 85 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 fc64206ad9b..e6cae19ca44 100644 --- a/components/esp_system/ld/esp32/sections.ld.in +++ b/components/esp_system/ld/esp32/sections.ld.in @@ -404,7 +404,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 @@ -430,5 +431,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/esp32c6/memory.ld.in b/components/esp_system/ld/esp32c6/memory.ld.in index 86a0c117e1d..584727d9225 100644 --- a/components/esp_system/ld/esp32c6/memory.ld.in +++ b/components/esp_system/ld/esp32c6/memory.ld.in @@ -45,12 +45,8 @@ #define IDRAM0_2_SEG_SIZE (CONFIG_MMU_PAGE_SIZE << 8) #endif -#if CONFIG_ESP32C6_USE_FIXED_STATIC_RAM_SIZE -ASSERT((CONFIG_ESP32C6_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.") -#define DRAM0_0_SEG_LEN CONFIG_ESP3C6_FIXED_STATIC_RAM_SIZE -#else #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE -#endif // CONFIG_ESP32C6_USE_FIXED_STATIC_RAM_SIZE + MEMORY { /** @@ -100,13 +96,6 @@ MEMORY } -#if CONFIG_ESP32C6_USE_FIXED_STATIC_RAM_SIZE -/* static data ends at defined address */ -_static_data_end = 0x40820000 + DRAM0_0_SEG_LEN; -#else -_static_data_end = _bss_end; -#endif // CONFIG_ESP32C6_USE_FIXED_STATIC_RAM_SIZE - /* Heap ends at top of dram0_0_seg */ _heap_end = 0x40000000; diff --git a/components/esp_system/ld/esp32h2/memory.ld.in b/components/esp_system/ld/esp32h2/memory.ld.in index be4ee545c8c..603cd9dab10 100644 --- a/components/esp_system/ld/esp32h2/memory.ld.in +++ b/components/esp_system/ld/esp32h2/memory.ld.in @@ -45,12 +45,8 @@ #define IDRAM0_2_SEG_SIZE (CONFIG_MMU_PAGE_SIZE << 8) #endif -#if CONFIG_ESP32H2_USE_FIXED_STATIC_RAM_SIZE -ASSERT((CONFIG_ESP32H2_FIXED_STATIC_RAM_SIZE <= I_D_SRAM_SIZE), "Fixed static ram data does not fit.") -#define DRAM0_0_SEG_LEN CONFIG_ESP32H2_FIXED_STATIC_RAM_SIZE -#else #define DRAM0_0_SEG_LEN I_D_SRAM_SIZE -#endif // CONFIG_ESP32H2_USE_FIXED_STATIC_RAM_SIZE + MEMORY { /** @@ -95,13 +91,6 @@ MEMORY } -#if CONFIG_ESP32H2_USE_FIXED_STATIC_RAM_SIZE -/* static data ends at defined address */ -_static_data_end = 0x40820000 + DRAM0_0_SEG_LEN; -#else -_static_data_end = _bss_end; -#endif // CONFIG_ESP32H2_USE_FIXED_STATIC_RAM_SIZE - /* Heap ends at top of dram0_0_seg */ _heap_end = 0x40000000; diff --git a/components/esp_system/ld/esp32h4/memory.ld.in b/components/esp_system/ld/esp32h4/memory.ld.in index 59507965d0d..cf209c67431 100644 --- a/components/esp_system/ld/esp32h4/memory.ld.in +++ b/components/esp_system/ld/esp32h4/memory.ld.in @@ -34,12 +34,8 @@ #define I_D_SRAM_SIZE SRAM_DRAM_END - SRAM_DRAM_ORG -#if CONFIG_ESP32H4_USE_FIXED_STATIC_RAM_SIZE -ASSERT((CONFIG_ESP32H4_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_ESP32H4_USE_FIXED_STATIC_RAM_SIZE + MEMORY { /** @@ -83,13 +79,6 @@ MEMORY rtc_iram_seg(RWX) : org = 0x50000000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC } -#if CONFIG_ESP32H4_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_ESP32H4_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 cdf1999022b..2836f0ea769 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 b8e461df427..4d0a89c7613 100644 --- a/components/esp_system/ld/esp32s2/sections.ld.in +++ b/components/esp_system/ld/esp32s2/sections.ld.in @@ -398,7 +398,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 @@ -424,5 +425,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 d14f1da4021..e4ead117da6 100644 --- a/components/esp_system/ld/esp32s3/sections.ld.in +++ b/components/esp_system/ld/esp32s3/sections.ld.in @@ -437,7 +437,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 @@ -463,5 +464,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