Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
82ccd1e
Revert "[nrf noup] settings: zms: use dedicated lookup cache hash fun…
rghaddab Feb 19, 2025
dd235e5
Revert "[nrf fromlist] settings: ZMS: add a backend for ZMS (Zephyr M…
rghaddab Feb 19, 2025
860da44
[nrf fromtree] settings: ZMS: add a backend for ZMS (Zephyr Memory St…
rghaddab Sep 17, 2024
6affc2a
[nrf fromtree] tests: settings: Performance test for settings
omkar3141 Oct 23, 2024
1ee81c6
[nrf fromtree] fs: zms: multiple style fixes from previous PR review
rghaddab Oct 30, 2024
04dc9c3
[nrf fromtree] samples/subsys/fs/zms: run on native_sim instead of na…
aescolar Feb 25, 2025
347c8ef
[nrf fromtree] samples/subsys/fs/zms: Allow it to run and add check
aescolar Feb 25, 2025
bad257b
[nrf fromtree] sample: zms: add ZMS sample Kconfig
butok Feb 25, 2025
4134baf
[nrf fromtree] samples: zms: fix the loop_cnt iteration 0 check
butok Mar 3, 2025
3b68dd8
[nrf fromtree] settings: zms: fix some bugs related to the name's ID
rghaddab Feb 22, 2025
fbacc76
[nrf fromtree] doc: settings: add reference to ZMS backend
rghaddab Feb 22, 2025
b975c2c
[nrf fromtree] tests: zms: allow to build & run on real platforms
butok Feb 26, 2025
1bb29eb
[nrf fromtree] samples: zms: fix 9999 messages dropped
butok Mar 4, 2025
66f838a
[nrf fromlist] settings: zms: add option to disable updating linked list
rghaddab Feb 27, 2025
1582ac7
[nrf fromlist] zms: remove non needed lookup cache before writing
rghaddab Mar 7, 2025
71c548e
[nrf fromlist] zms: optimize cache for settings subsystem
rghaddab Mar 7, 2025
60cc271
[nrf fromlist] settings: zms: load only subtree in the argument
rghaddab Mar 11, 2025
de45a63
[nrf fromlist] settings: zms: add cache for linked list hash
rghaddab Mar 13, 2025
3b747c5
[nrf fromlist] settings: add an API function to load only one setting…
rghaddab Mar 18, 2025
b5fceed
[nrf fromlist] tests: settings: add a functional test for settings_lo…
rghaddab Mar 24, 2025
6f7b016
[nrf fromlist] tests: settings: add functional test for ZMS
rghaddab Mar 24, 2025
69fe25b
[nrf fromlist] settings: zms: add more robustness to the save function
rghaddab Mar 18, 2025
7100cec
[nrf fromlist] settings: zms: recover linked list if broken
rghaddab Mar 18, 2025
9aa0067
[nrf fromlist] settings: add new API function settings_get_val_len()
rghaddab Mar 25, 2025
e1cf30f
[nrf fromlist] settings: zms: use the safe function strnlen instead o…
rghaddab Mar 20, 2025
10f199a
[nrf fromlist] doc: settings: new API functions
rghaddab Mar 27, 2025
a08cf11
[nrf fromlist] settings: zms: code style clean up
rghaddab Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions doc/services/settings/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Settings

The settings subsystem gives modules a way to store persistent per-device
configuration and runtime state. A variety of storage implementations are
provided behind a common API using FCB, NVS, or a file system. These different
implementations give the application developer flexibility to select an
appropriate storage medium, and even change it later as needs change. This
provided behind a common API using FCB, NVS, ZMS or a file system. These
different implementations give the application developer flexibility to select
an appropriate storage medium, and even change it later as needs change. This
subsystem is used by various Zephyr components and can be used simultaneously by
user applications.

Expand All @@ -23,8 +23,8 @@ For an example of the settings subsystem refer to :zephyr:code-sample:`settings`

.. note::

As of Zephyr release 2.1 the recommended backend for non-filesystem
storage is :ref:`NVS <nvs_api>`.
As of Zephyr release 4.1 the recommended backends for non-filesystem
storage are :ref:`NVS <nvs_api>` and :ref:`ZMS <zms_api>`.

Handlers
********
Expand All @@ -39,7 +39,7 @@ for static handlers.
:c:func:`settings_runtime_get()` from the runtime backend.

**h_set**
This gets called when the value is loaded from persisted storage with
This gets called when the value is loaded from persistent storage with
:c:func:`settings_load()`, or when using :c:func:`settings_runtime_set()` from the
runtime backend.

Expand Down Expand Up @@ -78,6 +78,14 @@ backend.
This gets called when loading values from persistent storage using
:c:func:`settings_load()`.

**csi_load_one**
This gets called when loading only one item from persistent storage using
:c:func:`settings_load_one()`.

**csi_get_val_len**
This gets called when getting a value's length from persistent storage using
:c:func:`settings_get_val_len()`.

**csi_save**
This gets called when saving a single setting to persistent storage using
:c:func:`settings_save_one()`.
Expand All @@ -93,10 +101,12 @@ backend.
Zephyr Storage Backends
***********************

Zephyr has three storage backends: a Flash Circular Buffer
(:kconfig:option:`CONFIG_SETTINGS_FCB`), a file in the filesystem
(:kconfig:option:`CONFIG_SETTINGS_FILE`), or non-volatile storage
(:kconfig:option:`CONFIG_SETTINGS_NVS`).
Zephyr offers the following storage backends:

* Flash Circular Buffer (:kconfig:option:`CONFIG_SETTINGS_FCB`).
* A file in the filesystem (:kconfig:option:`CONFIG_SETTINGS_FILE`).
* Non-Volatile Storage (:kconfig:option:`CONFIG_SETTINGS_NVS`).
* Zephyr Memory Storage (:kconfig:option:`CONFIG_SETTINGS_ZMS`).

You can declare multiple sources for settings; settings from
all of these are restored when :c:func:`settings_load()` is called.
Expand All @@ -109,30 +119,49 @@ using :c:func:`settings_fcb_dst()`. As a side-effect, :c:func:`settings_fcb_src
initializes the FCB area, so it must be called before calling
:c:func:`settings_fcb_dst()`. File read target is registered using
:c:func:`settings_file_src()`, and write target by using :c:func:`settings_file_dst()`.

Non-volatile storage read target is registered using
:c:func:`settings_nvs_src()`, and write target by using
:c:func:`settings_nvs_dst()`.

Zephyr Memory Storage (ZMS) read target is registered using :c:func:`settings_zms_src()`,
and write target is registered using :c:func:`settings_zms_dst()`.

ZMS backend has the particularity of using hash functions to hash the settings
key before storing it to the persistent storage. This implementation implies
that some collisions between key's hashes could occur if a big number of
different keys are stored. This number depends on the selected hash function.

ZMS backend can handle :math:`2^n` maximum collisions where n is defined by
(:kconfig:option:`SETTINGS_ZMS_MAX_COLLISIONS_BITS`).


Storage Location
****************

The FCB and non-volatile storage (NVS) backends both look for a fixed
The FCB, non-volatile storage (NVS) and ZMS backends look for a fixed
partition with label "storage" by default. A different partition can be
selected by setting the ``zephyr,settings-partition`` property of the
chosen node in the devicetree.

The file path used by the file backend to store settings is selected via the
option :kconfig:option:`CONFIG_SETTINGS_FILE_PATH`.

Loading data from persisted storage
***********************************
Loading data from persistent storage
************************************

A call to :c:func:`settings_load()` uses an ``h_set`` implementation
to load settings data from storage to volatile memory.
After all data is loaded, the ``h_commit`` handler is issued,
signalling the application that the settings were successfully
retrieved.

Alternatively, a call to :c:func:`settings_load_one()` will load only one
Settings entry and store it in the provided buffer.

To get the value's length associated with the Settings entry, a call to
:c:func:`settings_get_val_len()` should be performed

Technically FCB and file backends may store some history of the entities.
This means that the newest data entity is stored after any
older existing data entities.
Expand All @@ -146,7 +175,7 @@ A call to :c:func:`settings_save_one()` uses a backend implementation to store
settings data to the storage medium. A call to :c:func:`settings_save()` uses an
``h_export`` implementation to store different data in one operation using
:c:func:`settings_save_one()`.
A key need to be covered by a ``h_export`` only if it is supposed to be stored
A key needs to be covered by a ``h_export`` only if it is supposed to be stored
by :c:func:`settings_save()` call.

For both FCB and file back-end only storage requests with data which
Expand Down Expand Up @@ -227,7 +256,7 @@ Example: Persist Runtime State

This is a simple example showing how to persist runtime state. In this example,
only ``h_set`` is defined, which is used when restoring value from
persisted storage.
persistent storage.

In this example, the ``main`` function increments ``foo_val``, and then
persists the latest number. When the system restarts, the application calls
Expand Down
Loading