|
2 | 2 | * Copyright (c) 2006-2023, RT-Thread Development Team |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | | - * |
6 | | - * Change Logs: |
7 | | - * Date Author Notes |
8 | | - * 2022/12/25 flyingcys first version |
9 | 5 | */ |
10 | 6 | #include <rtthread.h> |
11 | 7 |
|
12 | 8 | #ifdef RT_USING_DFS |
13 | 9 | #include <dfs_fs.h> |
14 | | -#include "dfs_romfs.h" |
15 | 10 |
|
16 | 11 | #define DBG_TAG "app.filesystem" |
17 | 12 | #define DBG_LVL DBG_LOG |
18 | 13 | #include <rtdbg.h> |
19 | 14 |
|
20 | | -static const struct romfs_dirent _romfs_root[] = |
21 | | -{ |
22 | | -#ifdef BSP_USING_ON_CHIP_FLASH |
23 | | - {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, |
24 | | -#endif |
25 | | - {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0} |
26 | | -}; |
27 | | - |
28 | | -const struct romfs_dirent romfs_root = |
| 15 | +static int _wait_device_ready(const char* devname) |
29 | 16 | { |
30 | | - ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0]) |
31 | | -}; |
| 17 | + int k; |
32 | 18 |
|
33 | | -static void sd_mount(void *parameter) |
34 | | -{ |
35 | | - while (1) |
| 19 | + for(k = 0; k < 10; k++) |
36 | 20 | { |
37 | | - rt_thread_mdelay(500); |
38 | | - |
39 | | - if (rt_device_find("sd0") != RT_NULL) |
| 21 | + if (rt_device_find(devname) != RT_NULL) |
40 | 22 | { |
41 | | - if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK) |
42 | | - { |
43 | | - LOG_I("sd card mount to '/sdcard'"); |
44 | | - break; |
45 | | - } |
46 | | - else |
47 | | - { |
48 | | - LOG_W("sd card mount to '/sdcard' failed! %d\n", rt_get_errno()); |
49 | | - } |
| 23 | + return 1; |
50 | 24 | } |
| 25 | + rt_thread_mdelay(50); |
51 | 26 | } |
| 27 | + |
| 28 | + return 0; |
52 | 29 | } |
53 | 30 |
|
54 | | -int mount_init(void) |
| 31 | +static void sd_mount(const char *devname) |
55 | 32 | { |
56 | | - if(dfs_mount(RT_NULL, "/", "rom", 0, &romfs_root) != 0) |
57 | | - { |
58 | | - LOG_E("rom mount to '/' failed!"); |
| 33 | + if (!_wait_device_ready(devname)) { |
| 34 | + LOG_W("Failed to find device: %s", devname); |
| 35 | + return; |
59 | 36 | } |
60 | 37 |
|
61 | | -#ifdef BSP_USING_ON_CHIP_FLASH_FS |
62 | | - struct rt_device *flash_dev = RT_NULL; |
63 | | - |
64 | | - /* 使用 filesystem 分区创建块设备,块设备名称为 filesystem */ |
65 | | - flash_dev = fal_blk_device_create("filesystem"); |
66 | | - if(flash_dev == RT_NULL) |
| 38 | + if (dfs_mount(devname, "/", "ext", 0, 0) == RT_EOK) |
67 | 39 | { |
68 | | - LOG_E("Failed to create device.\n"); |
69 | | - return -RT_ERROR; |
| 40 | + LOG_I("device '%s' is mounted to '/' as EXT", devname); |
70 | 41 | } |
71 | | - |
72 | | - if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0) |
| 42 | + else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK) |
73 | 43 | { |
74 | | - LOG_I("file system initialization failed!\n"); |
75 | | - if(dfs_mkfs("lfs", "filesystem") == 0) |
76 | | - { |
77 | | - if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) == 0) |
78 | | - { |
79 | | - LOG_I("mount to '/flash' success!"); |
80 | | - } |
81 | | - } |
| 44 | + LOG_I("device '%s' is mounted to '/' as FAT", devname); |
82 | 45 | } |
83 | 46 | else |
84 | 47 | { |
85 | | - LOG_I("mount to '/flash' success!"); |
| 48 | + LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno()); |
86 | 49 | } |
87 | | -#endif |
| 50 | +} |
88 | 51 |
|
| 52 | +int mount_init(void) |
| 53 | +{ |
89 | 54 | #ifdef BSP_USING_SDH |
90 | | - rt_thread_t tid; |
91 | | - |
92 | | - tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, |
93 | | - 4096, RT_THREAD_PRIORITY_MAX - 2, 20); |
94 | | - if (tid != RT_NULL) |
95 | | - { |
96 | | - rt_thread_startup(tid); |
97 | | - } |
98 | | - else |
99 | | - { |
100 | | - LOG_E("create sd_mount thread err!"); |
101 | | - } |
| 55 | + sd_mount("sd1"); |
102 | 56 | #endif |
103 | 57 |
|
104 | 58 | return RT_EOK; |
105 | 59 | } |
106 | | -INIT_APP_EXPORT(mount_init); |
| 60 | +INIT_ENV_EXPORT(mount_init); |
107 | 61 |
|
108 | 62 | #endif /* RT_USING_DFS */ |
0 commit comments