fs: shell: littlefs: add support of block devices
For flash device, littlefs should be located at the partition. Current implementation of the fs shell is hardcoded for the flash device and the compilation fails if STORAGE_PARTITION isn't defined in the device tree. Add options for block dev support. This allows to mount littlefs on the block device from the shell, and also removes the compile time dependency on STORAGE_PARTITION, if CONFIG_FS_LITTLEFS_BLK_DEV is set. Fix mounting of littlefs blk device. lfs_mount stucks in case when the read/prog buffer less than SDMMC block size, because it can cause memory corrupt, for example, look into function 'card_read_blocks' how it writes data to read buffer in case when buffer isn't aligned. With default config we have 32 bytes in the read buffer but trying to write 'block_size' to it and get memory corrupt, the same issue will be in case when the read buffer is aligned. This is an incremental improvement, ideally, someone should implement selection of the storage dev from the shell args. Co-authored-by: Mykola Kvach <mykola_kvach@epam.com> Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
This commit is contained in:
parent
26c9721b67
commit
8b33da03f3
1 changed files with 29 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <zephyr/shell/shell.h>
|
#include <zephyr/shell/shell.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/fs/fs.h>
|
#include <zephyr/fs/fs.h>
|
||||||
|
#include <zephyr/sd/sd_spec.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
@ -34,6 +35,33 @@ static struct fs_mount_t fatfs_mnt = {
|
||||||
/* LITTLEFS */
|
/* LITTLEFS */
|
||||||
#ifdef CONFIG_FILE_SYSTEM_LITTLEFS
|
#ifdef CONFIG_FILE_SYSTEM_LITTLEFS
|
||||||
#include <zephyr/fs/littlefs.h>
|
#include <zephyr/fs/littlefs.h>
|
||||||
|
|
||||||
|
/* TODO: Implement dynamic storage dev selection */
|
||||||
|
#ifdef CONFIG_FS_LITTLEFS_BLK_DEV
|
||||||
|
|
||||||
|
#if defined(CONFIG_DISK_DRIVER_SDMMC)
|
||||||
|
#define DISK_NAME CONFIG_SDMMC_VOLUME_NAME
|
||||||
|
#elif defined(CONFIG_DISK_DRIVER_MMC)
|
||||||
|
#define DISK_NAME CONFIG_MMC_VOLUME_NAME
|
||||||
|
#else
|
||||||
|
#error "No disk device defined, is your board supported?"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
FS_LITTLEFS_DECLARE_CUSTOM_CONFIG(
|
||||||
|
lfs_data,
|
||||||
|
CONFIG_SDHC_BUFFER_ALIGNMENT,
|
||||||
|
SDMMC_DEFAULT_BLOCK_SIZE,
|
||||||
|
SDMMC_DEFAULT_BLOCK_SIZE,
|
||||||
|
SDMMC_DEFAULT_BLOCK_SIZE,
|
||||||
|
2 * SDMMC_DEFAULT_BLOCK_SIZE);
|
||||||
|
|
||||||
|
static struct fs_mount_t littlefs_mnt = {
|
||||||
|
.type = FS_LITTLEFS,
|
||||||
|
.fs_data = &lfs_data,
|
||||||
|
.flags = FS_MOUNT_FLAG_USE_DISK_ACCESS,
|
||||||
|
.storage_dev = DISK_NAME,
|
||||||
|
};
|
||||||
|
#else
|
||||||
#include <zephyr/storage/flash_map.h>
|
#include <zephyr/storage/flash_map.h>
|
||||||
|
|
||||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(lfs_data);
|
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(lfs_data);
|
||||||
|
@ -43,6 +71,7 @@ static struct fs_mount_t littlefs_mnt = {
|
||||||
.storage_dev = (void *)STORAGE_PARTITION_ID,
|
.storage_dev = (void *)STORAGE_PARTITION_ID,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BUF_CNT 64
|
#define BUF_CNT 64
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue