summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorBaruch Siach2010-08-29 10:36:50 +0300
committerDenys Vlasenko2010-08-29 13:30:22 +0200
commit7715b48c36a453b41f4555ee57c2f936e25f06f1 (patch)
treee68fddaf8b2c515c68668fdb15e2b10bc020d9e0 /miscutils
parentb32a5436633f53f0abf0fa29105cf7e5b65091cf (diff)
downloadbusybox-7715b48c36a453b41f4555ee57c2f936e25f06f1.zip
busybox-7715b48c36a453b41f4555ee57c2f936e25f06f1.tar.gz
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>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/nandwrite.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
index 8df0fdc..f422426 100644
--- a/miscutils/nandwrite.c
+++ b/miscutils/nandwrite.c
@@ -52,7 +52,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
unsigned opts;
int fd;
ssize_t cnt;
- unsigned mtdoffset, meminfo_writesize;
+ unsigned mtdoffset, meminfo_writesize, blockstart;
struct mtd_info_user meminfo;
unsigned char *filebuf;
const char *opt_s = "0";
@@ -83,9 +83,21 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
filebuf = xmalloc(meminfo_writesize);
+ blockstart = mtdoffset & ~(meminfo.erasesize - 1);
+ if (blockstart != mtdoffset) {
+ unsigned tmp;
+ /* mtdoffset is in the middle of an erase block, verify that
+ * this block is OK. Advance mtdoffset only if this block is
+ * bad.
+ */
+ tmp = next_good_eraseblock(fd, &meminfo, blockstart);
+ if (tmp != blockstart) /* bad block(s), advance mtdoffset */
+ mtdoffset = tmp;
+ }
+
cnt = -1;
while (mtdoffset < meminfo.size) {
- unsigned blockstart = mtdoffset & ~(meminfo.erasesize - 1);
+ blockstart = mtdoffset & ~(meminfo.erasesize - 1);
if (blockstart == mtdoffset) {
/* starting a new eraseblock */
mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart);