Skip to content

Commit e82cea5

Browse files
committed
[nrf fromlist] samples: fs: zms: add a sample app for ZMS storage system
This adds a user application that shows the usage of ZMS The sample app shows three main functions of ZMS: - read/write/delete key/value pairs - fill all storage and delete it - calculate free remaining space Upstream PR: zephyrproject-rtos/zephyr#77930 Signed-off-by: Riadh Ghaddab <[email protected]> (cherry picked from commit 2ea214337f24795c40ddaf5282771dc317c96efb)
1 parent 951f097 commit e82cea5

File tree

5 files changed

+400
-0
lines changed

5 files changed

+400
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(zms)
7+
8+
9+
target_sources(app PRIVATE src/main.c)
10+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs/zms)

samples/subsys/fs/zms/README.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. zephyr:code-sample:: zms
2+
:name: Zephyr Memory Storage (ZMS)
3+
:relevant-api: zms_high_level_api
4+
5+
Store and retrieve data from storage using the ZMS API.
6+
7+
Overview
8+
********
9+
The sample shows how to use ZMS to store ID/VALUE pairs and reads them back.
10+
Deleting an ID/VALE pair is also shown in this sample.
11+
12+
The sample stores the following items:
13+
1- A string representing an IP-address: stored at id=1, data="192.168.1.1"
14+
2- A binary blob representing a key/value pair: stored at id=0xbeefdead,
15+
data={0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}
16+
3- A variable (32bit): stored at id=2, data=cnt
17+
4- A long set of data (128 bytes)
18+
A loop is executed where we mount the storage system, and then write all set
19+
of data.
20+
Each DELETE_ITERATION period, we delete all set of data and verify that it has been deleted.
21+
We generate as well incremented ID/value pairs, we store them until storage is full, then we
22+
delete them and verify that storage is empty.
23+
24+
Requirements
25+
************
26+
27+
* A board with flash support or native_sim target
28+
29+
Building and Running
30+
********************
31+
32+
This sample can be found under :zephyr_file:`samples/subsys/fs/zms` in the Zephyr tree.
33+
34+
The sample can be built for several platforms, but for the moment it has been tested only
35+
on native_sim target
36+
37+
.. zephyr-app-commands::
38+
:zephyr-app: samples/subsys/fs/zms
39+
:goals: build
40+
:compact:
41+
42+
After running the generated image on a native_sim target, the output on the console shows the
43+
multiple Iterations of read/write/delete exectuted.
44+
45+
Sample Output
46+
=============
47+
48+
.. code-block:: console
49+
50+
*** Booting Zephyr OS build v3.7.0-2383-g624f75400242 ***
51+
[00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
52+
[00:00:00.000,000] <inf> fs_zms: alloc wra: 0, fc0
53+
[00:00:00.000,000] <inf> fs_zms: data wra: 0, 0
54+
ITERATION: 0
55+
Adding IP_ADDRESS 172.16.254.1 at id 1
56+
Adding key/value at id beefdead
57+
Adding counter at id 2
58+
Adding Longarray at id 3
59+
[00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
60+
[00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f80
61+
[00:00:00.000,000] <inf> fs_zms: data wra: 0, 8c
62+
ITERATION: 1
63+
ID: 1, IP Address: 172.16.254.1
64+
Adding IP_ADDRESS 172.16.254.1 at id 1
65+
Id: beefdead, Key: de ad be ef de ad be ef
66+
Adding key/value at id beefdead
67+
Id: 2, loop_cnt: 0
68+
Adding counter at id 2
69+
Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5
70+
4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
71+
Adding Longarray at id 3
72+
.
73+
.
74+
.
75+
.
76+
.
77+
.
78+
[00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
79+
[00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f40
80+
[00:00:00.000,000] <inf> fs_zms: data wra: 0, 80
81+
ITERATION: 299
82+
ID: 1, IP Address: 172.16.254.1
83+
Adding IP_ADDRESS 172.16.254.1 at id 1
84+
Id: beefdead, Key: de ad be ef de ad be ef
85+
Adding key/value at id beefdead
86+
Id: 2, loop_cnt: 298
87+
Adding counter at id 2
88+
Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5
89+
4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
90+
Adding Longarray at id 3
91+
Memory is full let's delete all items
92+
Free space in storage is 8064 bytes
93+
Sample code finished Successfully

samples/subsys/fs/zms/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_FLASH=y
2+
CONFIG_FLASH_MAP=y
3+
4+
CONFIG_ZMS=y
5+
CONFIG_LOG=y

samples/subsys/fs/zms/sample.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sample:
2+
name: ZMS Sample
3+
4+
tests:
5+
sample.zms.basic:
6+
tags: zms
7+
depends_on: zms
8+
platform_allow:
9+
- qemu_x86
10+
- native_posix

0 commit comments

Comments
 (0)