Skip to content

Commit 9d4d04e

Browse files
jaccoo01adeaarm
authored andcommitted
RSE: Add routing tables getter functions
Add functions which abstract the storage location of the RSE routing tables. These functions can be used in place of tfm_plat_otp_read in rse_handshake.c. Change-Id: I5e4290eab1d0b49a58bdf0dfb4d25000d24ecbb2 Signed-off-by: Jackson Cooper-Driver <[email protected]>
1 parent d350d92 commit 9d4d04e

File tree

6 files changed

+132
-13
lines changed

6 files changed

+132
-13
lines changed

platform/ext/target/arm/rse/common/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,11 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config/otp_layout.csv
900900
############################## Routing tables ##################################
901901
902902
if (RSE_AMOUNT GREATER 1)
903+
target_sources(platform_bl1_1
904+
PRIVATE
905+
./rse_get_routing_tables.c
906+
)
907+
903908
add_custom_target(routing_tables_pickle
904909
ALL
905910
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/config/routing_tables.pickle

platform/ext/target/arm/rse/common/bl1/bl1_1_shared_symbols.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ dm_rotpk_area_info
129129
tfm_plat_otp_init
130130
tfm_plat_increment_nv_counter
131131
rse_count_zero_bits
132+
rse_get_sender_routing_tables
133+
rse_get_receiver_routing_tables

platform/ext/target/arm/rse/common/platform_error_codes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ enum tfm_plat_err_t {
166166
/* RSE zero count error codes */
167167
TFM_PLAT_ERR_ZERO_COUNT_MISMATCH,
168168
TFM_PLAT_ERR_ZERO_COUNT_INVALID_ARGUMENT,
169+
/* Routing tables errors */
170+
TFM_PLAT_ERR_SEND_ROUTING_TABLES_INVALID_SIZE,
171+
TFM_PLAT_ERR_RECEIVE_ROUTING_TABLES_INVALID_SIZE,
169172
/* Generic errors */
170173
TFM_PLAT_ERR_SYSTEM_ERR,
171174
TFM_PLAT_ERR_MAX_VALUE,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#include <stdint.h>
9+
#include <stddef.h>
10+
#include <string.h>
11+
12+
#include "platform_error_codes.h"
13+
#include "rse_routing_tables.h"
14+
#include "rse_get_routing_tables.h"
15+
#include "tfm_plat_otp.h"
16+
17+
#define SENDER_ROUTING_TABLES_SIZE ((NUM_NODES) * sizeof(uint8_t))
18+
#define RECEIVE_ROUTING_TABLES_SIZE ((NUM_NODES) * sizeof(uint8_t))
19+
20+
#ifndef RSE_OTP_HAS_ROUTING_TABLES
21+
extern struct rse_whole_system_routing_tables_t rse_system_routing_tables;
22+
#endif
23+
24+
enum tfm_plat_err_t rse_get_sender_routing_tables(uint8_t *routing_tables_buf, size_t buf_size,
25+
uint32_t rse_id)
26+
{
27+
if (buf_size < SENDER_ROUTING_TABLES_SIZE) {
28+
return TFM_PLAT_ERR_SEND_ROUTING_TABLES_INVALID_SIZE;
29+
}
30+
31+
#ifdef RSE_OTP_HAS_ROUTING_TABLES
32+
enum tfm_plat_err_t plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_TO_RSE_SENDER_ROUTING_TABLE,
33+
buf_size, routing_tables_buf);
34+
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
35+
return plat_err;
36+
}
37+
#else
38+
memcpy(routing_tables_buf, rse_system_routing_tables.routing_table[rse_id].send,
39+
SENDER_ROUTING_TABLES_SIZE);
40+
#endif
41+
42+
return TFM_PLAT_ERR_SUCCESS;
43+
}
44+
45+
enum tfm_plat_err_t rse_get_receiver_routing_tables(uint8_t *routing_tables_buf, size_t buf_size,
46+
uint32_t rse_id)
47+
{
48+
if (buf_size < RECEIVE_ROUTING_TABLES_SIZE) {
49+
return TFM_PLAT_ERR_RECEIVE_ROUTING_TABLES_INVALID_SIZE;
50+
}
51+
52+
#ifdef RSE_OTP_HAS_ROUTING_TABLES
53+
enum tfm_plat_err_t plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_TO_RSE_RECEIVER_ROUTING_TABLE,
54+
buf_size, routing_tables_buf);
55+
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
56+
return plat_err;
57+
}
58+
#else
59+
memcpy(routing_tables_buf, rse_system_routing_tables.routing_table[rse_id].receive,
60+
RECEIVE_ROUTING_TABLES_SIZE);
61+
#endif
62+
63+
return TFM_PLAT_ERR_SUCCESS;
64+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef __RSE_GET_ROUTING_TABLES_H__
9+
#define __RSE_GET_ROUTING_TABLES_H__
10+
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* \brief Retrieves the sender routing tables associated with a given RSE.
20+
*
21+
* This function populates the provided buffer with the sender routing table entries for the specified
22+
* RSE identifier. The number of entries returned is limited by the size of the buffer.
23+
*
24+
* \param[out] routing_tables_buf Pointer to a buffer where the routing table entries will be stored.
25+
* \param[in] buf_size Size of the buffer in bytes.
26+
* \param[in] rse_id Identifier for the RSE whose sender routing tables are to be retrieved.
27+
*
28+
* \return Returns a tfm_plat_err_t indicating success or failure.
29+
*/
30+
enum tfm_plat_err_t rse_get_sender_routing_tables(uint8_t *routing_tables_buf, size_t buf_size,
31+
uint32_t rse_id);
32+
33+
/**
34+
* \brief Retrieves the receiver routing tables associated with a given RSE.
35+
*
36+
* This function populates the provided buffer with the receiver routing table entries for the specified
37+
* RSE identifier. The number of entries returned is limited by the size of the buffer.
38+
*
39+
* \param[out] routing_tables_buf Pointer to a buffer where the routing table entries will be stored.
40+
* \param[in] buf_size Size of the buffer in bytes.
41+
* \param[in] rse_id Identifier for the RSE whose receiver routing tables are to be retrieved.
42+
*
43+
* \return Returns a tfm_plat_err_t indicating success or failure.
44+
*/
45+
enum tfm_plat_err_t rse_get_receiver_routing_tables(uint8_t *routing_tables_buf, size_t buf_size,
46+
uint32_t rse_id);
47+
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
52+
#endif /* __RSE_GET_ROUTING_TABLES_H__ */

