Skip to content

Commit 06eb147

Browse files
dssengfabiobaltieri
authored andcommitted
settings: tfm_psa: rename from its
Prepare for extending this backend to also allow storing settings in the PS (Protected Storage). Mostly file and kconfig renames, as well as updates to comments and log messages. Signed-off-by: Dmitrii Sharshakov <[email protected]>
1 parent 8fa52bf commit 06eb147

File tree

15 files changed

+77
-71
lines changed

15 files changed

+77
-71
lines changed

include/zephyr/psa/its_ids.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
#ifndef ZEPHYR_ITS_IDS_H_
7-
#define ZEPHYR_ITS_IDS_H_
6+
#ifndef ZEPHYR_PSA_ITS_IDS_H_
7+
#define ZEPHYR_PSA_ITS_IDS_H_
88

9-
/** UID range to be used by the TF-M ITS Settings backend. */
9+
/** UID range to be used by the TF-M PSA ITS Settings backend. */
1010
#define ZEPHYR_PSA_SETTINGS_TFM_ITS_UID_RANGE_BEGIN 0x28000000
1111
#define ZEPHYR_PSA_SETTINGS_TFM_ITS_UID_RANGE_SIZE 0x10000 /* 64 Ki */
1212

13-
#endif /* ZEPHYR_ITS_IDS_H_ */
13+
#endif /* ZEPHYR_PSA_ITS_IDS_H_ */

samples/subsys/settings/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ tests:
6363
integration_platforms:
6464
- mps2/an521/cpu0/ns
6565
extra_args:
66-
- CONFIG_SETTINGS_TFM_ITS=y
66+
- CONFIG_SETTINGS_TFM_PSA=y

subsys/settings/Kconfig

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,19 @@ config SETTINGS_CUSTOM
143143
help
144144
Use a custom settings storage back-end.
145145

146-
config SETTINGS_TFM_ITS
147-
bool "Internal Trusted Storage (ITS) settings backend"
146+
config SETTINGS_TFM_PSA
147+
bool "TF-M PSA"
148148
depends on TFM_PARTITION_INTERNAL_TRUSTED_STORAGE
149149
select EXPERIMENTAL
150150
help
151-
Enables Internal Trusted Storage (ITS) Settings backend. Intended for use with boards
151+
Enables PSA Settings backend. Intended for use with boards
152152
using TF-M which cannot make use of persistent storage otherwise.
153-
Note: This settings backend compacts settings data into as few ITS nodes as possible.
154-
On every save, the entire settings array is written to ITS.
153+
This backend uses the PSA Internal Trusted Storage (ITS) service to store settings data.
154+
Note: This settings backend compacts settings data into as few secure storage nodes as possible.
155+
After each save, the entire settings array is written to the secure storage. To avoid excessive
156+
latency on saving, settings are saved after a delay using a kernel work item.
155157
Note: With this backend, all settings are kept in RAM at all times. The RAM consumption
156-
is controlled by the SETTINGS_TFM_ITS_NUM_ENTRIES Kconfig option.
158+
is controlled by the SETTINGS_TFM_PSA_NUM_ENTRIES Kconfig option.
157159

158160
config SETTINGS_NONE
159161
bool "NONE"
@@ -265,28 +267,28 @@ config SETTINGS_SHELL
265267
size of the shell thread may need to be increased to accommodate this
266268
feature.
267269

268-
if SETTINGS_TFM_ITS
270+
if SETTINGS_TFM_PSA
269271

270-
config SETTINGS_TFM_ITS_NUM_ENTRIES
272+
config SETTINGS_TFM_PSA_NUM_ENTRIES
271273
int "Maximum number of settings entries"
272274
default 10
273275
help
274276
Configures the maximum number of settings that can be stored simultaneously.
275277
Note: This value determines the size of a statically-allocated buffer which holds
276278
all the settings entries in RAM at all times.
277279

278-
config SETTINGS_TFM_ITS_LAZY_PERSIST_DELAY_MS
280+
config SETTINGS_TFM_PSA_LAZY_PERSIST_DELAY_MS
279281
int "Milliseconds delay before persisting settings"
280282
default 500
281283
help
282-
ITS may block for a long period of time when writing to flash, which may be
284+
PSA Secure Storage APIs may block for a long period of time when writing to flash, which may be
283285
unacceptable for time-sensitive events.
284-
Data is always persisted to ITS using k_work_delayable, instead of happening in
285-
the same context as settings_its_save. This option sets the delay with which the
286+
Data is always persisted to the secure storage using k_work_delayable, instead of happening in
287+
the same context as settings_save. This option sets the delay with which the
286288
work item is scheduled. The delay is useful in cases where a PSA ITS write may
287-
block a time-sensitive event, Bluetooth pairing for example, which requires a
289+
block a time-sensitive event, for example Bluetooth pairing, which requires a
288290
sequence of settings writes.
289291

