Skip to content

Commit 567b823

Browse files
committed
Migrate from SPIFFS to LittleFS
1 parent eab5afb commit 567b823

File tree

20 files changed

+239
-245
lines changed

20 files changed

+239
-245
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
# set(PROJECT_VER "0.0.0")
99
project(ayab-esp32)
1010

11-
# Create spiffs partition image
12-
set(SPIFFS_PARTITION_NAME "spiffs")
13-
set(SPIFFS_DATA_DIR "${PROJECT_DIR}/data")
14-
spiffs_create_partition_image(
15-
"${SPIFFS_PARTITION_NAME}"
16-
"${SPIFFS_DATA_DIR}"
11+
# Create littlefs partition image
12+
set(LITTLEFS_PARTITION_NAME "littlefs")
13+
set(LITTLEFS_DATA_DIR "${PROJECT_DIR}/data")
14+
littlefs_create_partition_image(
15+
"${LITTLEFS_PARTITION_NAME}"
16+
"${LITTLEFS_DATA_DIR}"
1717
FLASH_IN_PROJECT
1818
)
1919

@@ -32,4 +32,4 @@ add_dependencies(create_flash_image app)
3232
add_dependencies(create_flash_image bootloader)
3333
add_dependencies(create_flash_image partition-table)
3434
add_dependencies(create_flash_image blank_ota_data)
35-
add_dependencies(create_flash_image spiffs_${SPIFFS_PARTITION_NAME}_bin)
35+
add_dependencies(create_flash_image littlefs_${LITTLEFS_PARTITION_NAME}_bin)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
- mDNS server to access device by name rather than IP address (default=ayab.local)
1212
- websocket to serial proxy enabling ayab api over a network (with webapp or ayab-desktop)
1313
- http server to access the ayab webapp
14-
- SPIFFS file system to store http server files (html, css, js, ...)
15-
- Over-The-Air (OTA) updates for esp32 firmware, ayab (RA4M1) firmware or SPIFFS (partition or individual files)
14+
- LITTLEFS file system to store http server files (html, css, js, ...)
15+
- Over-The-Air (OTA) updates for esp32 firmware, ayab (RA4M1) firmware or LITTLEFS (partition or individual files)
1616

1717
## How to build
1818
- Clone this repository

components/ota/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(COMPONENT_SRCS
22
ota_handler.c
33
ota_app.c
4-
ota_spiffs.c
4+
ota_littlefs.c
55
)
66

77
set(COMPONENT_PUBLIC_INCLUDE_DIRS
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef _OTA_LITTLEFS_H_
2+
#define _OTA_LITTLEFS_H_
3+
#include "esp_err.h"
4+
#include "esp_partition.h"
5+
6+
const esp_partition_t *ota_littlefs_get_partition();
7+
8+
/**
9+
* @brief Initialize the LITTLEFS file system for OTA updates.
10+
*
11+
* This function sets up the LITTLEFS file system for OTA updates.
12+
*
13+
* @return ESP_OK on success, or an error code on failure.
14+
*/
15+
esp_err_t ota_littlefs_begin();
16+
17+
/**
18+
* @brief Write chunk of data to LITTLEFS during OTA update.
19+
*
20+
* This function writes a chunk of data to LITTLEFS during an OTA update.
21+
*
22+
* @param data Pointer to the data to write.
23+
* @param len Length of the data in bytes.
24+
* @return ESP_OK on success, or an error code on failure.
25+
*/
26+
esp_err_t ota_littlefs_write(char *data, size_t len);
27+
28+
/**
29+
* @brief End the LITTLEFS file system update.
30+
*
31+
* This function finalizes the LITTLEFS file system update, marking it as complete.
32+
*
33+
* @return ESP_OK on success, or an error code on failure.
34+
*/
35+
esp_err_t ota_littlefs_end();
36+
37+
/**
38+
* @brief Check if the LITTLEFS update is in progress.
39+
*
40+
* This function checks if a LITTLEFS update is currently in progress.
41+
*
42+
* @return true if a LITTLEFS update is in progress, false otherwise.
43+
*/
44+
void ota_littlefs_abort();
45+
46+
#endif

components/ota/include/ota_spiffs.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

components/ota/ota_handler.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "ota_handler.h"
77
#include "ota_app.h"
8-
#include "ota_spiffs.h"
8+
#include "ota_littlefs.h"
99
#include "ra4m1_flash.h"
1010

1111
#define OTA_ESP32_APP 0
12-
#define OTA_ESP32_SPIFFS 1
12+
#define OTA_ESP32_LITTLEFS 1
1313
#define OTA_RA4M1_FIRMWARE 2
1414
#define OTA_BUFFER_SIZE 8192
1515

@@ -24,8 +24,8 @@ typedef struct {
2424
static const char *TAG = "ota_handler";
2525

2626
static ota_func_t ota_types[] = {
27-
{ .begin = ota_app_begin, .write = ota_app_write, .end = ota_app_end, .abort = ota_app_abort , .get_partition = ota_app_get_partition},
28-
{ .begin = ota_spiffs_begin, .write = ota_spiffs_write, .end = ota_spiffs_end, .abort = ota_spiffs_abort , .get_partition = ota_spiffs_get_partition},
27+
{ .begin = ota_app_begin, .write = ota_app_write, .end = ota_app_end, .abort = ota_app_abort, .get_partition = ota_app_get_partition},
28+
{ .begin = ota_littlefs_begin,.write = ota_littlefs_write,.end = ota_littlefs_end,.abort = ota_littlefs_abort, .get_partition = ota_littlefs_get_partition},
2929
{ .begin = ra4m1_flash_begin, .write = ra4m1_flash_write, .end = ra4m1_flash_end, .abort = ra4m1_flash_abort , .get_partition = ra4m1_flash_get_partition},
3030
};
3131

@@ -44,8 +44,8 @@ esp_err_t ota_post_handler(httpd_req_t *req) {
4444
if (httpd_query_key_value(query_buf, "binaryType", value, sizeof(value)) == ESP_OK) {
4545
if (!strcmp("esp32_app", value)) {
4646
ota_type = OTA_ESP32_APP;
47-
} else if (!strcmp("esp32_spiffs", value)) {
48-
ota_type = OTA_ESP32_SPIFFS;
47+
} else if (!strcmp("esp32_littlefs", value)) {
48+
ota_type = OTA_ESP32_LITTLEFS;
4949
} else if (!strcmp("ra4m1_app", value)) {
5050
ota_type = OTA_RA4M1_FIRMWARE;
5151
}

components/ota/ota_spiffs.c renamed to components/ota/ota_littlefs.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
#include "esp_log.h"
44

5-
#include "srv_spiffs.h"
6-
#include "ota_spiffs.h"
5+
#include "srv_littlefs.h"
6+
#include "ota_littlefs.h"
77

88
typedef struct {
9-
const esp_partition_t* partition; /*!< Pointer to the SPIFFS partition */
9+
const esp_partition_t* partition; /*!< Pointer to the LITTLEFS partition */
1010
size_t partition_offset; /*!< Current offset in the partition */
1111
char* buffer; /*!< Buffer for writing data */
1212
size_t buffer_offset; /*!< Current offset in the buffer */
13-
} ota_spiffs_data_t;
13+
} ota_littlefs_data_t;
1414

15-
static const char *TAG = "ota_spiffs";
15+
static const char *TAG = "ota_littlefs";
1616

17-
static ota_spiffs_data_t _self;
17+
static ota_littlefs_data_t _self;
1818

19-
const esp_partition_t *ota_spiffs_get_partition() {
19+
const esp_partition_t *ota_littlefs_get_partition() {
2020
return _self.partition;
2121
}
2222

23-
esp_err_t ota_spiffs_begin() {
23+
esp_err_t ota_littlefs_begin() {
2424
_self.buffer_offset = 0;
2525
_self.partition_offset = 0;
26-
_self.partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
26+
_self.partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL);
2727
if( ! _self.partition) {
28-
ESP_LOGE(TAG, "No SPIFFS partion found !");
28+
ESP_LOGE(TAG, "No LITTLEFS partion found !");
2929
return ESP_FAIL;
3030
}
3131

@@ -35,35 +35,35 @@ esp_err_t ota_spiffs_begin() {
3535
return ESP_FAIL;
3636
}
3737

38-
srv_spiffs_stop();
38+
srv_littlefs_stop();
3939

4040
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%"PRIx32"(size = 0x%"PRIx32")",
4141
_self.partition->subtype, _self.partition->address, _self.partition->size);
4242

4343
return ESP_OK;
4444
}
4545

46-
esp_err_t _ota_spiffs_writeBuffer(size_t len) {
46+
esp_err_t _ota_littlefs_writeBuffer(size_t len) {
4747
esp_err_t err = ESP_OK;
4848

4949
err = esp_partition_erase_range(_self.partition, _self.partition_offset, _self.partition->erase_size);
5050
if (err != ESP_OK) {
51-
ESP_LOGE(TAG, "Unable to erase spiffs sector @ 0x%08x (%s)", _self.partition_offset, esp_err_to_name(err));
51+
ESP_LOGE(TAG, "Unable to erase littlefs sector @ 0x%08x (%s)", _self.partition_offset, esp_err_to_name(err));
5252
return ESP_FAIL;
5353
}
5454

5555
err = esp_partition_write(_self.partition, _self.partition_offset, _self.buffer, len);
5656
if (err != ESP_OK) {
57-
ESP_LOGE(TAG, "Unable to write spiffs sector @ 0x%08x (%s)", _self.partition_offset, esp_err_to_name(err));
57+
ESP_LOGE(TAG, "Unable to write littlefs sector @ 0x%08x (%s)", _self.partition_offset, esp_err_to_name(err));
5858
return ESP_FAIL;
5959
}
6060
//ESP_LOGI(TAG, "Wrote %d bytes at 0x%08x", len , _self.partition_offset);
6161
return err;
6262
}
6363

6464
// TODO: Add support for compressed FS ?
65-
esp_err_t ota_spiffs_write(char *data, size_t len) {
66-
// FIXME: Need to check content to make sure it is a spiffs binary
65+
esp_err_t ota_littlefs_write(char *data, size_t len) {
66+
// FIXME: Need to check content to make sure it is a littlefs binary
6767
if ((_self.partition_offset + len) > _self.partition->size) {
6868
ESP_LOGE(TAG, "Not enough space left on flash!");
6969
return ESP_FAIL;
@@ -74,7 +74,7 @@ esp_err_t ota_spiffs_write(char *data, size_t len) {
7474
size_t data_to_cpy = _self.partition->erase_size - _self.buffer_offset;
7575
memcpy(_self.buffer + _self.buffer_offset, data + (len - data_left), data_to_cpy);
7676

77-
if (_ota_spiffs_writeBuffer(_self.partition->erase_size) != ESP_OK) {
77+
if (_ota_littlefs_writeBuffer(_self.partition->erase_size) != ESP_OK) {
7878
return ESP_FAIL;
7979
}
8080

@@ -89,22 +89,22 @@ esp_err_t ota_spiffs_write(char *data, size_t len) {
8989
return ESP_OK;
9090
}
9191

92-
esp_err_t ota_spiffs_end() {
92+
esp_err_t ota_littlefs_end() {
9393
esp_err_t err = ESP_OK;
9494

9595
if (_self.buffer_offset != 0) {
96-
err = _ota_spiffs_writeBuffer(_self.buffer_offset);
96+
err = _ota_littlefs_writeBuffer(_self.buffer_offset);
9797
}
9898

9999
free(_self.buffer);
100-
ESP_LOGI(TAG, "OTA spiffs update succeeded");
100+
ESP_LOGI(TAG, "OTA littlefs update succeeded");
101101

102-
srv_spiffs_restart();
102+
srv_littlefs_restart();
103103

104104
return err;
105105
}
106106

107-
void ota_spiffs_abort() {
107+
void ota_littlefs_abort() {
108108
free(_self.buffer);
109-
ESP_LOGI(TAG, "OTA spiffs update aborted");
109+
ESP_LOGI(TAG, "OTA littlefs update aborted");
110110
}

components/services/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set(COMPONENT_SRCS
22
srv_file.c
33
srv_http.c
44
srv_mdns.c
5-
srv_spiffs.c
5+
srv_littlefs.c
66
srv_websocket.c
77
srv_wifi.c
88
)
@@ -21,7 +21,7 @@ set(COMPONENT_REQUIRES
2121
set(COMPONENT_PRIV_REQUIRES
2222
esp_app_format
2323
esp_partition
24-
spiffs
24+
littlefs
2525
app_config
2626
ota
2727
ra4m1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef _SRV_SPIFFS_H_
2+
#define _SRV_SPIFFS_H_
3+
4+
#include "esp_err.h"
5+
6+
/**
7+
* @brief Initialize and mount the LITTLEFS filesystem.
8+
*
9+
* This function mounts the LITTLEFS filesystem at the given base path.
10+
* It must be called before any file operations.
11+
*
12+
* @param base_path The mount point path for LITTLEFS (e.g., "/littlefs").
13+
* @return ESP_OK on success, or an error code from esp_err_t on failure.
14+
*/
15+
esp_err_t srv_littlefs_start(char *base_path);
16+
17+
/**
18+
* @brief Restart (unmount and remount) the LITTLEFS filesystem.
19+
*
20+
* This function unmounts and remounts the LITTLEFS filesystem using the last base path.
21+
*
22+
* @return ESP_OK on success, or an error code from esp_err_t on failure.
23+
*/
24+
esp_err_t srv_littlefs_restart(void);
25+
26+
/**
27+
* @brief Unmount the LITTLEFS filesystem and release resources.
28+
*
29+
* This function unmounts the LITTLEFS filesystem and frees associated resources.
30+
*
31+
* @return ESP_OK on success, or an error code from esp_err_t on failure.
32+
*/
33+
esp_err_t srv_littlefs_stop(void);
34+
35+
#endif

components/services/include/srv_spiffs.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)