hujun260 opened a new pull request, #21661:
URL: https://github.com/apache/nuttx/pull/21661
# NuttX PR Description
## Title
arch/arm64/qemu: add TrustZone memory layout and shared memory mapping
## Description
This PR updates the ARM64 QEMU board support to use configurable memory
addresses and to support TrustZone-aware memory layout when booting through
Trusted Firmware-A (TF-A). It also adds a non-secure shared-memory MMU
mapping
for communication between the AP and TEE worlds.
## Changes
1. **arch/arm64/src/qemu: Make fixed addresses configurable**
- Replace hardcoded QEMU RAM addresses with `CONFIG_RAM_START`-based
values.
- Allow the kernel load address to be changed from `0x40280000` to
`0x42280000` for the arcn-hypervisor configuration.
- Keep the existing QEMU ARMv8A board configuration reusable without
adding
a separate board implementation.
- Update `dramboot.ld` and `ld-kernel.script` to use the configurable RAM
start address.
2. **arch/arm64/qemu: Add TrustZone memory layout and shared-memory mapping**
- Define `CONFIG_QEMU_DRAM_BASE` as the default QEMU DRAM base address.
- Add a secure memory region at `0x0e000000` with a size of 16 MiB.
- Add a 1 MiB inter-world shared-memory region at `0x45000000`.
- When `CONFIG_ARCH_TRUSTZONE_SECURE` is enabled, map RAMBANK1 to the
secure memory region and load the secure-world image at `0x0e100000`,
above BL31.
- Preserve the existing non-secure memory layout based on
`CONFIG_QEMU_DRAM_BASE`.
- Add the shared-memory region to the QEMU MMU page table with
`MT_NORMAL | MT_RW | MT_NS` attributes.
- Make the shared memory available to both AP and TEE worlds for
RPMsg/RP-TUN
resource tables and syslog buffers.
## Motivation
Provide a reusable QEMU ARM64 memory layout for normal-world, secure-world,
and
hypervisor configurations. The shared-memory mapping enables communication
and
logging between the AP and TEE worlds while keeping the secure-world load
region
above the TF-A BL31 image.
## Runtime Testing
The Vela QEMU ARM64 TrustZone environment was started with the
`qemu-arm64-v8a-ap` configuration using four Cortex-A53 CPUs, 1057 MiB of
RAM,
a 4 MiB ivshmem device, and a GDB server on TCP port `7775`.
### TF-A and world initialization
```text
NOTICE: Booting Trusted Firmware
NOTICE: BL1: v2.14.0(debug):fb1381d84
INFO: BL2: Loading image id 4
INFO: Handoff to BL32
NOTICE: BL1: Booting BL31
INFO: NUTTXSPD: BL32 ep=0xe100000
INFO: NUTTXSPD: BL32 CPU0 entry done
INFO: NUTTXSPD: BL32 CPU1 entry done
INFO: NUTTXSPD: BL32 CPU2 entry done
INFO: NUTTXSPD: BL32 CPU3 entry done
INFO: Entry point address = 0x40280000
```
### Shared-memory and AP initialization
```text
0.382308 8 I 0 ap pci_sdhci_probe: SDHCI controller at 10001000 irq=37
0.383143 8 I 0 ap pci_ivshmem_probe: shmem addr=0x8000400000 size=4194304
reg=0x10001100
0.393617 8 I 0 ap board_init_emmc: GPT partitions registered
NuttX 12.7.2 49d23ab02201-dirty Nov 10 2026 13:39:07 arm64 ap
```
The ivshmem device was detected with a 4 MiB region, confirming that the AP
side completed shared-memory device initialization.
### TEE initialization
```text
21 I 0 tee D/TC:0 21 call_initcalls:40 level 1 register_time_source()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 3 tee_cryp_init()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 4 host_fs_init()
21 I 0 tee D/TC:0 21 host_fs_init:141 perform host_fs_init action
21 I 0 tee D/TC:0 21 host_fs_init:162 host fs init success
21 I 0 tee D/TC:0 21 call_initcalls:40 level 4 tee_fs_init_key_manager()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 6 default_mobj_init()
```
### AP-side `ostest`
```text
qemu-armv8a-ap> ostest
...
user_main: smp call test
cpu_call_test: Test start
cpu_call_test: Call cpu 0, wait
cpu_call_test: Call cpu 1, wait
cpu_call_test: Call cpu 2, wait
cpu_call_test: Call cpu 3, wait
cpu_call_test: Call multi cpu, wait
cpu_call_test: Test success
user_main: Exiting
ostest_main: Exiting with status 0
```
### TEE-side `ostest`
```text
tee> ostest
...
user_main: smp call test
cpu_call_test: Test start
cpu_call_test: Call cpu 0, wait
cpu_call_test: Call cpu 1, wait
cpu_call_test: Call cpu 2, wait
cpu_call_test: Call cpu 3, wait
cpu_call_test: Call multi cpu, wait
cpu_call_test: Test success
user_main: Exiting
ostest_main: Exiting with status 0
```
## Testing Status
- [ ] Compile-tested with all affected QEMU TrustZone configurations
- [x] Runtime-tested on Vela QEMU ARM64
- [x] AP-side `ostest` completed with status 0
- [x] TEE-side `ostest` completed with status 0
- [ ] Verified the secure-world load address above BL31 on the final image
- [ ] Verified RPMsg/RP-TUN communication using the new shared-memory region
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]