From 85a7254326c57d36ad27bf4f60dcde9ea026942f Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 2 May 2020 22:06:38 +0200 Subject: [PATCH 1/3] pkg/littlefs: init MTD device before accessing it's parameters The parameters of the MTD device (`sector_count`, `page_size`) are only known after the device has been initialized. Init the device before using it to avoid reading all 0 on e.g. SD cards. --- pkg/littlefs/fs/littlefs_fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/littlefs/fs/littlefs_fs.c b/pkg/littlefs/fs/littlefs_fs.c index 0d7d61294f..8738aa57ea 100644 --- a/pkg/littlefs/fs/littlefs_fs.c +++ b/pkg/littlefs/fs/littlefs_fs.c @@ -132,6 +132,12 @@ static int prepare(littlefs_desc_t *fs) mutex_init(&fs->lock); mutex_lock(&fs->lock); + int ret = mtd_init(fs->dev); + + if (ret) { + return ret; + } + memset(&fs->fs, 0, sizeof(fs->fs)); if (!fs->config.block_count) { @@ -163,7 +169,7 @@ static int prepare(littlefs_desc_t *fs) fs->config.prog_buffer = fs->prog_buf; #endif - return mtd_init(fs->dev); + return 0; } static int _format(vfs_mount_t *mountp) From 891a05dca69c3103e6f3dbbec87928c891688e35 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 2 May 2020 22:07:30 +0200 Subject: [PATCH 2/3] pkg/littlefs2: init MTD device before accessing it's parameters The parameters of the MTD device (`sector_count`, `page_size`) are only known after the device has been initialized. Init the device before using it to avoid reading all 0 on e.g. SD cards. --- pkg/littlefs2/fs/littlefs2_fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/littlefs2/fs/littlefs2_fs.c b/pkg/littlefs2/fs/littlefs2_fs.c index 2bcf2f125f..5d43327590 100644 --- a/pkg/littlefs2/fs/littlefs2_fs.c +++ b/pkg/littlefs2/fs/littlefs2_fs.c @@ -132,6 +132,12 @@ static int prepare(littlefs_desc_t *fs) mutex_init(&fs->lock); mutex_lock(&fs->lock); + int ret = mtd_init(fs->dev); + + if (ret) { + return ret; + } + memset(&fs->fs, 0, sizeof(fs->fs)); if (!fs->config.block_count) { @@ -169,7 +175,7 @@ static int prepare(littlefs_desc_t *fs) fs->config.prog_buffer = fs->prog_buf; #endif - return mtd_init(fs->dev); + return 0; } static int _format(vfs_mount_t *mountp) From 348b45f600e7e523880c7edaf967d5e1cdcce4d0 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 2 May 2020 22:08:56 +0200 Subject: [PATCH 3/3] pkg/spiffs: init MTD device before accessing it's parameters The parameters of the MTD device (`sector_count`, `page_size`) are only known after the device has been initialized. Init the device before using it to avoid reading all 0 on e.g. SD cards. --- pkg/spiffs/fs/spiffs_fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/spiffs/fs/spiffs_fs.c b/pkg/spiffs/fs/spiffs_fs.c index 3a7d959468..4f9566578b 100644 --- a/pkg/spiffs/fs/spiffs_fs.c +++ b/pkg/spiffs/fs/spiffs_fs.c @@ -129,6 +129,12 @@ static int prepare(spiffs_desc_t *fs_desc) mtd_dev_t *dev = SPIFFS_MTD_DEV; #endif + int res = mtd_init(dev); + + if (res) { + return res; + } + fs_desc->config.hal_read_f = _dev_read; fs_desc->config.hal_write_f = _dev_write; fs_desc->config.hal_erase_f = _dev_erase; @@ -149,7 +155,7 @@ static int prepare(spiffs_desc_t *fs_desc) fs_desc->config.phys_erase_block = dev->page_size * dev->pages_per_sector; #endif - return mtd_init(dev); + return 0; } static int _format(vfs_mount_t *mountp)