blob: 02a2b2e444e327492162a88b61003de8f4568520 [file] [log] [blame] [edit]
diff -Naur mtd-utils-1.3.1.pristine/nanddump.c mtd-utils-1.3.1.N/nanddump.c
--- mtd-utils-1.3.1.pristine/nanddump.c 2015-08-24 17:31:43.707872733 -0700
+++ mtd-utils-1.3.1.N/nanddump.c 2015-08-24 17:52:22.608267037 -0700
@@ -178,20 +178,14 @@
}
/*
- * Buffers for reading data from flash
- */
-static unsigned char readbuf[4096];
-static unsigned char oobbuf[128];
-
-/*
* Main program
*/
int main(int argc, char * const argv[])
{
unsigned long ofs, end_addr = 0;
unsigned long long blockstart = 1;
- int ret, i, fd, ofd, bs, badblock = 0;
- struct mtd_oob_buf oob = {0, 16, oobbuf};
+ int ret, i, fd, ofd = 0, bs, badblock = 0;
+ struct mtd_oob_buf oob;
mtd_info_t meminfo;
char pretty_buf[80];
int oobinfochanged = 0 ;
@@ -199,6 +193,7 @@
struct mtd_ecc_stats stat1, stat2;
bool eccstats = false;
bool isempty;
+ unsigned char *readbuf = NULL, *oobbuf = NULL;
process_options(argc, argv);
@@ -215,18 +210,17 @@
exit (EXIT_FAILURE);
}
- /* Make sure device page sizes are valid */
- if (!(meminfo.oobsize == 128 && meminfo.writesize == 4096) &&
- !(meminfo.oobsize == 64 && meminfo.writesize == 2048) &&
- !(meminfo.oobsize == 32 && meminfo.writesize == 1024) &&
- !(meminfo.oobsize == 16 && meminfo.writesize == 512) &&
- !(meminfo.oobsize == 8 && meminfo.writesize == 256)) {
- fprintf(stderr, "Unknown flash (not normal NAND)\n");
- close(fd);
- exit(EXIT_FAILURE);
- }
- /* Read the real oob length */
+ /* Allocate buffers */
+ oobbuf = malloc(sizeof(oobbuf) * meminfo.oobsize);
+ readbuf = malloc(sizeof(readbuf) * meminfo.writesize);
+
+ if (oobbuf == NULL || readbuf == NULL)
+ goto closeall;
+
+ /* Fill in oob info */
+ oob.start = 0;
oob.length = meminfo.oobsize;
+ oob.ptr = oobbuf;
if (noecc) {
ret = ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW);
@@ -237,20 +231,17 @@
case ENOTTY:
if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
perror ("MEMGETOOBSEL");
- close (fd);
- exit (EXIT_FAILURE);
+ goto closeall;
}
if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
perror ("MEMSETOOBSEL");
- close (fd);
- exit (EXIT_FAILURE);
+ goto closeall;
}
oobinfochanged = 1;
break;
default:
perror ("MTDFILEMODE");
- close (fd);
- exit (EXIT_FAILURE);
+ goto closeall;
}
}
} else {
@@ -274,8 +265,7 @@
ofd = STDOUT_FILENO;
} else if ((ofd = open(dumpfile, O_WRONLY | O_TRUNC | O_CREAT, 0644))== -1) {
perror (dumpfile);
- close(fd);
- exit(EXIT_FAILURE);
+ goto closeall;
}
/* Initialize start/end addresses and block size */
@@ -420,14 +410,14 @@
if (oobinfochanged == 1) {
if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
perror ("MEMSETOOBSEL");
- close(fd);
- close(ofd);
- return EXIT_FAILURE;
+ goto closeall;
}
}
- /* Close the output file and MTD device */
+ /* Close the output file and MTD device, free memory */
close(fd);
close(ofd);
+ free(oobbuf);
+ free(readbuf);
/* Exit happy */
return EXIT_SUCCESS;
@@ -441,5 +431,7 @@
}
close(fd);
close(ofd);
+ free(oobbuf);
+ free(readbuf);
exit(EXIT_FAILURE);
}