1 /*
2  * Copyright (c) 2022 Antmicro <www.antmicro.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/fs/fs.h>
10 #include <zephyr/logging/log.h>
11 
12 #if defined(CONFIG_FILE_SYSTEM_LITTLEFS) && defined(CONFIG_FAT_FILESYSTEM_ELM)
13 #error "Only one file system may be used at once in that sample."
14 #endif
15 
16 
17 #if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
18 
19 #include <zephyr/storage/flash_map.h>
20 #include <zephyr/fs/littlefs.h>
21 
22 #define MKFS_FS_TYPE FS_LITTLEFS
23 #define MKFS_DEV_ID FIXED_PARTITION_ID(storage_partition)
24 #define MKFS_FLAGS 0
25 
26 #elif defined(CONFIG_FAT_FILESYSTEM_ELM)
27 
28 #include <zephyr/storage/disk_access.h>
29 #include <ff.h>
30 
31 #define MKFS_FS_TYPE FS_FATFS
32 #define MKFS_DEV_ID "RAM:"
33 #define MKFS_FLAGS 0
34 
35 #else
36 #error "No filesystem specified."
37 #endif
38 
39 LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
40 
main(void)41 int main(void)
42 {
43 	int rc;
44 
45 	rc = fs_mkfs(MKFS_FS_TYPE, (uintptr_t)MKFS_DEV_ID, NULL, MKFS_FLAGS);
46 
47 	if (rc < 0) {
48 		LOG_ERR("Format failed");
49 		return 0;
50 	}
51 
52 	LOG_INF("Format successful");
53 	return 0;
54 }
55