[PATCH] nanddump: dump rigth length when jumping bad blocks

Richard Genoud richard.genoud at gmail.com
Wed Jun 18 13:44:30 UTC 2014


With the "skip bad block" option, nanddump is not dumping the right
length if there's bad blocks.

This patch moves the end read address each time a bad block is
encountered.

Signed-off-by: Richard Genoud <richard.genoud at gmail.com>
---
 miscutils/nandwrite.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
index 8c4da802f6b3..a3593adedc82 100644
--- a/miscutils/nandwrite.c
+++ b/miscutils/nandwrite.c
@@ -166,6 +166,10 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
 				int bad_len = MIN(tmp, end_addr) - mtdoffset;
 				dump_bad(&meminfo, bad_len, opts & OPT_o);
 			}
+			/* with option skip bad block, increase the length */
+			if (IS_NANDDUMP && (opts & OPT_b)) {
+				end_addr += (tmp - blockstart);
+			}
 			mtdoffset = tmp;
 		}
 	}
@@ -182,9 +186,16 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
 			mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart);
 			if (IS_NANDWRITE)
 				printf("Writing at 0x%08x\n", mtdoffset);
-			else if (mtdoffset > blockstart && !(opts & OPT_b)) {
-				int bad_len = MIN(mtdoffset, limit) - blockstart;
-				dump_bad(&meminfo, bad_len, opts & OPT_o);
+			else if (mtdoffset > blockstart) {
+				if (opts & OPT_b) {
+					/* omit bad block, but increase the length */
+					end_addr += (mtdoffset - blockstart);
+					limit = MIN(meminfo.size, end_addr);
+				} else {
+					/* dump bad block if asked */
+					int bad_len = MIN(mtdoffset, limit) - blockstart;
+					dump_bad(&meminfo, bad_len, opts & OPT_o);
+				}
 			}
 			if (mtdoffset >= limit)
 				break;
-- 
1.8.5.5



More information about the busybox mailing list