mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
mtdconfig: support ram_mtdconfig device && lomtdconfig device
For nvs test in qemu Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
@@ -42,6 +42,9 @@
|
|||||||
#include <nuttx/fs/ioctl.h>
|
#include <nuttx/fs/ioctl.h>
|
||||||
#include <nuttx/fs/loopmtd.h>
|
#include <nuttx/fs/loopmtd.h>
|
||||||
#include <nuttx/mtd/mtd.h>
|
#include <nuttx/mtd/mtd.h>
|
||||||
|
#ifdef CONFIG_MTD_CONFIG
|
||||||
|
# include <nuttx/mtd/configdata.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@@ -551,8 +554,14 @@ static int filemtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_MTD_LOOP
|
#ifdef CONFIG_MTD_LOOP
|
||||||
|
# ifdef CONFIG_MTD_CONFIG
|
||||||
|
static int mtd_loop_setup(FAR const char *devname, FAR const char *filename,
|
||||||
|
int sectsize, int erasesize, off_t offset,
|
||||||
|
int configdata)
|
||||||
|
# else
|
||||||
static int mtd_loop_setup(FAR const char *devname, FAR const char *filename,
|
static int mtd_loop_setup(FAR const char *devname, FAR const char *filename,
|
||||||
int sectsize, int erasesize, off_t offset)
|
int sectsize, int erasesize, off_t offset)
|
||||||
|
# endif
|
||||||
{
|
{
|
||||||
FAR struct mtd_dev_s *mtd;
|
FAR struct mtd_dev_s *mtd;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -563,7 +572,29 @@ static int mtd_loop_setup(FAR const char *devname, FAR const char *filename,
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef CONFIG_MTD_CONFIG
|
||||||
|
if (configdata)
|
||||||
|
{
|
||||||
|
if (configdata == 2)
|
||||||
|
{
|
||||||
|
/* Try to erase the entire device, before register */
|
||||||
|
|
||||||
|
FAR struct file_dev_s *fdev = (FAR struct file_dev_s *)mtd;
|
||||||
|
mtd->erase(mtd, offset / erasesize, fdev->nblocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mtdconfig_register_by_path(mtd, devname);
|
||||||
|
if (ret == -EDEADLK)
|
||||||
|
{
|
||||||
|
ferr("ERROR: mtdconfig_register_by_path failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
{
|
||||||
ret = register_mtddriver(devname, mtd, 0755, NULL);
|
ret = register_mtddriver(devname, mtd, 0755, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
filemtd_teardown(mtd);
|
filemtd_teardown(mtd);
|
||||||
@@ -615,7 +646,17 @@ static int mtd_loop_teardown(FAR const char *devname)
|
|||||||
/* Now teardown the filemtd */
|
/* Now teardown the filemtd */
|
||||||
|
|
||||||
filemtd_teardown(&dev->mtd);
|
filemtd_teardown(&dev->mtd);
|
||||||
|
|
||||||
|
# ifdef CONFIG_MTD_CONFIG
|
||||||
|
if (inode->i_private)
|
||||||
|
{
|
||||||
|
mtdconfig_unregister_by_path(devname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
{
|
||||||
unregister_mtddriver(devname);
|
unregister_mtddriver(devname);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -674,9 +715,15 @@ static int mtd_loop_ioctl(FAR struct file *filep, int cmd,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
# ifdef CONFIG_MTD_CONFIG
|
||||||
|
ret = mtd_loop_setup(setup->devname, setup->filename,
|
||||||
|
setup->sectsize, setup->erasesize,
|
||||||
|
setup->offset, setup->configdata);
|
||||||
|
# else
|
||||||
ret = mtd_loop_setup(setup->devname, setup->filename,
|
ret = mtd_loop_setup(setup->devname, setup->filename,
|
||||||
setup->sectsize, setup->erasesize,
|
setup->sectsize, setup->erasesize,
|
||||||
setup->offset);
|
setup->offset);
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ struct mtd_losetup_s
|
|||||||
size_t erasesize; /* The erase size to use on the file */
|
size_t erasesize; /* The erase size to use on the file */
|
||||||
size_t sectsize; /* The sector / page size of the file */
|
size_t sectsize; /* The sector / page size of the file */
|
||||||
off_t offset; /* An offset that may be applied to the device */
|
off_t offset; /* An offset that may be applied to the device */
|
||||||
|
# ifdef CONFIG_MTD_CONFIG
|
||||||
|
int configdata; /* 1: register mtdconfig device, 2: erase before register */
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user