Skip to content

Commit

Permalink
samples/subsys/settings: FS and native_posix support
Browse files Browse the repository at this point in the history
Added support for native_posix targets.
Added setting FS back-end initialization which is used by
native_posix targets.

The test harness was adapted to the fact that key-value pairs
read-out order might be different for each back-end when call
settings_load().

Signed-off-by: Andrzej Puzdrowski <[email protected]>
  • Loading branch information
nvlsianpu authored and nashif committed Jan 31, 2020
1 parent d518f6a commit 8fa5b44
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
6 changes: 6 additions & 0 deletions samples/subsys/settings/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enable the LittleFS file system.
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_SETTINGS_FS=y
CONFIG_SETTINGS_FS_DIR="/ff/settings"
CONFIG_SETTINGS_FS_FILE="/ff/settings/run"
25 changes: 25 additions & 0 deletions samples/subsys/settings/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2019 Jan Van Winkel <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/delete-node/ &storage_partition;
/delete-node/ &scratch_partition;

&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

storage_partition: partition@70000 {
label = "storage";
reg = <0x00070000 0x8000>;
};
};
};
6 changes: 6 additions & 0 deletions samples/subsys/settings/boards/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enable the LittleFS file system.
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_SETTINGS_FS=y
CONFIG_SETTINGS_FS_DIR="/ff/settings"
CONFIG_SETTINGS_FS_FILE="/ff/settings/run"
25 changes: 25 additions & 0 deletions samples/subsys/settings/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2019 Jan Van Winkel <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/delete-node/ &storage_partition;
/delete-node/ &scratch_partition;

&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

storage_partition: partition@70000 {
label = "storage";
reg = <0x00070000 0x8000>;
};
};
};
10 changes: 6 additions & 4 deletions samples/subsys/settings/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tests:
sample.subsys.settings:
tags: settings
timeout: 10
platform_whitelist: qemu_x86
platform_whitelist: qemu_x86 native_posix native_posix_64
harness: console
harness_config:
type: multi_line
Expand All @@ -16,14 +16,16 @@ tests:
- "[.]*Can\\'t to load the <alpha/length> value as expected"
- "<gamma> = 0 \\(default\\)"
- "# iteration 1"
- "<alpha/length/2> = 59"
- "# iteration 2"
- "<alpha/length/1> = 42"
- "# iteration 3"
- "<alpha/beta/voltage> = -3100"
- "# iteration 4"
- "<alpha/beta/source> = abcd"
- "# iteration 5"
- "<alpha/length/2> = 55"
- "<alpha/length/1> = 45"
- "<alpha/angle/1> = 5"
- "<alpha/beta/source> is not compatible with the application"
- "<alpha/beta/voltage> = -3125"
- "direct.length = 100"
- "direct.length_1 = 46"
- "direct.length_2 = 54"
Expand Down
30 changes: 30 additions & 0 deletions samples/subsys/settings/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <errno.h>
#include <sys/printk.h>

#if IS_ENABLED(CONFIG_SETTINGS_FS)
#include <fs/fs.h>
#include <fs/littlefs.h>
#endif

#define GAMMA_DEFAULT_VAl 0
#define FAIL_MSG "fail (err %d)\n"
#define SECTION_BEGIN_LINE \
Expand Down Expand Up @@ -414,6 +419,31 @@ static void example_initialization(void)
{
int rc;

#if IS_ENABLED(CONFIG_SETTINGS_FS)
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);

/* mounting info */
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &cstorage,
.storage_dev = (void *)DT_FLASH_AREA_STORAGE_ID,
.mnt_point = "/ff"
};

rc = fs_mount(&littlefs_mnt);
if (rc != 0) {
printk("mounting littlefs error: [%d]\n", rc);
} else {

rc = fs_unlink(CONFIG_SETTINGS_FS_FILE);
if ((rc != 0) && (rc != -ENOENT)) {
printk("can't delete config file%d\n", rc);
} else {
printk("FS initiqalized: OK\n");
}
}
#endif

rc = settings_subsys_init();
if (rc) {
printk("settings subsys initialization: fail (err %d)\n", rc);
Expand Down

0 comments on commit 8fa5b44

Please sign in to comment.