1 /* 2 * Copyright (c) 2022-2025 Nordic Semiconductor ASA 3 * Copyright (c) 2023 Husqvarna AB 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 #if FFCONF_DEF != 80386 8 #error "Configuration version mismatch" 9 #endif 10 11 #include <zephyr/devicetree.h> 12 13 /* 14 * Overrides of FF_ options from ffconf.h 15 */ 16 #if defined(CONFIG_FS_FATFS_READ_ONLY) 17 #undef FF_FS_READONLY 18 #define FF_FS_READONLY CONFIG_FS_FATFS_READ_ONLY 19 #endif /* defined(CONFIG_FS_FATFS_READ_ONLY) */ 20 21 #if defined(CONFIG_FS_FATFS_MKFS) 22 #undef FF_USE_MKFS 23 #define FF_USE_MKFS CONFIG_FS_FATFS_MKFS 24 #else 25 /* Note that by default the ffconf.h disables MKFS */ 26 #undef FF_USE_MKFS 27 #define FF_USE_MKFS 1 28 #endif /* defined(CONFIG_FS_FATFS_MKFS) */ 29 30 #if defined(CONFIG_FS_FATFS_CODEPAGE) 31 #undef FF_CODE_PAGE 32 #define FF_CODE_PAGE CONFIG_FS_FATFS_CODEPAGE 33 #else 34 /* Note that default value, in ffconf.h, for FF_CODE_PAGE is 932 */ 35 #undef FF_CODE_PAGE 36 #define FF_CODE_PAGE 437 37 #endif /* defined(CONFIG_FS_FATFS_CODEPAGE) */ 38 39 #if defined(CONFIG_FS_FATFS_FF_USE_LFN) 40 #if CONFIG_FS_FATFS_FF_USE_LFN <= 3 41 #undef FF_USE_LFN 42 #define FF_USE_LFN CONFIG_FS_FATFS_FF_USE_LFN 43 #else 44 #error Invalid LFN buffer location 45 #endif 46 #endif /* defined(CONFIG_FS_FATFS_LFN) */ 47 48 #if defined(CONFIG_FS_FATFS_MAX_LFN) 49 #undef FF_MAX_LFN 50 #define FF_MAX_LFN CONFIG_FS_FATFS_MAX_LFN 51 #endif /* defined(CONFIG_FS_FATFS_MAX_LFN) */ 52 53 #if defined(CONFIG_FS_FATFS_MIN_SS) 54 #undef FF_MIN_SS 55 #define FF_MIN_SS CONFIG_FS_FATFS_MIN_SS 56 #endif /* defined(CONFIG_FS_FATFS_MIN_SS) */ 57 58 #if defined(CONFIG_FS_FATFS_MAX_SS) 59 #undef FF_MAX_SS 60 #define FF_MAX_SS CONFIG_FS_FATFS_MAX_SS 61 #endif /* defined(CONFIG_FS_FATFS_MAX_SS) */ 62 63 #if defined(CONFIG_FS_FATFS_EXFAT) 64 #undef FF_FS_EXFAT 65 #define FF_FS_EXFAT CONFIG_FS_FATFS_EXFAT 66 #endif /* defined(CONFIG_FS_FATFS_EXFAT) */ 67 68 #if defined(CONFIG_FS_FATFS_REENTRANT) 69 #undef FF_FS_REENTRANT 70 #undef FF_FS_TIMEOUT 71 #include <zephyr/kernel.h> 72 #define FF_FS_REENTRANT CONFIG_FS_FATFS_REENTRANT 73 #define FF_FS_TIMEOUT K_FOREVER 74 #endif /* defined(CONFIG_FS_FATFS_REENTRANT) */ 75 76 #if defined(CONFIG_FS_FATFS_LBA64) 77 #undef FF_LBA64 78 #define FF_LBA64 CONFIG_FS_FATFS_LBA64 79 #endif /* defined(CONFIG_FS_FATFS_LBA64) */ 80 81 #if defined(CONFIG_FS_FATFS_MULTI_PARTITION) 82 #undef FF_MULTI_PARTITION 83 #define FF_MULTI_PARTITION CONFIG_FS_FATFS_MULTI_PARTITION 84 #endif /* defined(CONFIG_FS_FATFS_MULTI_PARTITION) */ 85 86 /* 87 * These options are override from default values, but have no Kconfig 88 * options. 89 */ 90 #undef FF_FS_TINY 91 #define FF_FS_TINY 1 92 93 #undef FF_FS_NORTC 94 #if defined(CONFIG_FS_FATFS_HAS_RTC) 95 #define FF_FS_NORTC 0 96 #else 97 #define FF_FS_NORTC 1 98 #endif /* defined(CONFIG_FS_FATFS_HAS_RTC) */ 99 100 /* Zephyr uses FF_VOLUME_STRS */ 101 #undef FF_STR_VOLUME_ID 102 #define FF_STR_VOLUME_ID 1 103 104 /* By default FF_STR_VOLUME_ID in ffconf.h is 0, which means that 105 * FF_VOLUME_STRS is not used. Zephyr uses FF_VOLUME_STRS. 106 * The array of volume strings is automatically generated from devicetree. 107 */ 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(zephyr_mmc_disk, _FF_DISK_NAME) \ 117 DT_FOREACH_STATUS_OKAY(st_stm32_sdmmc, _FF_DISK_NAME) 118 119 #undef FF_VOLUMES 120 #define FF_VOLUMES NUM_VA_ARGS_LESS_1(FF_VOLUME_STRS _) 121 122 #if defined(CONFIG_FS_FATFS_EXTRA_NATIVE_API) 123 #undef FF_USE_LABEL 124 #undef FF_USE_EXPAND 125 #undef FF_USE_FIND 126 #define FF_USE_LABEL 1 127 #define FF_USE_EXPAND 1 128 #define FF_USE_FIND 1 129 #endif /* defined(CONFIG_FS_FATFS_EXTRA_NATIVE_API) */ 130 131 /* 132 * When custom mount points are activated FF_VOLUME_STRS needs 133 * to be undefined in order to be able to provide a custom 134 * VolumeStr array containing the contents of 135 * CONFIG_FS_FATFS_CUSTOM_MOUNT_POINTS. Additionally the 136 * FF_VOLUMES define needs to be set to the correct mount 137 * point count contained in 138 * CONFIG_FS_FATFS_CUSTOM_MOUNT_POINT_COUNT. 139 */ 140 #if CONFIG_FS_FATFS_CUSTOM_MOUNT_POINT_COUNT 141 #undef FF_VOLUMES 142 #define FF_VOLUMES CONFIG_FS_FATFS_CUSTOM_MOUNT_POINT_COUNT 143 #undef FF_VOLUME_STRS 144 #endif /* CONFIG_FS_FATFS_CUSTOM_MOUNT_POINT_COUNT */ 145 146 /* 147 * Options provided below have been added to ELM FAT source code to 148 * support Zephyr specific features, and are not part of ffconf.h. 149 */ 150 /* 151 * The FS_FATFS_WINDOW_ALIGNMENT is used to align win buffer of FATFS structure 152 * to allow more optimal use with MCUs that require specific bufer alignment 153 * for DMA to work. 154 */ 155 #if defined(CONFIG_FS_FATFS_WINDOW_ALIGNMENT) 156 #define FS_FATFS_WINDOW_ALIGNMENT CONFIG_FS_FATFS_WINDOW_ALIGNMENT 157 #else 158 #define FS_FATFS_WINDOW_ALIGNMENT 1 159 #endif /* defined(CONFIG_FS_FATFS_WINDOW_ALIGNMENT) */ 160