diff options
-rw-r--r-- | miscutils/nandwrite.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index 8df0fdc81..f42242687 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c | |||
@@ -52,7 +52,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) | |||
52 | unsigned opts; | 52 | unsigned opts; |
53 | int fd; | 53 | int fd; |
54 | ssize_t cnt; | 54 | ssize_t cnt; |
55 | unsigned mtdoffset, meminfo_writesize; | 55 | unsigned mtdoffset, meminfo_writesize, blockstart; |
56 | struct mtd_info_user meminfo; | 56 | struct mtd_info_user meminfo; |
57 | unsigned char *filebuf; | 57 | unsigned char *filebuf; |
58 | const char *opt_s = "0"; | 58 | const char *opt_s = "0"; |
@@ -83,9 +83,21 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) | |||
83 | 83 | ||
84 | filebuf = xmalloc(meminfo_writesize); | 84 | filebuf = xmalloc(meminfo_writesize); |
85 | 85 | ||
86 | blockstart = mtdoffset & ~(meminfo.erasesize - 1); | ||
87 | if (blockstart != mtdoffset) { | ||
88 | unsigned tmp; | ||
89 | /* mtdoffset is in the middle of an erase block, verify that | ||
90 | * this block is OK. Advance mtdoffset only if this block is | ||
91 | * bad. | ||
92 | */ | ||
93 | tmp = next_good_eraseblock(fd, &meminfo, blockstart); | ||
94 | if (tmp != blockstart) /* bad block(s), advance mtdoffset */ | ||
95 | mtdoffset = tmp; | ||
96 | } | ||
97 | |||
86 | cnt = -1; | 98 | cnt = -1; |
87 | while (mtdoffset < meminfo.size) { | 99 | while (mtdoffset < meminfo.size) { |
88 | unsigned blockstart = mtdoffset & ~(meminfo.erasesize - 1); | 100 | blockstart = mtdoffset & ~(meminfo.erasesize - 1); |
89 | if (blockstart == mtdoffset) { | 101 | if (blockstart == mtdoffset) { |
90 | /* starting a new eraseblock */ | 102 | /* starting a new eraseblock */ |
91 | mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart); | 103 | mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart); |