This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f0df6591a840eba17adecfecbdb7668e54b05e2e Author: hujun5 <[email protected]> AuthorDate: Tue Mar 24 10:59:54 2026 +0800 arch/arm64/qemu: add TrustZone memory layout and shared memory MMU mapping Add TrustZone-aware memory configuration for the QEMU virt machine when booting through Trusted Firmware-A (TF-A). chip.h changes: - Define CONFIG_QEMU_DRAM_BASE (0x40000000) to replace the hardcoded RAMBANK1 address with a named constant. - Add CONFIG_SECURE_MEM_BASEADDR (0x0e000000) and CONFIG_SECURE_MEM_SIZE (16MB) for the secure SRAM region. - Add CONFIG_SHMEM_BASEADDR (0x45000000) and CONFIG_SHMEM_SIZE (1MB) for inter-world shared memory used by rptun/syslog. - When CONFIG_ARCH_TRUSTZONE_SECURE is set, map RAMBANK1 to the secure memory region and set CONFIG_LOAD_BASE to 0x0e100000 (above BL31). - When non-secure, keep existing behavior using CONFIG_QEMU_DRAM_BASE. qemu_boot.c changes: - Add SHMEM MMU region entry (MT_NORMAL | MT_RW | MT_NS) so that both AP and TEE cores can access the shared memory at 0x45000000 for rptun resource tables and syslog buffers. Signed-off-by: hujun5 <[email protected]> --- arch/arm64/include/qemu/chip.h | 34 +++++++++++++++++++++++++++++++--- arch/arm64/src/qemu/qemu_boot.c | 4 ++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/qemu/chip.h b/arch/arm64/include/qemu/chip.h index cb32bbcede9..727c8f6be41 100644 --- a/arch/arm64/include/qemu/chip.h +++ b/arch/arm64/include/qemu/chip.h @@ -58,6 +58,15 @@ #endif /* CONFIG_ARM64_GIC_VERSION */ +#define CONFIG_QEMU_DRAM_BASE 0x40000000 + +#define CONFIG_SECURE_MEM_BASEADDR 0x0e000000 +#define CONFIG_SECURE_MEM_SIZE MB(16) + +#ifdef CONFIG_ARCH_TRUSTZONE_SECURE +# define CONFIG_RAMBANK1_ADDR CONFIG_SECURE_MEM_BASEADDR +# define CONFIG_RAMBANK1_SIZE CONFIG_SECURE_MEM_SIZE +#else /* QEMU virt machine physical RAM always starts at 0x40000000. * RAMBANK1 must cover from physical RAM base through the end of * NuttX's configured RAM region (CONFIG_RAM_START + CONFIG_RAM_SIZE) @@ -72,9 +81,10 @@ * (CONFIG_RAM_START - 0x40000000 + CONFIG_RAM_SIZE) */ -#define CONFIG_RAMBANK1_ADDR 0x40000000 -#define CONFIG_RAMBANK1_SIZE (CONFIG_RAM_START - CONFIG_RAMBANK1_ADDR + \ +# define CONFIG_RAMBANK1_ADDR CONFIG_QEMU_DRAM_BASE +# define CONFIG_RAMBANK1_SIZE (CONFIG_RAM_START - CONFIG_RAMBANK1_ADDR + \ CONFIG_RAM_SIZE) +#endif #define CONFIG_DEVICEIO_BASEADDR 0x7000000 #define CONFIG_DEVICEIO_SIZE MB(512) @@ -88,9 +98,27 @@ #define CONFIG_PCI_IO_BASEADDR 0x3eff0000 #define CONFIG_PCI_IO_SIZE KB(64) +#define CONFIG_SHMEM_BASEADDR 0x45000000 +#define CONFIG_SHMEM_SIZE MB(1) + +#ifdef CONFIG_ARCH_TRUSTZONE_SECURE +/* When booting via TF-A (Trusted Firmware-A), BL2 and BL31 occupy the + * secure SRAM region starting at 0x0e000000: + * + * 0x0e000000 - 0x0e001000 : Shared RAM (mailbox) + * 0x0e05b000 - 0x0e090000 : BL2 (212KB) + * 0x0e090000 - 0x0e100000 : BL31 (448KB) + * + * BL31 remains resident at runtime, so NuttX must be placed above + * 0x0e100000 (secure DRAM) to avoid overwriting BL31 code and data. + */ + +# define CONFIG_LOAD_BASE (CONFIG_SECURE_MEM_BASEADDR + 0x100000) +#else /* Load base is 0x280000 (2.5MB) offset from CONFIG_RAM_START */ -#define CONFIG_LOAD_BASE (CONFIG_RAM_START + 0x280000) +# define CONFIG_LOAD_BASE (CONFIG_RAM_START + 0x280000) +#endif #define MPID_TO_CLUSTER_ID(mpid) ((mpid) & ~0xff) diff --git a/arch/arm64/src/qemu/qemu_boot.c b/arch/arm64/src/qemu/qemu_boot.c index 94c96cdddec..f96bb41eaea 100644 --- a/arch/arm64/src/qemu/qemu_boot.c +++ b/arch/arm64/src/qemu/qemu_boot.c @@ -77,6 +77,10 @@ static const struct arm_mmu_region g_mmu_regions[] = MMU_REGION_FLAT_ENTRY("PCI_IO", CONFIG_PCI_IO_BASEADDR, CONFIG_PCI_IO_SIZE, MT_NORMAL | MT_RW | MT_SECURE), + + MMU_REGION_FLAT_ENTRY("SHMEM", + CONFIG_SHMEM_BASEADDR, CONFIG_SHMEM_SIZE, + MT_NORMAL | MT_RW | MT_NS), }; const struct arm_mmu_config g_mmu_config =
