From 891a05dca69c3103e6f3dbbec87928c891688e35 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 2 May 2020 22:07:30 +0200 Subject: [PATCH] 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)