1515/* TF-M config file containing ITS_MAX_ASSET_SIZE */
1616#include <config_base.h>
1717
18- #include "settings_its_priv .h"
18+ #include "settings_tfm_psa_priv .h"
1919
2020LOG_MODULE_DECLARE (settings , CONFIG_SETTINGS_LOG_LEVEL );
2121
2222K_MUTEX_DEFINE (worker_mutex );
2323static struct k_work_delayable worker ;
2424
25- static struct setting_entry entries [CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES ];
25+ static struct setting_entry entries [CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES ];
2626static int entries_count ;
2727
28- static int settings_its_load (struct settings_store * cs , const struct settings_load_arg * arg );
29- static int settings_its_save (struct settings_store * cs , const char * name , const char * value ,
28+ static int settings_psa_load (struct settings_store * cs , const struct settings_load_arg * arg );
29+ static int settings_psa_save (struct settings_store * cs , const char * name , const char * value ,
3030 size_t val_len );
3131
32- static const struct settings_store_itf settings_its_itf = {
33- .csi_load = settings_its_load ,
34- .csi_save = settings_its_save ,
32+ static const struct settings_store_itf settings_psa_itf = {
33+ .csi_load = settings_psa_load ,
34+ .csi_save = settings_psa_save ,
3535};
3636
37- static struct settings_store default_settings_its = {.cs_itf = & settings_its_itf };
37+ static struct settings_store default_settings_psa = {.cs_itf = & settings_psa_itf };
3838
3939/* Ensure Key configured max size does not exceed reserved Key range */
40- BUILD_ASSERT (sizeof (entries ) / ITS_MAX_ASSET_SIZE <= ZEPHYR_PSA_SETTINGS_TFM_ITS_UID_RANGE_SIZE ,
40+ BUILD_ASSERT (sizeof (entries ) / ITS_MAX_ASSET_SIZE <=
41+ ZEPHYR_PSA_SETTINGS_TFM_ITS_UID_RANGE_BEGIN ,
4142 "entries array exceeds reserved ITS UID range" );
4243
4344static int store_entries (void )
@@ -49,9 +50,9 @@ static int store_entries(void)
4950 const uint8_t * data_ptr = (const uint8_t * )& entries ;
5051
5152 /*
52- * Each ITS UID is treated like a sector. Data is written to each ITS node until
53- * that node is full, before incrementing the UID. This is done to minimize the
54- * number of allocated ITS nodes and to avoid wasting allocated bytes .
53+ * Each storage UID is treated like a sector. Data is written to each KV pair until
54+ * that data field is full, before incrementing the UID. This is done to minimize the
55+ * number of allocated UIDs and to allocate bytes in the most efficient way .
5556 */
5657 while (remaining > 0 ) {
5758 size_t write_size = (remaining > chunk_size ) ? chunk_size : remaining ;
@@ -69,7 +70,7 @@ static int store_entries(void)
6970 uid ++ ;
7071 }
7172
72- LOG_DBG ("ITS entries stored successfully - bytes_saved: %d num_entries: %d max_uid: %lld" ,
73+ LOG_DBG ("PSA storage entries stored successfully - bytes_saved: %d num_entries: %d max_uid: %lld" ,
7374 sizeof (entries ), entries_count , uid );
7475
7576 return 0 ;
@@ -85,9 +86,9 @@ static int load_entries(void)
8586 uint8_t * data_ptr = (uint8_t * )& entries ;
8687
8788 /*
88- * Each ITS UID is treated like a sector. Data is written to each ITS node until
89- * that node is full, before incrementing the UID. This is done to minimize the
90- * number of allocated ITS nodes and to avoid wasting allocated bytes .
89+ * Each storage UID is treated like a sector. Data is written to each KV pair until
90+ * that data field is full, before incrementing the UID. This is done to minimize the
91+ * number of allocated UIDs and to allocate bytes in the most efficient way .
9192 */
9293 while (remaining > 0 ) {
9394 size_t to_read = (remaining > chunk_size ) ? chunk_size : remaining ;
@@ -102,27 +103,27 @@ static int load_entries(void)
102103 uid ++ ;
103104 }
104105
105- for (int i = 0 ; i < CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES ; i ++ ) {
106+ for (int i = 0 ; i < CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES ; i ++ ) {
106107 if (strnlen (entries [i ].name , SETTINGS_MAX_NAME_LEN ) != 0 ) {
107108 entries_count ++ ;
108109 }
109110 }
110111
111- LOG_DBG ("ITS entries restored successfully - bytes_loaded: %d, num_entries: %d" ,
112+ LOG_DBG ("PSA storage entries restored successfully - bytes_loaded: %d, num_entries: %d" ,
112113 sizeof (entries ), entries_count );
113114
114115 return 0 ;
115116}
116117
117118/* void *back_end is the index of the entry in metadata entries struct */
118- static ssize_t settings_its_read_fn (void * back_end , void * data , size_t len )
119+ static ssize_t settings_psa_read_fn (void * back_end , void * data , size_t len )
119120{
120121 int index = * (int * )back_end ;
121122
122- LOG_DBG ("ITS Read - index: %d" , index );
123+ LOG_DBG ("reading index: %d" , index );
123124
124- if (index < 0 || index >= CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES ) {
125- LOG_ERR ("Invalid index %d in ITS metadata" , index );
125+ if (index < 0 || index >= CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES ) {
126+ LOG_ERR ("Invalid index %d in metadata" , index );
126127 return 0 ;
127128 }
128129
@@ -134,7 +135,7 @@ static ssize_t settings_its_read_fn(void *back_end, void *data, size_t len)
134135 return entries [index ].val_len ;
135136}
136137
137- static int settings_its_load (struct settings_store * cs , const struct settings_load_arg * arg )
138+ static int settings_psa_load (struct settings_store * cs , const struct settings_load_arg * arg )
138139{
139140 int ret ;
140141
@@ -145,7 +146,7 @@ static int settings_its_load(struct settings_store *cs, const struct settings_lo
145146 * to be read during callback function later.
146147 */
147148 ret = settings_call_set_handler (entries [i ].name , entries [i ].val_len ,
148- settings_its_read_fn , (void * )& i ,
149+ settings_psa_read_fn , (void * )& i ,
149150 (void * )arg );
150151 if (ret ) {
151152 return ret ;
@@ -156,12 +157,12 @@ static int settings_its_load(struct settings_store *cs, const struct settings_lo
156157 return 0 ;
157158}
158159
159- static int settings_its_save (struct settings_store * cs , const char * name , const char * value ,
160+ static int settings_psa_save (struct settings_store * cs , const char * name , const char * value ,
160161 size_t val_len )
161162{
162- if (entries_count >= CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES ) {
163+ if (entries_count >= CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES ) {
163164 LOG_ERR ("%s: Max settings reached: %d" , __func__ ,
164- CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES );
165+ CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES );
165166 return - ENOMEM ;
166167 }
167168
@@ -183,7 +184,7 @@ static int settings_its_save(struct settings_store *cs, const char *name, const
183184 * Search metadata to see if entry already exists. Array is compacted, so first blank entry
184185 * signals end of settings.
185186 */
186- for (index = 0 ; index < CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES ; index ++ ) {
187+ for (index = 0 ; index < CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES ; index ++ ) {
187188 if (strncmp (entries [index ].name , name , SETTINGS_MAX_NAME_LEN ) == 0 ) {
188189 break ;
189190 } else if (entries [index ].val_len == 0 ) {
@@ -201,7 +202,7 @@ static int settings_its_save(struct settings_store *cs, const char *name, const
201202 }
202203 }
203204
204- LOG_DBG ("ITS Save - index %d: name %s, val_len %d" , index , name , val_len );
205+ LOG_DBG ("writing index %d: name %s, val_len %d" , index , name , val_len );
205206
206207 if (delete ) {
207208 /* Clear metadata */
@@ -226,7 +227,7 @@ static int settings_its_save(struct settings_store *cs, const char *name, const
226227 }
227228
228229 k_mutex_unlock (& worker_mutex );
229- k_work_schedule (& worker , K_MSEC (CONFIG_SETTINGS_TFM_ITS_LAZY_PERSIST_DELAY_MS ));
230+ k_work_schedule (& worker , K_MSEC (CONFIG_SETTINGS_TFM_PSA_LAZY_PERSIST_DELAY_MS ));
230231
231232 return 0 ;
232233}
@@ -242,7 +243,7 @@ int settings_backend_init(void)
242243{
243244 psa_status_t status ;
244245
245- /* Load ITS metadata */
246+ /* Load settings from storage */
246247 status = load_entries ();
247248
248249 /* If resource DNE, we need to allocate it */
@@ -257,8 +258,8 @@ int settings_backend_init(void)
257258 return - EIO ;
258259 }
259260
260- settings_dst_register (& default_settings_its );
261- settings_src_register (& default_settings_its );
261+ settings_dst_register (& default_settings_psa );
262+ settings_src_register (& default_settings_psa );
262263
263264 k_work_init_delayable (& worker , worker_persist_entries_struct_fn );
264265
0 commit comments