mtd/util eraseall.c,1.13,1.14 nandwrite.c,1.9,1.10
David Woodhouse
dwmw2 at infradead.org
Wed May 5 08:20:33 EDT 2004
Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv2259/util
Modified Files:
eraseall.c nandwrite.c
Log Message:
From: Pantelis Antoniou <panto at intracom.gr>
The following patch fixes nandwrite/eraseall to work correctly on NANDs
with the current mtd code.
There is a new option for nandwrite -a/--autoplace which places the OOB
bytes according to the autoplaced OOB of the current code.
Index: eraseall.c
===================================================================
RCS file: /home/cvs/mtd/util/eraseall.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- eraseall.c 5 May 2004 11:57:55 -0000 1.13
+++ eraseall.c 5 May 2004 12:20:30 -0000 1.14
@@ -112,8 +112,20 @@
struct mtd_oob_buf oob;
oob.ptr = (unsigned char *) &cleanmarker;
oob.start = erase.start;
- oob.start += meminfo.oobsize == 16 ? 8 : 6;
- oob.length = meminfo.oobsize == 16 ? 8 : 2;
+ 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 += 2;
+ oob.length = 8;
+ break;
+ }
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- nandwrite.c 5 May 2004 11:57:55 -0000 1.9
+++ nandwrite.c 5 May 2004 12:20:30 -0000 1.10
@@ -47,24 +47,29 @@
// oob layouts to pass into the kernel as default
struct nand_oobinfo none_oobinfo = {
- useecc: 0,
+ .useecc = MTD_NANDECC_OFF,
};
struct nand_oobinfo jffs2_oobinfo = {
- useecc: 1,
- eccpos: { 0, 1, 2, 3, 6, 7}
+ .useecc = MTD_NANDECC_PLACE,
+ .eccpos = { 0, 1, 2, 3, 6, 7 }
};
struct nand_oobinfo yaffs_oobinfo = {
- useecc: 1,
- eccpos: { 8, 9, 10, 13, 14, 15}
+ .useecc = MTD_NANDECC_PLACE,
+ .eccpos = { 8, 9, 10, 13, 14, 15}
+};
+
+struct nand_oobinfo autoplace_oobinfo = {
+ .useecc = MTD_NANDECC_AUTOPLACE
};
void display_help (void)
{
printf("Usage: nandwrite [OPTION] MTD_DEVICE INPUTFILE\n"
- "Erases all of the specified MTD device.\n"
+ "Writes to the specified MTD device.\n"
"\n"
+ " -a, --autoplace Use auto oob layout\n"
" -j, --jffs2 force jffs2 oob layout\n"
" -y, --yaffs force yaffs oob layout\n"
" -n, --noecc write without ecc\n"
@@ -95,6 +100,7 @@
int mtdoffset = 0;
int quiet = 0;
int writeoob = 0;
+int autoplace = 0;
int forcejffs2 = 0;
int forceyaffs = 0;
int noecc = 0;
@@ -105,12 +111,13 @@
for (;;) {
int option_index = 0;
- static const char *short_options = "os:jynq";
+ static const char *short_options = "os:ajynq";
static const struct option long_options[] = {
{"help", no_argument, 0, 0},
{"version", no_argument, 0, 0},
{"oob", no_argument, 0, 'o'},
{"start", required_argument, 0, 's'},
+ {"autoplace", no_argument, 0, 'a'},
{"jffs2", no_argument, 0, 'j'},
{"yaffs", no_argument, 0, 'y'},
{"noecc", no_argument, 0, 'n'},
@@ -138,6 +145,9 @@
case 'q':
quiet = 1;
break;
+ case 'a':
+ autoplace = 1;
+ break;
case 'j':
forcejffs2 = 1;
break;
@@ -166,14 +176,13 @@
img = argv[optind];
}
-
/*
* Main program
*/
int main(int argc, char **argv)
{
int cnt, fd, ifd, imglen, pagelen, blockstart = -1;
- mtd_info_t meminfo;
+ struct mtd_info_user meminfo;
struct mtd_oob_buf oob;
process_options(argc, argv);
@@ -202,6 +211,15 @@
// write without ecc ?
if (noecc) {
if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
+ perror ("MEMSETOOBSEL");
+ close (fd);
+ exit (1);
+ }
+ }
+
+ // autoplace ECC ?
+ if (autoplace) {
+ if (ioctl (fd, MEMSETOOBSEL, &autoplace_oobinfo) != 0) {
perror ("MEMSETOOBSEL");
close (fd);
exit (1);
More information about the linux-mtd-cvs
mailing list