summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
authorChen Wang <[email protected]>2024-11-26 10:37:43 +0800
committerMeco Man <[email protected]>2024-11-26 21:45:00 -0500
commit032fe9c3a3dbfdcb338ef7ff5f0023c8f20d6b30 (patch)
tree6a18b8a7e8ca2f0295e9060cf5594e493e3f85c2 /bsp
parent1052f99537c31c38dc1aad39cec3d8fd38a06a2c (diff)
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]>
Diffstat (limited to 'bsp')
-rw-r--r--bsp/cvitek/drivers/port/mnt_diskfs.c90
1 files changed, 22 insertions, 68 deletions
diff --git a/bsp/cvitek/drivers/port/mnt_diskfs.c b/bsp/cvitek/drivers/port/mnt_diskfs.c
index 799b7c5ccf..ca80816f5a 100644
--- a/bsp/cvitek/drivers/port/mnt_diskfs.c
+++ b/bsp/cvitek/drivers/port/mnt_diskfs.c
@@ -2,107 +2,61 @@
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2022/12/25 flyingcys first version
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_fs.h>
-#include "dfs_romfs.h"
#define DBG_TAG "app.filesystem"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
-static const struct romfs_dirent _romfs_root[] =
-{
-#ifdef BSP_USING_ON_CHIP_FLASH
- {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
-#endif
- {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}
-};
-
-const struct romfs_dirent romfs_root =
+static int _wait_device_ready(const char* devname)
{
- ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])
-};
+ int k;
-static void sd_mount(void *parameter)
-{
- while (1)
+ for(k = 0; k < 10; k++)
{
- rt_thread_mdelay(500);
-
- if (rt_device_find("sd0") != RT_NULL)
+ if (rt_device_find(devname) != RT_NULL)
{
- if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
- {
- LOG_I("sd card mount to '/sdcard'");
- break;
- }
- else
- {
- LOG_W("sd card mount to '/sdcard' failed! %d\n", rt_get_errno());
- }
+ return 1;
}
+ rt_thread_mdelay(50);
}
+
+ return 0;
}
-int mount_init(void)
+static void sd_mount(const char *devname)
{
- if(dfs_mount(RT_NULL, "/", "rom", 0, &romfs_root) != 0)
- {
- LOG_E("rom mount to '/' failed!");
+ if (!_wait_device_ready(devname)) {
+ LOG_W("Failed to find device: %s", devname);
+ return;
}
-#ifdef BSP_USING_ON_CHIP_FLASH_FS
- struct rt_device *flash_dev = RT_NULL;
-
- /* 使用 filesystem 分区创建块设备,块设备名称为 filesystem */
- flash_dev = fal_blk_device_create("filesystem");
- if(flash_dev == RT_NULL)
+ if (dfs_mount(devname, "/", "ext", 0, 0) == RT_EOK)
{
- LOG_E("Failed to create device.\n");
- return -RT_ERROR;
+ LOG_I("device '%s' is mounted to '/' as EXT", devname);
}
-
- if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0)
+ else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK)
{
- LOG_I("file system initialization failed!\n");
- if(dfs_mkfs("lfs", "filesystem") == 0)
- {
- if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) == 0)
- {
- LOG_I("mount to '/flash' success!");
- }
- }
+ LOG_I("device '%s' is mounted to '/' as FAT", devname);
}
else
{
- LOG_I("mount to '/flash' success!");
+ LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno());
}
-#endif
+}
+int mount_init(void)
+{
#ifdef BSP_USING_SDH
- rt_thread_t tid;
-
- tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
- 4096, RT_THREAD_PRIORITY_MAX - 2, 20);
- if (tid != RT_NULL)
- {
- rt_thread_startup(tid);
- }
- else
- {
- LOG_E("create sd_mount thread err!");
- }
+ sd_mount("sd1");
#endif
return RT_EOK;
}
-INIT_APP_EXPORT(mount_init);
+INIT_ENV_EXPORT(mount_init);
#endif /* RT_USING_DFS */