RAM Layout
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: For capacity, please refer to the datasheet.
Chipset integrates internal SRAM and expandable PSRAM with the following capacities:
Internal SRAM: 768KB
Expandable PSRAM: Refer to datasheet.
Chipset integrates internal SRAM and expandable PSRAM with the following capacities:
Internal SRAM: 512KB
Expandable PSRAM: Refer to datasheet.
Chipset integrates internal SRAM and expandable PSRAM with the following capacities:
Internal SRAM: 512KB
Expandable PSRAM: Refer to datasheet.
RAM & PSRAM Hybrid Layout
RAM layout (with PSRAM)
Item |
Start address |
Size (KB) |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
40 |
For ROM BSS, MSP, … |
√ |
KM4 Bootloader |
0x3000_A000 |
32 |
KM4 secure bootloader, including code and data |
√ |
KM4 BD RAM TZ |
0x2001_2000 |
64 |
KM4 IMG3 BD RAM, can be merged to KM4 BD RAM if not need |
x |
KM4 BD RAM |
0x2002_2000 |
280 |
KM4 BDRAM data, BSS and heap |
√ |
KM0 BD RAM |
0x2006_8000 |
96 |
KM0 BDRAM data, BSS and heap |
√ |
KM4 BD PSRAM TZ |
0x6000_0000 |
64 |
KM4 IMG3 PSRAM, can be merged to KM4 PSRAM if not need |
x |
KM4 BD PSRAM |
0x6001_0000 |
3220 |
KM4 BD PSRAM code and data |
√ |
KM0 BD PSRAM |
0x6032_5000 |
876 |
KM0 BD PSRAM code and data |
√ |
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 |
Note
When Trustzone is disabled, the KM4 BD RAM TZ
and KM4 BD PSRAM TZ
will be configured as Non-secure regions, and will be merged into KM4 BD RAM
and KM4 BD PSRAM
respectively.
RAM layout With PSRAM
Note
If Trustzone is not enabled, the KM4_BD_PSRAM_TZ
are non-secure and would be merged into KM4_BD_PSRAM
.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
40KB |
For ROM BSS, MSP … |
√ |
KM4 BOOTLOADER |
0x3000_A000 |
28KB |
For Bootloader |
√ |
KM4 BD RAM |
0x2001_1000 |
348KB |
KM4 BDRAM data, BSS and heap |
√ |
KR4 BD RAM |
0x2006_8000 |
96KB |
KR4 BDRAM data, BSS and heap |
√ |
KM4 BD PSRAM TZ |
0x6000_0000 |
64KB |
KM4 IMG3, can be merged into KM4 PSRAM if IMG3 is not needed |
x |
KM4 BD PSRAM |
0x6001_0000 |
1472KB |
KM4 code |
√ |
KR4 BD 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 Trustzone is not enabled, the KM4_BD_RAM_TZ
are non-secure and would be merged into KM4_BD_RAM
.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
40KB |
For ROM BSS, MSP … |
√ |
KM4 BOOTLOADER |
0x3000_A000 |
28KB |
For Bootloader |
√ |
KM4 BD RAM TZ |
0x2001_1000 |
64KB |
KM4 IMG3, can be used by users if IMG3 is not needed |
x |
KM4 BD RAM |
0x2002_0000 |
288KB |
KM4 BDRAM data, BSS and heap |
√ |
KR4 BD RAM |
0x2006_8000 |
96KB |
KR4 BDRAM data, BSS and heap |
√ |
Note
If Trustzone is not enabled, the KM4_BD_PSRAM_TZ
are non-secure and would be merged into KM4_BD_PSRAM
.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
40KB |
For ROM BSS, MSP and so on |
√ |
KM4 BOOTLOADER |
0x3000_A000 |
28KB |
For Bootloader |
√ |
KM4_BD_PSRAM_TZ |
0x6000_0000 |
64KB |
KM4 IMG3, can be merged into KM4 BD PSRAM if IMG3 is not needed |
x |
KM4 BD PSRAM |
0x6001_0000 |
1472KB |
KM4 code, data, BSS and heap |
√ |
KR4 BD PSRAM |
0x6018_0000 |
1536KB |
KR4 code, data, BSS and heap |
√ |
DSP BD 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 |
Note
If Trustzone is not enabled, the KM4_BD_PSRAM_TZ
are non-secure and would be merged into KM4_BD_PSRAM
.
Item |
Start address |
Size |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
40KB |
For ROM BSS, MSP and so on |
√ |
KM4 BOOTLOADER |
0x3000_A000 |
28KB |
For Bootloader |
√ |
KM4_BD_PSRAM_TZ |
0x6000_0000 |
64KB |
KM4 IMG3, can be merged into KM4 BD PSRAM if IMG3 is not needed |
x |
KM4 BD PSRAM |
0x6001_0000 |
1472KB |
KM4 code, data, BSS and heap |
√ |
KR4 BD PSRAM |
0x6018_0000 |
1536KB |
KR4 code, data, BSS and heap |
√ |
DSP BD 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 |
Item |
Sub-item |
Physical address |
Size |
Description |
Mandatory |
---|---|---|---|---|---|
KM4 DRAM |
KM4_IMG2_RAM_NS |
0x6000_0000 |
1388KB |
KM4 image2 SRAM, including code, data, BSS and heap |
√ |
KM4_BD_RAM_NSC |
0x6015_B000 |
4KB |
KM4 Non-secure Callable region |
x |
|
KM4_BD_RAM_ENTRY |
0x6015_C000 |
16KB |
KM4 Non-secure Callable function entry |
x |
|
KM4_BD_RAM_S |
0x7016_0000 |
128KB |
KM4 secure image, including secure code, data, BSS and heap |
x |
|
KM4_DRAM_HEAP_EXT |
0x6070_0000 |
1MB |
KM4 heap extend |
√ |
|
CA32 DARM |
BL1_RO |
0x6018_0000 |
128KB |
AP BL1 code and RO data |
√ |
BL1_RW |
0x601A_0000 |
64KB |
AP BL1 Stack and BSS |
√ |
|
SHARED_RAM |
0x601B_0000 |
64KB |
AP shared memory for multi-core |
√ |
|
BL2 |
0x601C_0000 |
256KB |
AP BL2 code, data, stack and BSS |
√ |
|
BL32 |
0x6020_0000 |
1MB |
AP BL32 code, data, stack and BSS For FreeRTOS SDK, BL32 is SP_MIN. |
√ |
|
BL33 |
0x6030_0000 |
4MB |
AP BL33 code, data, stack and BSS For FreeRTOS SDK, BL33 is image2 (application). |
√ |
|
KM4 SRAM |
KM4_BOOT_RAM_S |
0x3000_3000 |
68KB |
KM4 Secure bootloader, including data and code |
√ |
KM4_BD_RAM |
0x2001_4000 |
28KB |
KM4 MAIN SRAM, used when XIP only |
x |
|
ATF SHARE SRAM |
0x3001_F000 |
3.5KB |
used for atf share ram when XIP only |
x |
|
CA32_BL1 SRAM_S |
0x3001_FE00 |
512B |
CA32 BL1 SRAM |
√ |
|
RSVD for Audio |
0x2002_0000 |
128KB |
Reserved for Audio |
√ |
|
KM0 SRAM |
KM0_BD_RAM |
0x2300_2000 |
119.25KB |
KM0 image2 SRAM, including code, data, BSS and heap |
√ |
IPC_MEM |
0x2301_FD00 |
768B |
Buffer for IPC between CPUs |
√ |
Note
If Trustzone is not enabled, the KM4 BD RAM TZ
and KM4 BD PSRAM TZ
are non-secure and would be merged into KM4 BD RAM
and KM4 BD PSRAM
, respectively.
Item |
Start address |
Size (KB) |
Description |
Mandatory |
---|---|---|---|---|
SRAM FIXED |
0x2000_0000 |
20 |
For ROM BSS, MSP, … |
√ |
KM4TZ Bootloader |
0x3000_5000 |
32 |
KM4TZ secure bootloader, including code and data |
√ |
KM4TZ BD RAM TZ |
0x2000_D000 |
64 |
KM4TZ IMG3 BD RAM, can be merged to KM4TZ BD RAM if not need |
x |
KM4TZ BD RAM |
0x2001_D000 |
204 |
KM4TZ BDRAM data, BSS and heap |
√ |
KM4NS BD RAM |
0x2005_0000 |
192 |
KM4NS BDRAM data, BSS and heap |
√ |
KM4TZ BD PSRAM TZ |
0x6000_0000 |
148 |
KM4TZ IMG3 PSRAM, can be merged to KM4TZ PSRAM if not need |
x |
KM4TZ BD PSRAM |
0x6002_5000 |
3072 |
KM4TZ BD PSRAM code, data and heap |
√ |
KM4NS BD PSRAM |
0x6032_5000 |
876 |
KM4NS BD PSRAM code, data and heap |
√ |
KM4TZ HEAP EXT |
0x6FFF_FFFF |
0 |
If KM4TZ heap is not enough, it can be used to extend heap size |
x |
KM4NS HEAP EXT |
0x6FFF_FFFF |
0 |
If KM4NS heap is not enough, it can be used to extend heap size |
x |
Note
If Trustzone is not enabled, the KM4TZ BD RAM TZ
and KM4TZ BD PSRAM TZ
are non-secure and would be merged into KM4TZ BD RAM
and KM4TZ BD PSRAM
, respectively.
Kconfig Link Option
menuconfig provides configuration options for controlling code/data loading locations. Navigate to CONFIG Link Option
IMG1(Bootloader) running on FLASH or SRAM? (FLASH) --->
IMG2(Application) running on FLASH, SRAM, or PSRAM? (FLASH) --->
IMG2 Data and Heap in SRAM or PSRAM? (SRAM) --->
IMG3(SecureImage) running on PSRAM or SRAM? (PSRAM) --->
[*] ALL PSRAM USED FOR APPLICATION HEAP
Option descriptions:
IMG1(Bootloader) running on FLASH or SRAM?
:FLASH : Entire bootloader code runs from FLASH.
SRAM : Load full bootloader code into SRAM. Typically used for high-security scenarios with sufficient SRAM space.
IMG2(Application) running on FLASH, SRAM, or PSRAM?
:FLASH: Execute application code directly from FLASH (NOR FLASH only).
SRAM: Load application code into SRAM for specific scenarios.
PSRAM: Load application code into PSRAM for faster execution or higher security requirements.
IMG2 Data and Heap in SRAM or PSRAM?
:SRAM: Application data in SRAM, both SRAM and PSRAM remaining space are used for heap.
PSRAM: Application data in PSRAM, only PSRAM remaining space used for heap (SRAM typically reserved for DSP).
IMG3(SecureImage) running on PSRAM or SRAM?
:SRAM: TrustZone code runs from SRAM (higher security, more SRAM consumption).
PSRAM: TrustZone code runs from PSRAM.
ALL PSRAM USED FOR APPLICATION HEAP
: When PSRAM isn’t used for code/data, allocate all PSRAM space to application heap.
Note
Verify PSRAM integration (internal/external) before selecting PSRAM-related options.
Bootloader_RAM
The ameba_layout.ld
contains:
#if defined(CONFIG_IMG1_FLASH)
#define KM4_IMG1_SIZE KBYTES(4)
#else
#define KM4_IMG1_SIZE KBYTES(32)
#endif
KM4_BOOTLOADER_RAM_S (rwx) : ORIGIN = KM4_IMG1_RAM_SATRT + SECURE_ADDR_OFFSET + IMAGE_HEADER_LEN, LENGTH = KM4_IMG1_SIZE - IMAGE_HEADER_LEN
Configuration in menuconfig affects RAM allocation:
IMG1 –> FLASH:
KM4_BOOTLOADER_RAM_S
preset 4KBIMG1 –> SRAM:
KM4_BOOTLOADER_RAM_S
preset 32KB
Maintain 4KB alignment when modifying (MPC uses 4KB units).
In ameba_layout.ld
:
#if defined(CONFIG_IMG1_FLASH)
#define KM4_IMG1_SIZE KBYTES(4)
#else
#define KM4_IMG1_SIZE KBYTES(28)
#endif
KM4_BOOTLOADER_RAM_S (rwx) : ORIGIN = KM4_IMG1_RAM_SATRT + SECURE_ADDR_OFFSET + IMAGE_HEADER_LEN, LENGTH = KM4_IMG1_SIZE - IMAGE_HEADER_LEN
Configure via menuconfig CONFIG Link Option to adjust bootloader RAM space:
When selecting IMG1 → FLASH,
KM4_BOOTLOADER_RAM_S
preset to 4KBWhen selecting IMG1 → SRAM,
KM4_BOOTLOADER_RAM_S
preset to 28KB
To expand KM4_BOOT_RAM_S
, ensure adjusted size aligns with 4KB boundaries (MPC protection uses 4KB units).
In ameba_layout.ld
:
#if defined(CONFIG_IMG1_FLASH)
#define KM4_IMG1_SIZE KBYTES(4)
#else
#define KM4_IMG1_SIZE KBYTES(28)
#endif
KM4_BOOTLOADER_RAM_S (rwx) : ORIGIN = KM4_IMG1_RAM_SATRT + SECURE_ADDR_OFFSET + IMAGE_HEADER_LEN, LENGTH = KM4_IMG1_SIZE - IMAGE_HEADER_LEN
Configure via menuconfig CONFIG Link Option to adjust bootloader RAM space:
When selecting IMG1 → FLASH,
KM4_BOOTLOADER_RAM_S
preset to 4KBWhen selecting IMG1 → SRAM,
KM4_BOOTLOADER_RAM_S
preset to 28KB
To expand KM4_BOOT_RAM_S
, ensure adjusted size aligns with 4KB boundaries (MPC protection uses 4KB units).
In ameba_layout.ld
:
#if defined(CONFIG_IMG1_FLASH)
#define KM4_IMG1_SIZE KBYTES(4)
#else
#define KM4_IMG1_SIZE KBYTES(28)
#endif
KM4_BOOTLOADER_RAM_S (rwx) : ORIGIN = KM4_IMG1_RAM_SATRT + SECURE_ADDR_OFFSET + IMAGE_HEADER_LEN, LENGTH = KM4_IMG1_SIZE - IMAGE_HEADER_LEN
Configure via menuconfig CONFIG Link Option to adjust bootloader RAM space:
When selecting IMG1 → FLASH,
KM4_BOOTLOADER_RAM_S
preset to 4KBWhen selecting IMG1 → SRAM,
KM4_BOOTLOADER_RAM_S
preset to 28KB
To expand KM4_BOOT_RAM_S
, ensure adjusted size aligns with 4KB boundaries (MPC protection uses 4KB units).
The following in ameba_layout.ld
:
KM4_BOOTLOADER_RAM_S (rwx) : ORIGIN = 0x30003020, LENGTH = 0x30014000 - 0x30003020
In ameba_layout.ld
:
#if defined(CONFIG_IMG1_FLASH)
#define KM4TZ_IMG1_SIZE KBYTES(4)
#else
#define KM4TZ_IMG1_SIZE KBYTES(32)
#endif
KM4TZ_BOOTLOADER_RAM_S (rwx) : ORIGIN = KM4TZ_IMG1_RAM_SATRT + SECURE_ADDR_OFFSET + IMAGE_HEADER_LEN, LENGTH = KM4TZ_IMG1_SIZE - IMAGE_HEADER_LEN
Configure in menuconfig CONFIG Link Option to adjust bootloader RAM allocation:
When selecting IMG1 –> FLASH,
KM4TZ_BOOTLOADER_RAM_S
defaults to 4KBWhen selecting IMG1 –> SARM,
KM4TZ_BOOTLOADER_RAM_S
defaults to 32KB
To expand KM4TZ_BOOTLOADER_RAM_S
, ensure adjusted size is 4KB-aligned (MPC protection uses 4KB units).
BD_RAM and BD_PSRAM
BD_RAM
In ameba_layout.ld
:
#define RAM_KM4_IMG3_SIZE KBYTES(44)
#define RAM_KM0_IMG2_SIZE KBYTES(96)
#define KM4_IMG2_RAM_START (KM4_RAM_TZ_SECURE_START + RAM_KM4_IMG3_SIZE)
#define KM0_IMG2_RAM_START (SRAM_END - RAM_KM0_IMG2_SIZE)
KM4_BD_RAM (rwx) : ORIGIN = KM4_IMG2_RAM_START + IMAGE_HEADER_LEN, LENGTH = KM0_IMG2_RAM_START - KM4_IMG2_RAM_START - IMAGE_HEADER_LEN
KM0_BD_RAM (rwx) : ORIGIN = KM0_IMG2_RAM_START + IMAGE_HEADER_LEN, LENGTH = RAM_KM0_IMG2_SIZE - IMAGE_HEADER_LEN
Remaining SRAM space (after Fixed RAM and IMG1 allocation) is distributed to KM4_IMG3, KM0_IMG2, and KM4_IMG2.
RAM_KM4_IMG3_SIZE
defines KM4_IMG3’s SRAM size,RAM_KM0_IMG2_SIZE
defines KM0_IMG2’s size. Users can adjust these values.
BD_PSRAM
In ameba_layout.ld
:
#define PSRAM_BASE (0x60000000)
#define PSRAM_END (0x60400000)
#define PSRAM_KM4_IMG3_SIZE KBYTES(44)
#define PSRAM_KM4_IMG2_SIZE (KBYTES(3220) - (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 KM0_IMG2_PSRAM_START (KM4_IMG2_PSRAM_START + PSRAM_KM4_IMG2_SIZE)
#define PSRAM_KM0_IMG2_SIZE (PSRAM_END - KM0_IMG2_PSRAM_START)
KM4_BD_PSRAM (rwx) : ORIGIN = KM4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4_IMG2_SIZE - IMAGE_HEADER_LEN
KM0_BD_PSRAM (rwx) : ORIGIN = KM0_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM0_IMG2_SIZE - IMAGE_HEADER_LEN
PSRAM space allocation sequence: KM4_IMG3 -> KM4_IMG2 -> KM0_IMG2. Default size 4MB (
PSRAM_BASE
toPSRAM_END
). AdjustPSRAM_END
for actual PSRAM size.To reallocate space between
PSRAM_BASE
-PSRAM_END
: ModifyPSRAM_KM4_IMG3_SIZE
for KM4_IMG3,PSRAM_KM4_IMG2_SIZE
for KM4_IMG2. Remaining space goes to KM0_IMG2.Space after
PSRAM_END
(if exists) can be used as extended heapxxx_PSRAM_HEAP_EXT
(disabled by default).
BD_RAM
In ameba_layout.ld
:
#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
KM4_BD_RAM
andKR4_BD_RAM
allocate all remaining SRAM space (excluding IMG1 and Fixed RAM). ModifyRAM_KR4_IMG2_SIZE
orRAM_KM4_IMG2_SIZE
to adjust their allocation ratio.
BD_PSRAM
In ameba_layout.ld
:
#define PSRAM_BASE (0x60000000)
#define PSRAM_DSP_START (0x60300000)
#define PSRAM_KM4_IMG3_SIZE KBYTES(44)
#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)
KM4_BD_PSRAM (rwx) : ORIGIN = KM4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4_IMG2_SIZE - IMAGE_HEADER_LEN
KR4_BD_PSRAM (rwx) : ORIGIN = KR4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KR4_IMG2_SIZE - IMAGE_HEADER_LEN
PSRAM space between
PSRAM_BASE
toPSRAM_DSP_START
is allocated to KM4_IMG3, KM4_IMG2 and KR4_IMG2. Adjust viaPSRAM_KM4_IMG3_SIZE
(KM4_IMG3),PSRAM_KM4_IMG2_SIZE
(KM4_IMG2), remaining space goes to KR4_IMG2.Space after
PSRAM_DSP_START
can be: 1) Used as extended heap 2) Merged intoBD_PSRAM
by adjustingPSRAM_DSP_START
(keep within PSRAM physical range).
BD_PSRAM
Defined in ameba_layout.ld
:
#define PSRAM_BASE (0x60000000)
#define PSRAM_DSP_START (0x60300000)
#define PSRAM_END (0x60400000)
#define PSRAM_KM4_IMG3_SIZE KBYTES(44)
#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)
KM4_BD_PSRAM (rwx) : ORIGIN = KM4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4_IMG2_SIZE - IMAGE_HEADER_LEN
KR4_BD_PSRAM (rwx) : ORIGIN = KR4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KR4_IMG2_SIZE - IMAGE_HEADER_LEN
Space between
PSRAM_BASE
-PSRAM_DSP_START
: Allocated to KM4_IMG3/KM4_IMG2/KR4_IMG2 in order. Adjust viaPSRAM_KM4_IMG3_SIZE
(KM4_IMG3),PSRAM_KM4_IMG2_SIZE
(KM4_IMG2), remaining space auto-allocated to KR4_IMG2.PSRAM_DSP_START
-PSRAM_END
: For DSP (adjustPSRAM_END
per actual PSRAM size)Beyond
PSRAM_END
(if any): Available asxxx_PSRAM_HEAP_EXT
(disabled by default)
BD_PSRAM
Defined in ameba_layout.ld
:
#define PSRAM_BASE (0x60000000)
#define PSRAM_DSP_START (0x60300000)
#define PSRAM_END (0x60400000)
#define PSRAM_KM4_IMG3_SIZE KBYTES(44)
#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)
KM4_BD_PSRAM (rwx) : ORIGIN = KM4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4_IMG2_SIZE - IMAGE_HEADER_LEN
KR4_BD_PSRAM (rwx) : ORIGIN = KR4_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KR4_IMG2_SIZE - IMAGE_HEADER_LEN
Space between
PSRAM_BASE
-PSRAM_DSP_START
: Allocated to KM4_IMG3/KM4_IMG2/KR4_IMG2 in order. Adjust viaPSRAM_KM4_IMG3_SIZE
(KM4_IMG3),PSRAM_KM4_IMG2_SIZE
(KM4_IMG2), remaining space auto-allocated to KR4_IMG2.PSRAM_DSP_START
-PSRAM_END
: For DSP (adjustPSRAM_END
per actual PSRAM size)Beyond
PSRAM_END
(if any): Available asxxx_PSRAM_HEAP_EXT
(disabled by default)
BD_RAM
In ameba_layout.ld
:
KM4_BD_RAM (rwx) : ORIGIN = 0x20014020, LENGTH = 0x2001B000 - 0x20014020
KM0_BD_RAM (rwx) : ORIGIN = 0x23002020, LENGTH = 0x2301FD00 - 0x23002020
BD_PSRAM
In ameba_layout.ld
:
#if CONFIG_IMG2_FLASH
KM4_BD_DRAM (rwx) : ORIGIN = 0x60000020, LENGTH = 0x60060000 - 0x60000020
CA32_BL3_DRAM_NS (rwx) : ORIGIN = 0x60094000, LENGTH = PSRAM_END - 0x60094000
#else
KM4_BD_RAM_S (rwx) : ORIGIN = 0x70160020, LENGTH = 0x70180000 - 0x70160020
CA32_BL3_DRAM_NS (rwx) : ORIGIN = 0x60300000, LENGTH = 0x60700000 - 0x60300000
#endif
BD_RAM
Defined in ameba_layout.ld
:
#define RAM_KM4TZ_IMG3_SIZE KBYTES(44)
#define RAM_KM4NS_IMG2_SIZE KBYTES(192)
#define KM4TZ_IMG2_RAM_START (KM4TZ_RAM_TZ_SECURE_START + RAM_KM4TZ_IMG3_SIZE)
#define KM4NS_IMG2_RAM_START (SRAM_END - RAM_KM4NS_IMG2_SIZE)
KM4TZ_BD_RAM (rwx) : ORIGIN = KM4TZ_IMG2_RAM_START + IMAGE_HEADER_LEN, LENGTH = KM4NS_IMG2_RAM_START - KM4TZ_IMG2_RAM_START - IMAGE_HEADER_LEN
KM4NS_BD_RAM (rwx) : ORIGIN = KM4NS_IMG2_RAM_START + IMAGE_HEADER_LEN, LENGTH = RAM_KM4NS_IMG2_SIZE - IMAGE_HEADER_LEN
Remaining SRAM (after Fixed RAM and IMG1) allocated to KM4TZ_IMG3/KM4NS_IMG2/KM4TZ_IMG2. Adjust via
RAM_KM4TZ_IMG3_SIZE
(KM4_IMG3),RAM_KM4NS_IMG2_SIZE
(KM4NS_IMG2), remaining space → KM4TZ_IMG2
BD_PSRAM
Defined in ameba_layout.ld
:
#define PSRAM_BASE (0x60000000)
#define PSRAM_END (0x60400000)
#define PSRAM_KM4TZ_IMG3_SIZE KBYTES(128)
#define PSRAM_KM4TZ_IMG2_SIZE (KBYTES(3220) - (PSRAM_TZ_NSC_SIZE + PSRAM_TZ_ENTRY_SIZE + PSRAM_KM4TZ_IMG3_SIZE))
#define KM4TZ_IMG2_PSRAM_START (KM4TZ_PSRAM_TZ_SECURE_START + PSRAM_KM4TZ_IMG3_SIZE)
#define KM4NS_IMG2_PSRAM_START (KM4TZ_IMG2_PSRAM_START + PSRAM_KM4TZ_IMG2_SIZE)
#define PSRAM_KM4NS_IMG2_SIZE (PSRAM_END - KM4NS_IMG2_PSRAM_START)
KM4TZ_BD_PSRAM (rwx) : ORIGIN = KM4TZ_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4TZ_IMG2_SIZE - IMAGE_HEADER_LEN /* KM4TZ BD PSRAM : Tz off,3220K; TZ on, 3072K */
KM4NS_BD_PSRAM (rwx) : ORIGIN = KM4NS_IMG2_PSRAM_START + IMAGE_HEADER_LEN, LENGTH = PSRAM_KM4NS_IMG2_SIZE - IMAGE_HEADER_LEN
PSRAM allocation order: KM4TZ_IMG3 → KM4TZ_IMG2 → KM4NS_IMG2. Default 4MB range defined by
PSRAM_BASE
(fixed) andPSRAM_END
(adjustable)Adjust via
PSRAM_KM4TZ_IMG3_SIZE
(KM4TZ_IMG3),PSRAM_KM4TZ_IMG2_SIZE
(KM4TZ_IMG2), remaining space → KM4NS_IMG2Beyond
PSRAM_END
(if any): Available asxxx_PSRAM_HEAP_EXT
(disabled by default)
Heap Memory
Adjusting HEAP Size
Adjust BD_RAM/BD_PSRAM regions to modify heap size via remaining space after static loading (see BD_RAM and BD_PSRAM)
Define free PSRAM addresses to
xxx_PSRAM_HEAP_EXT
:Default invalid configuration:
xxx_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF /* PSRAM HEAP EXT */
Example configuration (e.g.,
0x60400000 ~ 0x60800000
):xxx_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x60400000, LENGTH = 0x60800000 - 0x60400000 /* PSRAM HEAP EXT */
Note
Check
__bdram_heap_buffer_size__
,__psram_heap_buffer_size__
, and__psram_heap_extend_size__
inxxx_gcc_project/project_xx/xsdk/image/target_img2.map
When ALL PSRAM USED FOR APPLICATION HEAP is selected, PSARM_BDRAM and PSRAM_HEAP_EXT become invalid
API Reference
MALLOC_TYPES
typedef enum {
TYPE_TCM = 0,
TYPE_SRAM,
TYPE_DRAM,
TYPE_ALL
} MALLOC_TYPES;
Memory types:
- TYPE_TCM:
Allocate from TCM/SRAM/DRAM (0x00000000+)
- TYPE_SRAM:
Allocate from SRAM/DRAM only (0x20000000+)
- TYPE_DRAM:
Allocate from DRAM only (0x60000000+)
- TYPE_ALL:
No restrictions (0x00000000+)
malloc
void *rtos_mem_malloc(uint32_t size);
Allocate memory from initialized heap regions (no type restriction).
Parameters:
- size:
Memory block size
Returns: Pointer to allocated memory
void *rtos_heap_types_malloc(uint32_t size, MALLOC_TYPES type);
Allocate memory from initialized heap regions (type-restricted).
Parameters:
- size:
Memory block size
- type:
Memory type
Returns: Pointer to allocated memory
zmalloc
void *rtos_mem_zmalloc(uint32_t size);
Allocate and zero-initialize memory (no type restriction).
Parameters:
- size:
Memory block size
Returns: Pointer to allocated memory
void *rtos_heap_types_zmalloc(uint32_t size, MALLOC_TYPES type);
Allocate and zero-initialize memory (type-restricted).
Parameters:
- size:
Memory block size
- type:
Memory type
Returns: Pointer to allocated memory
calloc
void *rtos_mem_calloc(uint32_t elementNum, uint32_t elementSize);
Allocate array with zero-initialization (no type restriction).
Parameters:
- elementNum:
Number of elements
- elementSize:
Element size
Returns: Pointer to allocated array
void *rtos_heap_types_calloc(uint32_t elementNum, uint32_t elementSize, MALLOC_TYPES type);
Allocate array with zero-initialization (type-restricted).
Parameters:
- elementNum:
Number of elements
- elementSize:
Element size
- type:
Memory type
Returns: Pointer to allocated array
realloc
void *rtos_mem_realloc(void *ptr, uint32_t new_size);
Resize memory block (no type restriction). New areas uninitialized.
Parameters:
- ptr:
Original memory pointer
- new_size:
New size
Returns: New pointer (NULL if failed, original memory remains)
void *rtos_heap_types_realloc(void *ptr, uint32_t new_size, MALLOC_TYPES type);
Resize memory block (type-restricted). New areas uninitialized.
Parameters:
- ptr:
Original memory pointer
- new_size:
New size
- type:
Memory type
Returns: New pointer (NULL if failed, original memory remains)
free
void rtos_mem_free(void *pbuf);
void rtos_heap_types_free(void *pbuf);
Release memory block.
Parameters:
- pbuf:
Pointer to memory block
Returns: None