Commit graph

83 commits

Author SHA1 Message Date
Markus Becker f08045f077 settings: Fix uninitialised variables
When compiling the settings subsystems, I was getting the following
compiler warning:

```
/home/markus/src/wrp-n4m/zephyr/subsys/settings/src/settings_line.c: In function 'settings_line_cmp':
/home/markus/src/wrp-n4m/zephyr/subsys/settings/src/settings_line.c:477:6: warning: 'rc' may be used uninitialized in this function [-Wmaybe-uninitialized]
  477 |  int rc;
      |      ^~
/home/markus/src/wrp-n4m/zephyr/subsys/settings/src/settings_line.c: In function 'settings_line_entry_copy':
/home/markus/src/wrp-n4m/zephyr/subsys/settings/src/settings_line.c:453:9: warning: 'rc' may be used uninitialized in this function [-Wmaybe-uninitialized]
  453 |  return rc;
```

This patch fixes the warning.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-06-17 08:55:59 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Marek Pieta 775b2457d7 settings_fcb: Fix storing the data
Change fixes storing the data by adding missing write retry after
the last compression. Without the change error was returned instead
of retrying.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-05-21 17:42:20 +02:00
Kumar Gala ff579a3af3 flash: Convert DT_FLASH_AREA to FLASH_AREA macros
Convert with a combo of scripts and by hand fixups:

git grep -l DT_FLASH_AREA_.*_ID | \
 xargs sed -i -r 's/DT_FLASH_AREA_(.*)_ID/FLASH_AREA_ID(\L\1)/'

git grep -l DT_FLASH_AREA_.*_OFFSET | \
 xargs sed -i -r 's/DT_FLASH_AREA_(.*)_OFFSET/FLASH_AREA_OFFSET(\L\1)/'

git grep -l DT_FLASH_AREA_.*_SIZE | \
 xargs sed -i -r 's/DT_FLASH_AREA_(.*)_SIZE/FLASH_AREA_SIZE(\L\1)/'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-13 21:22:53 +02:00
Peter Bigot e052c7991c settings: add const qualifier for unmodified data source
Code using this API to set a key to a value that is a string literal
produces errors in C++ because the passed pointer is not const
qualified, allowing the possibility that the callee modifies the
referenced string literal memory.  Add the required const qualifiers
since the set function does not change the passed to it.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-07 10:51:49 +02:00
Dominik Ermel dab67c35f1 settings: settings_register static table does not need mutex
It is not needed to protect static table of handlers, with mutex,
as there is no possibility that there will be anything added to the
table at runtime.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-02-08 10:07:38 +02:00
Dominik Ermel c0d31bf02b settings: Reduction of settings_src_register function
The contentes of the function has been reduced with use of
sys_slist_append instead of sys_slist_insert.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-02-03 18:39:49 +01:00
Dominik Ermel 2addfb4696 settings: Deprecate base64 in fs backed settings
Encoding of values with use of base64 has been marked as deprecated and
will be removed in future releases.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-01-16 10:21:29 -05:00
Dominik Ermel 220f7607da settings: Moving initialization code to proper backend sources
Backend initialization code has been moved from common settings_init.c
to proper backend source files. Missing static specifiers have been
added.
Minor cleanup has been done to source files: exported functions have
been moved to the end of source files and definitions of static
variables, that are used by only a single function, have been moved from
global scope into functions that use them.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2019-12-16 12:11:20 +01:00
Dominik Ermel c16691ffd0 settings: file: Fix possible success status while failed to write
Assuming that fs_seek has been successful; in case when fs_write
would be unsuccessful and fs_close, that follows, would be successful,
the success code would have been returned for the entire procedure,
although it has failed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2019-12-12 10:44:31 -06:00
François Delawarde bec05a5d7f settings: Fix settings runtime read callback return value
The settings runtime read callback should return the actual length of
the data that has been read.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-12-12 13:22:27 +01:00
Kumar Gala ec4714a5ea include: Fix use of <nvs/nvs.h> -> <fs/nvs.h>
Fix #include <nvs/nvs.h> as it has been deprecated and
should be #include <fs/nvs.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Kumar Gala 2fab7413f7 include: Fix use of <flash_map.h> -> <storage/flash_map.h>
Fix #include <flash_map.h> as it has been deprecated and
should be #include <storage/flash_map.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Radoslaw Koppel 86afb9c776 settings: Set a default value to name_key before processing
This commit fixes the settings_call_set_handler function
in a situation where the user calls settings_load_subtree_direct
with NULL as a subtree parameter.

Fixes: #20514

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-11-15 14:49:55 +01:00
Stephanos Ioannidis c839d7b458 settings: Fix undefined behaviours in settings_line.c.
This commit fixes the source of potential undefined behaviours in
settings_line.c.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-13 17:36:36 -08:00
Andrzej Puzdrowski aae2c84619 setting: fix NVS error handling on write
In settings write NVS errors were not handled
in a few places.
This patch improve that.

fixes #20515

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-11-13 14:11:23 -06:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
François Delawarde 8024c7a2c4 settings: fix runtime settings length
The length passed to settings_runtime_set was not taken into account
in the read callback. This commit fixes it.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-03 12:57:12 +01:00
Andrzej Puzdrowski 06cd8583ed settings: fix integer to unsigned compression in nvs back-en
ssize_t type variable was compared to size_t type variable which will
cause error for comparison while ssize_t value will be nagative.
This patch fixes that.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-11-01 17:53:35 +01:00
Andrzej Puzdrowski 9ac3755612 settings: (NVS) fetch sector size from driver
NVS back-end initialization should fetch size of the flash erase blocks
from the flash API instead of DT. This allows to work well when used
storage partition is not located in embedded memory.

