From 3728cdea3130c62f3d766df040d2cb85f1e6caa4 Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 16 Jun 2007 05:52:46 +0200 Subject: * Add new command 'nanddump' for the console shell * Avoid dumping non-mtd files because writesize = 0 - Properly close the file when failing * Better doc/pieces documentation --- src/dump.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index af453a4..167d3c4 100644 --- a/src/dump.c +++ b/src/dump.c @@ -124,6 +124,9 @@ int mtd_open(char *file, mtd_info_t *meminfo, int *oobinfochanged, int mtd_close(int fd, struct nand_oobinfo *old_oobinfo, int oobinfochanged) { + if (fd == -1) + return 1; + /* reset oobinfo */ if (oobinfochanged == 1) { if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) { @@ -264,6 +267,12 @@ int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char fd = mtd_open(mtddev, &meminfo, &oobinfochanged, &old_oobinfo, &eccstats, flags); + if (meminfo.writesize == 0) { + printf("What the fuck.. this is not an MTD device!\n"); + close(fd); + return 1; + } + /* Read the real oob length */ oob.length = meminfo.oobsize; fprintf(stderr, "Block size %u, page size %u, OOB size %u\n", @@ -271,7 +280,6 @@ int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char fprintf(stderr, "Size %u, flags %u, type 0x%x\n", meminfo.size, meminfo.flags, (int)meminfo.type); - if (flags & M_OMITECC) { // (noecc) switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) { case -ENOTTY: -- cgit v1.2.3