Skip to content

Commit f2a0beb

Browse files
committed
Merge branch 'fix/esp32p4-memory-layout' into 'master'
fix(heap): Update the heap memory layout on esp32p4 target Closes IDF-8024, IDF-7921, and IDF-8002 See merge request espressif/esp-idf!26702
2 parents 8074fa4 + fd2b8b5 commit f2a0beb

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

components/bootloader/subproject/main/ld/esp32p4/bootloader.ld

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Make sure the bootloader can load into main memory without overwriting itself.
1010
*
1111
* ESP32-P4 ROM static data usage is as follows:
12-
* - 0x4086ad08 - 0x4087c610: Shared buffers, used in UART/USB/SPI download mode only
13-
* - 0x4087c610 - 0x4087e610: CPU1 stack, can be reclaimed as heap after RTOS startup
14-
* - 0x4087e610 - 0x40880000: ROM .bss and .data (not easily reclaimable)
12+
* - 0x4ff296b8 - 0x4ff3afc0: Shared buffers, used in UART/USB/SPI download mode only
13+
* - 0x4ff3afc0 - 0x4ff3fba4: CPU1 stack, can be reclaimed as heap after RTOS startup
14+
* - 0x4ff3fba4 - 0x4ff40000: ROM .bss and .data (not easily reclaimable)
1515
*
1616
* The 2nd stage bootloader can take space up to the end of ROM shared
1717
* buffers area (0x4087c610).
@@ -217,34 +217,38 @@ SECTIONS
217217
/**
218218
* Appendix: Memory Usage of ROM bootloader
219219
*
220-
* 0x4086ad08 ------------------> _dram0_0_start
220+
* 0x4ff296b8 ------------------> _dram0_0_start
221221
* | |
222222
* | |
223223
* | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h
224224
* | |
225225
* | |
226-
* 0x4087c610 ------------------> __stack_sentry
226+
* 0x4ff3afc0 ------------------> __stack_sentry
227227
* | |
228228
* | | 2. Startup pro cpu stack (freed when IDF app is running)
229229
* | |
230-
* 0x4087e610 ------------------> __stack (pro cpu)
230+
* 0x4ff3cfc0 ------------------> __stack (pro cpu)
231+
* | |
232+
* | | Startup app cpu stack
233+
* | |
234+
* 0x4ff3efc0 ------------------> __stack_app (app cpu)
231235
* | |
232236
* | |
233237
* | | 3. Shared memory only used in startup code or nonos/early boot*
234238
* | | (can be freed when IDF runs)
235239
* | |
236240
* | |
237-
* 0x4087f564 ------------------> _dram0_rtos_reserved_start
241+
* 0x4ff3fba4 ------------------> _dram0_rtos_reserved_start
238242
* | |
239243
* | |
240244
* | | 4. Shared memory used in startup code and when IDF runs
241245
* | |
242246
* | |
243-
* 0x4087fab0 ------------------> _dram0_rtos_reserved_end
247+
* 0x4ff3ff94 ------------------> _dram0_rtos_reserved_end
244248
* | |
245-
* 0x4087fce8 ------------------> _data_start_interface
249+
* 0x4ff3ffc8 ------------------> _data_start_interface
246250
* | |
247251
* | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible)
248252
* | |
249-
* 0x40880000 ------------------> _data_end_interface
253+
* 0x4ff40000 ------------------> _data_end_interface
250254
*/

