2023-09-15 03:41 AM
Ask this at arm.com, but maybe it is STM32U5 specific:
I try run an unprivileged application in secure mode and get a strange behavior:
STM32U5 has TZ enabled, all application runs in secure mode.
1) LR = 0xffff_fff9, CONTROL = 1 => BX LR increments the SP, but all registers become 0 (including PC and XPSR!)
2) When setting CONTROL = 1 and executing SVC, SP is decremented correctly, but nothing is stored on the stack?
I check all errata I could find, but no hint.
If TZ is disabled, the system behaves normal.
Solved! Go to Solution.
2023-10-10 07:10 AM
I think this is STM32U5 specific. ST adds "Resource isolation improvements" on top of the ARMv8-M TrustZone. These improvements allow a block-based secure and privilege configuration for internal SRAM.
See page 8 on the STM32U5-Security-Overview (SECOVW) presentation.
2023-09-19 02:32 AM
Dummy reply.
2023-09-19 06:11 AM
Hello @42Bastian Schick ,
Thank you for your question.
Here is some guidance:
#define EnablePrivilegedMode() __asm("SVC #0")
Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-19 06:33 AM
The application is our RTOS.
The switch between kernel (privileged) and user process (unprivileged) works correct with TZ disabled on SoC level.
So MPU settings should be correct and there is no access violation directly after the return or after the "svc".
But since the "return" pops all 0 (that is r0..r3,r12,lr and xpsr), the next instruction will cause an invalidate instruction exception.
And since "svc" does not push anything onto the stack, the following code crashes, as the stack contains nonsense.
It is weird, that SP is correctly updated in both cases.
Whether I place my SP in 0x3000.0000 or 0x2000.0000 RAM does not change anything.
There is no change of security, so no "SG".
There is no MPU error.
2023-09-19 07:24 AM
I made an example, the absolute minimum which just runs.
Same behavior "svc" with CONTROL == 0 => registers pushed
CONTROL == 1 => SP reduced, no registers pushed.
The attached ELF can be flashed. Run until "HelloSciopta", single step "svc" => registers pushed and PC at sc_sysSVC.
Do it again, set CONTROL == 1 before step. Single step, PC at sc_sysSVC, but no registers pushed.
2023-09-20 01:48 AM - edited 2023-09-20 01:49 AM
Thank you for your ELF file @42Bastian Schick , I flashed it and get this error :
Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-20 02:28 AM
Yes there are memory regions with the same start address, but of size 0. So you can ignore the warning.
OB:
I hope above makes sense. CubeProgrammer does not allow to "dump" the OB info nicely :(
WRP2 same, only 0x081...
I attached a new ELF which I flashed w/o error/warning with CubeProgrammer.
Cheers
42Bastian
2023-09-26 08:45 AM - edited 2023-09-26 08:47 AM
Hello @42Bastian Schick ,
Here is some remark, information demand :
Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-26 09:02 AM
Salut,
yes, this file is meant to be run with TZEN=1. It is tested on nucleo-u575zi-q.
If the system just runs it ends in an error condition, that is "wanted". At the label HelloSciopta is an "svc" instruction and the kernel detects that it is build w/o support for SVC.
Nevertheless, the issue happens when stepping through HelloSciopta function into "svc" opcode.
If CONTROL==0 (default), the step over SVC pushes the r0-r3,r12,lr and XPSR (you can see them on the stack).
If CONTROL==1 then the step over SVC only decrements the SP by the correct amount, but there is nothing stored on the stack.
Cheers
42Bastian
2023-09-27 09:29 AM
Hello @42Bastian Schick ,
I am currently using the same board.
Here is some remark :
Only privileged software can write to the CONTROL register to change the privilege level for software execution in
Thread mode. Unprivileged software can use the SVC instruction to make a Supervisor Call to transfer control to
privileged software. Here is the PM of the STM32 Cortex -M33 in case.
Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.