2024-04-24 05:40:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
|
|
|
#define DBG_TAG "app.filesystem"
|
|
|
|
#define DBG_LVL DBG_LOG
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
2024-11-26 10:37:43 +08:00
|
|
|
static int _wait_device_ready(const char* devname)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
int k;
|
2024-04-24 05:40:22 +08:00
|
|
|
|
2024-11-26 10:37:43 +08:00
|
|
|
for(k = 0; k < 10; k++)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
if (rt_device_find(devname) != RT_NULL)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
return 1;
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
2024-11-26 10:37:43 +08:00
|
|
|
rt_thread_mdelay(50);
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
2024-11-26 10:37:43 +08:00
|
|
|
|
|
|
|
return 0;
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
|
|
|
|
2024-11-26 10:37:43 +08:00
|
|
|
static void sd_mount(const char *devname)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
if (!_wait_device_ready(devname)) {
|
|
|
|
LOG_W("Failed to find device: %s", devname);
|
|
|
|
return;
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
|
|
|
|
2024-11-26 10:37:43 +08:00
|
|
|
if (dfs_mount(devname, "/", "ext", 0, 0) == RT_EOK)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
LOG_I("device '%s' is mounted to '/' as EXT", devname);
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
2024-11-26 10:37:43 +08:00
|
|
|
else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK)
|
2024-04-24 05:40:22 +08:00
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
LOG_I("device '%s' is mounted to '/' as FAT", devname);
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-11-26 10:37:43 +08:00
|
|
|
LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno());
|
2024-04-24 05:40:22 +08:00
|
|
|
}
|
2024-11-26 10:37:43 +08:00
|
|
|
}
|
2024-04-24 05:40:22 +08:00
|
|
|
|
2024-11-26 10:37:43 +08:00
|
|
|
int mount_init(void)
|
|
|
|
{
|
2024-04-24 05:40:22 +08:00
|
|
|
#ifdef BSP_USING_SDH
|
2024-11-26 10:37:43 +08:00
|
|
|
sd_mount("sd1");
|
2024-04-24 05:40:22 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
2024-11-26 10:37:43 +08:00
|
|
|
INIT_ENV_EXPORT(mount_init);
|
2024-04-24 05:40:22 +08:00
|
|
|
|
|
|
|
#endif /* RT_USING_DFS */
|