mtd/util flash_eraseall.c,1.16,1.17 nandwrite.c,1.14,1.15
gleixner at infradead.org
gleixner at infradead.org
Sat Sep 11 16:05:54 EDT 2004
Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv4641
Modified Files:
flash_eraseall.c nandwrite.c
Log Message:
fix auto oob placement
Index: flash_eraseall.c
===================================================================
RCS file: /home/cvs/mtd/util/flash_eraseall.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- flash_eraseall.c 6 May 2004 06:51:20 -0000 1.16
+++ flash_eraseall.c 11 Sep 2004 20:05:51 -0000 1.17
@@ -42,8 +42,8 @@
#include <mtd/mtd-user.h>
#include <mtd/jffs2-user.h>
-#define PROGRAM "eraseall"
-#define VERSION "0.1.2"
+#define PROGRAM "flash_eraseall"
+#define VERSION "1.17"
static const char *exe_name;
static const char *mtd_device;
@@ -59,7 +59,7 @@
int main (int argc, char *argv[])
{
mtd_info_t meminfo;
- int fd;
+ int fd, clmpos = 0, clmlen = 8;
erase_info_t erase;
int isNAND;
@@ -85,8 +85,44 @@
cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
if (!isNAND)
cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
- else
- cleanmarker.totlen = cpu_to_je32(8); /* NAND code expects this to be 8 ! */
+ else {
+ struct nand_oobinfo oobinfo;
+
+ if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
+ fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", exe_name, mtd_device);
+ exit(1);
+ }
+
+ /* Check for autoplacement */
+ if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
+ /* Get the position of the free bytes */
+ if (!oobinfo.oobfree[0][1]) {
+ fprintf (stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
+ exit(1);
+ }
+ clmpos = oobinfo.oobfree[0][0];
+ clmlen = oobinfo.oobfree[0][1];
+ if (clmlen > 8)
+ clmlen = 8;
+ } else {
+ /* Legacy mode */
+ switch (meminfo.oobsize) {
+ case 8:
+ clmpos = 6;
+ clmlen = 2;
+ break;
+ case 16:
+ clmpos = 8;
+ clmlen = 8;
+ break;
+ case 64:
+ clmpos = 16;
+ clmlen = 8;
+ break;
+ }
+ }
+ cleanmarker.totlen = cpu_to_je32(8);
+ }
cleanmarker.hdr_crc = cpu_to_je32 (crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
}
@@ -105,29 +141,16 @@
continue;
}
- // format for JFFS2
+ /* format for JFFS2 ? */
if (!jffs2)
continue;
- // write cleanmarker
+ /* write cleanmarker */
if (isNAND) {
struct mtd_oob_buf oob;
oob.ptr = (unsigned char *) &cleanmarker;
- oob.start = erase.start;
- switch (meminfo.oobsize) {
- case 8:
- oob.start += 6;
- oob.length = 2;
- break;
- case 16:
- oob.start += 8;
- oob.length = 8;
- break;
- case 64:
- oob.start += 16;
- oob.length = 8;
- break;
- }
+ oob.start = erase.start + clmpos;
+ oob.length = clmlen;
if (ioctl (fd, MEMWRITEOOB, &oob) != 0) {
fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
continue;
Index: nandwrite.c
===================================================================
RCS file: /home/cvs/mtd/util/nandwrite.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- nandwrite.c 13 Aug 2004 09:29:53 -0000 1.14
+++ nandwrite.c 11 Sep 2004 20:05:51 -0000 1.15
@@ -38,7 +38,7 @@
#include "mtd/mtd-user.h"
#define PROGRAM "nandwrite"
-#define VERSION "1.2"
+#define VERSION "1.14"
/*
* Buffer array used for writing data
@@ -190,11 +190,13 @@
*/
int main(int argc, char **argv)
{
- int cnt, fd, ifd, imglen, pagelen, blockstart = -1;
+ int cnt, fd, ifd, imglen = 0, pagelen, blockstart = -1;
struct mtd_info_user meminfo;
struct mtd_oob_buf oob;
loff_t offs;
int ret, readlen;
+ int oobinfochanged = 0;
+ struct nand_oobinfo old_oobinfo;
process_options(argc, argv);
@@ -224,6 +226,13 @@
close(fd);
exit(1);
}
+
+ /* Read the current oob info */
+ if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
+ perror ("MEMGETOOBSEL");
+ close (fd);
+ exit (1);
+ }
// write without ecc ?
if (noecc) {
@@ -231,16 +240,19 @@
perror ("MEMSETOOBSEL");
close (fd);
exit (1);
- }
+ }
+ oobinfochanged = 1;
}
// autoplace ECC ?
- if (autoplace) {
+ if (autoplace && (old_oobinfo.useecc != MTD_NANDECC_AUTOPLACE)) {
+
if (ioctl (fd, MEMSETOOBSEL, &autoplace_oobinfo) != 0) {
perror ("MEMSETOOBSEL");
close (fd);
exit (1);
}
+ oobinfochanged = 1;
}
// force oob layout for jffs2 or yaffs ?
@@ -250,8 +262,7 @@
if (forceyaffs && meminfo.oobsize == 8) {
if (forceyaffs) {
fprintf (stderr, "YAFSS cannot operate on 256 Byte page size");
- close (fd);
- exit (1);
+ goto restoreoob;
}
/* Adjust number of ecc bytes */
jffs2_oobinfo.eccbytes = 3;
@@ -259,8 +270,7 @@
if (ioctl (fd, MEMSETOOBSEL, oobsel) != 0) {
perror ("MEMSETOOBSEL");
- close (fd);
- exit (1);
+ goto restoreoob;
}
}
@@ -270,9 +280,7 @@
/* Open the input file */
if ((ifd = open(img, O_RDONLY)) == -1) {
perror("open input file");
- close(fd);
- close(ifd);
- exit(1);
+ goto restoreoob;
}
// get image length
@@ -284,17 +292,13 @@
// Check, if file is pagealigned
if ((!pad) && ((imglen % pagelen) != 0)) {
perror ("Input file is not page aligned");
- close (fd);
- close (ifd);
- exit (1);
+ goto closeall;
}
// Check, if length fits into device
if ( ((imglen / pagelen) * meminfo.oobblock) > (meminfo.size - mtdoffset)) {
perror ("Input file does not fit into device");
- close (fd);
- close (ifd);
- exit (1);
+ goto closeall;
}
/* Get data from input and write to the device */
@@ -307,9 +311,7 @@
fprintf (stdout, "Writing data to block %x\n", blockstart);
if ((ret = ioctl(fd, MEMGETBADBLOCK, &offs)) < 0) {
perror("ioctl(MEMGETBADBLOCK)");
- close (ifd);
- close (fd);
- exit (1);
+ goto closeall;
}
if (ret == 1) {
if (!quiet)
@@ -331,26 +333,20 @@
if (cnt == 0) // EOF
break;
perror ("File I/O error on input file");
- close (fd);
- close (ifd);
- exit (1);
- }
-
+ goto closeall;
+ }
+
if (writeoob) {
/* Read OOB data from input file, exit on failure */
if ((cnt = read(ifd, oobbuf, meminfo.oobsize)) != meminfo.oobsize) {
perror ("File I/O error on input file");
- close (fd);
- close (ifd);
- exit (1);
+ goto closeall;
}
/* Write OOB data first, as ecc will be placed in there*/
oob.start = mtdoffset;
if (ioctl(fd, MEMWRITEOOB, &oob) != 0) {
perror ("ioctl(MEMWRITEOOB)");
- close (fd);
- close (ifd);
- exit (1);
+ goto closeall;
}
imglen -= meminfo.oobsize;
}
@@ -358,18 +354,26 @@
/* Write out the Page data */
if (pwrite(fd, writebuf, meminfo.oobblock, mtdoffset) != meminfo.oobblock) {
perror ("pwrite");
- close (fd);
- close (ifd);
- exit (1);
+ goto closeall;
}
imglen -= readlen;
mtdoffset += meminfo.oobblock;
}
- /* Close the output file and MTD device */
- close(fd);
+ closeall:
close(ifd);
+ restoreoob:
+ if (oobinfochanged) {
+ if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
+ perror ("MEMSETOOBSEL");
+ close (fd);
+ exit (1);
+ }
+ }
+
+ close(fd);
+
if (imglen > 0) {
perror ("Data did not fit into device, due to bad blocks\n");
exit (1);
More information about the linux-mtd-cvs
mailing list