diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 4d1418b80856..8a369bb05c4a 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -137,6 +137,90 @@ 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(). + + 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) 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" 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;