This section explains how DDR Memory is divided and configured. Since all software components (boot loaders and Linux) needs to have the same settings, we will discuss all the software components in this section.
Description of Areas
Secure Area:
In order to use Trust Zone and OP-TEE in your system, the secure area must be hidden from Linux. This means early in boot in the ARM Trusted Firmware code (BL2), the memory sections are configure so that non-secure code (u-boot and kernel) cannot access them.
By default, the BSP allocates 128MB of space at the beginning of DDR Memory. That is why in the Device Tree settings for u-boot and kernel, the starting memory address is not the begging of physical DDR space because we are trying 'hide' this from Linux. In fact, even if the CPU tries to access this area, a hardware fault will occur.
CR7 and CM33 Area:
The DDR area for the the sub-cores should be mapped below the memory allocated for the Linux kernel.
The DDR location can be in Secure or non-Secure area.
The default non-secure physical DDR address for the CR7 is 0x40040000
The default non-secure physical DDR address for the CM33 is 0x40010000
H.264 Encode/Decode Area:
The H.264 video codec drivers require dedicated memory. This is allocated in the "mmp_reserved: linux, multimedia" area of the kernel Device Tree.
The size of this area depends on the resolution of the images being encoded and decoded.
LCD Frame Buffer area
The LCD Frame buffer require dedicated memory. This is allocated in the "linux,cma" area of the kernel Device Tree.
The size of this area depends on the resolution of LCD.
DDR Restricted Area (beginning of DDR)
The first 64 bytes of DDR Address space (0x40000000) are restricted from being used.
The reason is that the DDR3/DDR4 controller uses these address locations.
Please do not allocate or use the beginning of the DDR address area.
Please refer to the SoC Hardware Manuals for more details.
(1)Β Boot partition selected by [179] field (PARTITION CONFIG) of the EXT_CSD register. eMMC / SD sector size = 512bytes
(2)Β Boot parameters are not executed, just copied
(3)Β These addresses are fixed and cannot be configured
(4)Β Relocated at the end of the DDR
(5)Β For secure boot, actual BL2 code starts at 0x13000, at 0x12000 there's the key certificate and at 0x12400 the code certificate
Cortex-M33 Multi-OS default memory map
Item
Cortex-M33 address
Cortex-A55 address
Non-secure vector table
0x10000-0x107FF
0x10000-0x107FF
Secure vector table
0x1001FF80-0x1001FFFF
0x1FF80-1FFFF
Non-secure code
0x60010000-0x6010FFFF
0x40010000-0x4010FFFF
Secure code
0x72EFF440-0x72EFF7FF
0x42EFF440-0x42EFF7FF
Non-secure data
0x600110000-0x72EFF43F
0x40110000-0x42EFF43F
Secure data
0x72EFF800-0x72EFFFFF
0x42EFF800-0x42EFFFFF
OpenAMP resource table
0x62F00000-0x62F0FFF
0x42F00000-0x42F0FFF
OpenAMP vring
0x63000000-0x637FFFFF
0x43000000-0x437FFFFF
MHU shared memory
0x62F01000-0x62F01FFF
0x42F01000-0x42F01FFF
How to modify ARM Trusted Firmware
This section explains how to modify the code for ARM Trusted Firmware.
Trusted Firmware (BL31) and OP-TEE should reside in the Secure Area. The will allow HW protection from non-secure code such as Linux.
There is no setting forΒ Total DDR Memory sizeΒ in the ARM Trusted Firmware. You only configure the size of the secure area and start of unsecure area (not the size of unsecure area)
Configure the settings in fileΒ plat/renesas/rz/common/include/plat_tzc_def.h
Start Address and size of Trusted Firmware (BL31):
This section explains how to modify the code for u-boot.
U-boot uses a Device Tree file to configure the memory size. There is a 'memory' node that configures the start address and size of DDR memory to use.
For example:
memory@48000000 {
device_type = "memory";
/* first 128MB is reserved for secure area. */
reg = <0 0x48000000 0 0x78000000>;
};
β The 'memory' node in the Device Tree of u-boot is used for u-boot and isΒ also used for the kernel Device Tree. When u-boot boots the kernel, itΒ automatically overwritesΒ the value in the kernel's Device Tree. This means that what you put in the kernel memory node in the kernel Device Tree will have no effect.
There is also a defineΒ DRAM_RSV_SIZEΒ that needs to be modified. This will be in the config file for your board. Set it to the size of your secure area that will be hidden from u-boot and Linux.
For example, for the RZ/G2L SMARC board, that is fileΒ include/configs/smarc-rzg2l.h
#define DRAM_RSV_SIZE 0x08000000 /* 128MB by default */
How to modify kernel
This section explains how to modify the code for the Linux.
You should only need to modify theΒ Device TreeΒ files
β Note that modifyingΒ memory nodeΒ in the kernel device tree hasΒ no effect. The reason is that before boot, u-boot willΒ overwriteΒ the values in the kernel device tree. This means it is important that you set the device tree in u-boot to the setting you want the kernel to have. However, the other settings such as "linux,cma" and "linux,multimedia" are only set in the kernel device tree.
memory Node
Defines the total memory for the Linux System
Should match what you put in u-boot Device Tree
Has no effect (overwritten by u-boot before boot)
memory@48000000 {
device_type = "memory";
/* first 128MB is reserved for secure area. */
reg = <0x0 0x48000000 0x0 0x78000000>;
};
linux,cma Node
CMA stands for "Contiguous Memory Allocator".
Allows allocation of big, physically-contiguous memory blocks used for things like DMA transfers, GPU buffers or LCD Frame Buffer.
CMA works by reserving a large memory area at boot time and immediately giving back the memory to the kernel memory subsystem with the constraint that memory can only be handed out either for CMA use or for movable pages. Basically this means this area can be used for small memory blocks (movable pages, like what the MMU uses for user application space), but if a big CMA request comes along, those small blocks get moved to prevent fragmentation so large contiguous blocks can be handed out.
Depending on the size (resolution) of your LCD, or how much GPU graphics work you are doing, you may need increase this size (or decrease if not using).
Since this is a general area used by all kernel drivers, if you are transferring a lot of data over a network (Ethernet) or USB, you might need to increase this area to have enough buffer area.