From 327a389642c91689f04d75944b2f5a6a865d26ef Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Fri, 17 Jan 2025 16:47:38 -0500 Subject: [PATCH 1/2] fs: littlefs: rename Kconfig option for multi-version support The name is now consistent with the name used upstream. This also frees up CONFIG_FS_LITTLEFS_DISK_VERSION for the actual version number. Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com> --- modules/littlefs/zephyr_lfs_config.h | 2 +- subsys/fs/Kconfig.littlefs | 2 +- subsys/fs/littlefs_fs.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/littlefs/zephyr_lfs_config.h b/modules/littlefs/zephyr_lfs_config.h index 32bd1e36f9bd0f..bff4a5cca98609 100644 --- a/modules/littlefs/zephyr_lfs_config.h +++ b/modules/littlefs/zephyr_lfs_config.h @@ -43,7 +43,7 @@ extern "C" { #endif -#ifdef CONFIG_FS_LITTLEFS_DISK_VERSION +#ifdef CONFIG_FS_LITTLEFS_MULTIVERSION #define LFS_MULTIVERSION #endif diff --git a/subsys/fs/Kconfig.littlefs b/subsys/fs/Kconfig.littlefs index 048e921f62bd18..16219bcc58079e 100644 --- a/subsys/fs/Kconfig.littlefs +++ b/subsys/fs/Kconfig.littlefs @@ -117,7 +117,7 @@ config FS_LITTLEFS_BLK_DEV Enable this option to provide support for littlefs on the block devices (like for example SD card). -config FS_LITTLEFS_DISK_VERSION +config FS_LITTLEFS_MULTIVERSION bool "Support for selecting littlefs disk version" default y if $(dt_compat_any_has_prop,$(DT_COMPAT_ZEPHYR_FSTAB_LITTLEFS),disk-version) help diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index b65523c6b345cc..a6418ca550c1f5 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -789,13 +789,13 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags) lookahead_size = CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE; } -#ifdef CONFIG_FS_LITTLEFS_DISK_VERSION +#ifdef CONFIG_FS_LITTLEFS_MULTIVERSION uint32_t disk_version = lcp->disk_version; if (disk_version == 0) { disk_version = LFS_DISK_VERSION; } -#endif /* CONFIG_FS_LITTLEFS_DISK_VERSION */ +#endif /* CONFIG_FS_LITTLEFS_MULTIVERSION */ /* No, you don't get to override this. */ lfs_size_t block_count = 0; @@ -881,12 +881,12 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags) lcp->sync = lfs_api_sync; } -#ifdef CONFIG_FS_LITTLEFS_DISK_VERSION +#ifdef CONFIG_FS_LITTLEFS_MULTIVERSION lcp->disk_version = disk_version; LOG_INF("partition disk version: %u.%u", (uint32_t)FS_LITTLEFS_DISK_VERSION_MAJOR_GET(disk_version), (uint32_t)FS_LITTLEFS_DISK_VERSION_MINOR_GET(disk_version)); -#endif /* CONFIG_FS_LITTLEFS_DISK_VERSION */ +#endif /* CONFIG_FS_LITTLEFS_MULTIVERSION */ lcp->block_size = block_size; lcp->block_count = block_count; @@ -1060,7 +1060,7 @@ static const struct fs_file_system_t littlefs_fs = { #define DT_DRV_COMPAT zephyr_fstab_littlefs #define FS_PARTITION(inst) DT_PHANDLE_BY_IDX(DT_DRV_INST(inst), partition, 0) -#ifdef CONFIG_FS_LITTLEFS_DISK_VERSION +#ifdef CONFIG_FS_LITTLEFS_MULTIVERSION #define FS_DISK_VERSION(inst) \ .disk_version = DT_INST_PROP_OR(inst, disk_version, LFS_DISK_VERSION), #else From 6c91685f9c96e38d757a8df336fe8c4a159ca27c Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Fri, 17 Jan 2025 16:52:50 -0500 Subject: [PATCH 2/2] fs: littlefs: define default disk version in Kconfig This makes it possible to set the disk version when Devicetree is not used for configuration. Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com> --- subsys/fs/Kconfig.littlefs | 7 +++++++ subsys/fs/littlefs_fs.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/subsys/fs/Kconfig.littlefs b/subsys/fs/Kconfig.littlefs index 16219bcc58079e..b16174d603e391 100644 --- a/subsys/fs/Kconfig.littlefs +++ b/subsys/fs/Kconfig.littlefs @@ -125,4 +125,11 @@ config FS_LITTLEFS_MULTIVERSION to maintain backward compatibility with existing littlefs with the same major disk version. +config FS_LITTLEFS_DISK_VERSION + hex "Default littlefs disk version" + default 0 + depends on FS_LITTLEFS_MULTIVERSION + help + Set to 0 to use the latest littlefs disk version (LFS_DISK_VERSION). + endif # FILE_SYSTEM_LITTLEFS diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index a6418ca550c1f5..9fffdc81b7f1fe 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -793,7 +793,10 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags) uint32_t disk_version = lcp->disk_version; if (disk_version == 0) { - disk_version = LFS_DISK_VERSION; + disk_version = CONFIG_FS_LITTLEFS_DISK_VERSION; + if (disk_version == 0) { + disk_version = LFS_DISK_VERSION; + } } #endif /* CONFIG_FS_LITTLEFS_MULTIVERSION */