diff options
author | Baruch Siach <baruch@tkos.co.il> | 2010-08-29 10:36:50 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-29 13:30:22 +0200 |
commit | 7715b48c36a453b41f4555ee57c2f936e25f06f1 (patch) | |
tree | e68fddaf8b2c515c68668fdb15e2b10bc020d9e0 | |
parent | b32a5436633f53f0abf0fa29105cf7e5b65091cf (diff) | |
download | busybox-w32-7715b48c36a453b41f4555ee57c2f936e25f06f1.tar.gz busybox-w32-7715b48c36a453b41f4555ee57c2f936e25f06f1.tar.bz2 busybox-w32-7715b48c36a453b41f4555ee57c2f936e25f06f1.zip |
nandwrite: always check the first erase block
Current code does not check the first erase block when mtdoffset is not erase
block aligned. Fix this.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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); |