RAM Layout Configuration Guide
Introduction
This chapter describes the default memory layout and provides guidance for customization.
RAM Memory Layout
Chipset integrates internal SRAM and expandable PSRAM with the following capacities:
Internal SRAM: 512KB
Expandable PSRAM: Available in various models with capacities including 0MB, 4MB, 8MB, and 16MB.
SRAM0 Layout (First 40KB)
The first 40KB of SRAM is reserved for storing ROM variables, BOOT code, and security processing functions, and this portion of memory is not accessible to users.
Items |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
KM0_ROM_BSS_RAM |
0x2000_0000 |
4KB |
KM0 ROM BSS |
√ |
KM0_MSP_RAM |
0x2000_1000 |
4KB |
KM0 Main Stack Pointer |
√ |
KM0_STDLIB_HEAP_NS |
0x2000_2000 |
4KB |
KM0 ROM STDLIB heap |
√ |
KM4_MSP_NS |
0x2000_3000 |
4KB |
KM4 non-secure Main Stack Pointer |
√ |
KM4_ROM_BSS_COMMON |
0x2000_4000 |
3.25KB |
KM4 ROM secure and non-secure common BSS |
√ |
KM0_BOOT_RAM |
0x2000_4D00 |
64B |
KM0 IMG2 entry |
√ |
KM0_IPC_RAM |
0x2000_4E00 |
512B |
Exchange messages between cores |
√ |
KM4_ROM_BSS_NS |
0x2000_5000 |
4KB |
KM4 ROM non-secure common BSS |
√ |
KM4_STDLIB_HEAP_NS |
0x2000_6000 |
4KB |
KM4 ROM non-secure STDLIB heap |
√ |
KM4_ROM_BSS_S |
0x3000_7000 |
4KB |
KM4 ROM secure-only BSS |
√ |
KM0_RTOS_STATIC_0_NS |
0x2000_8000 |
4KB |
KM0 RTOS static pool position |
√ |
KM4_MSP_S |
0x3000_9000 |
4KB |
KM4 secure Main Stack Pointer |
√ |
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
KR4_ROM_BSS_RAM |
0x2000_0000 |
4KB |
KR4 ROM BSS |
√ |
KR4_MSP_RAM |
0x2000_1000 |
4KB |
KR4 Main Stack Pointer |
√ |
KR4_STDLIB_HEAP_NS |
0x2000_2000 |
4KB |
KR4 ROM STDLIB heap |
√ |
KM4_MSP_NS |
0x2000_3000 |
4KB |
KM4 non-secure Main Stack Pointer |
√ |
KM4_ROM_BSS_COMMON |
0x2000_4000 |
2.25KB |
KM4 ROM secure and non-secure common BSS |
√ |
KR4_IPC_RAM |
0x2000_4900 |
768B |
Exchange messages between cores |
√ |
KR4_BOOT_ENTRY_BACKUP |
0x2000_4C00 |
64B |
Backup KR4 IMG2 entry when SRAM1 is not used by KR4 |
√ |
KM4_ROM_BSS_NS |
0x2000_5000 |
1.25KB |
KM4 ROM non-secure common BSS |
√ |
KR4_RAM_ONLY |
0x2000_4C20 |
1KB |
Used by power save flow when KR4 is NP |
√ |
KM4_RAM_ONLY |
0x2000_4E00 |
1KB |
Used by power save flow when KM4 is NP |
√ |
KM4_TIMER_IDLE_TASK_STACK |
0x2000_6000 |
4KB |
KM4 TIMER and IDLE task stack |
√ |
KM4_ROM_BSS_S |
0x3000_7000 |
4KB |
KM4 ROM secure-only BSS |
√ |
KM4_MSP_S |
0x3000_8000 |
8KB |
KM4 secure Main Stack Pointer |
√ |
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
KR4_ROM_BSS_RAM |
0x2000_0000 |
4KB |
KR4 ROM BSS |
√ |
KR4_MSP_RAM |
0x2000_1000 |
4KB |
KR4 Main Stack Pointer |
√ |
KR4_STDLIB_HEAP_NS |
0x2000_2000 |
4KB |
KR4 ROM STDLIB heap |
√ |
KM4_MSP_NS |
0x2000_3000 |
4KB |
KM4 non-secure Main Stack Pointer |
√ |
KM4_ROM_BSS_COMMON |
0x2000_4000 |
2.25KB |
KM4 ROM secure and non-secure common BSS |
√ |
KR4_IPC_RAM |
0x2000_4900 |
768B |
Exchange messages between cores |
√ |
KR4_BOOT_ENTRY_BACKUP |
0x2000_4C00 |
64B |
Backup KR4 IMG2 entry when SRAM1 is not used by KR4 |
√ |
KM4_ROM_BSS_NS |
0x2000_5000 |
1.25KB |
KM4 ROM non-secure common BSS |
√ |
KR4_RAM_ONLY |
0x2000_4C20 |
1KB |
Used by power save flow when KR4 is NP |
√ |
KM4_RAM_ONLY |
0x2000_4E00 |
1KB |
Used by power save flow when KM4 is NP |
√ |
KM4_TIMER_IDLE_TASK_STACK |
0x2000_6000 |
4KB |
KM4 TIMER and IDLE task stack |
√ |
KM4_ROM_BSS_S |
0x3000_7000 |
4KB |
KM4 ROM secure-only BSS |
√ |
KM4_MSP_S |
0x3000_8000 |
8KB |
KM4 secure Main Stack Pointer |
√ |
RAM & PSRAM Hybrid Layout
RAM layout With PSRAM
RAM layout (with PSRAM)
Item |
Start address |
Size (KB) |
Description |
Mandatory |
---|---|---|---|---|
SRAM0 |
0x2000_0000 |
40 |
For ROM BSS, MSP, … |
√ |
KM4 Bootloader |
0x3000_A000 |
24 |
KM4 secure bootloader, including code and data |
√ |
KM4 BD RAM |
0x2001_0000 |
352 |
KM4 BDRAM data, BSS and heap |
√ |
KM0 BD RAM |
0x2004_0000 |
96 |
KM0 BDRAM data, BSS and heap |
√ |
KM4 PSRAM |
0x6000_0000 |
3220 |
KM4 PSRAM code, can be empty |
√ |
KM0 PSRAM |
0x6032_5000 |
876 |
KM0 PSRAM code, can be empty |
√ |
KM4 HEAP EXT |
0x6FFF_FFFF |
0 |
If KM4 heap is not enough, it can be used to extend the heap size |
x |
KM0 HEAP EXT |
0x6FFF_FFFF |
0 |
If KM0 heap is not enough, it can be used to extend the heap size |
x |
RAM layout With PSRAM
Note
If RDP is not enabled, the KM4_BD_PSRAM_NSC/KM4_BD_PSRAM_ENTRY/KM4_BD_PSRAM_S are non-secure and would be merged into KM4_BD_PSRAM.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM0 |
0x2000_0000 |
40KB |
For ROM BSS, MSP and so on |
√ |
KM4 BOOTLOADER |
0x2000_A000 |
24KB |
For Bootloader |
√ |
KM4 IMG3 |
0x6000_0000 |
64KB |
KM4 IMG3, can be merged into KM4 PSRAM if IMG3 is not needed |
√ |
KM4 PSRAM |
0x6001_0000 |
1472KB |
KM4 code, data, BSS and heap |
√ |
KR4 PSRAM |
0x6018_0000 |
1536KB |
KR4 code, data, BSS and heap |
√ |
DSP PSRAM |
0x6030_0000 |
5120KB |
DSP PSRAM |
√ |
KM4 HEAP EXT |
0x6FFF_FFFF |
0 |
If KM4 Heap is not enough, it can be used to extend the heap size |
x |
KR4 HEAP EXT |
0x6FFF_FFFF |
0 |
If KR4 Heap is not enough, it can be used to extend the heap size |
x |
RAM layout With PSRAM
Note
If RDP is not enabled, the KM4_BD_PSRAM_NSC/KM4_BD_PSRAM_ENTRY/KM4_BD_PSRAM_S are non-secure and would be merged into KM4_BD_PSRAM.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM0 |
0x2000_0000 |
40KB |
For ROM BSS, MSP … |
√ |
KM4 BOOTLOADER |
0x2000_A000 |
24KB |
For Bootloader |
√ |
KM4 BD RAM |
0x2001_0000 |
352KB |
KM4 BDRAM data, BSS and heap |
√ |
KR4 BD RAM |
0x2006_8000 |
96KB |
KR4 BDRAM data, BSS and heap |
√ |
KM4 IMG3 |
0x6000_0000 |
64KB |
KM4 IMG3, can be merged into KM4 PSRAM if IMG3 is not needed |
√ |
KM4 PSRAM |
0x6001_0000 |
1472KB |
KM4 code |
√ |
KR4 PSRAM |
0x6018_0000 |
1536KB |
KR4 code |
√ |
KM4 HEAP EXT |
0x6FFF_FFFF |
0 |
If KM4 Heap is not enough, it can be used to extend the heap size |
x |
KR4 HEAP EXT |
0x6FFF_FFFF |
0 |
If KR4 Heap is not enough, it can be used to extend the heap size |
x |
RAM layout Without PSRAM
Note
If RDP is not enabled, the KM4_BD_RAM_NSC/KM4_BD_RAM_ENTRY/KM4_BD_RAM_S are non-secure and would be merged into KM4_BD_PSRAM.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM0 |
0x2000_0000 |
40KB |
For ROM BSS, MSP … |
√ |
KM4 BOOTLOADER |
0x2000_A000 |
24KB |
For Bootloader |
√ |
KM4 IMG3 |
0x2001_0000 |
64KB |
KM4 IMG3, can be used by users if IMG3 is not needed |
√ |
KM4 BD RAM |
0x2002_0000 |
288KB |
KM4 BDRAM data, BSS and heap |
√ |
KR4 BD RAM |
0x2006_8000 |
96KB |
KR4 BDRAM data, BSS and heap |
√ |
Bootloader Size Configuration
Bootloader Size Adjustment
When enlarging KM4_BOOT_RAM_S, ensure modified size is 4KB-aligned (MPC protection works in 4KB units).
Steps to modify bootloader size:
Configure CONFIG Link Option in menuconfig:
SRAM selection sets KM4_BOOTLOADER_RAM_S to 24KB
Flash selection sets KM4_BOOTLOADER_RAM_S to 4KB
Modify linker script parameter (path:
{SDK}\amebaxxx_gcc_project\amebaxxx_layout.ld
):Adjust KM4_IMG1_SIZE to change KM4_BOOTLOADER_RAM_S size
Rebuild project to generate new bootloader
If bootloader exceeds size limit:
Update end address in
km4_boot_all.bin
Flash updated bootloader
Note
New bootloader version must be higher than current version for boot ROM loading
Bootloader Size Adjustment
When enlarging KM4_BOOT_RAM_S, ensure modified size is 4KB-aligned (MPC protection works in 4KB units).
Steps to modify bootloader size:
Configure CONFIG Link Option in menuconfig:
SRAM selection sets KM4_BOOTLOADER_RAM_S to 24KB
Flash selection sets KM4_BOOTLOADER_RAM_S to 4KB
Modify linker script parameter (path:
{SDK}\amebaxxx_gcc_project\amebaxxx_layout.ld
):Adjust KM4_IMG1_SIZE to change KM4_BOOTLOADER_RAM_S size
Rebuild project to generate new bootloader
If bootloader exceeds size limit:
Update end address in
km4_boot_all.bin
Flash updated bootloader
Note
New bootloader version must be higher than current version for boot ROM loading
Bootloader Size Adjustment
When enlarging KM4_BOOT_RAM_S, ensure modified size is 4KB-aligned (MPC protection works in 4KB units).
Steps to modify bootloader size:
Configure CONFIG Link Option in menuconfig:
SRAM selection sets KM4_BOOTLOADER_RAM_S to 24KB
Flash selection sets KM4_BOOTLOADER_RAM_S to 4KB
Modify linker script parameter (path:
{SDK}\amebaxxx_gcc_project\amebaxxx_layout.ld
):Adjust KM4_IMG1_SIZE to change KM4_BOOTLOADER_RAM_S size
Rebuild project to generate new bootloader
If bootloader exceeds size limit:
Update end address in
km4_boot_all.bin
Flash updated bootloader
Note
New bootloader version must be higher than current version for boot ROM loading
BD_RAM/BD_PSRAM Capacity Adjustment
BD_RAM Configuration
Steps to modify KM4 BD_RAM size:
Adjust KM4_BD_RAM end address by modifying RAM_KM0_IMG2_SIZE in:
{SDK}\amebadplus_gcc_project\amebaDplus_layout.ld
Rebuild and flash Bootloader with IMG2 OTA2 following APP OTA1 section
BD_PSRAM Configuration
To modify KM4 BD_PSRAM size:
BD_RAM Configuration
Steps to modify KM4 BD_RAM size:
Configure IMG2 execution position in menuconfig (select any SRAM-related option):
Modify linker script parameters (path:
{SDK}\amebalite_gcc_project\amebalite_layout.ld
):Adjust
RAM_KM4_IMG2_SIZE
orRAM_KR4_IMG2_SIZE
Update KM4_BD_RAM end address
/* IMG2 Size*/ #if defined(CONFIG_AP_CORE_KM4) #define RAM_KR4_IMG2_SIZE KBYTES(96) #define KM4_IMG2_RAM_START (KM4_RAM_TZ_SECURE_START + RAM_KM4_IMG3_SIZE) #define KR4_IMG2_RAM_START (SRAM_END - RAM_KR4_IMG2_SIZE) #define RAM_KM4_IMG2_SIZE (KR4_IMG2_RAM_START - KM4_IMG2_RAM_START) #else #define RAM_KM4_IMG2_SIZE KBYTES(96) #define KM4_IMG2_RAM_START (KM4_RAM_TZ_SECURE_START + RAM_KM4_IMG3_SIZE) #define KR4_IMG2_RAM_START (KM4_IMG2_RAM_START + RAM_KM4_IMG2_SIZE) #define RAM_KR4_IMG2_SIZE (SRAM_END - KR4_IMG2_RAM_START) #endif
Rebuild and flash Bootloader with IMG2 OTA2 following APP OTA1 section
BD_PSRAM Configuration
Steps to modify KM4 BD_PSRAM size:
Configure IMG2 execution position in menuconfig (select any PSRAM-related option)
Modify linker script parameters (path:
{SDK}\amebalite_gcc_project\amebalite_layout.ld
):Adjust PSRAM_KM4_IMG2_SIZE
Update KM4_BD_PSRAM end address
#define PSRAM_KM4_IMG2_SIZE (KBYTES(1536) - (PSRAM_TZ_NSC_SIZE + PSRAM_TZ_ENTRY_SIZE + PSRAM_KM4_IMG3_SIZE)) #define KM4_IMG2_PSRAM_START (KM4_PSRAM_TZ_SECURE_START + PSRAM_KM4_IMG3_SIZE) #define KR4_IMG2_PSRAM_START (KM4_IMG2_PSRAM_START + PSRAM_KM4_IMG2_SIZE) #define PSRAM_KR4_IMG2_SIZE (PSRAM_DSP_START - KR4_IMG2_PSRAM_START)
BD_RAM Configuration
Steps to modify KM4 BD_RAM size:
Configure IMG2 execution position in menuconfig (select any SRAM-related option):
Modify linker script parameters (path:
{SDK}\amebalite_gcc_project\amebalite_layout.ld
):Adjust
RAM_KM4_IMG2_SIZE
orRAM_KR4_IMG2_SIZE
Update KM4_BD_RAM end address
/* IMG2 Size*/ #if defined(CONFIG_AP_CORE_KM4) #define RAM_KR4_IMG2_SIZE KBYTES(96) #define KM4_IMG2_RAM_START (KM4_RAM_TZ_SECURE_START + RAM_KM4_IMG3_SIZE) #define KR4_IMG2_RAM_START (SRAM_END - RAM_KR4_IMG2_SIZE) #define RAM_KM4_IMG2_SIZE (KR4_IMG2_RAM_START - KM4_IMG2_RAM_START) #else #define RAM_KM4_IMG2_SIZE KBYTES(96) #define KM4_IMG2_RAM_START (KM4_RAM_TZ_SECURE_START + RAM_KM4_IMG3_SIZE) #define KR4_IMG2_RAM_START (KM4_IMG2_RAM_START + RAM_KM4_IMG2_SIZE) #define RAM_KR4_IMG2_SIZE (SRAM_END - KR4_IMG2_RAM_START) #endif
Rebuild and flash Bootloader with IMG2 OTA2 following APP OTA1 section
BD_PSRAM Configuration
Steps to modify KM4 BD_PSRAM size:
Configure IMG2 execution position in menuconfig (select any PSRAM-related option)
Modify linker script parameters (path:
{SDK}\amebalite_gcc_project\amebalite_layout.ld
):Adjust PSRAM_KM4_IMG2_SIZE
Update KM4_BD_PSRAM end address
#define PSRAM_KM4_IMG2_SIZE (KBYTES(1536) - (PSRAM_TZ_NSC_SIZE + PSRAM_TZ_ENTRY_SIZE + PSRAM_KM4_IMG3_SIZE)) #define KM4_IMG2_PSRAM_START (KM4_PSRAM_TZ_SECURE_START + PSRAM_KM4_IMG3_SIZE) #define KR4_IMG2_PSRAM_START (KM4_IMG2_PSRAM_START + PSRAM_KM4_IMG2_SIZE) #define PSRAM_KR4_IMG2_SIZE (PSRAM_DSP_START - KR4_IMG2_PSRAM_START)
Heap Memory Configuration
System heap consists of multiple blocks initialized by os_heap_init()
in component\os\freertos\freertos_heap5_config.c
.
Initial PSRAM Heap Definition
PSRAM_HEAP1_START is invalid address
PSRAM_HEAP1_SIZE set to 0
KM4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KM4 PSRAM Extended Heap */
KM0_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KM0 PSRAM Extended Heap */
KM4 Heap Extension
For insufficient KM4 heap:
Define unused PSRAM regions in linker script
amebaDplus_layout.ld
:Set valid Heap Start address
Configure Heap Size value
Add heap blocks via system API:
bool os_heap_add(u8 *start_addr, size_t heap_size);
Rebuild and flash image to activate configuration
Note
Symbols defined in linker script (amebaDplus_layout.ld
) must be declared in ameba_boot.h
before usage
KM0 Heap Extension
For insufficient KM0 heap, modify KM0_PSRAM_HEAP_EXT
parameter
Initial PSRAM Heap Definition
PSRAM_HEAP1_START is invalid address
PSRAM_HEAP1_SIZE set to 0
KM4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KM4 PSRAM Extended Heap */
KR4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KR4 PSRAM Extended Heap */
KM4 Heap Extension Procedure
When KM4 heap is insufficient:
Define unused PSRAM regions in linker script
amebalite_layout.ld
:Set valid Heap Start address
Configure Heap Size value
Add heap blocks via system API:
bool os_heap_add(u8 *start_addr, size_t heap_size);
Note
Address must point to valid PSRAM space
Rebuild project and flash new image to activate extended heap
General Notes
Note
Symbols defined in linker script (
amebalite_layout.ld
) must be declared inameba_boot.h
KR4 heap extension follows the same procedure
Initial PSRAM Heap Definition
PSRAM_HEAP1_START is invalid address
PSRAM_HEAP1_SIZE set to 0
KM4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KM4 PSRAM Extended Heap */
KR4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* KR4 PSRAM Extended Heap */
KM4 Heap Extension Procedure
When KM4 heap is insufficient:
Define unused PSRAM regions in linker script
amebalite_layout.ld
:Set valid Heap Start address
Configure Heap Size value
Add heap blocks via system API:
bool os_heap_add(u8 *start_addr, size_t heap_size);
Note
Address must point to valid PSRAM space
Rebuild project and flash new image to activate extended heap
General Notes
Note
Symbols defined in linker script (
amebalite_layout.ld
) must be declared inameba_boot.h
KR4 heap extension follows the same procedure