NVS back-end sector multiplier configuration was set to 8K as
DT value for native posix targets
flash sector sizes is 1 B, while its flash driver supports 8k.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-10-22 10:52:36 -05:00
Radoslaw Koppel 687a02a02d settings: file: Duplicates filtering option
This commit adds a possibility to activate duplicates filtering
during direct loading.

JIRA: NCSDK-3017

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-10-14 12:05:42 +02:00
Radoslaw Koppel 0b0f375190 settings: fcb: Duplicates filtering option
This commit adds a possibility to activate duplicates filtering
during direct loading.

JIRA: NCSDK-3017

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-10-14 12:05:42 +02:00
Kamil Piszczek ff75620b45 settings: fix Kconfig SETTINGS_NVS dependency
The SETTINGS_NVS now depend on the NVS and FLASH_MAP as it was intended.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-10-11 14:55:24 +02:00
Kamil Piszczek 7866ea615a settings: addding NVS & FS to default settings backend config
Added default backends in the Settings Kconfig for NVS and FS.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-10-11 14:55:24 +02:00
Kamil Piszczek d52cdd940a settings: nvs: aligned error code on delete operation
Aligned error code on Settings delete operation of non-existing record.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-10-11 14:55:24 +02:00
Laczen JMS b9dc69b38e subsys/settings: Remove optional from Kconfig
Kconfig does not set SETTINGS_NONE as default backend (meaning no
backend) because SETTINGS_NONE is optional. There is no difference
between SETTINGS_NONE and SETTINGS_CUSTOM. By removing the optional line
SETTINGS_NONE is selected as default, to use a custom backend
SETTINGS_CUSTOM=y must be set.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-10-01 06:20:36 -05:00
Radoslaw Koppel c68ff8b99c settings: Generic function to call set handler
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>
2019-09-24 14:15:38 +02:00
Radoslaw Koppel 6c2add5445 settings: Direct loading functionality
This commit allows loading data from settings permanent storage
directly to the given callback function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-09-24 14:15:38 +02:00
Andrzej Puzdrowski 94a022c954 fcb: start using errno codes
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>
2019-09-08 12:42:53 +02:00
Kamil Piszczek 1aca71b93e settings: nvs backend: fix build warning due to the type mismatch
Fixed the build warning that was caused by type mismatch.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-09-08 12:35:15 +02:00
Kamil Piszczek 2c43dede04 settings: adding missing header
Added missing header in the Settings private include.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-09-07 10:01:09 -04:00
Faisal Saleem 07cfaa27b6 Settings: Improve error handling of settings load
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>
2019-08-27 20:15:31 +02:00
Declan Traill c313c484a8 Settings: Fix incorrect return of -EINVAL for deleted entries
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>
2019-08-20 13:18:38 +02:00
Andrzej Puzdrowski 4ea3c9560a settings: align nvs read_callback return value
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>
2019-08-12 15:25:17 +02:00
Tobias Svehagen e55f3eba4c Settings: Initialize settings_lock mutex
The settings_lock mutex was never initialized

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-08-05 21:48:22 +02:00
Krzysztof Chruscinski af9a2670d2 settings: Fix missing kernel.h include
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>
2019-08-01 14:42:40 +02:00
Peter A. Bigot e3ba01ec76 subsys/storage/flash_map: detect missing flash device
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>
2019-07-24 09:20:56 -04:00
Kamil Piszczek 88bb7597b1 settings: adding new nvs backend
Added NVS backend to the Settings subsystem.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-07-10 10:57:22 +02:00
Anas Nashif bd977d06f8 cleanup: include/: move base64.h to sys/base64.h
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>
2019-06-27 22:55:49 -04:00
Anas Nashif d918c98e1d cleanup: include/: move fcb.h to fs/fcb.h
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>
2019-06-27 22:55:49 -04:00
Anas Nashif 656f4dfdac cleanup: include/: move fs.h to fs/fs.h
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>
2019-06-27 22:55:49 -04:00
Laczen JMS c20ff1150f subsys/settings: Enable handler ROM registration
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>
2019-06-26 16:31:01 +02:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
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>
2019-06-19 15:34:13 -05:00
Laczen JMS 36edf92ca8 subsys/settings: change processing to const char
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>
2019-06-18 17:57:08 +02:00
Radoslaw Koppel b748a54c7f subsys/settings: Cleanup the initialisation of the subsys
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>
2019-06-03 11:58:05 +02:00
Radoslaw Koppel 974231ee6e subsys/settings: Add const modifier to the value pointer
This commit adds const modifier for value pointer in
settings_save_one function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-05-29 10:11:12 -04:00
François Delawarde 43492817ab subsys/settings: Correct size in strncpy to avoid unterminated strings
This fixes some Coverity warnings.

Coverity-CID: 198391
Coverity-CID: 198390
Coverity-CID: 198389
Fixes #15989
Fixes #15990
Fixes #15991

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-05-10 09:01:40 -04:00
François Delawarde 2038365e9a subsys/settings: Use strncpy instead of strcpy in settings_runtime
This fixes some Coverity warnings.

Coverity-CID: 198022
Coverity-CID: 198019
Coverity-CID: 198016
Fixes #15762
Fixes #15764
Fixes #15766

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-05-02 11:38:16 -04:00
François Delawarde 94451b22fc subsys/settings: Allow to register custom backends in settings subsystem
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>
2019-04-26 11:24:31 +03:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
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>
2019-04-07 08:45:22 -04:00