samples: tfm_integration: Update tfm_ipc for 1.7.0
Update the sample to be compatible with API changes introduced in TF-M 1.7.0, adding a new direct call to the PSA Crypto API to generate random data, and cleaning up existing functions for compatibility sake. Signed-off-by: Kevin Townsend <kevin.townsend@linaro.org> Signed-off-by: David Brown <david.brown@linaro.org>
This commit is contained in:
parent
c63fb21760
commit
dd12dfb5ad
|
@ -7,17 +7,17 @@ tests:
|
|||
tags: introduction tfm
|
||||
platform_allow: mps2_an521_ns mps3_an547_ns
|
||||
nrf5340dk_nrf5340_cpuapp_ns nrf9160dk_nrf9160_ns nucleo_l552ze_q_ns
|
||||
stm32l562e_dk_ns v2m_musca_s1_ns v2m_musca_b1_ns bl5340_dvk_cpuapp_ns
|
||||
stm32l562e_dk_ns v2m_musca_s1_ns bl5340_dvk_cpuapp_ns
|
||||
integration_platforms:
|
||||
- mps2_an521_ns
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "The version of the PSA Framework API is"
|
||||
- "The minor version is"
|
||||
- "Connect success!"
|
||||
- "TF-M IPC on .*"
|
||||
- "The version of the PSA Framework API is"
|
||||
- "The PSA Crypto service minor version is"
|
||||
- "Generating 256 bytes of random data"
|
||||
sample.tfm_ipc.no_bl2:
|
||||
tags: introduction tfm
|
||||
platform_allow: mps2_an521_ns
|
||||
|
@ -27,7 +27,7 @@ tests:
|
|||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "The version of the PSA Framework API is"
|
||||
- "The minor version is"
|
||||
- "Connect success!"
|
||||
- "TF-M IPC on .*"
|
||||
- "The version of the PSA Framework API is"
|
||||
- "The PSA Crypto service minor version is"
|
||||
- "Generating 256 bytes of random data"
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2019,2020, 2021 Linaro Limited
|
||||
* Copyright (c) 2019,2020, 2021, 2023 Linaro Limited
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
|
||||
#include "tfm_api.h"
|
||||
#include "tfm_ns_interface.h"
|
||||
#ifdef TFM_PSA_API
|
||||
#include "psa_manifest/sid.h"
|
||||
#include "psa/crypto.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@
|
|||
* mean to test all possible combinations of
|
||||
* input parameters and return values.
|
||||
*/
|
||||
static void tfm_ipc_test_01(void)
|
||||
static void tfm_get_version(void)
|
||||
{
|
||||
uint32_t version;
|
||||
|
||||
|
@ -35,10 +35,11 @@ static void tfm_ipc_test_01(void)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TFM_PSA_API
|
||||
/**
|
||||
* Retrieve the minor version of a RoT Service.
|
||||
* \brief Retrieve the minor version of a RoT Service.
|
||||
*/
|
||||
static void tfm_ipc_test_02(void)
|
||||
static void tfm_get_sid(void)
|
||||
{
|
||||
uint32_t version;
|
||||
|
||||
|
@ -50,44 +51,36 @@ static void tfm_ipc_test_02(void)
|
|||
}
|
||||
|
||||
/* Valid version number */
|
||||
printk("The minor version is %d.\n", version);
|
||||
printk("The PSA Crypto service minor version is %d.\n", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a RoT Service by its SID.
|
||||
* \brief Generates random data using the TF-M crypto service.
|
||||
*/
|
||||
static void tfm_ipc_test_03(void)
|
||||
void tfm_psa_crypto_rng(void)
|
||||
{
|
||||
psa_handle_t handle;
|
||||
psa_status_t status;
|
||||
uint8_t outbuf[256] = { 0 };
|
||||
|
||||
handle = psa_connect(TFM_SP_PLATFORM_SYSTEM_RESET_SID,
|
||||
TFM_SP_PLATFORM_SYSTEM_RESET_VERSION);
|
||||
if (handle > 0) {
|
||||
printk("Connect success!\n");
|
||||
} else {
|
||||
printk("The RoT Service has refused the connection!\n");
|
||||
return;
|
||||
status = psa_generate_random(outbuf, 256);
|
||||
printk("Generating 256 bytes of random data:");
|
||||
for (uint16_t i = 0; i < 256; i++) {
|
||||
if (!(i % 16)) {
|
||||
printk("\n");
|
||||
}
|
||||
printk("%02X ", (uint8_t)(outbuf[i] & 0xFF));
|
||||
}
|
||||
psa_close(handle);
|
||||
printk("\n");
|
||||
}
|
||||
|
||||
/* For performing secure reset in PSA API mode (TFM_IPC)
|
||||
* we invoke directly Arm's sys_arch_reboot, instead of
|
||||
* sys_reboot(..) since the latter will first do an
|
||||
* irq_lock() which will make the psa_connect() call to
|
||||
* fail. See #36998.
|
||||
*/
|
||||
extern void sys_arch_reboot(int);
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
tfm_ipc_test_01();
|
||||
tfm_ipc_test_02();
|
||||
tfm_ipc_test_03();
|
||||
|
||||
printk("TF-M IPC on %s\n", CONFIG_BOARD);
|
||||
|
||||
k_sleep(K_MSEC(5000));
|
||||
/* TODO switch to sys_reboot() when #36998 is resolved. */
|
||||
sys_arch_reboot(0);
|
||||
tfm_get_version();
|
||||
#ifdef TFM_PSA_API
|
||||
tfm_get_sid();
|
||||
tfm_psa_crypto_rng();
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue