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/**
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
8277void 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