Skip to content

Commit 930471b

Browse files
modules: storage: Add littleFS backend
Add littleFS based flash storage backend for the storage module. Uses a file per storage data type to store a circular buffer of records. Signed-off-by: Trond F. Christiansen <[email protected]>
1 parent 0317536 commit 930471b

File tree

19 files changed

+782
-26
lines changed

19 files changed

+782
-26
lines changed

app/src/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,8 +1927,20 @@ static void fota_rebooting_entry(void *o)
19271927
{
19281928
ARG_UNUSED(o);
19291929

1930+
struct storage_msg msg = { .type = STORAGE_CLEAR };
1931+
int err;
1932+
19301933
LOG_DBG("%s", __func__);
19311934

1935+
/* Tell storage module to clear any stored data */
1936+
err = zbus_chan_pub(&STORAGE_CHAN, &msg, K_MSEC(ZBUS_PUBLISH_TIMEOUT_MS));
1937+
if (err) {
1938+
LOG_ERR("Failed to publish storage clear message, error: %d", err);
1939+
SEND_FATAL_ERROR();
1940+
1941+
return;
1942+
}
1943+
19321944
/* Reboot the device */
19331945
LOG_WRN("Rebooting the device to apply the FOTA update");
19341946

app/src/modules/cloud/Kconfig.cloud

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ endchoice
111111

112112
config APP_CLOUD_THREAD_STACK_SIZE
113113
int "Thread stack size"
114-
default 5632
114+
default 6352
115115

116116
config APP_CLOUD_MESSAGE_QUEUE_SIZE
117117
int "Message queue size"

app/src/modules/storage/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ zephyr_linker_sources(SECTIONS storage_sections.ld)
1616
target_sources_ifdef(CONFIG_APP_STORAGE_BACKEND_RAM app PRIVATE
1717
backends/ram_ring_buffer_backend.c
1818
)
19+
target_sources_ifdef(CONFIG_APP_STORAGE_BACKEND_LITTLEFS app PRIVATE
20+
backends/littlefs_backend.c
21+
)
1922

2023
target_sources_ifdef(CONFIG_APP_STORAGE_SHELL app PRIVATE
2124
storage_shell.c

app/src/modules/storage/Kconfig.storage

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,45 @@ if APP_STORAGE
1212

1313
config APP_STORAGE_THREAD_STACK_SIZE
1414
int "Storage module thread stack size"
15-
default 1536
15+
default 1720 if APP_STORAGE_BACKEND_RAM
16+
default 3000 if APP_STORAGE_BACKEND_LITTLEFS
17+
18+
choice APP_STORAGE_BACKEND
19+
prompt "Storage backend"
20+
default APP_STORAGE_BACKEND_RAM
21+
help
22+
Select the storage backend to use for storing data samples.
1623

1724
config APP_STORAGE_BACKEND_RAM
1825
bool "RAM storage backend"
19-
default y
2026
help
2127
Store data in RAM. Data will be lost on power loss or reset.
2228

29+
config APP_STORAGE_BACKEND_LITTLEFS
30+
bool "LittleFS storage backend"
31+
select FILE_SYSTEM_LITTLEFS
32+
select PM_PARTITION_REGION_LITTLEFS_EXTERNAL
33+
help
34+
Store data in LittleFS filesystem. Data will persist across power
35+
loss and resets, as long as the underlying flash storage is intact.
36+
37+
endchoice
38+
39+
if APP_STORAGE_BACKEND_LITTLEFS
40+
41+
# Setup PM partition size for LittleFS to 64KB by default
42+
config PM_PARTITION_SIZE_LITTLEFS
43+
default 0x10000
44+
45+
config APP_STORAGE_LITTLEFS_MAX_NAME_LEN
46+
int "Maximum length of storage file names"
47+
default 64
48+
help
49+
Maximum length of file names used by the storage module
50+
in the LittleFS backend.
51+
52+
endif # APP_STORAGE_BACKEND_LITTLEFS
53+
2354
config APP_STORAGE_MAX_TYPES
2455
int "Maximum number of data types"
2556
default 4
@@ -97,6 +128,7 @@ endchoice
97128
config APP_STORAGE_SHELL
98129
bool "Enable storage shell commands"
99130
default y if SHELL
131+
select FILE_SYSTEM_SHELL if APP_STORAGE_BACKEND_LITTLEFS
100132
help
101133
Enable shell commands for interacting with the storage module.
102134
This allows you to manage stored data from the command line.

0 commit comments

Comments
 (0)