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
---
 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: Sat, 10 Aug 2013 20:38:52 +0200
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> Subject: Re: [PATCH] Let MTD support skipping bad chunks
> 
> On 2013-08-09 10:54 PM, Joe XUE wrote:
> > NAND flash has very 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.
> Please change the patch to limit this behavior to NAND flash. On NOR
> flash it should always fail if it cannot erase a block.
> 
> Thanks,
> 
> - Felix
                                          
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to