2024-02-02 05:11 AM
Hi there,
I currently work on the integration of OPTEE to our custom STM32MP151C-based platform. The problem that I've faced is that U-boot hangs just after the board_init_f() function and relocation procedure:
NOTICE: CPU: STM32MP151CAC Rev.Z
NOTICE: Model: STMicroelectronics custom STM32CubeMX board (TF-A)
INFO: Reset reason (0x15):
INFO: Power-on Reset (rst_por)
INFO: FCONF: Reading TB_FW firmware configuration file from: 0x2ffe2000
INFO: FCONF: Reading firmware configuration information for: stm32mp_io
INFO: Using USB
INFO: Instance 2
INFO: Boot used partition fsbl1
NOTICE: BL2: v2.6-stm32mp1-r1.0(debug):v2.6-dirty
NOTICE: BL2: Built : 13:14:26, Nov 23 2021
INFO: BL2: Doing platform setup
INFO: RAM: DDR3-DDR3L 16bits 533000Khz
INFO: Memory size = 0x8000000 (128 MB)
INFO: DFU USB START...
INFO: phase ID :3, Manifestation 3 at c7146592
INFO: Send detach request
INFO: Receive DFU Detach
INFO: DFU USB STOP...
INFO: BL2: Loading image id 31
INFO: Loading image id=31 at address 0x2ffff000
INFO: Image id=31 loaded: 0x2ffff000 - 0x2ffff1fa
INFO: FCONF: Reading FW_CONFIG firmware configuration file from: 0x2ffff000
INFO: FCONF: Reading firmware configuration information for: dyn_cfg
INFO: FCONF: Reading firmware configuration information for: stm32mp1_firewall
INFO: BL2: Loading image id 4
INFO: Loading image id=4 at address 0x2ffc0000
INFO: Image id=4 loaded: 0x2ffc0000 - 0x2ffc002c
INFO: OPTEE ep=0x2ffc0000
INFO: OPTEE header info:
INFO: magic=0x4554504f
INFO: version=0x2
INFO: arch=0x0
INFO: flags=0x0
INFO: nb_images=0x2
INFO: BL2: Loading image id 21
INFO: Loading image id=21 at address 0x2ffc0000
INFO: Image id=21 loaded: 0x2ffc0000 - 0x2ffd2628
INFO: BL2: Loading image id 22
INFO: Loading image id=22 at address 0xc6200000
INFO: Image id=22 loaded: 0xc6200000 - 0xc624d000
INFO: BL2: Loading image id 23
INFO: Loading image id=23 at address 0xc0500000
INFO: Image id=23 loaded: 0xc0500000 - 0xc0511fb0
INFO: BL2: Skip loading image id 26
INFO: BL2: Loading image id 5
INFO: Loading image id=5 at address 0xc0100000
INFO: Image id=5 loaded: 0xc0100000 - 0xc01d4c6c
NOTICE: BL2: Booting BL32
INFO: Entry point address = 0x2ffc0000
INFO: SPSR = 0x1d3
I/TC: Early console on UART#4
I/TC:
I/TC: Pager is enabled. Hashes: 2784 bytes
I/TC: Pager pool size: 60kB
I/TC: Non-secure external DT found
I/TC: Embedded DTB found
I/TC: OP-TEE version: 3.16.0-dev (gcc version 12.2.0 (GCC)) #19 Fri Jan 28 02:28:18 PM UTC 2022 arm
I/TC: WARNING: This OP-TEE configuration might be insecure!
I/TC: WARNING: Please check https://optee.readthedocs.io/en/latest/architecture/porting_guidelines.html
I/TC: Primary CPU initializing
I/TC: DT clock tree configurations were ignored
I/TC: WARNING: All debug access are allowed
I/TC: Platform stm32mp1: flavor PLATFORM_FLAVOR - DT stm32mp151c-0068-new-1-mx.dts
I/TC: DTB enables console (non-secure)
I/TC: Primary CPU switching to normal world boot
...
U-Boot 2021.10-stm32mp-r1-dirty (Oct 04 2021 - 15:09:26 +0000)
U-Boot code: C0100000 -> C01BCBF4 BSS: -> C01C9568
psci psci: set_state_simple op missing
stm32mp_bsec efuse@5c005000: set_state_simple op missing
CPU: STM32MP151CAC Rev.Z
Model: STMicroelectronics custom STM32CubeMX (U-Boot)
Board: stm32mp1 in trusted mode (st,stm32mp151c-0068-new-linux-mx)
DRAM: stm32mp1_ddr ddr@5a003000: set_state_simple op missing
Monitor len: 000C9568
Ram size: 08000000
Ram top: C8000000
Reserving 805k for U-Boot at: c7f26000
Reserving 33024k for malloc() at: c5ee6000
Reserving 1M for noncached_alloc() at: c5d00000
Reserving 72 Bytes for Board Info at: c5cfffb0
Reserving 216 Bytes for Global Data at: c5cffed0
Reserving 72640 Bytes for FDT at: c5cee310
RAM Configuration:
Bank #0: c0000000
DRAM: 128 MiB
New Stack Pointer is: c5cee2f0
Relocation Offset is: 07e26000
Relocating to c7f26000, new gd at c5cffed0, sp at c5cee2f0
I guess the issue might be related to the incorrect memory mapping and potential overlaps. The only thing I changed compared to the previous well working configuration (non OPTEE based) was increasing CONFIG_SYS_MALLOC_F_LEN from 0x3000 to 0x40000 which solves the problem regarding to "alloc space exhausted" error.
I use the stm32mpu-ecosystem-v4 provided by the meta-st-stm32mp yocto layer (langdale).
Is there something I missed or have to configure in addition?
Thanks in advance for any hints!
Solved! Go to Solution.
2024-02-05 01:36 AM
Hi,
in your trace, it seems the OP-TEE in loaded at address: 0xc6200000
INFO: Loading image id=22 at address 0xc6200000
INFO: Image id=22 loaded: 0xc6200000 - 0xc624d000
And U-Boot use the end of DDR (128 MiB) for relocation address with "Ram top: C8000000":
Relocating to c7f26000, new gd at c5cffed0, sp at c5cee2f0
So relocated U-Boot is clearly overridden the OP-TEE location.
Normally the OP-TEE reserved memory is preserved by U-Boot, when it is correctly configured in the U-Boot device tree.
Check in your device tree in U-Boot, if you have the node with the correct address (I don't sure of the size with size of memory used by OP-TEE (you need crosscheck with OP-TEE configuration)
/ {
reserved-memory {
optee@c6200000 {
reg = <0xc6200000 0x50000>;
no-map;
};
};
};
See also https://wiki.st.com/stm32mpu/wiki/How_to_configure_a_256MB_DDR_mapping_from_STM32_MPU_Distribution_Package#U-Boot_updates
As alternate dirty solution (for test)
=> change in U-boot code the "ram top" value, it is the result of board_get_usable_ram_top() in arch/arm/mach-stm32mp/dram_init.c
return 0xc6200000;
And U-Boot willl be reloaded before OP-TEE location = 0xc6200000.
regards,
Patrick
2024-02-05 01:36 AM
Hi,
in your trace, it seems the OP-TEE in loaded at address: 0xc6200000
INFO: Loading image id=22 at address 0xc6200000
INFO: Image id=22 loaded: 0xc6200000 - 0xc624d000
And U-Boot use the end of DDR (128 MiB) for relocation address with "Ram top: C8000000":
Relocating to c7f26000, new gd at c5cffed0, sp at c5cee2f0
So relocated U-Boot is clearly overridden the OP-TEE location.
Normally the OP-TEE reserved memory is preserved by U-Boot, when it is correctly configured in the U-Boot device tree.
Check in your device tree in U-Boot, if you have the node with the correct address (I don't sure of the size with size of memory used by OP-TEE (you need crosscheck with OP-TEE configuration)
/ {
reserved-memory {
optee@c6200000 {
reg = <0xc6200000 0x50000>;
no-map;
};
};
};
See also https://wiki.st.com/stm32mpu/wiki/How_to_configure_a_256MB_DDR_mapping_from_STM32_MPU_Distribution_Package#U-Boot_updates
As alternate dirty solution (for test)
=> change in U-boot code the "ram top" value, it is the result of board_get_usable_ram_top() in arch/arm/mach-stm32mp/dram_init.c
return 0xc6200000;
And U-Boot willl be reloaded before OP-TEE location = 0xc6200000.
regards,
Patrick
2024-02-05 03:30 AM
Hi PatrickD,
As you suggested, my OPTEE node had the incorrect addresses set.
Thank you