Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vmpn committed Nov 9, 2013
1 parent 80f8cdf commit b778dc9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions miscutils/nandwrite.c
Expand Up @@ -64,8 +64,8 @@ static void dump_bad(struct mtd_info_user *meminfo, unsigned len, int oob)
unsigned char buf[meminfo->writesize];
unsigned count;

/* round len to the next page */
len = (len | ~(meminfo->writesize - 1)) + 1;
/* round len to the next page only if len is not already on a page */
len = ((len - 1) | (meminfo->writesize - 1)) + 1;

memset(buf, 0xff, sizeof(buf));
for (count = 0; count < len; count += meminfo->writesize) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down

0 comments on commit b778dc9

Please sign in to comment.