summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32/mboot/fsload.c25
-rw-r--r--ports/stm32/mboot/vfs.h4
-rw-r--r--ports/stm32/mboot/vfs_lfs.c26
3 files changed, 24 insertions, 31 deletions
diff --git a/ports/stm32/mboot/fsload.c b/ports/stm32/mboot/fsload.c
index 591b670aa..fe98426be 100644
--- a/ports/stm32/mboot/fsload.c
+++ b/ports/stm32/mboot/fsload.c
@@ -31,6 +31,11 @@
#include "pack.h"
#include "vfs.h"
+// Default block size used for mount operations if none given.
+#ifndef MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE
+#define MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE (4096)
+#endif
+
#if MBOOT_FSLOAD
#if !(MBOOT_VFS_FAT || MBOOT_VFS_LFS1 || MBOOT_VFS_LFS2)
@@ -213,8 +218,19 @@ int fsload_process(void) {
elem = ELEM_DATA_START;
for (;;) {
elem = elem_search(elem, ELEM_TYPE_MOUNT);
- if (elem == NULL || elem[-1] != 10) {
- // End of elements, or invalid MOUNT element
+ if (elem == NULL) {
+ // End of elements.
+ return -1;
+ }
+ uint32_t block_size;
+ if (elem[-1] == 10) {
+ // No block size given, use default.
+ block_size = MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE;
+ } else if (elem[-1] == 14) {
+ // Block size given, extract it.
+ block_size = get_le32(&elem[10]);
+ } else {
+ // Invalid MOUNT element.
return -1;
}
if (elem[0] == mount_point) {
@@ -235,19 +251,20 @@ int fsload_process(void) {
const stream_methods_t *methods;
#if MBOOT_VFS_FAT
if (elem[1] == ELEM_MOUNT_FAT) {
+ (void)block_size;
ret = vfs_fat_mount(&ctx.fat, base_addr, byte_len);
methods = &vfs_fat_stream_methods;
} else
#endif
#if MBOOT_VFS_LFS1
if (elem[1] == ELEM_MOUNT_LFS1) {
- ret = vfs_lfs1_mount(&ctx.lfs1, base_addr, byte_len);
+ ret = vfs_lfs1_mount(&ctx.lfs1, base_addr, byte_len, block_size);
methods = &vfs_lfs1_stream_methods;
} else
#endif
#if MBOOT_VFS_LFS2
if (elem[1] == ELEM_MOUNT_LFS2) {
- ret = vfs_lfs2_mount(&ctx.lfs2, base_addr, byte_len);
+ ret = vfs_lfs2_mount(&ctx.lfs2, base_addr, byte_len, block_size);
methods = &vfs_lfs2_stream_methods;
} else
#endif
diff --git a/ports/stm32/mboot/vfs.h b/ports/stm32/mboot/vfs.h
index 6cf883a13..22bb98936 100644
--- a/ports/stm32/mboot/vfs.h
+++ b/ports/stm32/mboot/vfs.h
@@ -65,7 +65,7 @@ typedef struct _vfs_lfs1_context_t {
extern const stream_methods_t vfs_lfs1_stream_methods;
-int vfs_lfs1_mount(vfs_lfs1_context_t *ctx, uint32_t base_addr, uint32_t byte_len);
+int vfs_lfs1_mount(vfs_lfs1_context_t *ctx, uint32_t base_addr, uint32_t byte_len, uint32_t block_size);
#endif
@@ -89,7 +89,7 @@ typedef struct _vfs_lfs2_context_t {
extern const stream_methods_t vfs_lfs2_stream_methods;
-int vfs_lfs2_mount(vfs_lfs2_context_t *ctx, uint32_t base_addr, uint32_t byte_len);
+int vfs_lfs2_mount(vfs_lfs2_context_t *ctx, uint32_t base_addr, uint32_t byte_len, uint32_t block_size);
#endif
diff --git a/ports/stm32/mboot/vfs_lfs.c b/ports/stm32/mboot/vfs_lfs.c
index e4dc511db..3e4c9caf1 100644
--- a/ports/stm32/mboot/vfs_lfs.c
+++ b/ports/stm32/mboot/vfs_lfs.c
@@ -43,10 +43,6 @@
#define VFS_LFSx_MOUNT vfs_lfs1_mount
#define VFS_LFSx_STREAM_METHODS vfs_lfs1_stream_methods
-#define SUPERBLOCK_MAGIC_OFFSET (40)
-#define SUPERBLOCK_BLOCK_SIZE_OFFSET (28)
-#define SUPERBLOCK_BLOCK_COUNT_OFFSET (32)
-
static uint8_t lfs_read_buffer[LFS_READ_SIZE];
static uint8_t lfs_prog_buffer[LFS_PROG_SIZE];
static uint8_t lfs_lookahead_buffer[LFS_LOOKAHEAD_SIZE / 8];
@@ -59,10 +55,6 @@ static uint8_t lfs_lookahead_buffer[LFS_LOOKAHEAD_SIZE / 8];
#define VFS_LFSx_MOUNT vfs_lfs2_mount
#define VFS_LFSx_STREAM_METHODS vfs_lfs2_stream_methods
-#define SUPERBLOCK_MAGIC_OFFSET (8)
-#define SUPERBLOCK_BLOCK_SIZE_OFFSET (24)
-#define SUPERBLOCK_BLOCK_COUNT_OFFSET (28)
-
static uint8_t lfs_read_buffer[LFS_CACHE_SIZE];
static uint8_t lfs_prog_buffer[LFS_CACHE_SIZE];
static uint8_t lfs_lookahead_buffer[LFS_LOOKAHEAD_SIZE];
@@ -90,23 +82,7 @@ static int dev_sync(const struct LFSx_API (config) * c) {
return LFSx_MACRO(_ERR_OK);
}
-int VFS_LFSx_MOUNT(VFS_LFSx_CONTEXT_T *ctx, uint32_t base_addr, uint32_t byte_len) {
- // Read start of superblock.
- uint8_t buf[48];
- hw_read(base_addr, sizeof(buf), buf);
-
- // Verify littlefs and detect block size.
- if (memcmp(&buf[SUPERBLOCK_MAGIC_OFFSET], "littlefs", 8) != 0) {
- return -1;
- }
- uint32_t block_size = get_le32(&buf[SUPERBLOCK_BLOCK_SIZE_OFFSET]);
- uint32_t block_count = get_le32(&buf[SUPERBLOCK_BLOCK_COUNT_OFFSET]);
-
- // Verify size of volume.
- if (block_size * block_count != byte_len) {
- return -1;
- }
-
+int VFS_LFSx_MOUNT(VFS_LFSx_CONTEXT_T *ctx, uint32_t base_addr, uint32_t byte_len, uint32_t block_size) {
ctx->bdev_base_addr = base_addr;
struct LFSx_API (config) *config = &ctx->config;