我正在为mt29f nand芯片在nrf52840上实现yaffs。我已将所有源文件导入到我的项目中,并且已经按照本教程“ https://www.eeweb.com/profile/yanvasilij/articles/nand-flash-memories-bad-block-management-and-the-yaffs-file-system”进行操作 我已经实现了所有读写功能,但问题是挂载文件系统时始终出现-1错误。该功能甚至没有调用我的读写或擦除功能。我调试了问题,发现的是“ yaffs_guts_initialise” “函数返回错误。
struct yaffs_dev *dev = malloc(sizeof(struct yaffs_dev));
struct yaffs_param *param;
struct yaffs_driver *drv;
param = &dev->param;
drv = &dev->drv;
memset(dev, 0, sizeof(*dev));
param->total_bytes_per_chunk = 2048;
param->chunks_per_block =64;
param->n_reserved_blocks = 2;
param->start_block = 0; // Can use block 0
param->end_block = 1023; // Last block
param->use_nand_ecc = 0; // use YAFFS's ECC
param->is_yaffs2 = 1;
param->inband_tags=1;
drv->drv_write_chunk_fn = yaffs_nand_write_chunk_fn;
drv->drv_read_chunk_fn = yaffs_nand_read_chunk_fn;
drv->drv_erase_fn = yaffs_nand_erase_fn;
drv->drv_mark_bad_fn = yaffs_nand_mark_bad_fn;
drv->drv_check_bad_fn = yaffs_nand_check_bad_fn;
drv->drv_initialise_fn = yaffs_nand_drv_Initialise;
drv->drv_deinitialise_fn = yaffs_nand_drv_Deinitialise;
yaffs_add_device(dev);
int status=yaffs_mount(dev,"/a");
char str[] = "This string is placed in NAND!\r\n\0\0\0";
int f = yaffs_open("\a\file0.txt", O_RDONLY, S_IREAD);
if (f != -1)
{
memset (str, 0x00, 35);
yaffs_read(f, str, 35);
yaffs_close(f);
printf("----> %s \r\n", str);
}
else
{
printf("----> There is no file. Let's create it...\r\n");
int f = yaffs_open("nand/file0.txt", O_CREAT | O_RDWR, (S_IREAD | S_IWRITE));
if ( f != -1)
{
yaffs_write(f, str, 35);
yaffs_flush(f);
yaffs_close(f);
printf("----> Done! Restart the app to read the file.\r\n");
}
}