1# Copyright (c) 2018 Nordic Semiconductor ASA
2# Copyright (c) 2025 Analog Devices, Inc.
3# SPDX-License-Identifier: Apache-2.0
4
5menuconfig SETTINGS
6	bool "Settings"
7	help
8	  The settings subsystem allows its users to serialize and
9	  deserialize state in memory into and from non-volatile memory.
10	  It supports several back-ends to store and load serialized data from
11	  and it can do so atomically for all involved modules.
12
13if SETTINGS
14
15module = SETTINGS
16module-str = settings
17source "subsys/logging/Kconfig.template.log_config"
18
19config SETTINGS_RUNTIME
20	bool "runtime storage back-end"
21	help
22	  Enables runtime storage back-end.
23
24config SETTINGS_DYNAMIC_HANDLERS
25	bool "dynamic settings handlers"
26	default y
27	help
28	  Enables the use of dynamic settings handlers
29
30# Hidden option to enable encoding length into settings entry
31config SETTINGS_ENCODE_LEN
32	bool
33
34DT_CHOSEN_ZEPHYR_SETTINGS_PARTITION := zephyr,settings-partition
35DT_ZEPHYR_RETENTION := zephyr,retention
36
37config SETTINGS_SUPPORTED_RETENTION
38	bool
39	default y if RETENTION && $(dt_chosen_has_compat,$(DT_CHOSEN_ZEPHYR_SETTINGS_PARTITION),$(DT_ZEPHYR_RETENTION))
40
41choice SETTINGS_BACKEND
42	prompt "Storage back-end"
43	default SETTINGS_ZMS if ZMS
44	default SETTINGS_NVS if NVS
45	default SETTINGS_FCB if FCB
46	default SETTINGS_FILE if FILE_SYSTEM
47	default SETTINGS_TFM_ITS if TFM_PARTITION_INTERNAL_TRUSTED_STORAGE
48	default SETTINGS_RETENTION if SETTINGS_SUPPORTED_RETENTION
49	default SETTINGS_NONE
50	help
51	  Storage back-end to be used by the settings subsystem.
52
53config SETTINGS_ZMS
54	bool "ZMS (Zephyr Memory Storage)"
55	depends on ZMS
56	select SYS_HASH_FUNC32
57	help
58	  Use ZMS as settings storage backend.
59
60if SETTINGS_ZMS
61
62config SETTINGS_ZMS_LL_CACHE
63	bool "ZMS linked list lookup cache"
64	help
65	  Enable ZMS lookup cache for linked list, used to reduce the
66	  Settings load time by having most linked list elements already
67	  in cache.
68
69config SETTINGS_ZMS_LL_CACHE_SIZE
70	int "ZMS linked list lookup cache size"
71	default 128
72	range 1 $(UINT32_MAX)
73	depends on SETTINGS_ZMS_LL_CACHE
74	help
75	  Number of entries in Settings ZMS linked list cache.
76
77endif # SETTINGS_ZMS
78
79config SETTINGS_FCB
80	bool "FCB"
81	depends on FCB
82	help
83	  Use FCB as a settings storage back-end.
84
85config SETTINGS_FILE
86	bool "File"
87	depends on FILE_SYSTEM
88	select SETTINGS_ENCODE_LEN
89	help
90	  Use a file (on mounted file system) as a settings storage back-end.
91
92config SETTINGS_NVS
93	bool "NVS non-volatile storage support"
94	depends on NVS
95	depends on FLASH_MAP
96	help
97	  Enables NVS storage support
98
99if SETTINGS_NVS
100
101config SETTINGS_NVS_NAME_CACHE
102	bool "NVS name lookup cache"
103	help
104	  Enable NVS name lookup cache, used to reduce the Settings name
105	  lookup time.
106
107config SETTINGS_NVS_NAME_CACHE_SIZE
108	int "NVS name lookup cache size"
109	default 128
110	range 1 $(UINT16_MAX)
111	depends on SETTINGS_NVS_NAME_CACHE
112	help
113	  Number of entries in Settings NVS name cache.
114
115endif # SETTINGS_NVS
116
117config SETTINGS_RETENTION
118	bool "Retention storage support"
119	depends on SETTINGS_SUPPORTED_RETENTION
120	help
121	  Enables retention storage support (bulk load/save supported only).
122
123config SETTINGS_CUSTOM
124	bool "CUSTOM"
125	help
126	  Use a custom settings storage back-end.
127
128config SETTINGS_TFM_ITS
129	bool "Internal Trusted Storage (ITS) settings backend"
130	depends on TFM_PARTITION_INTERNAL_TRUSTED_STORAGE
131	help
132	  Enables Internal Trusted Storage (ITS) Settings backend. Intended for use with boards
133	  using TF-M which cannot make use of persistent storage otherwise.
134	  Note: This settings backend compacts settings data into as few ITS nodes as possible.
135	  On every save, the entire settings array is written to ITS.
136	  Note: With this backend, all settings are kept in RAM at all times. The RAM consumption
137	  is controlled by the SETTINGS_TFM_ITS_NUM_ENTRIES Kconfig option.
138
139config SETTINGS_NONE
140	bool "NONE"
141	help
142	  No storage back-end.
143endchoice
144
145config SETTINGS_FCB_NUM_AREAS
146	int "Number of flash areas used by the settings subsystem"
147	default 8
148	depends on SETTINGS_FCB
149	help
150	  Number of areas to allocate in the settings FCB. A smaller number is
151	  used if the flash hardware cannot support this value.
152
153config SETTINGS_FCB_MAGIC
154	hex "FCB magic for the settings subsystem"
155	default 0xc0ffeeee
156	depends on SETTINGS_FCB
157	help
158	  Magic 32-bit word for to identify valid settings area
159
160config SETTINGS_FILE_PATH
161	string "Default settings file"
162	default "/settings/run"
163	depends on SETTINGS_FILE
164	help
165	  Full path to the default settings file.
166
167config SETTINGS_FILE_MAX_LINES
168	int "Compression threshold"
169	default 32
170	depends on SETTINGS_FILE
171	help
172	  Limit how many items stored in a file before compressing
173
174config SETTINGS_NVS_SECTOR_SIZE_MULT
175	int "Sector size of the NVS settings area"
176	default 1
177	depends on SETTINGS_NVS
178	help
179	  The sector size to use for the NVS settings area as a multiple of
180	  FLASH_ERASE_BLOCK_SIZE.
181
182config SETTINGS_NVS_SECTOR_COUNT
183	int "Sector count of the NVS settings area"
184	default 8
185	depends on SETTINGS_NVS
186	help
187	  Number of sectors used for the NVS settings area
188
189config SETTINGS_ZMS_SECTOR_SIZE_MULT
190	int "Sector size of the ZMS settings area"
191	default 1
192	depends on SETTINGS_ZMS
193	help
194	  The sector size to use for the ZMS settings area as a multiple of
195	  FLASH_ERASE_BLOCK_SIZE.
196
197config SETTINGS_ZMS_CUSTOM_SECTOR_COUNT
198	bool "Customize the sector count of the ZMS settings partition"
199	depends on SETTINGS_ZMS
200	help
201	  The number of sectors used by default is the maximum value that can
202	  fit in the settings storage partition.
203	  Enabling this config allows to customize the number of used sectors.
204
205config SETTINGS_ZMS_SECTOR_COUNT
206	int "Sector count of the ZMS settings area"
207	default 8
208	depends on SETTINGS_ZMS && SETTINGS_ZMS_CUSTOM_SECTOR_COUNT
209	help
210	  Number of sectors used for the ZMS settings area
211
212config SETTINGS_ZMS_MAX_COLLISIONS_BITS
213	int "number of bits reserved to handle collisions between hash numbers"
214	default 4
215	depends on SETTINGS_ZMS
216	help
217	  The maximum number of hash collisions needs to be well sized depending
218	  on the data that is going to be stored in ZMS and its hash values
219
220config SETTINGS_ZMS_NO_LL_DELETE
221	bool "Disable deletion of Linked list hashes"
222	help
223	  For some applications, the Settings delete operation is too long for
224	  ZMS because of the linked list update.
225	  As a tradeoff for performance the linked list is not updated. As a
226	  result, some nodes will be unused and will occupy some space in the
227	  storage.
228	  These nodes will be used again when the same Settings element that has
229	  been deleted is created again.
230
231config SETTINGS_ZMS_LOAD_SUBTREE_PATH
232	bool "Load only subtree path if provided"
233	help
234	  Loads first the key defined by the subtree path.
235	  If the callback handler returns a zero value it will
236	  continue to look for all the keys under that subtree path.
237	  If the callback handler returns a non negative value, it
238	  returns immeditaley.
239
240config SETTINGS_SHELL
241	bool "Settings shell"
242	depends on SHELL
243	help
244	  Enable shell commands for listing and reading the settings. Note that
245	  reading the settings requires quite a big stack buffer, so the stack
246	  size of the shell thread may need to be increased to accommodate this
247	  feature.
248
249if SETTINGS_TFM_ITS
250
251config SETTINGS_TFM_ITS_NUM_ENTRIES
252	int "Maximum number of settings entries"
253	default 10
254	help
255	  Configures the maximum number of settings that can be stored simultaneously.
256	  Note: This value determines the size of a statically-allocated buffer which holds
257	  all the settings entries in RAM at all times.
258
259config SETTINGS_TFM_ITS_LAZY_PERSIST_DELAY_MS
260	int "Milliseconds delay before persisting settings"
261	default 500
262	help
263	  ITS may block for a long period of time when writing to flash, which may be
264	  unacceptable for time-sensitive events.
265	  Data is always persisted to ITS using k_work_delayable, instead of happening in
266	  the same context as settings_its_save. This option sets the delay with which the
267	  work item is scheduled. The delay is useful in cases where a PSA ITS write may
268	  block a time-sensitive event, Bluetooth pairing for example, which requires a
269	  sequence of settings writes.
270
271endif # SETTINGS_TFM_ITS
272
273endif # SETTINGS
274