This commit implements generic function to decide
witch functions to call for selected value name with given
loading parameters.
Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
This commit allows loading data from settings permanent storage
directly to the given callback function.
Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
Switch form using privater FCB error codes to
errno codes. FCB private codes convention were compatible
with <errno.h> codes:
- 0 mean success
- negative values mean errors
- similar error types.
There was no sense to kept private FCB error codes.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
if base64_decode function returns error, function can't continue
otherwise a fatal error will cause the thread to spin, putting the
system into an unrecoverable state
Signed-off-by: Faisal Saleem <faisal.saleem@setec.com.au>
Fix for Zephyr bug #17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y
Signed-off-by: Declan Traill <declan.traill@setec.com.au>
The callback might return more than length of data read.
It should return nothing more than read length requested.
Patch fixes this behavior.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Apparently, settings were relying on other headers
including kernel.h, once that include got removed from the
logger header samples fail to compile.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
If the flash device is not configured, return an error rather than
dereferencing a null device pointer.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
move base64.h to sys/base64.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move fcb.h to fs/fcb.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move fs.h to fs/fs.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Add the possibility to register handles to ROM using a new macro
SETTINGS_REGISTER_STATIC(handler), the handler is of type
settings_handler_stat and has to be declared as const:
```
const struct settings_handler_stat test_handler = {
.name = "test", /* this can also be "ps/data"
.h_get = get,
.h_set = set,
.h_commit = NULL, /* NULL defines can be ommited */
.h_export = NULL /* NULL defines can be ommited */
};
SETTINGS_REGISTER_STATIC(test_handler);
```
To maintain support for handlers stored in RAM (dynamic handlers)
`CONFIG_SETTINGS_DYNAMIC_HANDLERS`must be enabled, which is by default.
When registering static handlers there is no check if this handler has
been registered earlier, the latest registered static handler will be
considered valid for any set/get routine, while the commit and export
routines will be executed for both registered handlers.
When a dynamic handler is registered a check is done to see if there was
an earlier registration of the name as a static or dynamic handler
registration will fail.
To get to the lowest possible RAM usage it is advised to set
`CONFIG_SETTINGS_DYNAMIC_HANDLERS=n`.
Updates:
a. Changed usage of RAM to DYNAMIC/dynamic, ROM to STATIC/static
b. Updated settings.h to remove added #if defined()
c. Make static handlers always enabled
d. Corrected error introduced in common-rom.ld.
e. Changed return value of settings_parse_and_lookup to
settings_handler_stat type to reduce stack usage.
f. Updated the name generated to store a handler item in ROM. It now
uses the name used to register in combination with the line where
SETTINGS_REGISTER_STATIC() is called.
g. renamed settings_handler_stat type to settings_handler_static
h. renamed SETTINGS_REGISTER_STATIC to SETTINGS_STATIC_HANDLER_DEFINE()
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
This commit removes redundant checks if the module
was already initialized.
The variable to mark the fact of initialization is
moved as a global module variable.
This allows creating more sophisticated unit tests
of the settings subsystem by giving a possibility to modify
the internal mark of the fact the system was initialized.
Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
Major changes are:
- Expose settings backend API to enable custom backend support.
- Add a new CONFIG_SETTINGS_CUSTOM backend to allow registering a custom
backend.
- Change api of the handlers h_set() routines to allow for
backend-specific read callbacks.
- Provide a customizable settings_backend_init() routine for custom
backends.
- Move runtime settings support to be its own backend.
Signed-off-by: François Delawarde <fnde@oticon.com>
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier. Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.
By default all files without license information are under the default
license of Zephyr, which is Apache version 2.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The code for checking duplicates in the existing settings store was
incorrectly identifying a new value with the same initial content but
shorter length as a duplicate. Fix this by doing an early check on a
new vs old length mismatch, and immediately flag this as not a
duplicate.
Fixes#14840
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Enforce that NULL value is never given with a non-zero length. This
way we don't need to check this over and over again further down the
call path.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Patch removes dead, replaced code which was accidentally not
removed within the stream-codec PR #9521.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
In case of corrupted key in settings, error message is shown. However,
the key name is lost by logger if it is not explicitly copied.
Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
This patch introduce logging to settings.
Error in stored data record might occurred in runtime, so
better to switch assertion to error logging.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
It was possible via Kconfig to assign any partition for FCB using
its number. Partitions flash_area_id becomes non predefined
(are auto-generated). So it is possible only to guess which
number will be signed to certain area.
Unfortunately it is not possible to transfer FLASH_AREA_XXX_ID
label via Kconfig.
Patch assigns settings to the storage partition and remove
SETTINGS_FCB_FLASH_AREA property from settings Kconfig.
fixes#13388
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
settings_line_len_calc() is used to determine key-value record size.
It unnecessary aligned this size to write-block-size.
Record size in flash layout is actually adjusted independently by
fcb itself and setting settings_line_write().
Patch fixes this behavior.
fixes#12967
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Patch remove unnecessary call chain which fetched flash write-block-size
already available in fcb instance.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.
This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.
All files that use these macros have been updated.
Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
Use the value extracted from DT instead of a hardcoded 4, as it is done
in commit 977b292d80 for tests.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
When setting read handler was requested for more
data than is stored, it should read reduced amount
of data (by the API define).
Back-end implementation support that, but not for corner-case
when the last call to back-end handler was out of data bounds.
This patch makes any request to read data which begins outside
of the record zero-length read-out, instead of being prohibited
before, which fix the issue.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
fcb instance might use less areas than CONFIG_SETTINGS_FCB_NUM_AREAS.
During compression of completely filled up fcb it was possible to try
compress areas more than once.
What this patch fixes is not a bug - rather fix for inefficient service
of the corner case.
fixes#12657
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
While base64 encoding was enabled settings_val_get_len_cb() returned
encoded length instead of decoded value length.
This patches introduce procedure which calculates the value length
properly. For that additional read of the end of the encoded value is
required for checking how many form last 3 value bytes wear encoded.
fixes#12122
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Whenever a new key-value is about to be stored, the settings
perform check whether the value really changes. This check
after #9521 patch should work differently as `\0` is not
the value terminator anymore. Because of above any value which
starts from \0 will be treated mistakenly as a NULL.
This patch uses check-length callback instead read-callback which
fix the issue and simplify the code a little.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
So far to deleting av existing key-value pair it was
required to storing NULL value using setting_save_one().
This patch introduce more intuitive API which takes only
the name key string.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Such API is convinient for check the persistent storage
value size or whether the value is NULL.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Thanks to previous commit base64 encoding of the settings
value is not required anymore for NFFS and FCB back-end.
This patch makes encoding an option in case it will be required
in the future.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This patch reworks routines used to store and read the settings data.
Provide stream-style encoding and decoding to/from flash, so the the
API only requires a pointer to binary data, and the settings
implementation takes care of encoding/decoding to/from base64 and
writing/reading to/from flash on the fly. This would eliminate the
need of a separate base64 value buffer on the application-side, thereby
further contributing to the stack footprint reduction.
Above changes allows to remove:
256-byte value length limitation.
removing enum settings_type usage so all settings data are treated
now as a byte array (i.e. what's previously SETTINGS_BYTES)
Introduced routine settings_val_read_cb for read and decode the
settings data from storage inside h_set handler implementations.
h_set settings handler now provide persistent value's context
used along with read routine instead of immediately value.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
The settings subsystem has been adding nffs's include dir to the
global set of paths. Presumably because app's will need acces. But
this is no longer necessary as we default to linking 'app' with FS,
which again has the NFFS include paths.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Bool symbols implicitly default to 'n'.
A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.
Remove some 'default ""' properties on string symbols too.
Also make definitions more consistent by converting some
config FOO
<type>
prompt "foo"
definitions to a shorter form:
config FOO
<type> "foo"
This shorthand works for int/hex/string symbols too, not just for bool
symbols.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Fix file exist error within settings_subsys_init in order to correctly
reload existing settings when CONFIG_SETTINGS_FS is enabled.
Signed-off-by: Daniele Biagetti <daniele.biagetti@cblelectronics.com>