290-
endif # SETTINGS_TFM_ITS
292+
endif # SETTINGS_TFM_PSA
291293

292294
endif # SETTINGS

subsys/settings/src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ zephyr_sources_ifdef(CONFIG_SETTINGS_NVS settings_nvs.c)
1414
zephyr_sources_ifdef(CONFIG_SETTINGS_NONE settings_none.c)
1515
zephyr_sources_ifdef(CONFIG_SETTINGS_SHELL settings_shell.c)
1616
zephyr_sources_ifdef(CONFIG_SETTINGS_ZMS settings_zms.c)
17-
zephyr_sources_ifdef(CONFIG_SETTINGS_TFM_ITS settings_its.c)
18-
zephyr_library_link_libraries_ifdef(CONFIG_SETTINGS_TFM_ITS tfm_api)
17+
if(CONFIG_SETTINGS_TFM_PSA)
18+
zephyr_sources(settings_tfm_psa.c)
19+
zephyr_library_link_libraries(tfm_api)
20+
endif()
1921
zephyr_sources_ifdef(CONFIG_SETTINGS_RETENTION settings_retention.c)
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@
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

2020
LOG_MODULE_DECLARE(settings, CONFIG_SETTINGS_LOG_LEVEL);
2121

2222
K_MUTEX_DEFINE(worker_mutex);
2323
static 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];
2626
static 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

4344
static 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

File renamed without changes.

tests/subsys/settings/functional/src/settings_basic_test.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ LOG_MODULE_REGISTER(settings_basic_test);
2424
#elif defined(CONFIG_SETTINGS_FILE)
2525
#include <zephyr/fs/fs.h>
2626
#include <zephyr/fs/littlefs.h>
27-
#elif defined(CONFIG_SETTINGS_TFM_ITS)
27+
#elif defined(CONFIG_SETTINGS_TFM_PSA)
28+
2829
#include <psa/internal_trusted_storage.h>
2930
#include <zephyr/psa/its_ids.h>
3031
/* TF-M config file containing ITS_MAX_ASSET_SIZE */
3132
#include <config_base.h>
3233

33-
#include <settings_its_priv.h>
34+
#include <settings_tfm_psa_priv.h>
3435
#else
3536
#error "Settings backend not selected"
3637
#endif
@@ -45,14 +46,14 @@ LOG_MODULE_REGISTER(settings_basic_test);
4546
*/
4647
ZTEST(settings_functional, test_clear_settings)
4748
{
48-
#if defined(CONFIG_SETTINGS_TFM_ITS)
49+
#if defined(CONFIG_SETTINGS_TFM_PSA)
4950
psa_status_t status;
5051

5152
/* Remove all potentially accessed ITS entries in the UID range */
52-
for (int i = 0; i < sizeof(struct setting_entry) * CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES /
53+
for (int i = 0; i < sizeof(struct setting_entry) * CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES /
5354
ITS_MAX_ASSET_SIZE + 1; i++) {
5455
status = psa_its_remove(ZEPHYR_PSA_SETTINGS_TFM_ITS_UID_RANGE_BEGIN + i);
55-
zassert_true(status == PSA_SUCCESS || status == PSA_ERROR_DOES_NOT_EXIST,
56+
zassert_true((status == PSA_SUCCESS) || (status == PSA_ERROR_DOES_NOT_EXIST),
5657
"psa_its_remove failed");
5758
}
5859
#elif !defined(CONFIG_SETTINGS_FILE)

tests/subsys/settings/functional/tfm_psa/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ CONFIG_ZTEST=y
33
CONFIG_SETTINGS=y
44

55
# 10 is not sufficient for the test
6-
CONFIG_SETTINGS_TFM_ITS_NUM_ENTRIES=11
6+
CONFIG_SETTINGS_TFM_PSA_NUM_ENTRIES=11

tests/subsys/settings/functional/tfm_psa/testcase.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ tests:
1313
- settings
1414
- trusted-firmware-m
1515
extra_args:
16-
- CONFIG_SETTINGS_TFM_ITS=y
16+
- CONFIG_SETTINGS_TFM_PSA=y

tests/subsys/settings/its/CMakeLists.txt renamed to tests/subsys/settings/tfm_psa/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
cmake_minimum_required(VERSION 3.20.0)
66
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7-
project(test_settings_its_raw)
7+
project(test_settings_psa)
88

9-
add_subdirectory(./src its_test_bindir)
9+
add_subdirectory(./src psa_test_bindir)

0 commit comments

Comments
 (0)