From 73081588529d04799080947bf09e979a6f46989c Mon Sep 17 00:00:00 2001 From: angryproton Date: Mon, 6 Jul 2026 00:03:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[feat][dfs]=20Elm=20FatFS=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=85=8D=E7=BD=AE=20FAT=20=E8=A1=A8=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E7=B0=87=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/Kconfig | 17 +++++++++++++++++ .../dfs/dfs_v1/filesystems/elmfat/dfs_elm.c | 6 ++++++ .../dfs/dfs_v2/filesystems/elmfat/dfs_elm.c | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 4d1418b80856..2a369e6efdab 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -137,6 +137,23 @@ endif help If you use some spi nor flash for fatfs, please set this the erase sector size, for example 4096. + config RT_DFS_ELM_NFATS + int "Number of FATs (File Allocation Tables) on the volume" + range 1 2 + default 1 + help + Number of copies of the FAT table. Setting 1 saves space while 2 + provides redundancy for fault tolerance. Used by f_mkfs(). + + config RT_DFS_ELM_CLUSTER_SIZE + int "Cluster size in bytes (0 = auto)" + default 0 + help + Cluster size (allocation unit size) used by f_mkfs(). + Set to 0 to let f_mkfs auto-select based on volume size. + Common values: 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536. + Must be a power of 2 and >= sector size. + config RT_DFS_ELM_USE_ERASE bool "Enable sector erase feature" default n diff --git a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c index effd1bcd7c7c..80209f806c52 100644 --- a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c @@ -275,6 +275,12 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name) /* [IN] Size of working buffer */ rt_memset(&opt, 0, sizeof(opt)); opt.fmt = FM_ANY|FM_SFD; +#ifdef RT_DFS_ELM_NFATS + opt.n_fat = RT_DFS_ELM_NFATS; +#endif +#ifdef RT_DFS_ELM_CLUSTER_SIZE + opt.au_size = RT_DFS_ELM_CLUSTER_SIZE; +#endif result = f_mkfs(logic_nbr, &opt, work, FF_MAX_SS); rt_free(work); work = RT_NULL; diff --git a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c index 90b87a178b4e..b0f74bf10461 100644 --- a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c @@ -313,6 +313,12 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name) /* [IN] Size of working buffer */ rt_memset(&opt, 0, sizeof(opt)); opt.fmt = FM_ANY|FM_SFD; +#ifdef RT_DFS_ELM_NFATS + opt.n_fat = RT_DFS_ELM_NFATS; +#endif +#ifdef RT_DFS_ELM_CLUSTER_SIZE + opt.au_size = RT_DFS_ELM_CLUSTER_SIZE; +#endif result = f_mkfs(logic_nbr, &opt, work, FF_MAX_SS); rt_free(work); work = RT_NULL; From 3dde34e2b2593c2021ffbb4713506b40efac1ec3 Mon Sep 17 00:00:00 2001 From: angryproton Date: Sun, 23 Aug 2026 13:30:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[CHG]=20RT=5FDFS=5FELM=5FCLUSTER=5FSIZE=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9E=9A=E4=B8=BE=E9=80=89=E6=8B=A9=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20512=20=E5=88=B0=2016M=20=E7=9A=84=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E5=80=BC=E5=8F=8A=20exFAT=20=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=87=AA=E5=8A=A8=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/Kconfig | 81 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 2a369e6efdab..8a369bb05c4a 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -145,14 +145,81 @@ endif Number of copies of the FAT table. Setting 1 saves space while 2 provides redundancy for fault tolerance. Used by f_mkfs(). - config RT_DFS_ELM_CLUSTER_SIZE - int "Cluster size in bytes (0 = auto)" - default 0 + choice + prompt "Cluster size in bytes (allocation unit size) used by f_mkfs()" + default RT_DFS_ELM_CLUSTER_SIZE_0 help - Cluster size (allocation unit size) used by f_mkfs(). - Set to 0 to let f_mkfs auto-select based on volume size. - Common values: 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536. - Must be a power of 2 and >= sector size. + Cluster size (allocation unit size) passed to f_mkfs(). + Must be a power of 2 and >= sector size (RT_DFS_ELM_MAX_SECTOR_SIZE). + Select "Auto" to let f_mkfs auto-select based on volume size. + A value smaller than the sector size (e.g. 512 on a 4096-byte + sector device) is invalid and will be silently overridden by + f_mkfs with its auto-selection, so pick a value >= sector size. + + config RT_DFS_ELM_CLUSTER_SIZE_0 + bool "Auto (0 = let f_mkfs decide)" + config RT_DFS_ELM_CLUSTER_SIZE_512 + bool "512 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_1024 + bool "1024 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_2048 + bool "2048 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_4096 + bool "4096 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_8192 + bool "8192 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_16384 + bool "16384 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_32768 + bool "32768 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_65536 + bool "65536 bytes" + config RT_DFS_ELM_CLUSTER_SIZE_131072 + bool "131072 bytes (128K) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_262144 + bool "262144 bytes (256K) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_524288 + bool "524288 bytes (512K) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_1048576 + bool "1048576 bytes (1M) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_2097152 + bool "2097152 bytes (2M) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_4194304 + bool "4194304 bytes (4M) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_8388608 + bool "8388608 bytes (8M) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + config RT_DFS_ELM_CLUSTER_SIZE_16777216 + bool "16777216 bytes (16M, FatFs max) - exFAT recommended" + depends on RT_DFS_ELM_USE_EXFAT + endchoice + + config RT_DFS_ELM_CLUSTER_SIZE + int + range 0 16777216 + default 0 if RT_DFS_ELM_CLUSTER_SIZE_0 + default 512 if RT_DFS_ELM_CLUSTER_SIZE_512 + default 1024 if RT_DFS_ELM_CLUSTER_SIZE_1024 + default 2048 if RT_DFS_ELM_CLUSTER_SIZE_2048 + default 4096 if RT_DFS_ELM_CLUSTER_SIZE_4096 + default 8192 if RT_DFS_ELM_CLUSTER_SIZE_8192 + default 16384 if RT_DFS_ELM_CLUSTER_SIZE_16384 + default 32768 if RT_DFS_ELM_CLUSTER_SIZE_32768 + default 65536 if RT_DFS_ELM_CLUSTER_SIZE_65536 + default 131072 if RT_DFS_ELM_CLUSTER_SIZE_131072 + default 262144 if RT_DFS_ELM_CLUSTER_SIZE_262144 + default 524288 if RT_DFS_ELM_CLUSTER_SIZE_524288 + default 1048576 if RT_DFS_ELM_CLUSTER_SIZE_1048576 + default 2097152 if RT_DFS_ELM_CLUSTER_SIZE_2097152 + default 4194304 if RT_DFS_ELM_CLUSTER_SIZE_4194304 + default 8388608 if RT_DFS_ELM_CLUSTER_SIZE_8388608 + default 16777216 if RT_DFS_ELM_CLUSTER_SIZE_16777216 config RT_DFS_ELM_USE_ERASE bool "Enable sector erase feature"