psoc64: Update TF-M release image

- Fix key derivation issue
- Update PSoC64 BSP
- Replace IPC semaphore spin-lock with IPC lock

Signed-off-by: Charley Chu <haoc@cypress.com>
pull/13418/head
Charley Chu 2020-08-11 17:58:23 -07:00
parent d8a50aa21e
commit 4749e176d7
6 changed files with 12564 additions and 12687 deletions

View File

@ -13,7 +13,6 @@
#include "cy_ipc_drv.h"
#include "cy_sysint.h"
#include "cy_ipc_sema.h"
#include "ns_ipc_config.h"
#include "tfm_ns_mailbox.h"
@ -52,21 +51,6 @@ int32_t tfm_ns_mailbox_hal_notify_peer(void)
}
}
static int32_t mailbox_sema_init(void)
{
#if defined(CY_IPC_DEFAULT_CFG_DISABLE)
/* semaphore data */
static uint32_t tfm_sema __attribute__((section("TFM_SHARED_DATA")));
if (Cy_IPC_Sema_Init(PLATFORM_MAILBOX_IPC_CHAN_SEMA,
sizeof(tfm_sema) * CHAR_BIT,
&tfm_sema) != CY_IPC_SEMA_SUCCESS) {
return PLATFORM_MAILBOX_INIT_ERROR;
}
#endif
return PLATFORM_MAILBOX_SUCCESS;
}
int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
{
uint32_t stage;
@ -75,10 +59,6 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
return MAILBOX_INVAL_PARAMS;
}
/* Init semaphores used for critical sections */
if (mailbox_sema_init() != PLATFORM_MAILBOX_SUCCESS)
return MAILBOX_INIT_ERROR;
/*
* FIXME
* Further verification of mailbox queue address may be required according
@ -120,7 +100,7 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
const void *tfm_ns_mailbox_get_task_handle(void)
{
return osThreadGetId();;
return osThreadGetId();
}
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
@ -128,137 +108,39 @@ void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
osThreadFlagsWait(handle, osFlagsWaitAll, osWaitForever);
}
static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
uint32_t sema_num)
{
uint32_t semaIndex;
uint32_t semaMask;
cy_stc_ipc_sema_t *semaStruct;
cy_en_ipcdrv_status_t acqStatus;
cy_en_ipcsema_status_t ret = CY_IPC_SEMA_BAD_PARAM;
bool is_lock = false;
IPC_STRUCT_Type *semaIpcStruct;
/* Get IPC register structure */
semaIpcStruct = Cy_IPC_Drv_GetIpcBaseAddress(ipc_channel);
/* Get pointer to structure */
semaStruct = (cy_stc_ipc_sema_t *)Cy_IPC_Drv_ReadDataValue(semaIpcStruct);
if (sema_num < semaStruct->maxSema) {
semaIndex = sema_num / CY_IPC_SEMA_PER_WORD;
semaMask = (uint32_t)(1ul << (sema_num - \
(semaIndex * CY_IPC_SEMA_PER_WORD)));
while (!is_lock) {
/* Check to make sure the IPC channel is released
If so, check if specific channel can be locked. */
do {
acqStatus = Cy_IPC_Drv_LockAcquire(semaIpcStruct);
} while (acqStatus != CY_IPC_DRV_SUCCESS);
if ((semaStruct->arrayPtr[semaIndex] & semaMask) == 0ul) {
semaStruct->arrayPtr[semaIndex] |= semaMask;
is_lock = true;
}
/* Release, but do not trigger a release event */
(void)Cy_IPC_Drv_LockRelease(semaIpcStruct,
CY_IPC_NO_NOTIFICATION);
if (!is_lock) {
/*
* The secure core is occupying this lock. Insert a small delay
* to give the secure core a chance to acquire the IPC channel
* and release the lock.
* Otherwise, the secure core may not be able to release the
* lock if non-secure core has higher CPU frequency. It will
* generate a deadlock.
* This delay won't harm performance too much since non-secure
* core has to busy wait here anyway.
* Alternatively, non-secure core can wait for release
* notification event from secure core. However, it is more
* complex and requires more code and more modifications.
*/
volatile uint32_t count = 1000;
while(count > 0) {
count--;
}
Cy_IPC_Sema_Status(sema_num);
}
}
ret = CY_IPC_SEMA_SUCCESS;
}
return ret;
}
static cy_en_ipcsema_status_t mailbox_raw_spin_unlock(uint32_t ipc_channel,
uint32_t sema_num)
{
uint32_t semaIndex;
uint32_t semaMask;
cy_stc_ipc_sema_t *semaStruct;
cy_en_ipcdrv_status_t acqStatus;
cy_en_ipcsema_status_t ret = CY_IPC_SEMA_BAD_PARAM;
bool is_unlock = false;
IPC_STRUCT_Type *semaIpcStruct;
/* Get IPC register structure */
semaIpcStruct = Cy_IPC_Drv_GetIpcBaseAddress(ipc_channel);
/* Get pointer to structure */
semaStruct = (cy_stc_ipc_sema_t *)Cy_IPC_Drv_ReadDataValue(semaIpcStruct);
if (sema_num < semaStruct->maxSema) {
semaIndex = sema_num / CY_IPC_SEMA_PER_WORD;
semaMask = (uint32_t)(1ul << (sema_num - \
(semaIndex * CY_IPC_SEMA_PER_WORD)));
while (!is_unlock) {
/* Check to make sure the IPC channel is released
If so, check if specific channel can be locked. */
do {
acqStatus = Cy_IPC_Drv_LockAcquire(semaIpcStruct);
} while (acqStatus != CY_IPC_DRV_SUCCESS);
if ((semaStruct->arrayPtr[semaIndex] & semaMask) != 0ul) {
semaStruct->arrayPtr[semaIndex] &= ~semaMask;
is_unlock = true;
}
/* Release, but do not trigger a release event */
(void)Cy_IPC_Drv_LockRelease(semaIpcStruct,
CY_IPC_NO_NOTIFICATION);
}
ret = CY_IPC_SEMA_SUCCESS;
}
return ret;
}
void tfm_ns_mailbox_hal_enter_critical(void)
{
saved_irq_state = Cy_SysLib_EnterCriticalSection();
mailbox_raw_spin_lock(CY_IPC_CHAN_SEMA, MAILBOX_SEMAPHORE_NUM);
IPC_STRUCT_Type* ipc_struct =
Cy_IPC_Drv_GetIpcBaseAddress(IPC_PSA_MAILBOX_LOCK_CHAN);
while(CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_LockAcquire (ipc_struct))
{
}
}
void tfm_ns_mailbox_hal_exit_critical(void)
{
mailbox_raw_spin_unlock(CY_IPC_CHAN_SEMA, MAILBOX_SEMAPHORE_NUM);
IPC_STRUCT_Type* ipc_struct =
Cy_IPC_Drv_GetIpcBaseAddress(IPC_PSA_MAILBOX_LOCK_CHAN);
Cy_IPC_Drv_LockRelease(ipc_struct, CY_IPC_NO_NOTIFICATION);
Cy_SysLib_ExitCriticalSection(saved_irq_state);
}
void tfm_ns_mailbox_hal_enter_critical_isr(void)
{
mailbox_raw_spin_lock(CY_IPC_CHAN_SEMA, MAILBOX_SEMAPHORE_NUM);
IPC_STRUCT_Type* ipc_struct =
Cy_IPC_Drv_GetIpcBaseAddress(IPC_PSA_MAILBOX_LOCK_CHAN);
while(CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_LockAcquire (ipc_struct))
{
}
}
void tfm_ns_mailbox_hal_exit_critical_isr(void)
{
mailbox_raw_spin_unlock(CY_IPC_CHAN_SEMA, MAILBOX_SEMAPHORE_NUM);
IPC_STRUCT_Type* ipc_struct =
Cy_IPC_Drv_GetIpcBaseAddress(IPC_PSA_MAILBOX_LOCK_CHAN);
Cy_IPC_Drv_LockRelease(ipc_struct, CY_IPC_NO_NOTIFICATION);
}
static bool mailbox_clear_intr(void)

View File

@ -24,6 +24,8 @@
#define IPC_PSA_CLIENT_REPLY_NOTIFY_MASK (1 << IPC_PSA_CLIENT_REPLY_INTR_STRUCT)
#define IPC_PSA_CLIENT_REPLY_IPC_INTR cpuss_interrupts_ipc_8_IRQn
#define IPC_PSA_MAILBOX_LOCK_CHAN (10)
#define IPC_RX_RELEASE_MASK (0)
#define CY_IPC_NOTIFY_SHIFT (16)