Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1249503
  • 博文数量: 479
  • 博客积分: 12240
  • 博客等级: 上将
  • 技术积分: 4999
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-24 17:12
文章分类

全部博文(479)

文章存档

2014年(1)

2013年(1)

2012年(1)

2011年(95)

2010年(177)

2009年(167)

2008年(16)

2007年(21)

分类: LINUX

2008-01-02 21:32:05



文件:u-boot-yaffs2.gz
大小:2KB
下载:下载



这是一篇从网上其它地方看来的文章,应该是鬼佬写的。

先把原文放在这里吧,等有需要的时候再来看。

原文:


It adds two sub-commands, "write.yaffs" and "write.yaffs1", to the nand
command set, which write YAFFS filesystem images generated by
mkyaffs2image and mkyaffsimage from RAM to NAND flash.

YAFFS images cannot be written using the normal nand write command
because they contain data which must be written to the NAND OOB area.

The "write.yaffs" command writes images generated by mkyaffs2image for
2048+64 NAND chips. I do not have access to this type of chip, so it
has not been tested (any takers?).

The "write.yaffs1" command writes images generated by mkyaffsimage for
512+16 NAND. It writes the older yaffs1 OOB format used by Linux
kernels before 2.6.18, or, by defining a CFG parameter, it writes the
newer OOB format used by Linux 2.6.18 and up.

This patch is much simpler than the previous version because the new
nand_util.c code contains most of the required functionality. It uses
two CFG parameters:

CFG_NAND_WRITE_YAFFS - enables the YAFFS writing code.

CFG_NAND_WRITE_YAFFS1_NEW_OOB_LAYOUT - writes the OOB data in the
format used by Linux 2.6.18 and up.

I find it VERY convenient to write YAFFS filesystems in U-Boot,
especially the Linux root filesystem. Without this patch, I need to
maintain a separate non-YAFFS root filesystem in NAND so that I can boot
Linux in order to update my YAFFS root filesystem. This wastes
valuable NAND space and is more time-consuming.

补丁:

鬼佬还提供了一个附件,现在也放在这里吧。


diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index b011b5e..2760874 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -351,6 +351,23 @@ #endif
                 opts.quiet = quiet;
                 ret = nand_write_opts(nand, &opts);
             }
+#ifdef CFG_NAND_YAFFS_WRITE
+        } else if (!read && s != NULL &&
+             (!strcmp(s, ".yaffs") || !strcmp(s, ".yaffs1"))) {
+            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;
+            if (s[6] == '1')
+                opts.forceyaffs = 1;
+            ret = nand_write_opts(nand, &opts);
+#endif
         } else {
             if (read)
                 ret = nand_read(nand, off, &size, (u_char *)addr);
@@ -462,6 +479,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_YAFFS_WRITE
+    "nand write[.yaffs[1]] - addr off|partition size - write `size' byte yaffs image\n"
+    " starting at offset `off' from memory address `addr' (.yaffs1 for 512+16 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 10bf036..bea5c1e 100644
--- a/drivers/nand/nand_util.c
+++ b/drivers/nand/nand_util.c
@@ -343,6 +343,10 @@ int nand_write_opts(nand_info_t *meminfo
         struct nand_oobinfo *oobsel =
             opts->forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;
 
+#ifdef CFG_NAND_YAFFS1_NEW_OOB_LAYOUT
+        /* jffs2_oobinfo matches 2.6.18+ MTD nand_oob_16 ecclayout */
+        oobsel = &jffs2_oobinfo;
+#endif
         if (meminfo->oobsize == 8) {
             if (opts->forceyaffs) {
                 printf("YAFSS cannot operate on "
@@ -443,6 +447,28 @@ int nand_write_opts(nand_info_t *meminfo
             memcpy(oob_buf, buffer, meminfo->oobsize);
             buffer += meminfo->oobsize;
 
+            if (opts->forceyaffs) {
+#ifdef CFG_NAND_YAFFS1_NEW_OOB_LAYOUT
+                /* translate OOB for yaffs1 on Linux 2.6.18+ */
+                oob_buf[15] = oob_buf[12];
+                oob_buf[14] = oob_buf[11];
+                oob_buf[13] = (oob_buf[7] & 0x3f)
+                    | (oob_buf[5] == 'Y' ? 0 : 0x80)
+                    | (oob_buf[4] == 0 ? 0 : 0x40);
+                oob_buf[12] = oob_buf[6];
+                oob_buf[11] = oob_buf[3];
+                oob_buf[10] = oob_buf[2];
+                oob_buf[9] = oob_buf[1];
+                oob_buf[8] = oob_buf[0];
+                memset(oob_buf, 0xff, 8);
+#else
+                /* 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*/

             result = meminfo->write_oob(meminfo,

阅读(6474) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~