按照手册与其它例子来挂载文件系统感觉不是很优美,研究了一下装载表的方式
然后在你的代码里(不限定具体文件,只要参与编译即可)加入以下代码:
//必要的头文件
#include
#include
#include
#include
#include
rt_uint8_t rampool[1024];
#define FAL_PART_NAME "filesystem" //在fal_cfg.h中FAL_PART_TABLE定义
//ROMFS需要创建的目录,创建的目录位于/目录下给其它文件系统挂载
const struct romfs_dirent _root_dirent[] =
{
{ROMFS_DIRENT_DIR, "ram", 0, 0},
{ROMFS_DIRENT_DIR, "flash", 0, 0},
};
//自动挂载表
const struct dfs_mount_tbl mount_table[] =
{
{RT_NULL, "/", "rom", 0, &(romfs_root)},//必须先创建rom文件系统,以提供后面的挂载目录
{RT_NULL, "/ram", "ram", 0, (const void*)rampool},
{FAL_PART_NAME, "/flash", "lfs", 0, 0},
{0}
};
void norflash_init()
{
fal_init();
/* Create a block device on the file system partition of spi flash*/
struct rt_device *flash_dev = fal_mtd_nor_device_create(FAL_PART_NAME);
}
//上电自动初始化norflash创建,保证在norflash挂载前创建设备,其它需要前期初始化的也可放入此函数
INIT_COMPONENT_EXPORT(norflash_init);
以下是执行结果:
| /
- RT - Thread Operating System
/ | 4.0.5 build Jun 23 2022 16:33:28
2006 - 2021 Copyright by rt-thread team
lwIP-2.1.2 initialized!
[4] I/sal.skt: Socket Abstraction Layer initialize success.
[D/FAL] (fal_flash_init:47) Flash device | norflash0 | addr:
0x80000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
m
[I/FAL] | name | flash_dev | offset | length |
m
[I/FAL] | app | norflash0 | 0x00000000 | 0x00400000 |
[I/FAL] | easyflash | norflash0 | 0x00400000 | 0x00300000 |
[I/FAL] | download | norflash0 | 0x00700000 | 0x00500000 |
[I/FAL] | filesystem | norflash0 | 0x00c00000 | 0x00400000 |
m
0m
[I/FAL] The FAL MTD NOR device (filesystem) created successfully
Not find the device(winUSB).Not find the device(i2c1).msh />[2098] I/NO_TAG
: PHY Status: Link up
[2098] I/NO_TAG: PHY Speed: 100Mbps
[2098] I/NO_TAG: PHY Duplex: full duplex
msh />mount
filesystem device mountpoint
---------- ------ ----------
devfs (NULL) /dev
rom (NULL) /
ram (NULL) /ram
lfs filesy /flash
msh />cd flash
msh /flash>ls
Directory /flash:
hello
msh /flash>mkdir hs
msh /flash>ls
Directory /flash:
hello
hs
当然了必要的硬件与驱动需要打开,这里不再赘述。 需要加新的文件系统只用修改这个表即可,需要提前初始化的加到norflash_init()里面即可。
原作者:mumumu
|