From 032fe9c3a3dbfdcb338ef7ff5f0023c8f20d6b30 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 26 Nov 2024 10:37:43 +0800 Subject: [PATCH] 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 --- bsp/cvitek/drivers/port/mnt_diskfs.c | 108 ++++++++------------------- 1 file changed, 31 insertions(+), 77 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 #ifdef RT_USING_DFS #include -#include "dfs_romfs.h" #define DBG_TAG "app.filesystem" #define DBG_LVL DBG_LOG #include -static const struct romfs_dirent _romfs_root[] = +static int _wait_device_ready(const char* devname) { -#ifdef BSP_USING_ON_CHIP_FLASH - {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, -#endif - {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0} -}; + int k; -const struct romfs_dirent romfs_root = -{ - ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0]) -}; - -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; +} + +static void sd_mount(const char *devname) +{ + if (!_wait_device_ready(devname)) { + LOG_W("Failed to find device: %s", devname); + return; + } + + if (dfs_mount(devname, "/", "ext", 0, 0) == RT_EOK) + { + LOG_I("device '%s' is mounted to '/' as EXT", devname); + } + else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK) + { + LOG_I("device '%s' is mounted to '/' as FAT", devname); + } + else + { + LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno()); } } int mount_init(void) { - if(dfs_mount(RT_NULL, "/", "rom", 0, &romfs_root) != 0) - { - LOG_E("rom mount to '/' failed!"); - } - -#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) - { - LOG_E("Failed to create device.\n"); - return -RT_ERROR; - } - - if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0) - { - 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!"); - } - } - } - else - { - LOG_I("mount to '/flash' success!"); - } -#endif - #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 */