* [PATCH 1/6] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
2015-02-10 9:03 ` [PATCH 2/6] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
This is broken since:
| commit 00f119a29387cfb1b188fcc4daa4aa94186ac7a9
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date: Fri Aug 1 14:09:48 2014 +0200
|
| mtd: omap gpmc: fix ecc bytes/size
|
| The ecc bytes / size are per subpage, not per page.
|
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The ecc code in omap_correct_data() expects to correct a whole page
at once, so we must tell the nand layer that we have 4 * 13 bytes of
ecc bytes and 4 * 512 bytes of ecc size. Otherwise the NAND layer will
iterate over 512 byte steps over a page and call the .correct callback
each time.
This only works for 2k pagesize and needs revisit once other page sizes
shall be supported. It would be better to tell the nand layer the real
ecc bytes (13) and ecc size (512) instead and drop the iteration in
omap_correct_bch(). However, this needs better testing so it isn't done
here now.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand_omap_gpmc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index b1d266f..d254042 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -815,8 +815,8 @@ static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
omap_oobinfo.eccpos[i] = i + offset;
break;
case OMAP_ECC_BCH8_CODE_HW:
- oinfo->nand.ecc.bytes = 13;
- oinfo->nand.ecc.size = 512;
+ oinfo->nand.ecc.bytes = 13 * 4;
+ oinfo->nand.ecc.size = 512 * 4;
oinfo->nand.ecc.strength = BCH8_MAX_ERROR;
omap_oobinfo.oobfree->offset = offset;
omap_oobinfo.oobfree->length = minfo->oobsize -
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] mtd: Fix allowing to erase bad blocks on partitions
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
2015-02-10 9:03 ` [PATCH 1/6] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
2015-02-10 9:03 ` [PATCH 3/6] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
Partitions are mtd devices themselves, but the 'erasebad'
parameter is only set to the master mtd device. To allow to
erase bad blocks on partitions test the master device instead
of the partition devices.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 82fb5f7..345752e 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -168,10 +168,10 @@ static int mtd_op_erase(struct cdev *cdev, size_t count, loff_t offset)
while (count > 0) {
dev_dbg(cdev->dev, "erase %d %d\n", addr, erase.len);
- if (!mtd->allow_erasebad)
- ret = mtd_block_isbad(mtd, addr);
- else
+ if (mtd->allow_erasebad || (mtd->master && mtd->master->allow_erasebad))
ret = 0;
+ else
+ ret = mtd_block_isbad(mtd, addr);
erase.addr = addr;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] mtd: nand-bb: Fix accesses beyond device
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
2015-02-10 9:03 ` [PATCH 1/6] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
2015-02-10 9:03 ` [PATCH 2/6] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
2015-02-10 9:03 ` [PATCH 4/6] mtd: nand-bb: fix erasing bb devices with bad blocks Sascha Hauer
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
When a block is marked bad after the bb device has been created
the real size of the bb device is smaller than the calculated size
on creation. In this case we can't rely on the upper layers anymore
that they won't pass read/write sizes in that fit into the device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index d888f90..e38517d 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -57,6 +57,11 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
debug("%s 0x%08llx %d\n", __func__, offset, count);
while (count) {
+ loff_t max = bb->mtd->size - bb->offset;
+
+ if (max <= 0)
+ break;
+
if (mtd_block_isbad(bb->mtd, offset)) {
printf("skipping bad block at 0x%08llx\n", bb->offset);
bb->offset += bb->mtd->erasesize;
@@ -66,6 +71,9 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
now = min(count, (size_t)(bb->mtd->erasesize -
((size_t)bb->offset % bb->mtd->erasesize)));
+ if (now > max)
+ now = max;
+
ret = mtd_read(bb->mtd, bb->offset, now, &retlen, buf);
if (ret < 0)
return ret;
@@ -90,6 +98,11 @@ static int nand_bb_write_buf(struct nand_bb *bb, size_t count)
loff_t cur_ofs = bb->offset & ~(BB_WRITEBUF_SIZE - 1);
while (count) {
+ loff_t max = bb->mtd->size - bb->offset;
+
+ if (max <= 0)
+ return -ENOSPC;
+
if (mtd_block_isbad(bb->mtd, cur_ofs)) {
debug("skipping bad block at 0x%08llx\n", cur_ofs);
bb->offset += bb->mtd->erasesize;
@@ -98,6 +111,9 @@ static int nand_bb_write_buf(struct nand_bb *bb, size_t count)
}
now = min(count, (size_t)(bb->mtd->erasesize));
+ if (now > max)
+ return -ENOSPC;
+
ret = mtd_write(bb->mtd, cur_ofs, now, &retlen, buf);
if (ret < 0)
return ret;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] mtd: nand-bb: fix erasing bb devices with bad blocks
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
` (2 preceding siblings ...)
2015-02-10 9:03 ` [PATCH 3/6] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
2015-02-10 9:03 ` [PATCH 5/6] mtd: nand-bb: Fix test for bad block when reading Sascha Hauer
2015-02-10 9:03 ` [PATCH 6/6] mtd: nand-bb: Also print raw position in debug messages Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
mtd_erase does not skip bad blocks, we must skip them in nand_bb_erase
instead.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index e38517d..f134635 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -159,16 +159,34 @@ static int nand_bb_erase(struct cdev *cdev, size_t count, loff_t offset)
{
struct nand_bb *bb = cdev->priv;
struct erase_info erase = {};
+ int ret;
if (offset != 0) {
printf("can only erase from beginning of device\n");
return -EINVAL;
}
- erase.addr = 0;
- erase.len = bb->mtd->size;
+ while (count) {
+ if (offset + bb->mtd->erasesize > bb->mtd->size)
+ return 0;
+
+ if (mtd_block_isbad(bb->mtd, offset)) {
+ offset += bb->mtd->erasesize;
+ continue;
+ }
- return mtd_erase(bb->mtd, &erase);
+ erase.addr = offset;
+ erase.len = bb->mtd->erasesize;
+
+ ret = mtd_erase(bb->mtd, &erase);
+ if (ret)
+ return ret;
+
+ offset += bb->mtd->erasesize;
+ count -= bb->mtd->erasesize;
+ }
+
+ return 0;
}
#endif
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] mtd: nand-bb: Fix test for bad block when reading
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
` (3 preceding siblings ...)
2015-02-10 9:03 ` [PATCH 4/6] mtd: nand-bb: fix erasing bb devices with bad blocks Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
2015-02-10 9:03 ` [PATCH 6/6] mtd: nand-bb: Also print raw position in debug messages Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
in nand_bb_read() 'offset' contains the virtual position on the device,
but we have to test for a bad block on the raw physical position, so
use bb->offset instead of offset
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index f134635..c8f6988 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -62,7 +62,7 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
if (max <= 0)
break;
- if (mtd_block_isbad(bb->mtd, offset)) {
+ if (mtd_block_isbad(bb->mtd, bb->offset)) {
printf("skipping bad block at 0x%08llx\n", bb->offset);
bb->offset += bb->mtd->erasesize;
continue;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] mtd: nand-bb: Also print raw position in debug messages
2015-02-10 9:03 [PATCH v2] nand-bb fixes Sascha Hauer
` (4 preceding siblings ...)
2015-02-10 9:03 ` [PATCH 5/6] mtd: nand-bb: Fix test for bad block when reading Sascha Hauer
@ 2015-02-10 9:03 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-02-10 9:03 UTC (permalink / raw)
To: Barebox List
When debugging the nand-bb devices also the raw position on the
device is interesting, print it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index c8f6988..23957c3 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -54,7 +54,8 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
size_t retlen;
int ret, bytes = 0, now;
- debug("%s 0x%08llx %d\n", __func__, offset, count);
+ debug("%s offset: 0x%08llx (raw: 0x%08llx) count: 0x%08x\n",
+ __func__, offset, bb->offset, count);
while (count) {
loff_t max = bb->mtd->size - bb->offset;
@@ -131,7 +132,8 @@ static ssize_t nand_bb_write(struct cdev *cdev, const void *buf, size_t count,
struct nand_bb *bb = cdev->priv;
int bytes = count, now, wroffs, ret;
- debug("%s offset: 0x%08llx count: 0x%08x\n", __func__, offset, count);
+ debug("%s offset: 0x%08llx (raw: 0x%08llx) count: 0x%08x\n",
+ __func__, offset, bb->offset, count);
while (count) {
wroffs = bb->offset % BB_WRITEBUF_SIZE;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread