This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can NVS be used with TF-M?

Hi,

I tried to run a quick test to see if NVS functionality works out of the box when adding it to the tfm_ipc sample in Zephyr and it seems that my call to nvs_init hangs. Is NVS supported when using TF-M? It might also be that my NVS configuration is not correct. I've put the diff of my changes to the tfm_ipc sample below. The board used is nrf9160 DK and the sdk-zephyr revision is v2.6.0-rc1-ncs1.

diff --git a/samples/tfm_integration/tfm_ipc/prj.conf b/samples/tfm_integration/tfm_ipc/prj.conf
index 0abedb7153..7656aecd40 100644
--- a/samples/tfm_integration/tfm_ipc/prj.conf
+++ b/samples/tfm_integration/tfm_ipc/prj.conf
@@ -8,3 +8,8 @@ CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
 
 CONFIG_MAIN_STACK_SIZE=4096
 CONFIG_HEAP_MEM_POOL_SIZE=4096
+
+CONFIG_FLASH=y
+CONFIG_FLASH_PAGE_LAYOUT=y
+CONFIG_MPU_ALLOW_FLASH_WRITE=y
+CONFIG_NVS=y
diff --git a/samples/tfm_integration/tfm_ipc/src/main.c b/samples/tfm_integration/tfm_ipc/src/main.c
index d0fdb29c6b..dabcf12b0b 100644
--- a/samples/tfm_integration/tfm_ipc/src/main.c
+++ b/samples/tfm_integration/tfm_ipc/src/main.c
@@ -176,6 +176,21 @@ static void tfm_ipc_test_1006(void)
        psa_close(handle);
 }
 
+#include <fs/nvs.h>
+
+/* Multiple of FLASH_PAGE_SIZE */
+#define NVS_SECTOR_SIZE DT_PROP(DT_CHOSEN(zephyr_flash), erase_block_size)
+/* At least 2 sectors */
+#define NVS_SECTOR_COUNT 3
+/* Start address of the filesystem in flash */
+#define NVS_STORAGE_OFFSET DT_REG_ADDR(DT_NODE_BY_FIXED_PARTITION_LABEL(storage))
+
+static struct nvs_fs fs = {
+       .sector_size = NVS_SECTOR_SIZE,
+       .sector_count = NVS_SECTOR_COUNT,
+       .offset = NVS_STORAGE_OFFSET,
+};
+
 void main(void)
 {
        tfm_ipc_test_1001();
@@ -187,6 +202,10 @@ void main(void)
 
        printk("TF-M IPC on %s\n", CONFIG_BOARD);
 
+       printk("NVS init\n");
+       nvs_init(&fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
+       printk("NVS init done\n");
+
        k_sleep(K_MSEC(5000));
        sys_reboot(0);
 }

Related