aboutsummaryrefslogtreecommitdiffstats
path: root/package/system/mtd/src/mtd.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-12-02 19:28:23 +0000
committerJohn Crispin <blogic@openwrt.org>2014-12-02 19:28:23 +0000
commit31de27e5ec744d6cb89340204b9d554503f872a3 (patch)
tree0f60b537da4503c434eedc43b3684dc90005f700 /package/system/mtd/src/mtd.c
parent9a03fea5aead67bec1b49cc4e372720f3d989770 (diff)
downloadupstream-31de27e5ec744d6cb89340204b9d554503f872a3.tar.gz
upstream-31de27e5ec744d6cb89340204b9d554503f872a3.tar.bz2
upstream-31de27e5ec744d6cb89340204b9d554503f872a3.zip
mtd: make the mtd dump call run properly on nand flash
Signed-off-by: John Crispin <blogic@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@43503 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/system/mtd/src/mtd.c')
-rw-r--r--package/system/mtd/src/mtd.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index e0a90f6719..db3fc804c9 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -276,8 +276,9 @@ mtd_erase(const char *mtd)
static int
mtd_dump(const char *mtd, int size)
{
- int ret = 0;
+ int ret = 0, offset = 0;
int fd;
+ char *buf;
if (quiet < 2)
fprintf(stderr, "Dumping %s ...\n", mtd);
@@ -288,9 +289,15 @@ mtd_dump(const char *mtd, int size)
return -1;
}
+ if (!size)
+ size = mtdsize;
+
+ buf = malloc(erasesize);
+ if (!buf)
+ return -1;
+
do {
- char buf[256];
- int len = (size > sizeof(buf)) ? (sizeof(buf)) : (size);
+ int len = (size > erasesize) ? (erasesize) : (size);
int rlen = read(fd, buf, len);
if (rlen < 0) {
@@ -299,9 +306,15 @@ mtd_dump(const char *mtd, int size)
ret = -1;
goto out;
}
- if (!rlen)
+ if (!rlen || rlen != len)
break;
- write(1, buf, rlen);
+ if (mtd_block_is_bad(fd, offset)) {
+ fprintf(stderr, "skipping bad block at 0x%08x\n", offset);
+ } else {
+ size -= rlen;
+ write(1, buf, rlen);
+ }
+ offset += rlen;
} while (size > 0);
out: