Skip to content

Commit dd12dfb

Browse files
microbuildernashif
authored andcommitted
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 <[email protected]> Signed-off-by: David Brown <[email protected]>
1 parent c63fb21 commit dd12dfb

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

samples/tfm_integration/tfm_ipc/sample.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ tests:
77
tags: introduction tfm
88
platform_allow: mps2_an521_ns mps3_an547_ns
99
nrf5340dk_nrf5340_cpuapp_ns nrf9160dk_nrf9160_ns nucleo_l552ze_q_ns
10-
stm32l562e_dk_ns v2m_musca_s1_ns v2m_musca_b1_ns bl5340_dvk_cpuapp_ns
10+
stm32l562e_dk_ns v2m_musca_s1_ns bl5340_dvk_cpuapp_ns
1111
integration_platforms:
1212
- mps2_an521_ns
1313
harness: console
1414
harness_config:
1515
type: multi_line
1616
regex:
17-
- "The version of the PSA Framework API is"
18-
- "The minor version is"
19-
- "Connect success!"
2017
- "TF-M IPC on .*"
18+
- "The version of the PSA Framework API is"
19+
- "The PSA Crypto service minor version is"
20+
- "Generating 256 bytes of random data"
2121
sample.tfm_ipc.no_bl2:
2222
tags: introduction tfm
2323
platform_allow: mps2_an521_ns
@@ -27,7 +27,7 @@ tests:
2727
harness_config:
2828
type: multi_line
2929
regex:
30-
- "The version of the PSA Framework API is"
31-
- "The minor version is"
32-
- "Connect success!"
3330
- "TF-M IPC on .*"
31+
- "The version of the PSA Framework API is"
32+
- "The PSA Crypto service minor version is"
33+
- "Generating 256 bytes of random data"
Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* Copyright (c) 2019,2020, 2021 Linaro Limited
2+
* Copyright (c) 2019,2020, 2021, 2023 Linaro Limited
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include <zephyr/kernel.h>
88
#include <zephyr/sys/printk.h>
9-
#include <zephyr/sys/reboot.h>
109

1110
#include "tfm_api.h"
1211
#include "tfm_ns_interface.h"
1312
#ifdef TFM_PSA_API
1413
#include "psa_manifest/sid.h"
14+
#include "psa/crypto.h"
1515
#endif
1616

1717
/**
@@ -21,7 +21,7 @@
2121
* mean to test all possible combinations of
2222
* input parameters and return values.
2323
*/
24-
static void tfm_ipc_test_01(void)
24+
static void tfm_get_version(void)
2525
{
2626
uint32_t version;
2727

@@ -35,10 +35,11 @@ static void tfm_ipc_test_01(void)
3535
}
3636
}
3737

38+
#ifdef TFM_PSA_API
3839
/**
39-
* Retrieve the minor version of a RoT Service.
40+
* \brief Retrieve the minor version of a RoT Service.
4041
*/
41-
static void tfm_ipc_test_02(void)
42+
static void tfm_get_sid(void)
4243
{
4344
uint32_t version;
4445

@@ -50,44 +51,36 @@ static void tfm_ipc_test_02(void)
5051
}
5152

5253
/* Valid version number */
53-
printk("The minor version is %d.\n", version);
54+
printk("The PSA Crypto service minor version is %d.\n", version);
5455
}
5556

5657
/**
57-
* Connect to a RoT Service by its SID.
58+
* \brief Generates random data using the TF-M crypto service.
5859
*/
59-
static void tfm_ipc_test_03(void)
60+
void tfm_psa_crypto_rng(void)
6061
{
61-
psa_handle_t handle;
62+
psa_status_t status;
63+
uint8_t outbuf[256] = { 0 };
6264

63-
handle = psa_connect(TFM_SP_PLATFORM_SYSTEM_RESET_SID,
64-
TFM_SP_PLATFORM_SYSTEM_RESET_VERSION);
65-
if (handle > 0) {
66-
printk("Connect success!\n");
67-
} else {
68-
printk("The RoT Service has refused the connection!\n");
69-
return;
65+
status = psa_generate_random(outbuf, 256);
66+
printk("Generating 256 bytes of random data:");
67+
for (uint16_t i = 0; i < 256; i++) {
68+
if (!(i % 16)) {
69+
printk("\n");
70+
}
71+
printk("%02X ", (uint8_t)(outbuf[i] & 0xFF));
7072
}
71-
psa_close(handle);
73+
printk("\n");
7274
}
73-
74-
/* For performing secure reset in PSA API mode (TFM_IPC)
75-
* we invoke directly Arm's sys_arch_reboot, instead of
76-
* sys_reboot(..) since the latter will first do an
77-
* irq_lock() which will make the psa_connect() call to
78-
* fail. See #36998.
79-
*/
80-
extern void sys_arch_reboot(int);
75+
#endif
8176

8277
void main(void)
8378
{
84-
tfm_ipc_test_01();
85-
tfm_ipc_test_02();
86-
tfm_ipc_test_03();
87-
8879
printk("TF-M IPC on %s\n", CONFIG_BOARD);
8980

90-
k_sleep(K_MSEC(5000));
91-
/* TODO switch to sys_reboot() when #36998 is resolved. */
92-
sys_arch_reboot(0);
81+
tfm_get_version();
82+
#ifdef TFM_PSA_API
83+
tfm_get_sid();
84+
tfm_psa_crypto_rng();
85+
#endif
9386
}

0 commit comments

Comments
 (0)