mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mtd: Do not write empty pages, UBI fix
@ 2013-02-20 10:47 Sascha Hauer
  2013-02-20 10:47 ` [PATCH 1/2] mtd: nand: do not write empty pages Sascha Hauer
  2013-02-20 10:47 ` [PATCH 2/2] libubi: Use global mtd_all_ff function Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-02-20 10:47 UTC (permalink / raw)
  To: barebox

This is a patch for everybody flashing UBI images to nand devices.
Since some time we no longer skip empty pages during writes which
leads to CRC errors once an UBIFS is mounted r/w on a nand device.

Sascha

----------------------------------------------------------------
Sascha Hauer (2):
      mtd: nand: do not write empty pages
      libubi: Use global mtd_all_ff function

 drivers/mtd/core.c            |   32 ++++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_write.c |   10 ++++++----
 include/linux/mtd/mtd.h       |    2 ++
 lib/libscan.c                 |   13 +------------
 4 files changed, 41 insertions(+), 16 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] mtd: nand: do not write empty pages
  2013-02-20 10:47 [PATCH] mtd: Do not write empty pages, UBI fix Sascha Hauer
@ 2013-02-20 10:47 ` Sascha Hauer
  2013-02-20 10:47 ` [PATCH 2/2] libubi: Use global mtd_all_ff function Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-02-20 10:47 UTC (permalink / raw)
  To: barebox

Do not write pages which only contain 0xff. UBI expects pages which
seem empty to be writable. This got lost with:

| commit 3139c3e9a61e70846be8c4f95bb9cffd4465d88a
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date:   Thu Nov 29 11:16:40 2012 +0100
|
|    mtd core: call driver write function with complete buffer
|
|    mtd->write is supposed to loop around pages internally, no need
|    to do this in mtd_write. This fixes a huge write performance drop
|    with the m25p80 driver when it was converted to a mtd driver recently.
|    Since mtd->writesize is 1 for this driver mtd_write ended up doing
|    single byte writes on the flash.

Introduce mtd_all_ff as a global function since UBI currently has its own
implementation.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/core.c            |   32 ++++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand_write.c |   10 ++++++----
 include/linux/mtd/mtd.h       |    2 ++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 070fda6..ef98556 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -30,6 +30,38 @@
 
 static LIST_HEAD(mtd_register_hooks);
 
+int mtd_all_ff(const void *buf, unsigned int len)
+{
+	while ((unsigned long)buf & 0x3) {
+		if (*(const uint8_t *)buf != 0xff)
+			return 0;
+		len--;
+		if (!len)
+			return 1;
+		buf++;
+	}
+
+	while (len > 0x3) {
+		if (*(const uint32_t *)buf != 0xffffffff)
+			return 0;
+
+		len -= sizeof(uint32_t);
+		if (!len)
+			return 1;
+
+		buf += sizeof(uint32_t);
+	}
+
+	while (len) {
+		if (*(const uint8_t *)buf != 0xff)
+			return 0;
+		len--;
+		buf++;
+	}
+
+	return 1;
+}
+
 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
 {
 	if (!mtd->block_isbad)
diff --git a/drivers/mtd/nand/nand_write.c b/drivers/mtd/nand/nand_write.c
index 12a57a0..cd8ee06 100644
--- a/drivers/mtd/nand/nand_write.c
+++ b/drivers/mtd/nand/nand_write.c
@@ -320,10 +320,12 @@ int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 			memset(chip->oob_poi, 0xff, mtd->oobsize);
 		}
 
-		ret = chip->write_page(mtd, chip, wbuf, page, cached,
-				       (ops->mode == MTD_OOB_RAW));
-		if (ret)
-			break;
+		if (!mtd_all_ff(wbuf, mtd->writesize)) {
+			ret = chip->write_page(mtd, chip, wbuf, page, cached,
+					       (ops->mode == MTD_OOB_RAW));
+			if (ret)
+				break;
+		}
 
 		writelen -= bytes;
 		if (!writelen)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index cb8b3bc..bd059ba 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -253,6 +253,8 @@ static inline void mtd_erase_callback(struct erase_info *instr)
 
 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
 
+int mtd_all_ff(const void *buf, unsigned int len);
+
 /*
  * Debugging macro and defines
  */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] libubi: Use global mtd_all_ff function
  2013-02-20 10:47 [PATCH] mtd: Do not write empty pages, UBI fix Sascha Hauer
  2013-02-20 10:47 ` [PATCH 1/2] mtd: nand: do not write empty pages Sascha Hauer
@ 2013-02-20 10:47 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-02-20 10:47 UTC (permalink / raw)
  To: barebox

We introduced a global function for this, so use it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/libscan.c |   13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/lib/libscan.c b/lib/libscan.c
index af55269..202266b 100644
--- a/lib/libscan.c
+++ b/lib/libscan.c
@@ -33,17 +33,6 @@
 #include <mtd/ubi-media.h>
 #include <asm-generic/div64.h>
 
-static int all_ff(const void *buf, int len)
-{
-	int i;
-	const uint8_t *p = buf;
-
-	for (i = 0; i < len; i++)
-		if (p[i] != 0xFF)
-			return 0;
-	return 1;
-}
-
 int libscan_ubi_scan(struct mtd_dev_info *mtd, int fd, struct ubi_scan_info **info,
 	     int verbose)
 {
@@ -95,7 +84,7 @@ int libscan_ubi_scan(struct mtd_dev_info *mtd, int fd, struct ubi_scan_info **in
 			goto out_ec;
 
 		if (be32_to_cpu(ech.magic) != UBI_EC_HDR_MAGIC) {
-			if (all_ff(&ech, sizeof(struct ubi_ec_hdr))) {
+			if (mtd_all_ff(&ech, sizeof(struct ubi_ec_hdr))) {
 				si->empty_cnt += 1;
 				si->ec[eb] = EB_EMPTY;
 				if (v)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-20 10:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-20 10:47 [PATCH] mtd: Do not write empty pages, UBI fix Sascha Hauer
2013-02-20 10:47 ` [PATCH 1/2] mtd: nand: do not write empty pages Sascha Hauer
2013-02-20 10:47 ` [PATCH 2/2] libubi: Use global mtd_all_ff function Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox