上原kaera094磁力:使u-boot支持yaffs2烧写

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 02:18:52

使u-boot支持yaffs2烧写

分类: arm-linux2008-07-31 08:512740人阅读评论(0)收藏举报

        修改u-boot,使其能正确烧写oob区。 

 

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index a90fcab..69e82fd 100755
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -10,7 +10,7 @@
 
 #include
 
-
+#define CFG_NAND_YAFFS2_WRITE
 #ifndef CFG_NAND_LEGACY
 /*
  *
@@ -363,6 +363,23 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
                                opts.quiet      = quiet;
                                ret = nand_write_opts(nand, &opts);
                        }
+#ifdef CFG_NAND_YAFFS2_WRITE
+               } else if (!read && s != NULL &&
+                       (!strcmp(s, ".yaffs2"))) {
+                       nand_write_options_t opts;
+                       memset(&opts, 0, sizeof(opts));
+                       opts.buffer    = (u_char*) addr;
+                       opts.length    = size;
+                       opts.offset    = off;
+                       opts.pad    = 0;
+                       opts.blockalign = 1;
+                       opts.quiet = quiet;
+                       opts.writeoob    = 1;
+                       opts.autoplace    = 1;
+                       opts.forceyaffs = 2;
+                       ret = nand_write_opts(nand, &opts);
+#endif
+
                } else {
                        if (read)
                                ret = nand_read(nand, off, &size, (u_char *)addr);
@@ -480,6 +497,10 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
        "nand read[.jffs2]     - addr off|partition size/n"
        "nand write[.jffs2]    - addr off|partiton size - read/write `size' bytes starting/n"
        "    at offset `off' to/from memory address `addr'/n"
+#ifdef CFG_NAND_YAFFS2_WRITE
+       "nand write[.yaffs2] - addr off|partition size - write `size' byte yaffs image/n"
+       " starting at offset `off' from memory address `addr' (.yaffs2 for 2048+64 NAND)/n"
+#endif
        "nand erase [clean] [off size] - erase `size' bytes from/n"
        "    offset `off' (entire device if not specified)/n"
        "nand bad - show bad blocks/n"
diff --git a/drivers/nand/nand_util.c b/drivers/nand/nand_util.c
index 761c0aa..605d079 100644
--- a/drivers/nand/nand_util.c
+++ b/drivers/nand/nand_util.c
@@ -31,7 +31,7 @@
  */
 
 #include
-
+#define CFG_NAND_YAFFS2_WRITE
 #if (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CFG_NAND_LEGACY)
 
 #include
@@ -288,6 +288,18 @@ static struct nand_oobinfo yaffs_oobinfo = {
        .eccpos = { 8, 9, 10, 13, 14, 15}
 };
 
+#ifdef CFG_NAND_YAFFS2_WRITE
+static struct nand_oobinfo yaffs2_oobinfo = {
+       .useecc = MTD_NANDECC_PLACE,
+       .eccbytes = 24,
+       .eccpos = {
+               40, 41, 42, 43, 44, 45, 46, 47,
+               48, 49, 50, 51, 52, 53, 54, 55,
+               56, 57, 58, 59, 60, 61, 62, 63},
+       .oobfree = { {2, 38} }
+};
+#endif
+
 static struct nand_oobinfo autoplace_oobinfo = {
        .useecc = MTD_NANDECC_AUTOPLACE
 };
@@ -363,6 +375,11 @@ int nand_write_opts(nand_info_t *meminfo, const nand_write_options_t *opts)
                struct nand_oobinfo *oobsel =
                        opts->forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;
 
+#ifdef CFG_NAND_YAFFS2_WRITE
+               if(opts->forceyaffs == 2)
+                       oobsel = &yaffs2_oobinfo;
+#endif
+
                if (meminfo->oobsize == 8) {
                        if (opts->forceyaffs) {
                                printf("YAFSS cannot operate on "
@@ -462,6 +479,15 @@ int nand_write_opts(nand_info_t *meminfo, const nand_write_options_t *opts)
                         * on failure */
                        memcpy(oob_buf, buffer, meminfo->oobsize);
                        buffer += meminfo->oobsize;
+#ifdef CFG_NAND_YAFFS2_WRITE
+                       if (opts->forceyaffs == 2) {
+                               /* set the ECC bytes to 0xff so MTD will
+                                       calculate it */
+                               int i;
+                               for (i = 0; i < meminfo->oobinfo.eccbytes; i++)
+                                       oob_buf[meminfo->oobinfo.eccpos[i]] = 0xff;
+                       }
+#endif
 
                        /* write OOB data first, as ecc will be placed
                         * in there*/