Skip to content

Commit a59cb04

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 520d417 commit a59cb04

File tree

15 files changed

+736
-21
lines changed

15 files changed

+736
-21
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/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: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,38 @@ if APP_STORAGE
1212

1313
config APP_STORAGE_THREAD_STACK_SIZE
1414
int "Storage module thread stack size"
15-
default 1536
15+
default 1536 if APP_STORAGE_BACKEND_RAM
16+
default 4096 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+
endif # APP_STORAGE_BACKEND_LITTLEFS
46+
2347
config APP_STORAGE_MAX_TYPES
2448
int "Maximum number of data types"
2549
default 4
@@ -97,6 +121,7 @@ endchoice
97121
config APP_STORAGE_SHELL
98122
bool "Enable storage shell commands"
99123
default y if SHELL
124+
select FILE_SYSTEM_SHELL if APP_STORAGE_BACKEND_LITTLEFS
100125
help
101126
Enable shell commands for interacting with the storage module.
102127
This allows you to manage stored data from the command line.

0 commit comments

Comments
 (0)