This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit f3e417741a1834e1ae78d5912470c68889e261c1
Author: Andrzej Kaczmarek <andrzej.kaczma...@codecoup.pl>
AuthorDate: Tue Oct 11 22:52:32 2022 +0200

    fs/littlefs: Fix glue
    
    read_buffer and prog_buffer have to be cache_size
    cache_size has to be factor of block size (assume block size 4096)
    lookahead_size has to be multiple of 8
    
    and move checks for block size and block count to restrictions
---
 fs/littlefs/src/mynewt_glue.c | 26 ++++++++++++--------------
 fs/littlefs/syscfg.yml        |  8 ++++++--
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/fs/littlefs/src/mynewt_glue.c b/fs/littlefs/src/mynewt_glue.c
index df11deb13..75755118d 100644
--- a/fs/littlefs/src/mynewt_glue.c
+++ b/fs/littlefs/src/mynewt_glue.c
@@ -32,10 +32,6 @@
 #include <fs/fs.h>
 #include <fs/fs_if.h>
 
-#if ((MYNEWT_VAL(LITTLEFS_BLOCK_SIZE) < 0) || 
(MYNEWT_VAL(LITTLEFS_BLOCK_COUNT) < 0))
-#error "Must configure LITTLEFS_BLOCK_SIZE and LITTLEFS_BLOCK_COUNT syscfgs"
-#endif
-
 static int littlefs_open(const char *path, uint8_t access_flags,
                          struct fs_file **out_file);
 static int littlefs_close(struct fs_file *fs_file);
@@ -222,12 +218,14 @@ flash_sync(const struct lfs_config *c)
 static lfs_t *g_lfs = NULL;
 static bool g_lfs_alloc_done = false;
 
-#define READ_SIZE (MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE) * 2)
-static uint8_t read_buffer[READ_SIZE];
-#define WRITE_SIZE (MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE) * 2)
-static uint8_t prog_buffer[WRITE_SIZE];
-#define CACHE_SIZE 8
-static uint8_t __attribute__((aligned(4))) lookahead_buffer[CACHE_SIZE];
+#define READ_SIZE       MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE)
+#define PROG_SIZE       MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE)
+#define CACHE_SIZE      16
+#define LOOKAHEAD_SIZE  16
+
+static uint8_t read_buffer[CACHE_SIZE];
+static uint8_t prog_buffer[CACHE_SIZE];
+static uint8_t __attribute__((aligned(4))) lookahead_buffer[LOOKAHEAD_SIZE];
 static struct lfs_config g_lfs_cfg = {
     .context = NULL,
 
@@ -238,12 +236,12 @@ static struct lfs_config g_lfs_cfg = {
 
     /* block device configuration */
     .read_size = READ_SIZE,
-    .prog_size = WRITE_SIZE,
+    .prog_size = PROG_SIZE,
     .block_size = MYNEWT_VAL(LITTLEFS_BLOCK_SIZE),
     .block_count = MYNEWT_VAL(LITTLEFS_BLOCK_COUNT),
     .block_cycles = 500,
-    .cache_size = 16,
-    .lookahead_size = CACHE_SIZE,
+    .cache_size = CACHE_SIZE,
+    .lookahead_size = LOOKAHEAD_SIZE,
     .read_buffer = read_buffer,
     .prog_buffer = prog_buffer,
     .lookahead_buffer = lookahead_buffer,
@@ -470,7 +468,7 @@ littlefs_read(struct fs_file *fs_file, uint32_t len, void 
*out_data,
     lfs = ((struct littlefs_file *) fs_file)->lfs;
 
     littlefs_lock();
-    size = lfs_file_read(lfs, file, out_data, *out_len);
+    size = lfs_file_read(lfs, file, out_data, len);
     littlefs_unlock();
     if (size < 0) {
         return littlefs_to_vfs_error((int)size);
diff --git a/fs/littlefs/syscfg.yml b/fs/littlefs/syscfg.yml
index 4dbbad042..8ffc9cc2a 100644
--- a/fs/littlefs/syscfg.yml
+++ b/fs/littlefs/syscfg.yml
@@ -34,7 +34,7 @@ syscfg.defs:
         description: >
             Size of the sectors used to store a littlefs partition. All sectors
             must have the same size.
-        value: -1
+        value: 0
 
     LITTLEFS_MIGRATE_V1:
         description: >
@@ -49,7 +49,7 @@ syscfg.defs:
     LITTLEFS_BLOCK_COUNT:
         description: >
             Number of blocks/sectors use by this partition.
-        value: -1
+        value: 0
 
     LITTLEFS_DISABLE_SYSINIT:
         description: >
@@ -60,3 +60,7 @@ syscfg.defs:
         description: >
             Sysinit stage for littlefs functionality.
         value: 200
+
+syscfg.restrictions:
+    - LITTLEFS_BLOCK_SIZE > 0
+    - LITTLEFS_BLOCK_COUNT > 0

Reply via email to