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.

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

diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index a660486..e44789c 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -425,13 +425,17 @@ resume:
                         fprintf(stderr, "\b\b\b   \n");
                         goto resume;
                     } else {
-                        fprintf(stderr, "Failed to erase block\n");
-                        exit(1);
+                        /* skip this bad chunk */
+                        lseek(fd, erasesize, SEEK_CUR);
+                        e += erasesize;
+                        w += erasesize;
+                        fprintf(stderr, "Skip a bad chunk\n");
                     }
-                }
+                } else {
 
-                /* erase the chunk */
-                e += erasesize;
+                    /* erase the chunk */
+                    e += erasesize;
+                }
             }
         }
 
-- 
1.8.1.2                                           
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to