Skip to content

Commit 032fe9c

Browse files
unicornxmysterywolf
authored andcommitted
bsp: cvitek: support mount fat/ext rootfs for rt-smart
Support mount rootfs automaticly during booting up. First try ext, then fat. Plus some code cleanup, such as remove BSP_USING_ON_CHIP_FLASH_FS, which is not defined and unused. Signed-off-by: Chen Wang <[email protected]>
1 parent 1052f99 commit 032fe9c

File tree

1 file changed

+22
-68
lines changed

1 file changed

+22
-68
lines changed

bsp/cvitek/drivers/port/mnt_diskfs.c

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,61 @@
22
* Copyright (c) 2006-2023, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
5-
*
6-
* Change Logs:
7-
* Date Author Notes
8-
* 2022/12/25 flyingcys first version
95
*/
106
#include <rtthread.h>
117

128
#ifdef RT_USING_DFS
139
#include <dfs_fs.h>
14-
#include "dfs_romfs.h"
1510

1611
#define DBG_TAG "app.filesystem"
1712
#define DBG_LVL DBG_LOG
1813
#include <rtdbg.h>
1914

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)
2916
{
30-
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])
31-
};
17+
int k;
3218

33-
static void sd_mount(void *parameter)
34-
{
35-
while (1)
19+
for(k = 0; k < 10; k++)
3620
{
37-
rt_thread_mdelay(500);
38-
39-
if (rt_device_find("sd0") != RT_NULL)
21+
if (rt_device_find(devname) != RT_NULL)
4022
{
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;
5024
}
25+
rt_thread_mdelay(50);
5126
}
27+
28+
return 0;
5229
}
5330

54-
int mount_init(void)
31+
static void sd_mount(const char *devname)
5532
{
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;
5936
}
6037

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)
6739
{
68-
LOG_E("Failed to create device.\n");
69-
return -RT_ERROR;
40+
LOG_I("device '%s' is mounted to '/' as EXT", devname);
7041
}
71-
72-
if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0)
42+
else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK)
7343
{
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);
8245
}
8346
else
8447
{
85-
LOG_I("mount to '/flash' success!");
48+
LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno());
8649
}
87-
#endif
50+
}
8851

52+
int mount_init(void)
53+
{
8954
#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");
10256
#endif
10357

10458
return RT_EOK;
10559
}
106-
INIT_APP_EXPORT(mount_init);
60+
INIT_ENV_EXPORT(mount_init);
10761

10862
#endif /* RT_USING_DFS */

0 commit comments

Comments
 (0)