1 /*
2  * Copyright (c) 2006-2020, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2020/12/31     Bernard      Add license info
9  */
10 
11 #include <rtthread.h>
12 
13 #define DBG_TAG     "FileSystem"
14 #define DBG_LVL     DBG_INFO
15 #include <rtdbg.h>
16 
17 #ifdef RT_USING_DFS
18 #include <dfs_fs.h>
19 
mnt_init(void)20 int mnt_init(void)
21 {
22     rt_thread_delay(RT_TICK_PER_SECOND);
23 
24     if (dfs_mount("sd", "/", "elm", 0, 0) == 0)
25     {
26         LOG_I("file system initialization done!\n");
27         return 0;
28     }
29     else
30     {
31         LOG_W("[sd] File System on SD ('sd') initialization failed!");
32         LOG_W("[sd] Try to format and re-mount...");
33         if (dfs_mkfs("elm", "sd") == 0)
34         {
35             if (dfs_mount("sd", "/", "elm", 0, 0) == 0)
36             {
37                 LOG_I("[sd] File System on SD ('sd') initialized!");
38                 return 0;
39             }
40         }
41 
42         LOG_E("[sd] File System on SD ('sd') initialization failed!");
43         return -1;
44     }
45 
46 }
47 INIT_ENV_EXPORT(mnt_init);
48 #endif
49