platform/ext/target/arm/rse/common/rse_handshake/rse_handshake.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "cmsis.h"
2828
#include "dpa_hardened_word_copy.h"
2929
#include "rse_routing_tables.h"
30+
#include "rse_get_routing_tables.h"
3031

3132
#include <string.h>
3233

@@ -36,8 +37,8 @@
3637
#define VHUK_SEED_SIZE 32
3738
#define VHUK_SEED_WORD_SIZE 8
3839

39-
uint32_t sending_mhu[RSE_AMOUNT];
40-
uint32_t receiving_mhu[RSE_AMOUNT];
40+
uint8_t sending_mhu[RSE_AMOUNT];
41+
uint8_t receiving_mhu[RSE_AMOUNT];
4142

4243
enum rse_handshake_msg_type {
4344
RSE_HANDSHAKE_SESSION_KEY_MSG,
@@ -511,27 +512,20 @@ static enum tfm_plat_err_t rse_handshake_server(uint32_t *vhuk_seeds_buf)
511512

512513
enum tfm_plat_err_t rse_handshake(uint32_t *vhuk_seeds_buf)
513514
{
514-
#ifndef RSE_OTP_HAS_ROUTING_TABLES
515-
/* The handshake can't be supported without routing tables in OTP */
516-
return TFM_PLAT_ERR_UNSUPPORTED;
517-
#else
518515
uint32_t rse_id;
519516
enum tfm_plat_err_t plat_err;
520517

521-
plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_TO_RSE_SENDER_ROUTING_TABLE,
522-
sizeof(sending_mhu), (uint8_t *)sending_mhu);
518+
plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_ID, sizeof(rse_id), (uint8_t *)&rse_id);
523519
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
524520
return plat_err;
525521
}
526522

527-
plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_TO_RSE_RECEIVER_ROUTING_TABLE,
528-
sizeof(receiving_mhu), (uint8_t *)receiving_mhu);
523+
plat_err = rse_get_sender_routing_tables(sending_mhu, sizeof(sending_mhu), rse_id);
529524
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
530525
return plat_err;
531526
}
532527

533-
plat_err = tfm_plat_otp_read(PLAT_OTP_ID_RSE_ID, sizeof(rse_id),
534-
(uint8_t*)&rse_id);
528+
plat_err = rse_get_receiver_routing_tables(receiving_mhu, sizeof(receiving_mhu), rse_id);
535529
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
536530
return plat_err;
537531
}
@@ -545,5 +539,4 @@ enum tfm_plat_err_t rse_handshake(uint32_t *vhuk_seeds_buf)
545539
} else {
546540
return rse_handshake_client(rse_id, vhuk_seeds_buf);
547541
}
548-
#endif /* RSE_OTP_HAS_ROUTING_TABLES */
549542
}

0 commit comments

Comments
 (0)