/* * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "sdkconfig.h" /** * Simplified memory map for the bootloader. * Make sure the bootloader can load into main memory without overwriting itself. * * ESP32-P4 ROM static data usage is as follows: * - 0x4ff296b8 - 0x4ff3afc0: Shared buffers, used in UART/USB/SPI download mode only * - 0x4ff3afc0 - 0x4ff3fba4: CPU1 stack, can be reclaimed as heap after RTOS startup * - 0x4ff3fba4 - 0x4ff40000: ROM .bss and .data (not easily reclaimable) * * The 2nd stage bootloader can take space up to the end of ROM shared * buffers area (0x4087c610). */ /* We consider 0x4087c610 to be the last usable address for 2nd stage bootloader stack overhead, dram_seg, * and work out iram_seg and iram_loader_seg addresses from there, backwards. */ /* These lengths can be adjusted, if necessary: */ #if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 bootloader_usable_dram_end = 0x4ffbcfc0; #else bootloader_usable_dram_end = 0x4ff3abd0; #endif bootloader_stack_overhead = 0x2000; /* For safety margin between bootloader data section and startup stacks */ bootloader_dram_seg_len = 0x5000; bootloader_iram_loader_seg_len = 0x8000; bootloader_iram_seg_len = 0x2D00; /* Start of the lower region is determined by region size and the end of the higher region */ bootloader_dram_seg_end = bootloader_usable_dram_end - bootloader_stack_overhead; bootloader_dram_seg_start = bootloader_dram_seg_end - bootloader_dram_seg_len; bootloader_iram_loader_seg_start = bootloader_dram_seg_start - bootloader_iram_loader_seg_len; bootloader_iram_seg_start = bootloader_iram_loader_seg_start - bootloader_iram_seg_len; MEMORY { iram_seg (RWX) : org = bootloader_iram_seg_start, len = bootloader_iram_seg_len iram_loader_seg (RWX) : org = bootloader_iram_loader_seg_start, len = bootloader_iram_loader_seg_len dram_seg (RW) : org = bootloader_dram_seg_start, len = bootloader_dram_seg_len } /* The app may use RAM for static allocations up to the start of iram_loader_seg. * If you have changed something above and this assert fails: * 1. Check what the new value of bootloader_iram_loader_seg start is. * 2. Update the value in this assert. * 3. Update SRAM_DRAM_END in components/esp_system/ld/esp32p4/memory.ld.in to the same value. */ #if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 #define BOOTLOADER_IRAM_LOADER_SEG_START_EXPECTED 0x4FFADFC0 #else #define BOOTLOADER_IRAM_LOADER_SEG_START_EXPECTED 0x4FF2BBD0 #endif ASSERT(bootloader_iram_loader_seg_start == BOOTLOADER_IRAM_LOADER_SEG_START_EXPECTED, "bootloader_iram_loader_seg_start inconsistent with SRAM_DRAM_END"); /** * Appendix: Memory Usage of ROM bootloader * * Addresses are valid for chip revision (r): * r <= ECO4 / r > ECO4 * 0x4ff296b8 / 0x4ffa96b8 ------------------> _dram0_0_start * | | * | | * | | 1. Large buffers that are only used in certain boot modes, see shared_buffers.h * | | * | | * 0x4ff3afc0 / 0x4ffbafc0 ------------------> __stack_sentry * | | * | | 2. Startup pro cpu stack (freed when IDF app is running) * | | * 0x4ff3cfc0 / 0x4ffbcfc0 ------------------> __stack (pro cpu) * | | * | | Startup app cpu stack * | | * 0x4ff3efc0 / 0x4ffbefc0 ------------------> __stack_app (app cpu) * | | * | | * | | 3. Shared memory only used in startup code or nonos/early boot* * | | (can be freed when IDF runs) * | | * | | * 0x4ff3fba4 / 0x4ffbfbb0 ------------------> _dram0_rtos_reserved_start * | | * | | * | | 4. Shared memory used in startup code and when IDF runs * | | * | | * 0x4ff3ff94 / 0x4ffbffa4 ------------------> _dram0_rtos_reserved_end * | | * 0x4ff3ffc8 / 0x4ffbffc8 ------------------> _data_start_interface * | | * | | 5. End of DRAM is the 'interface' data with constant addresses (ECO compatible) * | | * 0x4ff40000 / 0x4ffc0000 ------------------> _data_end_interface */