diff --git a/bsp/cvitek/cv18xx_risc-v/Kconfig b/bsp/cvitek/cv18xx_risc-v/Kconfig index e21d6bfedc..42796ddcb2 100755 --- a/bsp/cvitek/cv18xx_risc-v/Kconfig +++ b/bsp/cvitek/cv18xx_risc-v/Kconfig @@ -75,3 +75,18 @@ choice bool "milkv-duo256m-spinor" endchoice + +choice BSP_ROOTFS_TYPE + prompt "rootfs type" + default BSP_ROOTFS_TYPE_ROMFS + + config BSP_ROOTFS_TYPE_ROMFS + bool "ROMFS" + select RT_USING_DFS_ROMFS + + config BSP_ROOTFS_TYPE_CROMFS + bool "CROMFS" + select RT_USING_DFS_CROMFS + select PKG_USING_ZLIB + select PKG_USING_ZLIB_LATEST_VERSION +endchoice diff --git a/bsp/cvitek/drivers/SConscript b/bsp/cvitek/drivers/SConscript index 91961af61a..56bca8b136 100755 --- a/bsp/cvitek/drivers/SConscript +++ b/bsp/cvitek/drivers/SConscript @@ -38,10 +38,14 @@ if GetDepend('BSP_USING_PWM'): src += ['drv_pwm.c'] CPPPATH += [cwd + r'/libraries/cv180x/pwm'] -if GetDepend('BSP_USING_SDH'): - src += ['drv_sdhci.c', 'port/mnt.c'] - CPPPATH += [cwd + r'/libraries/sdif'] +if GetDepend('BSP_ROOTFS_TYPE_CROMFS'): + src += ['port/mnt_cromfs.c'] +elif GetDepend('BSP_ROOTFS_TYPE_ROMFS'): + src += ['port/mnt_romfs.c'] +if GetDepend('BSP_USING_SDH'): + src += ['drv_sdhci.c'] + CPPPATH += [cwd + r'/libraries/sdif'] if GetDepend('BSP_USING_ETH'): src += Split(''' diff --git a/bsp/cvitek/drivers/port/mnt_cromfs.c b/bsp/cvitek/drivers/port/mnt_cromfs.c new file mode 100644 index 0000000000..5ca7416215 --- /dev/null +++ b/bsp/cvitek/drivers/port/mnt_cromfs.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-06-18 Shell add cromfs support + */ + +#define DBG_TAG "app.filesystem" +#define DBG_LVL DBG_LOG +#include + +#include +#include +#include +#include +#include +#include + +#include + +struct _mount_table +{ + char *dev_name; + char *mount_point; + char *fs_name; + long rwflag; + void *data; +}; + +struct _mount_table _mount_table[] = { + [0] = {NULL, "/", "crom", 0, 0}, + +}; + +static int _wait_device_ready(const char* devname) +{ + int k; + + for(k = 0; k < 10; k++) + { + if (rt_device_find(devname) != RT_NULL) + { + return 1; + } + rt_thread_mdelay(50); + } + + return 0; +} + +int mnt_init(void) +{ + int i; + uint32_t crom_data_len = 0; + uint32_t length; + + _mount_table[0].data = cromfs_get_partition_data(&length); + crom_data_len = length; + + if (_mount_table[0].data && (crom_data_len > 0)) + { + for (i = 0; i < sizeof(_mount_table) / sizeof(_mount_table[0]); i++) + { + if (_mount_table[i].dev_name && !_wait_device_ready(_mount_table[i].dev_name)) + { + LOG_E("device %s find timeout", _mount_table[i].dev_name); + continue; + } + + if (dfs_mount(_mount_table[i].dev_name, _mount_table[i].mount_point, + _mount_table[i].fs_name, _mount_table[i].rwflag, _mount_table[i].data) != 0) + { + LOG_E("Dir %s %s mount failed!", _mount_table[i].mount_point, + _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name); + } + else + { + LOG_I("Dir %s %s mount ok!", _mount_table[i].mount_point, + _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name); + } + } + } + else + { + LOG_E("No mount data found!"); + } + + mkdir("/dev/shm", 0777); + + if (dfs_mount(NULL, "/dev/shm", "tmp", 0, 0) != 0) + { + LOG_E("Dir %s %s mount failed!", "/dev/shm", "tmp"); + } + else + { + LOG_I("Dir %s %s mount ok!", "/dev/shm", "tmp"); + } + + LOG_I("file system initialization done!\n"); + + return 0; +} +INIT_ENV_EXPORT(mnt_init); diff --git a/bsp/cvitek/drivers/port/mnt.c b/bsp/cvitek/drivers/port/mnt_romfs.c similarity index 100% rename from bsp/cvitek/drivers/port/mnt.c rename to bsp/cvitek/drivers/port/mnt_romfs.c diff --git a/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.h b/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.h index 97339bc510..a22bd5e433 100644 --- a/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.h +++ b/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.h @@ -11,6 +11,9 @@ #ifndef __DFS_CROMFS_H__ #define __DFS_CROMFS_H__ +#include + int dfs_cromfs_init(void); +uint8_t *cromfs_get_partition_data(uint32_t *len); #endif /*__DFS_CROMFS_H__*/