public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] Make the mtdblock read/write skip the bad nand sector
@ 2013-11-21  8:54 Hans Zhang
  2013-11-21 10:59 ` Richard Genoud
  0 siblings, 1 reply; 19+ messages in thread
From: Hans Zhang @ 2013-11-21  8:54 UTC (permalink / raw)
  To: dwmw2, linux-mtd, linux-kernel; +Cc: Hans Zhang, zhouguangming

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2418 bytes --]

 When read/write the nandblock device, it will abort writing if
 there's a bad block, it's reasonable to skip the bad block and
 finish the data writing.
 The data reading procedure should also skip the bad block since
 there's no data write to the block.

--v2:
 use the wrapped mtd_block_isbad instand of mtd->block_isbad

Signed-off-by: Hans Zhang <zhanghonghui@innofidei.com>
---
 drivers/mtd/mtdblock.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 485ea75..4f6acd1 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -124,6 +124,13 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
 			"at 0x%lx, size 0x%x\n", mtd->name,
 			mtdblk->cache_offset, mtdblk->cache_size);
 
+retry:
+	ret = mtd_block_isbad(mtd, mtdblk->cache_offset);
+	if (ret > 0) {
+		mtdblk->cache_offset += mtdblk->cache_size;
+		goto retry;
+	}
+
 	ret = erase_write (mtd, mtdblk->cache_offset,
 			   mtdblk->cache_size, mtdblk->cache_data);
 	if (ret)
@@ -163,6 +170,11 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
 			size = len;
 
 		if (size == sect_size) {
+			ret = mtd_block_isbad(mtd, pos);
+			if (ret > 0) {
+				pos += sect_size;
+				continue;
+			}
 			/*
 			 * We are covering a whole sector.  Thus there is no
 			 * need to bother with the cache while it may still be
@@ -242,6 +254,11 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
 		    mtdblk->cache_offset == sect_start) {
 			memcpy (buf, mtdblk->cache_data + offset, size);
 		} else {
+			ret = mtd_block_isbad(mtd, pos);
+			if (ret > 0) {
+				pos += sect_size;
+				continue;
+			}
 			ret = mtd_read(mtd, pos, size, &retlen, buf);
 			if (ret)
 				return ret;
-- 
1.7.1


¡°This E-mail and its attachments may contain legally privileged or confidential information from Innofidei Corporation. Any unauthorized copy, use, disclosure or distribution of this information is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by E-mail or telephone and delete this E-mail and all its attachments immediately.
±¾Óʼþ¼°Æä¸½¼þÄÚÈÝ¿ÉÄܰüº¬´´Ò㹫˾ÏíÓÐרÓз¨ÂÉȨÀûµÄ»òÕßÐèÒª±£ÃܵÄÐÅÏ¢¡£ÑϽûÈκÎÈËδ¾­·¢¼þÈËÐí¿ÉÒÔÈκÎÐÎʽ¸´ÖÆ¡¢Ê¹Óá¢Åû¶»òÕßÉ¢·¢´ËÏîÐÅÏ¢¡£Èç¹ûÄú²»ÊǸÃÊÕ¼þÈË£¬ÇëÄúÁ¢¼´Í¨¹ýÓʼþ»òÕߵ绰֪ͨ·¢¼þÈ˲¢Á¢¼´É¾³ý±¾Óʼþ¼°Æä¸½¼þÄÚÈÝ.¡±

^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [PATCH] Make the mtdblock read/write skip the bad nand sector
@ 2013-11-21  8:39 Hans Zhang
  0 siblings, 0 replies; 19+ messages in thread
From: Hans Zhang @ 2013-11-21  8:39 UTC (permalink / raw)
  To: dwmw2, linux-mtd, linux-kernel; +Cc: Hans Zhang, zhouguangming

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2469 bytes --]

 When read/write the nandblock device, it will abort writing if
 there's a bad block, it's reasonable to skip the bad block and
 finish the data writing.
 The data reading procedure should also skip the bad block since
 there's no data write to the block.

Signed-off-by: Hans Zhang <zhanghonghui@innofidei.com>
---
 drivers/mtd/mtdblock.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 485ea75..66e3b23 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -124,6 +124,14 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
 			"at 0x%lx, size 0x%x\n", mtd->name,
 			mtdblk->cache_offset, mtdblk->cache_size);
 
+retry:
+	if (mtd->block_isbad) {
+		ret = mtd->block_isbad(mtd, mtdblk->cache_offset);
+		if (ret > 0) {
+			mtdblk->cache_offset += mtdblk->cache_size;
+			goto retry;
+		}
+	}
 	ret = erase_write (mtd, mtdblk->cache_offset,
 			   mtdblk->cache_size, mtdblk->cache_data);
 	if (ret)
@@ -163,6 +171,13 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
 			size = len;
 
 		if (size == sect_size) {
+			if (mtd->block_isbad) {
+				ret = mtd->block_isbad(mtd, pos);
+				if (ret > 0) {
+					pos += sect_size;
+					continue;
+				}
+			}
 			/*
 			 * We are covering a whole sector.  Thus there is no
 			 * need to bother with the cache while it may still be
@@ -242,6 +257,13 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
 		    mtdblk->cache_offset == sect_start) {
 			memcpy (buf, mtdblk->cache_data + offset, size);
 		} else {
+			if (mtd->block_isbad) {
+				ret = mtd->block_isbad(mtd, pos);
+				if (ret > 0) {
+					pos += sect_size;
+					continue;
+				}
+			}
 			ret = mtd_read(mtd, pos, size, &retlen, buf);
 			if (ret)
 				return ret;
-- 
1.7.1


¡°This E-mail and its attachments may contain legally privileged or confidential information from Innofidei Corporation. Any unauthorized copy, use, disclosure or distribution of this information is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by E-mail or telephone and delete this E-mail and all its attachments immediately.
±¾Óʼþ¼°Æä¸½¼þÄÚÈÝ¿ÉÄܰüº¬´´Ò㹫˾ÏíÓÐרÓз¨ÂÉȨÀûµÄ»òÕßÐèÒª±£ÃܵÄÐÅÏ¢¡£ÑϽûÈκÎÈËδ¾­·¢¼þÈËÐí¿ÉÒÔÈκÎÐÎʽ¸´ÖÆ¡¢Ê¹Óá¢Åû¶»òÕßÉ¢·¢´ËÏîÐÅÏ¢¡£Èç¹ûÄú²»ÊǸÃÊÕ¼þÈË£¬ÇëÄúÁ¢¼´Í¨¹ýÓʼþ»òÕߵ绰֪ͨ·¢¼þÈ˲¢Á¢¼´É¾³ý±¾Óʼþ¼°Æä¸½¼þÄÚÈÝ.¡±

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

end of thread, other threads:[~2013-12-10  7:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21  8:54 [PATCH] Make the mtdblock read/write skip the bad nand sector Hans Zhang
2013-11-21 10:59 ` Richard Genoud
2013-11-22  1:22   ` Hans Zhang
2013-11-22  1:52     ` Ezequiel Garcia
2013-11-22  2:10       ` Hans Zhang
2013-11-22  8:14         ` Richard Weinberger
2013-11-22 11:45         ` Ezequiel Garcia
2013-11-25  1:29           ` Hans Zhang
2013-11-25 10:11             ` Ezequiel Garcia
2013-11-25 10:23               ` Richard Genoud
2013-11-25 11:30                 ` Hans Zhang
2013-11-25 11:52                   ` Ezequiel Garcia
2013-11-25 12:16                     ` David Woodhouse
2013-11-25 12:30                       ` Ezequiel Garcia
2013-11-25 15:12                         ` Peter Korsgaard
2013-11-25 15:46                           ` David Woodhouse
2013-11-29 13:26                             ` Pavel Machek
2013-12-10  7:43                               ` Brian Norris
  -- strict thread matches above, loose matches on Subject: below --
2013-11-21  8:39 Hans Zhang

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