In my work to port TF-M to IAR EWARM I have now gotten the MPC set up so
that the startup will properly switch to the NS code.
I'm now running into an issue where I get a SecureFault when attempting
to start the OS.
The idle and timer threads have been configured and the timer thread has
been put on run.curr and SVC_Exit issues a BX LR, which results in a
SecureFault.
SFSR indicates that it is an INVER (Invalid Exception Return):
---
Invalid exception return flag. This can be caused by EXC_RETURN.DCRS
being set to 0 when returning from
an exception in the Non-secure state, or by EXC_RETURN.ES being set to 1
when returning from an exception
in the Non-secure state. The possible values of this bit are:
0 Error has not occurred.
1 Error has occurred.
--
LR was 0xfffffffd (DCRS=1, ES=1) and the security bit was cleared, so it
appears to be the second condition that triggered the exception.
What am I missing here?
Is the OS supposed to be started from NS mode?
I am still using the ARM.TFM.1.1.0, ARM.Musca_A1_BSP.2.0.0,
ARM.mbedTLS.1.3.1 and ARM.CMSIS.5.5.0-dev2 packs.
Thanks,
/Thomas
*Thomas Törnblom*, /Product Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
Mobile: +46 76 180 17 80 Fax: +46 18 16 78 01
E-mail: thomas.tornblom(a)iar.com <mailto:thomas.tornblom@iar.com>
Website: www.iar.com <http://www.iar.com>
Twitter: www.twitter.com/iarsystems <http://www.twitter.com/iarsystems>
Hi Danny,
Could you please check my comments on [Mailbox design](https://developer.trustedfirmware.org/w/tf_m/design/twin-cpu/mailbo… in below?
I’d like to discuss about some high-level designs at the very first time. We can discuss about details later. 😊
1. As designed in Concepts section, secure core has a single dispatcher thread, which is the main thread on the secure core.
AFAIK, there is no such main thread in current TF-M Inter-Process Communication model implementation. Do you mind taking a look at the section "Interaction in thread model" in our [TF-M presentation](https://events.linuxfoundation.org/wp-content/uploads/2017/12…
On the other hand, implementing a dedicated thread in TF-M to handling the mailbox events can be a solution. But it might also bring some difficulties in implementation. I'd like to discuss in detail with Transport Layer together.
2. I like the concept of mailbox event. One of the key points is, after the information carried via mailbox arrives in TF-M, how to deliver it to TF-M core. We can have further discussions on the details.
3. PSA Firmware Framework specifies the parameters and return value for PSA Client APIs. Do you think if it is necessary to cover the mailbox message structure containing information of parameters and return value in mailbox design?
Thank you.
Best regards,
Hu Ziji
Hi Alan,
From my point of view, TZ_StoreContext_S() indicates the non-secure thread accesses secure service
is getting switching out, no one should access secure services before a calling of TZ_LoadContext_S().
This case could be covered in below condition in PSA FF client APIs (Picked on line from page 49 of PSA FF 1.0 beta0):
"Calling psa_connect() is a fatal error and will not return if any of the following conditions are met:
* ...
* The caller is not authorized to access the RoT Service, see RoT Service access control on page 28.
* ..."
Pining the calling non-secure thread is the proper way - which means, 'Does not return' to the non-secure thread in this case.
There should be no such an API to peek the status of SPM from caller out of SPM.
And there should be a similar API for SPM (only) to retrieve the current MemoryID (or information could be represented as MemoryID).
BR
-Ken
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars,
> Alan via TF-M
> Sent: Thursday, February 21, 2019 10:54 PM
> To: tf-m(a)lists.trustedfirmware.org
> Subject: [TF-M] What is the behavior of SPM between `TZ_StoreContext_S()` and
> `TZ_LoadContext_S()`
>
> Are calls to psa_connect/call/close allowed after `TZ_StoreContext_S()` has
> been called but before `TZ_LoadContext_S()` is called? If not, does that result in
> a panic or simply error return codes?
>
> Is there a secure-side SPM API that can be invoked from a custom veneer
> function to determine if the SPM is in the zone between `TZ_StoreContext_S()`
> and `TZ_LoadContext_S()`?
>
> Is there an API that returns the current MemoryId?
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Are calls to psa_connect/call/close allowed after `TZ_StoreContext_S()` has been called but before `TZ_LoadContext_S()` is called? If not, does that result in a panic or simply error return codes?
Is there a secure-side SPM API that can be invoked from a custom veneer function to determine if the SPM is in the zone between `TZ_StoreContext_S()` and `TZ_LoadContext_S()`?
Is there an API that returns the current MemoryId?
Alan
Hi Thomas,
(The code snippets are from the commit with hash 5c1756fbab6097f5688583d11dea5d1271d2d774 on https://review.trustedfirmware.org . I only added some comments at certain points)
This symptom is usually caused by a misconfigured MPC.
The MPC initialisation is also called from platform\ext\target\musca_a\spm_hal.c:
---------- 8< ----------
void tfm_spm_hal_init_isolation_hw(void)
{
/* Configures non-secure memory spaces in the target */
sau_and_idau_cfg();
mpc_init_cfg(); /* <- initialise MPC */
ppc_init_cfg();
}
---------- >8 ----------
Looking at mpc_init_cfg:
---------- 8< ----------
void mpc_init_cfg(void)
{
/* ... */
Driver_QSPI_MPC.Initialize();
Driver_QSPI_MPC.ConfigRegion(memory_regions.non_secure_partition_base,
memory_regions.non_secure_partition_limit,
ARM_MPC_ATTR_NONSECURE);
/* ... */
/* Lock down the MPC configuration */
Driver_QSPI_MPC.LockDown();
/* ... */
/* Add barriers to assure the MPC configuration is done before continue
* the execution.
*/
__DSB();
__ISB();
}
---------- 8< ----------
It is possible to change the MPC behaviour, to raise a bus fault on invalid access instead of the RAZ/WI behaviour, by setting the CFG_SEC_RESP bit in the MPC's control register.
You should do something like this after Driver_QSPI_MPC initialisation (see https://developer.arm.com/products/architecture/cpu-architecture/m-profile/… ):
---------- 8< ----------
uint32_t mpc_ctrl;
Driver_QSPI_MPC.GetCtrlConfig(&mpc_ctrl);
Driver_QSPI_MPC.SetCtrlConfig(mpc_ctrl | 0x10);
---------- 8< ----------
If you don't get the bus fault after this, further troubleshooting is needed.
Regards,
Mate
-----Original Message-----
From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of Thomas Törnblom via TF-M
Sent: 15 February 2019 15:57
To: tf-m(a)lists.trustedfirmware.org
Subject: [TF-M] Musca-A SAU setup issues
I am working on porting TF-M to the IAR Embedded Workbench for ARM
(EWARM) toolchain and I'm having some issues getting it to start properly.
I started out using the ARM.TFM.1.1.0, ARM.Musca_A1_BSP.2.0.0,
ARM.mbedTLS.1.3.1 and ARM.CMSIS.5.5.0-dev2 CMSIS packs and I've had to fix things in all of the packs to make the project build with our compiler, some things just to add our tools, some things that were just gcc:isms that are non standard-C.
The TF-M code is based on a snapshot of https://git.trustedfirmware.org/trusted-firmware-m.git repository of the following hash: 5c1756fbab6097f5688583d11dea5d1271d2d774
I know that some of these packs are old and I'm also working on a port of the bits on trustedfirmware.org, but I would like to bring the old version up first.
The (current) issue I have is that the NS code region becomes inaccessible from the secure part after setting the SAU up and I assume I am missing something.
in tfm_core_init() there are calls to:
---
tfm_spm_hal_init_isolation_hw();
configure_ns_code();
---
tfm_spm_hal_init_isolation_hw() calls sau_and_idau_cfg(), which sets up:
---
/* Configures SAU regions to be non-secure */
SAU->RNR = TFM_NS_REGION_CODE;
SAU->RBAR = (memory_regions.non_secure_partition_base
& SAU_RBAR_BADDR_Msk);
SAU->RLAR = (memory_regions.non_secure_partition_limit
& SAU_RLAR_LADDR_Msk)
| SAU_RLAR_ENABLE_Msk;
---
After this piece is run, the NS vector table becomes all zeros when viewed from secure mode. This causes the configure_ns_code() call above to fail to pick up the ns_msp and ns_entry addresses, they become 0.
If I swap the calls around so they become:
---
configure_ns_code();
tfm_spm_hal_init_isolation_hw();
---
then ns_msp and ns_entry are picked up OK.
How is this supposed to work?
When the SAU is setup I get RAZ/WI when accessing NS memory from S mode, the other way around results is a security violation, which is properly handled by the SecureFault_Handler().
What am I missing?
I run into other problems later, but that may very well a consequence of earlier issues.
Thanks,
/Thomas
--
*Thomas Törnblom*, /Product Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
Mobile: +46 76 180 17 80 Fax: +46 18 16 78 01
E-mail: thomas.tornblom(a)iar.com <mailto:thomas.tornblom@iar.com>
Website: www.iar.com <http://www.iar.com>
Twitter: www.twitter.com/iarsystems <http://www.twitter.com/iarsystems>
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
My concern was the value one would provide for the "line_num" field within the manifest. The SYSTICK uses vector 15 which I believe would correspond to "line_num" = -1. I'm not sure the design accommodates negative line_nums.
Also, disabling the SYSTICK interrupt while servicing its interrupt can't be handled in the normal way user IRQs are disabled. Special case code would be required in the SPM to support the SYSTICK as a secure partition interrupt.
Alan
-----Original Message-----
From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf Of Ken Liu (Arm Technology China) via TF-M
Sent: Monday, February 18, 2019 5:34 PM
To: tf-m(a)lists.trustedfirmware.org
Cc: nd
Subject: [EXTERNAL] Re: [TF-M] SYSTICK ownership
Hi Alan,
From your description, it looks like you want to use secure SYSTICK as an interrupt for Secure Partition, is this correct?
In this case, it is similar to the secure interrupt usage. Since the interrupt handling is under developing, I will add a note
in the task to remind how we could add SYSTICK as an interrupt in the manifest.
BR
-Ken
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars,
> Alan via TF-M
> Sent: Saturday, February 16, 2019 7:02 AM
> To: tf-m(a)lists.trustedfirmware.org
> Subject: [TF-M] SYSTICK ownership
>
> If not used anywhere else, can a Secure Partition own the secure SYSTICK timer
> and its interrupt?
> If so, how is it specified in the SP manifest?
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Hi Alan,
From your description, it looks like you want to use secure SYSTICK as an interrupt for Secure Partition, is this correct?
In this case, it is similar to the secure interrupt usage. Since the interrupt handling is under developing, I will add a note
in the task to remind how we could add SYSTICK as an interrupt in the manifest.
BR
-Ken
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars,
> Alan via TF-M
> Sent: Saturday, February 16, 2019 7:02 AM
> To: tf-m(a)lists.trustedfirmware.org
> Subject: [TF-M] SYSTICK ownership
>
> If not used anywhere else, can a Secure Partition own the secure SYSTICK timer
> and its interrupt?
> If so, how is it specified in the SP manifest?
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Thanks! I'll check back.
-----Original Message-----
From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf Of Ken Liu (Arm Technology China) via TF-M
Sent: Monday, February 18, 2019 5:16 PM
To: tf-m(a)lists.trustedfirmware.org
Cc: nd
Subject: [EXTERNAL] Re: [TF-M] interrupts not supported on feature-ipc branch?
Hi Alan,
There would be a merge to master in recent days; so master branch will support PSA IPC soon.
The interrupts for IPC is under developing, you can check the roadmap to know the plan.
Thanks.
-Ken
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars,
> Alan via TF-M
> Sent: Saturday, February 16, 2019 7:37 AM
> To: tf-m(a)lists.trustedfirmware.org
> Subject: [TF-M] interrupts not supported on feature-ipc branch?
>
> I guess interrupts are only supported on the master branch.
>
> When will the master branch support PSA IPC?
>
> Or, when will the feature-ipc branch support interrupts?
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Hi Alan,
There would be a merge to master in recent days; so master branch will support PSA IPC soon.
The interrupts for IPC is under developing, you can check the roadmap to know the plan.
Thanks.
-Ken
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars,
> Alan via TF-M
> Sent: Saturday, February 16, 2019 7:37 AM
> To: tf-m(a)lists.trustedfirmware.org
> Subject: [TF-M] interrupts not supported on feature-ipc branch?
>
> I guess interrupts are only supported on the master branch.
>
> When will the master branch support PSA IPC?
>
> Or, when will the feature-ipc branch support interrupts?
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
I obtained the following benchmarks for the 3 PSA APIs psa_connect(), psa_call(), and psa_close() using the attached implementation of a Secure Partition (my_sp.c) and building both my NS application and the SPE image with -O3 optimizations:
psa_connect() 2133 cycles
psa_call() 2650 cycles
psa_close() 2136 cycles
The psa_call() numbers were achieved by passing 'MY_SP_MSG_TYPE_NULL' as the message type to my test SP, thus eliminating any invec and outvec processing from the benchmark. The secure partition had been regenerated using the attached tfm manifest to reduce the number of user-provided SPs to just 2: the feature-ipc branch's test PSA service and my test PSA service.
With these benchmarks in mind and after reviewing the new PSA-compliant SST API implementations, I propose that a new, more efficient, PSA IPC API be provided for those user-facing SP service requests which require no state in the secure partition.
Below is the psa_sst_common() function shared by all of the new PSA compliant sst APIS (snipped from interface/src/tfm_sst_api_ipc.c):
static psa_status_t psa_sst_common(uint32_t sid, uint32_t minor_version,
const psa_invec *in_vecs, size_t in_len,
psa_outvec *out_vecs, size_t out_len)
{
psa_handle_t handle;
psa_status_t status;
handle = psa_connect(sid, minor_version);
if (handle <= 0) {
return PSA_SST_ERR_PARAM_ERROR;
}
status = psa_call(handle, in_vecs, in_len, out_vecs, out_len);
if (status < 0) {
status = PSA_SST_ERR_SYSTEM_ERROR;
}
psa_close(handle);
return status;
}
I propose that the functionality and signature of 'psa_sst_common' be promoted to a formal PSA API. For lack of a better name, call this new API 'psa_ccc()', to convey the meaning that it combines the CONNECT, CALL, and CLOSE functions. Internally, the SPM would skip allocating and deallocating a handle, then pass message type 'PSA_IPC_CCC' to the SP.
Here is a crude representation of how the PSA_IPC_CCC message type could be handled by a Secure Partition:
case PSA_IPC_CCC:
if (inuse) {
psa_reply(msg.handle, PSA_CONNECTION_REFUSED);
} else {
inuse = 1; /* to handle potential SP pre-emption during my_sp_call() case */
r = my_sp_call(&msg);
psa_reply(msg.handle, r);
inuse = 0;
}
break;
Please consider this proposal. The new API would save the overhead of entering and exiting the SP 3 times for SP service requests that require no state.
Alan