X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs%2F.git;a=blobdiff_plain;f=utils%2Fmkyaffs.c;h=a3ec11d2a46ef9d1dcf1080dd442739a7799ccdd;hp=3a0ed6776be3dd0a0d11f8022bf4613bb81d77b2;hb=7b5f93e758d963355b31ce0a1f0eafa16074f35d;hpb=a1d28cf77fe06fe98cea4c4e80cc1cab94ea6736 diff --git a/utils/mkyaffs.c b/utils/mkyaffs.c index 3a0ed67..a3ec11d 100644 --- a/utils/mkyaffs.c +++ b/utils/mkyaffs.c @@ -34,6 +34,7 @@ #include #include +const char *mkyaffs_c_version = "$Id: mkyaffs.c,v 1.8 2003-03-12 19:54:07 charles Exp $"; // countBits is a quick way of counting the number of bits in a byte. // ie. countBits[n] holds the number of 1 bits in a byte with the value n. @@ -65,6 +66,19 @@ static const char countBits[256] = unsigned char oobbuf[16]; unsigned char imgpage[528]; +/* + * OOB layout + */ + +struct nand_oobinfo yaffs_oobinfo = { + useecc: 1, + eccpos: {8, 9, 10, 13, 14, 15} +}; + +struct nand_oobinfo yaffs_noeccinfo = { + useecc: 0, +}; + /* * Main program @@ -73,21 +87,46 @@ int main(int argc, char **argv) { unsigned long addr; unsigned long offset; - int bs, fd, i; + int fd; int img=-1; + int optcnt = 1; + int usemtdecc = 0; int imglen = 0; + int showHelp = 0; struct mtd_oob_buf oob = {0, 16, (unsigned char *) &oobbuf}; mtd_info_t meminfo; erase_info_t erase; + struct nand_oobinfo oobsel; + + if (argc > 1 && strcmp (argv[optcnt], "-?") == 0) { + showHelp = 1; + } + if (argc > 1 && strcmp (argv[optcnt], "-h") == 0) { + showHelp = 1; + } + + if (argc > 1 && strcmp (argv[optcnt], "-e") == 0) { + optcnt++; + usemtdecc = 1; + } + + printf("argc %d sh %d optcnt %d\n",argc, showHelp, optcnt); + /* Make sure a device was specified */ - if(argc < 2) { - printf("usage: %s [image name]\n", argv[0]); + if(showHelp || argc < (optcnt + 1)) { + printf("usage: %s [-e] [image name]\n", argv[0]); + printf(" -e Use mtd ecc. Default: do not use mtd ecc\n"); + printf(" mtdname Name of mtd device\n"); + printf(" image name Name of optional image file\n\n"); + printf("Function: Formats a NAND mtd device for YAFFS. If the optional\n" + "image file is specified, then the file system is loaded with\n" + "this image.\n\n"); exit(1); } - - if(argc > 2 && - (img = open(argv[2],O_RDONLY)) == -1) { + + if( argc > (optcnt + 1) && + (img = open(argv[optcnt + 1],O_RDONLY)) == -1) { perror("opening image file"); exit(1); } @@ -103,7 +142,7 @@ int main(int argc, char **argv) lseek(img,0,SEEK_SET); /* Open the device */ - if((fd = open(argv[1], O_RDWR)) == -1) { + if((fd = open(argv[optcnt], O_RDWR)) == -1) { perror("opening flash"); exit(1); } @@ -115,6 +154,14 @@ int main(int argc, char **argv) exit(1); } + // set the appropriate oob layout selector + oobsel = usemtdecc ? yaffs_oobinfo : yaffs_noeccinfo; + if (ioctl (fd, MEMSETOOBSEL, &oobsel) != 0) { + perror ("MEMSETOOBSEL"); + close (fd); + exit (1); + } + /* Make sure device page sizes are valid */ if( !(meminfo.oobsize == 16 && meminfo.oobblock == 512)) { @@ -170,12 +217,21 @@ int main(int argc, char **argv) for(offset = 0; offset