From 3c54e66683b5ed0067dbcf5dc7d6e5478a597d83 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 1 May 2023 01:03:31 +0800 Subject: [PATCH] mtd/nand: Fix the comment and remove the uneeded inclusion Signed-off-by: Xiang Xiao --- arch/arm/src/sam34/sam4s_nand.c | 4 +-- arch/arm/src/sama5/sam_nand.c | 8 ++--- drivers/mtd/hamming.c | 5 ++- drivers/mtd/mtd_modeltab.c | 5 ++- drivers/mtd/mtd_nand.c | 64 +++++++++++++-------------------- drivers/mtd/mtd_nandecc.c | 22 ++++-------- drivers/mtd/mtd_nandmodel.c | 11 +++--- drivers/mtd/mtd_nandscheme.c | 23 ++++++------ drivers/mtd/mtd_onfi.c | 8 +---- include/nuttx/mtd/hamming.h | 5 +-- include/nuttx/mtd/nand_ecc.h | 2 +- include/nuttx/mtd/nand_model.h | 6 ++-- include/nuttx/mtd/nand_raw.h | 1 - include/nuttx/mtd/nand_scheme.h | 12 +++---- 14 files changed, 67 insertions(+), 109 deletions(-) diff --git a/arch/arm/src/sam34/sam4s_nand.c b/arch/arm/src/sam34/sam4s_nand.c index 953a799457..cd0bf743ce 100644 --- a/arch/arm/src/sam34/sam4s_nand.c +++ b/arch/arm/src/sam34/sam4s_nand.c @@ -437,8 +437,8 @@ static int nand_rawwrite(struct nand_raw_s *raw, off_t block, int ret = OK; DEBUGASSERT(raw); - finfo("block=%d page=%d data=%p spare=%p\n", - (int)block, page, data, spare); + finfo("block=%" PRIdOFF " page=%d data=%p spare=%p\n", + block, page, data, spare); /* Get page and spare sizes */ diff --git a/arch/arm/src/sama5/sam_nand.c b/arch/arm/src/sama5/sam_nand.c index 588417fcca..65ace74ab5 100644 --- a/arch/arm/src/sama5/sam_nand.c +++ b/arch/arm/src/sama5/sam_nand.c @@ -1945,8 +1945,8 @@ static int nand_readpage_noecc(struct sam_nandcs_s *priv, off_t block, off_t coladdr; int ret; - finfo("block=%d page=%d data=%p spare=%p\n", - (int)block, page, data, spare); + finfo("block=%" PRIdOFF " page=%d data=%p spare=%p\n", + block, page, data, spare); DEBUGASSERT(priv && (data || spare)); /* Get page and spare sizes */ @@ -2190,8 +2190,8 @@ static int nand_writepage_noecc(struct sam_nandcs_s *priv, off_t block, off_t rowaddr; int ret = OK; - finfo("block=%d page=%d data=%p spare=%p\n", - (int)block, page, data, spare); + finfo("block=%" PRIdOFF " page=%d data=%p spare=%p\n", + block, page, data, spare); /* Get page and spare sizes */ diff --git a/drivers/mtd/hamming.c b/drivers/mtd/hamming.c index 7146523824..49e361d8a2 100644 --- a/drivers/mtd/hamming.c +++ b/drivers/mtd/hamming.c @@ -37,9 +37,7 @@ ****************************************************************************/ #include -#include -#include #include #include @@ -372,7 +370,8 @@ static int hamming_verify256(FAR uint8_t *data, FAR const uint8_t *original) * ****************************************************************************/ -void hamming_compute256x(FAR const uint8_t *data, size_t size, uint8_t *code) +void hamming_compute256x(FAR const uint8_t *data, size_t size, + FAR uint8_t *code) { ssize_t remaining = (ssize_t)size; DEBUGASSERT((size & 0xff) == 0); diff --git a/drivers/mtd/mtd_modeltab.c b/drivers/mtd/mtd_modeltab.c index 1ae7d0d059..404045049e 100644 --- a/drivers/mtd/mtd_modeltab.c +++ b/drivers/mtd/mtd_modeltab.c @@ -37,7 +37,6 @@ ****************************************************************************/ #include -#include #include #include @@ -49,8 +48,8 @@ /* List of NandFlash models which can be recognized by the software */ /**************************************************************************** - * ID OPTIONS PAGE SPARE DEV BLOCK | SCHEME - * SIZE SIZE SIZE SIZE | + * ID OPTIONS PAGE SPARE DEV BLOCK | SCHEME + * SIZE SIZE SIZE SIZE | ****************************************************************************/ const struct nand_model_s g_nandmodels[NAND_NMODELS] = diff --git a/drivers/mtd/mtd_nand.c b/drivers/mtd/mtd_nand.c index 10551a1a27..0335acea0a 100644 --- a/drivers/mtd/mtd_nand.c +++ b/drivers/mtd/mtd_nand.c @@ -39,8 +39,6 @@ #include #include -#include -#include #include #include #include @@ -48,12 +46,9 @@ #include #include -#include #include #include -#include #include -#include #include /**************************************************************************** @@ -88,24 +83,24 @@ static int nand_devscan(FAR struct nand_dev_s *nand); /* Misc. NAND helpers */ -static uint32_t nand_chipid(struct nand_raw_s *raw); +static uint32_t nand_chipid(FAR struct nand_raw_s *raw); static int nand_eraseblock(FAR struct nand_dev_s *nand, - off_t block, bool scrub); + off_t block, bool scrub); static int nand_readpage(FAR struct nand_dev_s *nand, off_t block, - unsigned int page, FAR uint8_t *data); + unsigned int page, FAR uint8_t *data); static int nand_writepage(FAR struct nand_dev_s *nand, off_t block, - unsigned int page, FAR const void *data); + unsigned int page, FAR const void *data); /* 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 *buffer); -static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startblock, - size_t nblocks, const uint8_t *buffer); -static int nand_ioctl(struct mtd_dev_s *dev, int cmd, - unsigned long arg); +static int nand_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks); +static ssize_t nand_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, uint8_t *buffer); +static ssize_t nand_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, const uint8_t *buffer); +static int nand_ioctl(FAR struct mtd_dev_s *dev, int cmd, + unsigned long arg); /**************************************************************************** * Private Data @@ -214,8 +209,8 @@ static int nand_devscan(FAR struct nand_dev_s *nand) off_t nblocks; off_t block; #if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_FS) - off_t good; - unsigned int ngood; + off_t good = 0; + unsigned int ngood = 0; #endif int ret; @@ -234,10 +229,6 @@ static int nand_devscan(FAR struct nand_dev_s *nand) /* Retrieve block status from their first page spare area */ -#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_FS) - ngood = 0; -#endif - for (block = 0; block < nblocks; block++) { /* Read spare of first page */ @@ -301,7 +292,7 @@ static int nand_devscan(FAR struct nand_dev_s *nand) * ****************************************************************************/ -static uint32_t nand_chipid(struct nand_raw_s *raw) +static uint32_t nand_chipid(FAR struct nand_raw_s *raw) { uint8_t id[5]; @@ -512,7 +503,7 @@ static int nand_writepage(FAR struct nand_dev_s *nand, off_t block, * ****************************************************************************/ -static int nand_erase(struct mtd_dev_s *dev, off_t startblock, +static int nand_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks) { FAR struct nand_dev_s *nand = (FAR struct nand_dev_s *)dev; @@ -552,7 +543,7 @@ static int nand_erase(struct mtd_dev_s *dev, off_t startblock, * ****************************************************************************/ -static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage, +static ssize_t nand_bread(FAR struct mtd_dev_s *dev, off_t startpage, size_t npages, FAR uint8_t *buffer) { FAR struct nand_dev_s *nand = (FAR struct nand_dev_s *)dev; @@ -571,8 +562,8 @@ static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage, /* Retrieve the model */ - raw = nand->raw; - model = &raw->model; + raw = nand->raw; + model = &raw->model; /* Get the number of pages in one block, the size of one page, and * the number of blocks on the device. @@ -648,7 +639,7 @@ errout_with_lock: * ****************************************************************************/ -static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startpage, +static ssize_t nand_bwrite(FAR struct mtd_dev_s *dev, off_t startpage, size_t npages, const uint8_t *buffer) { FAR struct nand_dev_s *nand = (FAR struct nand_dev_s *)dev; @@ -667,8 +658,8 @@ static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startpage, /* Retrieve the model */ - raw = nand->raw; - model = &raw->model; + raw = nand->raw; + model = &raw->model; /* Get the number of pages in one block, the size of one page, and * the number of blocks on the device. @@ -740,7 +731,7 @@ errout_with_lock: * Name: nand_ioctl ****************************************************************************/ -static int nand_ioctl(struct mtd_dev_s *dev, int cmd, unsigned long arg) +static int nand_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { FAR struct nand_dev_s *nand = (FAR struct nand_dev_s *)dev; FAR struct nand_raw_s *raw; @@ -755,7 +746,7 @@ static int nand_ioctl(struct mtd_dev_s *dev, int cmd, unsigned long arg) { case MTDIOC_GEOMETRY: { - FAR struct mtd_geometry_s *geo = (struct mtd_geometry_s *)arg; + FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)arg; if (geo) { memset(geo, 0, sizeof(*geo)); @@ -819,11 +810,6 @@ static int nand_ioctl(struct mtd_dev_s *dev, int cmd, unsigned long arg) * * Input Parameters: * raw - Lower-half, raw NAND FLASH interface - * 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: * A non-NULL MTD driver instance is returned on success. NULL is @@ -919,7 +905,7 @@ FAR struct mtd_dev_s *nand_initialize(FAR struct nand_raw_s *raw) break; } - /* Disable any internal, embedded ECC function */ + /* Enable any internal, embedded ECC function */ onfi_embeddedecc(&onfi, raw->cmdaddr, raw->addraddr, raw->dataaddr, true); diff --git a/drivers/mtd/mtd_nandecc.c b/drivers/mtd/mtd_nandecc.c index 987616fa3a..83a0229a8a 100644 --- a/drivers/mtd/mtd_nandecc.c +++ b/drivers/mtd/mtd_nandecc.c @@ -39,8 +39,6 @@ #include #include -#include -#include #include #include #include @@ -90,11 +88,8 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block, unsigned int sparesize; int ret; - finfo("block=%d page=%d data=%p spare=%d\n", - (int)block, - page, - data, - spare); + finfo("block=%" PRIdOFF " page=%d data=%p spare=%p\n", + block, page, data, spare); /* Get convenience pointers */ @@ -122,7 +117,7 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block, ret = NAND_RAWREAD(raw, block, page, 0, spare); if (ret < 0) { - ferr("ERROR: Failed to read page:d\n", ret); + ferr("ERROR: Failed to read page:%d\n", ret); return ret; } @@ -131,7 +126,7 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block, ret = NAND_RAWREAD(nand->raw, block, page, data, 0); if (ret < 0) { - ferr("ERROR: Failed to read page:d\n", ret); + ferr("ERROR: Failed to read page:%d\n", ret); return ret; } @@ -186,11 +181,8 @@ int nandecc_writepage(FAR struct nand_dev_s *nand, off_t block, unsigned int sparesize; int ret; - finfo("block=%d page=%d data=%p spare=%d\n", - (int)block, - page, - data, - spare); + finfo("block=%" PRIdOFF " page=%d data=%p spare=%p\n", + block, page, data, spare); /* Get convenience pointers */ @@ -236,7 +228,7 @@ int nandecc_writepage(FAR struct nand_dev_s *nand, off_t block, ret = NAND_RAWWRITE(nand->raw, block, page, data, spare); if (ret < 0) { - ferr("ERROR: Failed to write page:d\n", ret); + ferr("ERROR: Failed to write page:%d\n", ret); } return ret; diff --git a/drivers/mtd/mtd_nandmodel.c b/drivers/mtd/mtd_nandmodel.c index 304e603c49..bafa50580e 100644 --- a/drivers/mtd/mtd_nandmodel.c +++ b/drivers/mtd/mtd_nandmodel.c @@ -37,15 +37,11 @@ ****************************************************************************/ #include -#include -#include -#include #include #include #include -#include #include /**************************************************************************** @@ -155,6 +151,7 @@ int nandmodel_find(FAR const struct nand_model_s *modeltab, size_t size, finfo(" pagesize: %d (B)\n", model->pagesize); finfo(" options: 0x%02x\n", model->options); } + break; } } @@ -181,13 +178,13 @@ int nandmodel_find(FAR const struct nand_model_s *modeltab, size_t size, * offset Stores the byte offset inside the first accessed page. * * Returned Value: - * OK on success; -EPIPE on failure. + * OK on success; -ESPIPE on failure. * ****************************************************************************/ int nandmodel_translate(FAR const struct nand_model_s *model, off_t address, - size_t size, FAR off_t *block, off_t *page, - off_t *offset) + size_t size, FAR off_t *block, FAR off_t *page, + FAR off_t *offset) { size_t blocksize; size_t pagesize; diff --git a/drivers/mtd/mtd_nandscheme.c b/drivers/mtd/mtd_nandscheme.c index 34e0586ec9..e177d34937 100644 --- a/drivers/mtd/mtd_nandscheme.c +++ b/drivers/mtd/mtd_nandscheme.c @@ -37,7 +37,6 @@ ****************************************************************************/ #include -#include #include #include @@ -46,7 +45,7 @@ #include /**************************************************************************** - * Private Data + * Public Data ****************************************************************************/ /* Spare area placement scheme for 256 byte pages */ @@ -134,7 +133,7 @@ void nandscheme_readbadblockmarker(FAR const struct nand_scheme_s *scheme, } /**************************************************************************** - * Name: nandscheme_readbadblockmarker + * Name: nandscheme_writebadblockmarker * * Description: * Modifies the bad block marker inside a spare area, using the given @@ -233,18 +232,18 @@ void nandscheme_readextra(FAR const struct nand_scheme_s *scheme, FAR const uint8_t *spare, FAR void *extra, unsigned int size, unsigned int offset) { - DEBUGASSERT((size + offset) < scheme->nxbytes); + DEBUGASSERT((size + offset) <= scheme->nxbytes); int i; for (i = 0; i < size; i++) { - ((uint8_t *)extra)[i] = spare[scheme->xbytepos[i + offset]]; + ((FAR uint8_t *)extra)[i] = spare[scheme->xbytepos[i + offset]]; } } /**************************************************************************** - * Name: nandscheme_readextra + * Name: nandscheme_writeextra * * Description: * Write extra bytes of information inside a spare area, using the provided @@ -266,17 +265,17 @@ void nandscheme_writeextra(FAR const struct nand_scheme_s *scheme, FAR uint8_t *spare, FAR const void *extra, unsigned int size, unsigned int offset) { - DEBUGASSERT((size + offset) < scheme->nxbytes); + DEBUGASSERT((size + offset) <= scheme->nxbytes); uint32_t i; for (i = 0; i < size; i++) { - spare[scheme->xbytepos[i + offset]] = ((uint8_t *) extra)[i]; + spare[scheme->xbytepos[i + offset]] = ((FAR uint8_t *) extra)[i]; } } /**************************************************************************** - * Name: nandscheme_readextra + * Name: nandscheme_build4096 * * Description: * Build a scheme instance for 4096 page size nand flash @@ -284,16 +283,14 @@ void nandscheme_writeextra(FAR const struct nand_scheme_s *scheme, * Input Parameters: * scheme Pointer to a nand_scheme_s instance. * sparesize Size of spare area. - * offset Index where to write the first extra byte. - * size Number of extra bytes to write. - * offset Index where to write the first extra byte. + * eccoffset Index where to write the first extra byte. * * Returned Value: * OK on success; a negated errno value on failure. * ****************************************************************************/ -int nandscheme_build4086(FAR struct nand_scheme_s *scheme, +int nandscheme_build4096(FAR struct nand_scheme_s *scheme, unsigned int sparesize, unsigned int eccoffset) { uint8_t eccsize = g_nand_sparescheme4096.eccsize; diff --git a/drivers/mtd/mtd_onfi.c b/drivers/mtd/mtd_onfi.c index 159eee1fa2..b89ad74d1c 100644 --- a/drivers/mtd/mtd_onfi.c +++ b/drivers/mtd/mtd_onfi.c @@ -37,13 +37,7 @@ ****************************************************************************/ #include -#include -#include - -#include -#include -#include #include #include #include @@ -95,7 +89,7 @@ } while (0) #define READ_NAND(a) \ - ((*(volatile uint8_t *)(uint32_t)a)) + ((*(volatile uint8_t *)(uintptr_t)a)) #define WRITE_NAND(d,a) \ do { \ diff --git a/include/nuttx/mtd/hamming.h b/include/nuttx/mtd/hamming.h index 94f5fd5927..8b3dc38081 100644 --- a/include/nuttx/mtd/hamming.h +++ b/include/nuttx/mtd/hamming.h @@ -44,9 +44,6 @@ #include #include -#include -#include - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -108,7 +105,7 @@ extern "C" void hamming_compute256x(FAR const uint8_t *data, size_t size, - uint8_t *code); + FAR uint8_t *code); /**************************************************************************** * Name: hamming_verify256x diff --git a/include/nuttx/mtd/nand_ecc.h b/include/nuttx/mtd/nand_ecc.h index 0eb7f8f28c..c342f7d2d8 100644 --- a/include/nuttx/mtd/nand_ecc.h +++ b/include/nuttx/mtd/nand_ecc.h @@ -40,8 +40,8 @@ ****************************************************************************/ #include -#include +#include #include /**************************************************************************** diff --git a/include/nuttx/mtd/nand_model.h b/include/nuttx/mtd/nand_model.h index b838f4e6a1..271cea21e9 100644 --- a/include/nuttx/mtd/nand_model.h +++ b/include/nuttx/mtd/nand_model.h @@ -141,13 +141,13 @@ int nandmodel_find(FAR const struct nand_model_s *modeltab, size_t size, * offset Stores the byte offset inside the first accessed page. * * Returned Value: - * OK on success; -EPIPE on failure. + * OK on success; -ESPIPE on failure. * ****************************************************************************/ int nandmodel_translate(FAR const struct nand_model_s *model, off_t address, - size_t size, FAR off_t *block, off_t *page, - off_t *offset); + size_t size, FAR off_t *block, FAR off_t *page, + FAR off_t *offset); /**************************************************************************** * Name: nandmodel_getscheme diff --git a/include/nuttx/mtd/nand_raw.h b/include/nuttx/mtd/nand_raw.h index 012007013b..cee12c313a 100644 --- a/include/nuttx/mtd/nand_raw.h +++ b/include/nuttx/mtd/nand_raw.h @@ -45,7 +45,6 @@ #include #include -#include #include /**************************************************************************** diff --git a/include/nuttx/mtd/nand_scheme.h b/include/nuttx/mtd/nand_scheme.h index e818b7bd63..573286815a 100644 --- a/include/nuttx/mtd/nand_scheme.h +++ b/include/nuttx/mtd/nand_scheme.h @@ -112,7 +112,7 @@ void nandscheme_readbadblockmarker(FAR const struct nand_scheme_s *scheme, FAR uint8_t *marker); /**************************************************************************** - * Name: nandscheme_readbadblockmarker + * Name: nandscheme_writebadblockmarker * * Description: * Modifies the bad block marker inside a spare area, using the given @@ -263,7 +263,7 @@ void nandscheme_readextra(FAR const struct nand_scheme_s *scheme, unsigned int size, unsigned int offset); /**************************************************************************** - * Name: nandscheme_readextra + * Name: nandscheme_writeextra * * Description: * Write extra bytes of information inside a spare area, using the provided @@ -286,7 +286,7 @@ void nandscheme_writeextra(FAR const struct nand_scheme_s *scheme, unsigned int size, unsigned int offset); /**************************************************************************** - * Name: nandscheme_readextra + * Name: nandscheme_build4096 * * Description: * Build a scheme instance for 4096 page size nand flash @@ -294,16 +294,14 @@ void nandscheme_writeextra(FAR const struct nand_scheme_s *scheme, * Input Parameters: * scheme Pointer to a nand_scheme_s instance. * sparesize Size of spare area. - * offset Index where to write the first extra byte. - * size Number of extra bytes to write. - * offset Index where to write the first extra byte. + * eccoffset Index where to write the first ecc byte. * * Returned Value: * OK on success; a negated errno value on failure. * ****************************************************************************/ -int nandscheme_build4086(FAR struct nand_scheme_s *scheme, +int nandscheme_build4096(FAR struct nand_scheme_s *scheme, unsigned int sparesize, unsigned int eccoffset); #undef EXTERN