Chinaunix首页 | 论坛 | 博客
  • 博客访问: 295109
  • 博文数量: 59
  • 博客积分: 2021
  • 博客等级: 大尉
  • 技术积分: 491
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-29 09:49
文章分类

全部博文(59)

文章存档

2011年(6)

2010年(11)

2009年(42)

我的朋友

分类: LINUX

2010-12-27 11:49:04

转载: 

作者:孙晓明,华清远见嵌入式学院讲师。 

uboot源码默认是不支持yaffs文件系统的,所以我们需要自己修改源码进行支持。 

首先我们进入U-Boot源码目录添加对yaffs镜像烧写的支持. 

在common/cmd_nand.c里仿照jffs2来写一些yaffs的内容: 

在: 

U_BOOT_CMD(nand, 5, 1, do_nand, 
       "nand - NAND sub-system\n", 
       "info - show available NAND devices\n" 
       "nand device [dev] - show or set current device\n" 
       "nand read[.jffs2] - addr off|partition size\n" 
       "nand write[.jffs2] - addr off|partition size - read/write `size' bytes starting\n" 
       " at offset `off' to/from memory address `addr'\n" 

之后添加nand read.yaffs 的使用说明: 

"nand read.yaffs - addr off|partition size\n" 
    "nand write.yaffs - addr off|partition size - read/write `size' bytes starting\n" 

然后在nand命令的处理函数里do_nand中增加对write.yaffs的支持,do_nand在common/cmd_nand.c中实现: 

在: 

if (s != NULL && 
            (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) { 
    ……. 

的判断后面加: 

else if (s != NULL && 
            (!strcmp(s, ".yaffs") || !strcmp(s, ".e") || !strcmp(s, ".i"))) { 
            if (read) { 
            /* read */ 
            nand_read_options_t opts; 
            memset(&opts, 0, sizeof(opts)); 
            opts.buffer = (u_char*) addr; 
            opts.length = size; 
            opts.offset = off; 
            opts.readoob = 1; 
            opts.quiet = quiet;

   ret = nand_read_opts(nand, &opts); 
        } else { 
            /* write */ 
            nand_write_options_t opts; 
            memset(&opts, 0, sizeof(opts)); 
            opts.buffer = (u_char*) addr; 
            opts.length = size; 
            opts.offset = off; 
            /* opts.forcejffs2 = 1; */ 
            //opts.pad = 1; 
            opts.noecc = 1; 
            opts.writeoob = 1; 
            opts.blockalign = 1; 
            opts.quiet = quiet; 
            ret = nand_write_opts(nand, &opts); 
        } 
     } 

由于前面设置了opts.noecc = 1,不使用ecc校验码,烧写过程中会提示这个信息: 

Writing data without ECC to NAND-FLASH is not recommended 
    Writing data without ECC to NAND-FLASH is not recommended 
    Writing data without ECC to NAND-FLASH is not recommended 
    Writing data without ECC to NAND-FLASH is not recommended 
    Writing data without ECC to NAND-FLASH is not recommended 

可以修改driver/mtd/nand/nand_base.c文件的nand_write_page函数,将它去掉,修改如下: 

case NAND_ECC_NONE: 
        //printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not ecommended\n"); 
        this->write_buf(mtd, this->data_poi, mtd->oobblock); 
        break; 

修改完这些,U-BOOT就可以支持yaffs文件镜像的烧写了。 









(四)

u-boot- 1.1.6已经可以通过"nand write...""nand write.jffs2..."等命令来烧写cramfsjffs2文件系统映象文件,下面增加"nand write.yaffs..."命令实现yaffs文件系统映象的烧写。

1、在commom/cmd_nand.c中增加"nand write.yaffs..."的使用说明,代码添加如下:

U_BOOT_CMD(nand, 5, 1, do_nand,
    "nand    - NAND sub-system\n",
    "info                  - show available NAND devices\n"
    "nand device [dev]     - show or set current device\n"
    "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"
   "nand read.yaffs addr off size - read the `size' byte yaffs image starting\n"
    "    at offset `off' to memory address `addr'\n"
    "nand write.yaffs addr off size - write the `size' byte yaffs image starting\n"
    "    at offset `off' from memory address `addr'\n"

    "nand erase [clean] [off size] - erase `size' bytes from\n"
    "    offset `off' (entire device if not specified)\n"
    "nand bad - show bad blocks\n"
……………………

……………………

然后,在nand命令的处理函数do_nand中增加对"nand yaffs..."的支持。do_nand函数仍在commom/cmd_nand.c中实现,代码修改如下:

……………………

……………………

opts.quiet     = quiet;

               ret = nand_write_opts(nand, &opts);

           }

}

else if (  s != NULL && !strcmp(s, ".yaffs")){    
            if (read) {
               
                nand_read_options_t opts;
                memset(&opts, 0, sizeof(opts));
                opts.buffer = (u_char*) addr;
                opts.length = size;
                opts.offset = off;
                opts.readoob = 1;
                opts.quiet      = quiet;
                ret = nand_read_opts(nand, &opts);
            } else {
               
                nand_write_options_t opts;
                memset(&opts, 0, sizeof(opts));
                opts.buffer = (u_char*) addr;
                opts.length = size;
                opts.offset = off;
               
                opts.noecc = 1;
                opts.writeoob = 1;
                opts.blockalign = 1;
                opts.quiet      = quiet;
                opts.skipfirstblk = 1;
                ret = nand_write_opts(nand, &opts);
            }   

 } else {

            if (read)

                ret = nand_read(nand, off, &size, (u_char *)addr);

            else

               ret = nand_write(nand, off, &size, (u_char *)addr);

       }

…………………

…………………

2include/nand.h中进行如下修改,增加skipfirstblk成员:

struct nand_write_options {
u_char *buffer;

………………

………………

int pad;

int blockalign;

int skipfirstblk;

}

3drivers/nand/nand_util.c修改nand_write_opts函数,增加对skipfirstblk成员的支持:

int nand_write_opts(nand_info_t *meminfo, const nand_write_options_t *opts)

{

   int imglen = 0;

………………

………………

int result;

   int skipfirstblk = opts->skipfirstblk;

………………

………………

 

} while (offs < blockstart + erasesize_blockalign);

        }


        if (skipfirstblk) {     
            mtdoffset += erasesize_blockalign;
            skipfirstblk = 0;
            continue;
        }

 readlen = meminfo->oobblock;

………………

进行上面移植后,u-boot已经支持yaffs文件系统映象的烧写,由于前面设置"opts.noecc=1" 不使用ECC校验码,烧写时会提示很多提示信息,可以修改drivers/nand/nand_base.c文件中的nand_write_page函数,将其注释掉。

   case NAND_ECC_NONE:
        //printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");

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