More NAND logic (still not complete)

This commit is contained in:
Gregory Nutt
2013-11-16 18:26:07 -06:00
parent d421eb4fd6
commit 03b9f5a8e6
7 changed files with 1029 additions and 50 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ CSRCS += mtd_partition.c
endif
ifeq ($(CONFIG_MTD_NAND),y)
CSRCS += mtd_nand.c mtd_onfi.c mtd_modeltab.c
CSRCS += mtd_nand.c mtd_onfi.c mtd_nandmodel.c mtd_modeltab.c
endif
ifeq ($(CONFIG_RAMMTD),y)
+188 -21
View File
@@ -51,8 +51,12 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/mtd/nand.h>
#include <nuttx/mtd/onfi.h>
#include <nuttx/mtd/nand_scheme.h>
@@ -70,6 +74,17 @@
* Private Function Prototypes
****************************************************************************/
/* MTD driver methods */
static int nand_erase(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks);
static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, uint8_t *buf);
static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, const uint8_t *buf);
static int nand_ioctl(struct mtd_dev_s *dev, int cmd,
unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
@@ -78,6 +93,132 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nand_erase
*
* Description:
* Erase several blocks, each of the size previously reported.
*
****************************************************************************/
static int nand_erase(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks)
{
struct nand_raw_s *priv = (struct nand_raw_s *)dev;
/* The interface definition assumes that all erase blocks are the same size.
* If that is not true for this particular device, then transform the
* start block and nblocks as necessary.
*/
#warning Missing logic
/* Erase the specified blocks and return status (OK or a negated errno) */
return OK;
}
/****************************************************************************
* Name: nand_bread
*
* Description:
* Read the specified number of blocks into the user provided buffer.
*
****************************************************************************/
static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, uint8_t *buf)
{
struct nand_raw_s *priv = (struct nand_raw_s *)dev;
/* The interface definition assumes that all read/write blocks are the same size.
* If that is not true for this particular device, then transform the
* start block and nblocks as necessary.
*/
/* Read the specified blocks into the provided user buffer and return status
* (The positive, number of blocks actually read or a negated errno).
*/
#warning Missing logic
return 0;
}
/****************************************************************************
* Name: nand_bwrite
*
* Description:
* Write the specified number of blocks from the user provided buffer.
*
****************************************************************************/
static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, const uint8_t *buf)
{
struct nand_raw_s *priv = (struct nand_raw_s *)dev;
/* The interface definition assumes that all read/write blocks are the same size.
* If that is not true for this particular device, then transform the
* start block and nblocks as necessary.
*/
/* Write the specified blocks from the provided user buffer and return status
* (The positive, number of blocks actually written or a negated errno)
*/
#warning Missing logic
return 0;
}
/****************************************************************************
* Name: nand_ioctl
****************************************************************************/
static int nand_ioctl(struct mtd_dev_s *dev, int cmd, unsigned long arg)
{
struct nand_raw_s *priv = (struct nand_raw_s *)dev;
int ret = -EINVAL; /* Assume good command with bad parameters */
switch (cmd)
{
case MTDIOC_GEOMETRY:
{
struct mtd_geometry_s *geo = (struct mtd_geometry_s *)arg;
if (geo)
{
/* Populate the geometry structure with information needed to know
* the capacity and how to access the device.
*
* NOTE: that the device is treated as though it where just an array
* of fixed size blocks. That is most likely not true, but the client
* will expect the device logic to do whatever is necessary to make it
* appear so.
*/
geo->blocksize = 512; /* Size of one read/write block */
geo->erasesize = 4096; /* Size of one erase block */
geo->neraseblocks = 1024; /* Number of erase blocks */
ret = OK;
}
}
break;
case MTDIOC_BULKERASE:
{
/* Erase the entire device */
ret = OK;
}
break;
case MTDIOC_XIPBASE:
default:
ret = -ENOTTY; /* Bad command */
break;
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -93,18 +234,24 @@
* cmdaddr - NAND command address base
* addraddr - NAND address address base
* dataaddr - NAND data address
* model - A pointer to the model data (probably in the raw MTD
* driver instance.
*
* Returned value.
* OK is returned on success; A negated errno value is returned on failure.
* A non-NULL MTD driver intstance is returned on success. NULL is
* returned on any failaure.
*
****************************************************************************/
int nand_initialize(FAR struct mtd_dev_s *raw,
uintptr_t cmdaddr, uintptr_t addraddr, uintptr_t dataaddr)
FAR struct mtd_dev_s *nand_initialize(FAR struct mtd_dev_s *raw,
uintptr_t cmdaddr, uintptr_t addraddr,
uintptr_t dataaddr,
FAR struct nand_model_s *model)
{
FAR struct nand_dev_s *priv;
struct onfi_pgparam_s onfi;
struct nand_model_s model;
bool compatible;
bool havemodel = false;
int ret;
fvdbg("cmdaddr=%p addraddr=%p dataaddr=%p\n",
@@ -116,7 +263,7 @@ int nand_initialize(FAR struct mtd_dev_s *raw,
{
fdbg("ERROR: No NAND device detected at: %p %p %p\n",
(FAR void *)cmdaddr, (FAR void *)addraddr, (FAR void *)dataaddr);
return -ENODEV;
return NULL;
}
/* Read the ONFI page parameters from the NAND device */
@@ -136,49 +283,69 @@ int nand_initialize(FAR struct mtd_dev_s *raw,
/* Construct the NAND model structure */
model.devid = onfi.manufacturer;
model.options = onfi.buswidth ? NANDMODEL_DATAWIDTH16 : NANDMODEL_DATAWIDTH8;
model.pagesize = onfi.pagesize;
model.sparesize = onfi.sparesize;
model->devid = onfi.manufacturer;
model->options = onfi.buswidth ? NANDMODEL_DATAWIDTH16 : NANDMODEL_DATAWIDTH8;
model->pagesize = onfi.pagesize;
model->sparesize = onfi.sparesize;
size = (uint64_t)onfi.pagesperblock *
(uint64_t)onfi.blocksperlun *
(uint64_t)onfi.pagesize;
size = (uint64_t)onfi.pagesperblock *
(uint64_t)onfi.blocksperlun *
(uint64_t)onfi.pagesize;
DEBUGASSERT(size < (uint64_t)(1 << 21));
model.devsize = (uint16_t)(size >> 20);
model->devsize = (uint16_t)(size >> 20);
size = (uint64_t)onfi.pagesperblock *
(uint64_t)onfi.pagesize;
size = (uint64_t)onfi.pagesperblock *
(uint64_t)onfi.pagesize;
DEBUGASSERT(size < (uint64_t)(1 << 11));
model.blocksize = (uint16_t)(size >> 10);
model->blocksize = (uint16_t)(size >> 10);
switch (onfi.pagesize)
{
case 256:
model.scheme = &g_nand_sparescheme256;
model->scheme = &g_nand_sparescheme256;
break;
case 512:
model.scheme = &g_nand_sparescheme512;
model->scheme = &g_nand_sparescheme512;
break;
case 2048:
model.scheme = &g_nand_sparescheme2048;
model->scheme = &g_nand_sparescheme2048;
break;
case 4096:
model.scheme = &g_nand_sparescheme4096;
model->scheme = &g_nand_sparescheme4096;
break;
}
havemodel = true;
/* Disable any internal, embedded ECC function */
(void)onfi_embeddedecc(&onfi, cmdaddr, addraddr, dataaddr, false);
}
#warning Missing logic
/* Allocate an NAND MTD device structure */
priv = (FAR struct nand_dev_s *)kzalloc(sizeof(struct nand_dev_s));
if (!priv)
{
fdbg("ERROR: Failed to allocate the NAND MTD device structure\n");
return NULL;
}
/* Initialize the NAND MTD device structure */
priv->mtd.erase = nand_erase;
priv->mtd.bread = nand_bread;
priv->mtd.bwrite = nand_bwrite;
priv->mtd.ioctl = nand_ioctl;
priv->raw = raw;
priv->model = model;
#warning Missing logic
/* Return the implementation-specific state structure as the MTD device */
File diff suppressed because it is too large Load Diff