Memory Layout and Configuration Guide#
This document is based on the Kconfig, linker scripts, and board-level implementation in the SDK source code, and describes the memory layout, configuration entries, and tuning methods for the K230/K230D RT-Smart.
Overall Memory Model#
In the current SDK, DDR is mainly divided into two regions:
RT-Smart system region (kernel + user space page pool + dynamic heap)
MMZ region (media-related large block memory)
The core configuration items are located in Board Configuration under Memory Layout:
CONFIG_MEM_RTSMART_BASE: RT-Smart start base address (default0x0)CONFIG_RTSMART_OPENSIB_MEMORY_SIZE: OpenSBI reserved region size (default0x20000)CONFIG_MEM_RTSMART_SIZE: RT-Smart total memory sizeCONFIG_MEM_RTSMART_HEAP_SIZE: RT-Smart heap sizeCONFIG_MEM_MMZ_BASE: MMZ base addressCONFIG_MEM_MMZ_SIZE: MMZ sizeCONFIG_MEM_TOTAL_SIZE: DDR total size (configured in static mode)
Source code reference:
boards/Kconfigboards/Kconfig.memory_staticboards/Kconfig.memory_autosrc/rtsmart/rtsmart/kernel/bsp/maix3/board/board.csrc/rtsmart/rtsmart/kernel/bsp/maix3/board/board.hsrc/rtsmart/rtsmart/kernel/bsp/maix3/link.lds.in
Two Configuration Modes#
Static Configuration Mode#
When CONFIG_AUTO_DETECT_DDR_SIZE=n, a set of fixed values from Kconfig.memory_static is used:
MEM_TOTAL_SIZEMEM_RTSMART_SIZEMEM_RTSMART_HEAP_SIZEMEM_MMZ_BASEMEM_MMZ_SIZE
These values are directly used as compilation configuration for linking and runtime initialization.
Applicable scenarios:
Board DDR is fixed (e.g., SiP with fixed capacity)
Need precise control over the size of each region
Auto DDR Detection Mode#
When CONFIG_AUTO_DETECT_DDR_SIZE=y, the tier configurations in Kconfig.memory_auto are used:
512M tier:
*_5121024M tier:
*_10242048M tier:
*_2048
Runtime flow (see board.c):
Obtain DDR capacity via
k230_atag_get_ddr_size()If the retrieval fails, fall back to
0x20000000(512M)Select the corresponding tier’s RT-Smart size, heap size, MMZ base address, and MMZ size based on capacity
Note: In auto mode, board.h redirects the CONFIG_MEM_* macros to the return values of get_*() functions, implementing switching based on the actual DDR size.
Key Address Calculation Formulas#
The following formulas come from board.c and link.lds.in:
System start address
System available total region (aligned to KB and reserving 1KB)
RAM_END (reserve an additional 4KB at the end)
Heap region
RT_HW_HEAP_BEGIN = &__bss_endRT_HW_HEAP_END = RT_HW_HEAP_BEGIN + CONFIG_MEM_RTSMART_HEAP_SIZE
MMZ region
MEM_MMZ_BASE = CONFIG_MEM_MMZ_BASEMEM_MMZ_SIZE = CONFIG_MEM_MMZ_SIZE - 4096(seeboard.h)
Default Tiers (Auto Mode)#
From boards/Kconfig.memory_auto:
512M tier
MEM_RTSMART_SIZE_512 = 0x10000000(256MB)MEM_RTSMART_HEAP_SIZE_512 = 0x02000000(32MB)MEM_MMZ_BASE_512 = 0x10000000MEM_MMZ_SIZE_512 = 0x10000000(256MB)
1024M tier
MEM_RTSMART_SIZE_1024 = 0x20000000(512MB)MEM_RTSMART_HEAP_SIZE_1024 = 0x04000000(64MB)MEM_MMZ_BASE_1024 = 0x20000000MEM_MMZ_SIZE_1024 = 0x20000000(512MB)
2048M tier
MEM_RTSMART_SIZE_2048 = 0x20000000(512MB)MEM_RTSMART_HEAP_SIZE_2048 = 0x04000000(64MB)MEM_MMZ_BASE_2048 = 0x20000000MEM_MMZ_SIZE_2048 = 0x60000000(1536MB)
Typical Configuration Entry#
Execute in the SDK root directory:
make menuconfig
Path:
Board Configuration
-> Memory Layout
You can:
Enable/disable
Auto Detect DRAM SizeConfigure 512/1024/2048 tier parameters in auto mode
Directly configure
MEM_TOTAL_SIZE,MEM_RTSMART_SIZE,MEM_RTSMART_HEAP_SIZE,MEM_MMZ_BASE,MEM_MMZ_SIZEin static mode
Configuration Recommendations and Constraints#
It is recommended to follow these rules:
Total size constraint
MEM_RTSMART_SIZE + MEM_MMZ_SIZEshould not exceedMEM_TOTAL_SIZE
Contiguous layout constraint (recommended)
It is recommended to set
MEM_MMZ_BASE = MEM_RTSMART_SIZE(under the default layout whereMEM_RTSMART_BASE=0)
Heap size constraint
MEM_RTSMART_HEAP_SIZEmust be smaller than the actual available space in the system region (after deducting kernel image, BSS, and page management overhead)
Media workload priority scenarios
Increase
MEM_MMZ_SIZEAt the same time, confirm that the RT-Smart heap still meets application requirements
Application workload priority scenarios
Increase
MEM_RTSMART_HEAP_SIZEAvoid squeezing MMZ and causing media module allocation failures
Verification Steps After Changes#
Recompile the image:
time make log
Check whether the target items in
.configtake effect (e.g.,CONFIG_MEM_RTSMART_SIZE,CONFIG_MEM_MMZ_SIZE)Execute typical business scenarios (media, AI, network) on the board side and observe whether out-of-memory or allocation failures occur
K230D Example (Static Configuration)#
Visible in configs/k230d_rtos_evb_defconfig:
CONFIG_MEM_RTSMART_SIZE=0x4400000CONFIG_MEM_RTSMART_HEAP_SIZE=0x1000000CONFIG_MEM_MMZ_BASE=0x4400000CONFIG_MEM_MMZ_SIZE=0x3C00000
This is a typical “system region + MMZ region” contiguous partitioning scheme.
Frequently Asked Questions#
Why does the actual behavior not match expectations under auto DDR detection?#
First confirm:
CONFIG_AUTO_DETECT_DDR_SIZE=yWhether the corresponding tier option exists (512/1024/2048)
Whether the board side can correctly obtain the ATAG DDR size (otherwise it will fall back to the 512M tier)
After modifying the memory configuration, compilation passes but runtime crashes?#
Priority troubleshooting:
Whether
MEM_RTSMART_HEAP_SIZEis too large and encroaches on subsequent page spaceWhether
MEM_MMZ_BASE/MEM_MMZ_SIZEis out of bounds or overlaps with the system regionWhether the actual DDR capacity of the board matches the configuration
