NAND flash has very high possibility to has bad blocks.

Some bootloaders such as u-boot support to skip bad blocks when it read
the kernel image from NAND falsh.

For now, the mtd just exits when it meet the bad block. That means even
there is one bad block in NAND flash, then we can't use mtd to write
image to it.

Change to let mtd skip bad blocks when it is writing the image to NAND flash.

    modified:   package/system/mtd/src/mtd.c
---
 package/system/mtd/src/mtd.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index a660486..675f26c 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -55,6 +55,7 @@ int quiet;
 int no_erase;
 int mtdsize = 0;
 int erasesize = 0;
+int mtdtype = 0;
 
 int mtd_open(const char *mtd, bool block)
 {
@@ -100,6 +101,7 @@ int mtd_check_open(const char *mtd)
     }
     mtdsize = mtdInfo.size;
     erasesize = mtdInfo.erasesize;
+    mtdtype = mtdInfo.type;
 
     return fd;
 }
@@ -425,13 +427,22 @@ resume:
                         fprintf(stderr, "\b\b\b   \n");
                         goto resume;
                     } else {
-                        fprintf(stderr, "Failed to erase block\n");
-                        exit(1);
+                        /* skip this bad chunk */
+                        if (mtdtype == MTD_NANDFLASH) {
+                            lseek(fd, erasesize, SEEK_CUR);
+                            e += erasesize;
+                            w += erasesize;
+                            fprintf(stderr, "Skip a bad chunk\n");
+                        } else {
+                            fprintf(stderr, "Failed to erase block\n");
+                            exit(1);
+                        }
                     }
-                }
+                } else {
 
-                /* erase the chunk */
-                e += erasesize;
+                    /* erase the chunk */
+                    e += erasesize;
+                }
             }
         }
 
-- 
1.8.1.2
----------------------------------------
> Date: Mon, 12 Aug 2013 07:57:02 +0200
> From: n...@openwrt.org
> To: lg...@hotmail.com
> CC: openwrt-devel@lists.openwrt.org
> Subject: Re: [PATCH] Let MTD support skipping bad chunks
>
> On 2013-08-12 1:54 AM, Joe XUE wrote:
>> NAND flash has very high possibility to have bad blocks.
>>
>> Some bootloaders such as u-boot support to skip bad blocks when it read
>> the kernel image from NAND falsh.
>>
>> For now, the mtd just exits when it meets the bad block. That means even
>> there is one bad block in NAND flash, then we can't use mtd to write
>> image to it.
>>
>> Change to let mtd skip bad blocks when it is writing the image to NAND
>> flash.
>>
>> modified: package/system/mtd/src/mtd.c
> The email does not preserve whitespace, so the patch doesn't apply
> (probably because it was sent as HTML email). Please fix your email
> client settings and resend (or use git-send-email).
>
> - Felix                                         
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to