components/heap/port/esp32p4/memory_layout.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,27 @@ const size_t soc_memory_type_count = sizeof(soc_memory_types) / sizeof(soc_memor
7171
/**
7272
* Register the shared buffer area of the last memory block into the heap during heap initialization
7373
*/
74-
#define APP_USABLE_DRAM_END (SOC_ROM_STACK_START - SOC_ROM_STACK_SIZE)
74+
#define APP_USABLE_DIRAM_END (SOC_ROM_STACK_START - SOC_ROM_STACK_SIZE) // 0x4ff3cfc0 - 0x2000 = 0x4ff3afc0
75+
#define STARTUP_DATA_SIZE (SOC_DRAM_HIGH - CONFIG_CACHE_L2_CACHE_SIZE - APP_USABLE_DIRAM_END) // 0x4ffc0000 - 0x20000/0x40000/0x80000 - 0x4ff3afc0 = 0x65040 / 0x45040 / 0x5040
7576

7677
const soc_memory_region_t soc_memory_regions[] = {
7778
#ifdef CONFIG_SPIRAM
78-
{ SOC_EXTRAM_LOW, SOC_EXTRAM_SIZE, SOC_MEMORY_TYPE_SPIRAM, 0, false}, //PSRAM, if available
79-
#endif
80-
// base 192k is always avaible, even if we config l2 cache size to 512k
81-
{ 0x4ff00000, 0x30000, SOC_MEMORY_TYPE_L2MEM, 0x4ff00000, false},
82-
// 64k for rom startup stack
83-
{ 0x4ff30000, 0x10000, SOC_MEMORY_TYPE_L2MEM, 0x4ff30000, true},
84-
#if CONFIG_ESP32P4_L2_CACHE_256KB // 768-256 = 512k avaible for l2 memory, add extra 256k
85-
{ 0x4ff40000, 0x40000, SOC_MEMORY_TYPE_L2MEM, 0x4ff40000, false},
86-
#endif
87-
#if CONFIG_ESP32P4_L2_CACHE_128KB // 768 - 128 = 640k avaible for l2 memory, add extra 384k
88-
{ 0x4ff40000, 0x60000, SOC_MEMORY_TYPE_L2MEM, 0x4ff40000, false},
79+
{ SOC_EXTRAM_LOW, SOC_EXTRAM_SIZE, SOC_MEMORY_TYPE_SPIRAM, 0, false}, //PSRAM, if available
8980
#endif
81+
{ SOC_DRAM_LOW, APP_USABLE_DIRAM_END - SOC_DRAM_LOW, SOC_MEMORY_TYPE_L2MEM, SOC_IRAM_LOW, false},
82+
{ APP_USABLE_DIRAM_END, STARTUP_DATA_SIZE, SOC_MEMORY_TYPE_L2MEM, APP_USABLE_DIRAM_END, true},
9083
#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
91-
{ 0x50108000, 0x8000, SOC_MEMORY_TYPE_RTCRAM, 0, false}, //LPRAM
84+
{ 0x50108000, 0x8000, SOC_MEMORY_TYPE_RTCRAM, 0, false}, //LPRAM
9285
#endif
93-
{ 0x30100000, 0x2000, SOC_MEMORY_TYPE_TCM, 0, false},
86+
{ 0x30100000, 0x2000, SOC_MEMORY_TYPE_TCM, 0, false},
9487
};
9588

9689
const size_t soc_memory_region_count = sizeof(soc_memory_regions) / sizeof(soc_memory_region_t);
9790

9891

9992
extern int _data_start, _heap_start, _iram_start, _iram_end, _rtc_force_slow_end;
10093
extern int _tcm_text_start, _tcm_data_end;
94+
extern int _rtc_reserved_start, _rtc_reserved_end;
10195

10296
/**
10397
* Reserved memory regions.
@@ -118,6 +112,7 @@ SOC_RESERVE_MEMORY_REGION( SOC_EXTRAM_LOW, SOC_EXTRAM_HIGH, extram_region);
118112
#endif
119113

120114
#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
121-
// TODO: IDF-6019 check reserved lp mem region
122115
SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_force_slow_end, rtcram_data);
123116
#endif
117+
118+
SOC_RESERVE_MEMORY_REGION((intptr_t)&_rtc_reserved_start, (intptr_t)&_rtc_reserved_end, rtc_reserved_data);

components/heap/port/memory_layout_utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ static void s_prepare_reserved_regions(soc_reserved_region_t *reserved, size_t c
7171
/* Get the ROM layout to find which part of DRAM is reserved */
7272
const ets_rom_layout_t *layout = ets_rom_layout_p;
7373
reserved[0].start = (intptr_t)layout->dram0_rtos_reserved_start;
74-
#if CONFIG_IDF_TARGET_ESP32P4
75-
//TODO: IDF-7921
74+
#ifdef SOC_DIRAM_ROM_RESERVE_HIGH
7675
reserved[0].end = SOC_DIRAM_ROM_RESERVE_HIGH;
7776
#else
7877
reserved[0].end = SOC_DIRAM_DRAM_HIGH;

components/soc/esp32p4/include/soc/soc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
#define SOC_DEBUG_HIGH 0x28000000
226226

227227
// Start (highest address) of ROM boot stack, only relevant during early boot
228-
#define SOC_ROM_STACK_START 0x4ff5abd0
228+
#define SOC_ROM_STACK_START 0x4ff3cfc0
229229
#define SOC_ROM_STACK_SIZE 0x2000
230230

231231
//On RISC-V CPUs, the interrupt sources are all external interrupts, whose type, source and priority are configured by SW.

0 commit comments

Comments
 (0)