* [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode
@ 2015-02-05 10:09 Sascha Hauer
2015-02-05 10:09 ` [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-02-05 10:09 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] 4+ messages in thread
* [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions
2015-02-05 10:09 [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
@ 2015-02-05 10:09 ` Sascha Hauer
2015-02-05 10:09 ` [PATCH 3/4] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
2015-02-05 10:09 ` [PATCH 4/4] mtd: nand: bb: fix erasing bb devices with bad blocks Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-02-05 10:09 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] 4+ messages in thread
* [PATCH 3/4] mtd: nand-bb: Fix accesses beyond device
2015-02-05 10:09 [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
2015-02-05 10:09 ` [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
@ 2015-02-05 10:09 ` Sascha Hauer
2015-02-05 10:09 ` [PATCH 4/4] mtd: nand: bb: fix erasing bb devices with bad blocks Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-02-05 10:09 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] 4+ messages in thread
* [PATCH 4/4] mtd: nand: bb: fix erasing bb devices with bad blocks
2015-02-05 10:09 [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
2015-02-05 10:09 ` [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
2015-02-05 10:09 ` [PATCH 3/4] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
@ 2015-02-05 10:09 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-02-05 10:09 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..853c617 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] 4+ messages in thread
end of thread, other threads:[~2015-02-05 10:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05 10:09 [PATCH 1/4] mtd: nand: omap: Fix OMAP_ECC_BCH8_CODE_HW ecc mode Sascha Hauer
2015-02-05 10:09 ` [PATCH 2/4] mtd: Fix allowing to erase bad blocks on partitions Sascha Hauer
2015-02-05 10:09 ` [PATCH 3/4] mtd: nand-bb: Fix accesses beyond device Sascha Hauer
2015-02-05 10:09 ` [PATCH 4/4] mtd: nand: bb: fix erasing bb devices with bad blocks Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox