2021-07-28 18:20:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-12-13 balanceTWK add sdcard port file
|
|
|
|
* 2021-05-10 Meco Man fix a bug that cannot use fatfs in the main thread at starting up
|
|
|
|
* 2021-07-28 Meco Man implement romfs as the root filesystem
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#ifdef BSP_USING_FS
|
|
|
|
#include <dfs_romfs.h>
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
#include <dfs_posix.h>
|
2021-08-04 18:22:04 +08:00
|
|
|
|
2021-07-28 18:20:02 +08:00
|
|
|
#if DFS_FILESYSTEMS_MAX < 4
|
|
|
|
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
|
|
|
|
#endif
|
|
|
|
#if DFS_FILESYSTEM_TYPES_MAX < 4
|
|
|
|
#error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DBG_TAG "app.filesystem"
|
|
|
|
#define DBG_LVL DBG_INFO
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
2021-08-06 15:15:56 +08:00
|
|
|
#ifdef BSP_USING_SDCARD_FATFS
|
2021-07-28 18:20:02 +08:00
|
|
|
static int onboard_sdcard_mount(void)
|
|
|
|
{
|
|
|
|
if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
|
|
|
|
{
|
2021-08-21 04:10:45 +08:00
|
|
|
LOG_I("SD card mount to '/sdcard'");
|
2021-07-28 18:20:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-21 04:10:45 +08:00
|
|
|
LOG_E("SD card mount to '/sdcard' failed!");
|
2021-07-28 18:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-08-05 10:47:34 +08:00
|
|
|
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
2021-08-05 21:11:03 +08:00
|
|
|
#include <fal.h>
|
|
|
|
#define FS_PARTITION_NAME "spiflash0"
|
2021-08-04 18:22:04 +08:00
|
|
|
|
2021-08-05 21:11:03 +08:00
|
|
|
static int onboard_spiflash_mount(void)
|
2021-08-04 18:22:04 +08:00
|
|
|
{
|
|
|
|
struct rt_device *mtd_dev = RT_NULL;
|
2021-08-05 21:11:03 +08:00
|
|
|
|
2021-08-04 18:22:04 +08:00
|
|
|
fal_init();
|
2021-08-06 15:15:56 +08:00
|
|
|
|
2021-08-04 18:22:04 +08:00
|
|
|
mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
|
|
|
|
if (!mtd_dev)
|
|
|
|
{
|
|
|
|
LOG_E("Can't create a mtd device on '%s' partition.", FS_PARTITION_NAME);
|
|
|
|
}
|
|
|
|
|
2021-08-05 21:11:03 +08:00
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK)
|
2021-08-04 18:22:04 +08:00
|
|
|
{
|
2021-08-05 21:11:03 +08:00
|
|
|
LOG_I("spi flash mount to '/spiflash'");
|
2021-08-04 18:22:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-05 21:11:03 +08:00
|
|
|
dfs_mkfs("lfs", FS_PARTITION_NAME);
|
|
|
|
if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK)
|
2021-08-04 18:22:04 +08:00
|
|
|
{
|
2021-08-05 21:11:03 +08:00
|
|
|
LOG_I("spi flash mount to '/spiflash'");
|
2021-08-04 18:22:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-05 21:11:03 +08:00
|
|
|
LOG_E("spi flash failed to mount to '/spiflash'");
|
2021-08-04 18:22:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-28 18:20:02 +08:00
|
|
|
static const struct romfs_dirent _romfs_root[] =
|
|
|
|
{
|
2021-08-06 15:15:56 +08:00
|
|
|
#ifdef BSP_USING_SDCARD_FATFS
|
2021-07-28 18:20:02 +08:00
|
|
|
{ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0},
|
|
|
|
#endif
|
2021-08-05 10:47:34 +08:00
|
|
|
|
|
|
|
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
2021-08-05 21:11:03 +08:00
|
|
|
{ROMFS_DIRENT_DIR, "spiflash", RT_NULL, 0},
|
2021-08-04 18:22:04 +08:00
|
|
|
#endif
|
2021-07-28 18:20:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct romfs_dirent romfs_root =
|
|
|
|
{
|
|
|
|
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
static int filesystem_mount(void)
|
|
|
|
{
|
|
|
|
if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0)
|
|
|
|
{
|
|
|
|
LOG_E("rom mount to '/' failed!");
|
|
|
|
}
|
2021-08-06 15:15:56 +08:00
|
|
|
#ifdef BSP_USING_SDCARD_FATFS
|
2021-07-28 18:20:02 +08:00
|
|
|
onboard_sdcard_mount();
|
|
|
|
#endif
|
2021-08-05 18:31:06 +08:00
|
|
|
|
2021-08-05 10:47:34 +08:00
|
|
|
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
|
|
|
|
onboard_spiflash_mount();
|
2021-08-04 18:22:04 +08:00
|
|
|
#endif
|
2021-08-05 18:31:06 +08:00
|
|
|
|
2021-07-28 18:20:02 +08:00
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
INIT_APP_EXPORT(filesystem_mount);
|
|
|
|
|
|
|
|
#endif /* BSP_USING_FS */
|