* [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