Skip to content

Commit befb464

Browse files
JordanYateskartben
authored andcommitted
modules: fatfs: volume strings from DTS
Instead of relying on a hardcoded list of valid strings, automatically create a perfectly sized array of disk names from devicetree. Signed-off-by: Jordan Yates <[email protected]>
1 parent 0b5021a commit befb464

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

modules/fatfs/zephyr_fatfs_config.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#error "Configuration version mismatch"
99
#endif
1010

11+
#include <zephyr/devicetree.h>
12+
1113
/*
1214
* Overrides of FF_ options from ffconf.h
1315
*/
@@ -100,13 +102,21 @@
100102
#define FF_STR_VOLUME_ID 1
101103

102104
/* By default FF_STR_VOLUME_ID in ffconf.h is 0, which means that
103-
* FF_VOLUME_STRS is not used. Zephyr uses FF_VOLUME_STRS, which
104-
* by default holds 8 possible strings representing mount points,
105-
* and FF_VOLUMES needs to reflect that, which means that dolt
106-
* value of 1 is overridden here with 8.
105+
* FF_VOLUME_STRS is not used. Zephyr uses FF_VOLUME_STRS.
106+
* The array of volume strings is automatically generated from devicetree.
107107
*/
108+
109+
#define _FF_DISK_NAME(node) DT_PROP(node, disk_name),
110+
111+
#undef FF_VOLUME_STRS
112+
#define FF_VOLUME_STRS \
113+
DT_FOREACH_STATUS_OKAY(zephyr_flash_disk, _FF_DISK_NAME) \
114+
DT_FOREACH_STATUS_OKAY(zephyr_ram_disk, _FF_DISK_NAME) \
115+
DT_FOREACH_STATUS_OKAY(zephyr_sdmmc_disk, _FF_DISK_NAME) \
116+
DT_FOREACH_STATUS_OKAY(st_stm32_sdmmc, _FF_DISK_NAME)
117+
108118
#undef FF_VOLUMES
109-
#define FF_VOLUMES 8
119+
#define FF_VOLUMES NUM_VA_ARGS_LESS_1(FF_VOLUME_STRS _)
110120

111121
#if defined(CONFIG_FS_FATFS_EXTRA_NATIVE_API)
112122
#undef FF_USE_LABEL

0 commit comments

Comments
 (0)