2022-06-09 14:28:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-06-08 supperthomas first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
|
|
|
|
#include "fal.h"
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
2022-06-13 21:15:12 +08:00
|
|
|
#define DBG_TAG "mnt"
|
|
|
|
#define DBG_LVL DBG_INFO
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
2022-06-09 14:28:36 +08:00
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
|
|
|
int mnt_init(void)
|
|
|
|
{
|
2022-06-13 21:15:12 +08:00
|
|
|
#ifdef BSP_USING_ON_CHIP_FLASH
|
2022-06-09 14:28:36 +08:00
|
|
|
fal_init();
|
|
|
|
#define FS_PARTITION_NAME "flash"
|
|
|
|
struct rt_device *mtd_dev;
|
|
|
|
mtd_dev = fal_blk_device_create(FS_PARTITION_NAME);
|
2022-06-13 21:15:12 +08:00
|
|
|
if (!mtd_dev)
|
|
|
|
{
|
|
|
|
LOG_E("Failed to create device.\n");
|
|
|
|
}
|
|
|
|
#ifdef BSP_USING_ON_CHIP_FLASH_FATFS
|
2022-06-09 14:28:36 +08:00
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == 0)
|
|
|
|
{
|
2022-06-13 21:15:12 +08:00
|
|
|
LOG_I("Filesystem initialized!");
|
2022-06-09 14:28:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dfs_mkfs("elm", FS_PARTITION_NAME);
|
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) != 0)
|
|
|
|
{
|
2022-06-13 21:15:12 +08:00
|
|
|
LOG_I("Failed to initialize filesystem!");
|
2022-06-09 14:28:36 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-13 21:15:12 +08:00
|
|
|
#endif /* BSP_USING_ON_CHIP_FLASH_FATFS */
|
|
|
|
#endif /* BSP_USING_ON_CHIP_FLASH */
|
2022-06-09 14:28:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
INIT_ENV_EXPORT(mnt_init);
|
2022-06-13 21:15:12 +08:00
|
|
|
#endif /* RT_USING_DFS */
|