【参考】+【原创】uboot 烧写 yaffs的补丁+补充

我用的uboot1.1.6,烧写yaffs的镜像和yaffs制作的工具紧密相关 .如果采用nand write.yaffs xxx xx xx,则需要修改mkyaffsimage,

如果不修改mkyaffsimage,这使用nand write.yaffs1 xxx xx xx

修改mkyaffsimage我会在下一篇文章介绍.

1、cmd_nand.c

/*添加yaffs支持? */
        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;
            opts.forceyaffs = 0;
            if (s[6] == '1') //判断yaffs最后的字符是否是 '1'
            {
                opts.forceyaffs = 1;    //1=实现translate_spare2oob功能,如果mkyaffsimage改后这个就不用了
                printf("force to layout yaffs's oob/n");
            }
            ret = nand_write_opts(nand, &opts);
        } /*yaffs支持结束*/

 

2、nand_util.c

if (opts->writeoob)

{
            /* read OOB data from input memory block, exit
             * on failure 这个oob是放在sdram的!!!*/
            memcpy(oob_buf, buffer, meminfo->oobsize);
            buffer += meminfo->oobsize;
/*添加yaffs支持 */

            if (opts->forceyaffs){
//#ifdef CFG_NAND_YAFFS1_NEW_OOB_LAYOUT
                /* translate OOB for yaffs1 on Linux 2.6.18+ 这一段可以跟内核的yaffs_mtdif.c对上*/
//这段代码就是在调整oob,实际上就是translate_spare2oob功能
                 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 ,我们只用上面的,现在本来就全部是0xff
                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,
                            mtdoffset,
                            meminfo->oobsize,
                            &written,
                            (unsigned char *)
                            &oob_buf);

 

3、注意uboot再写buf后会调用nand_verify_page校验,把那个oob校验去掉,不然会与uboot产生的oob比较,这会报错的.

你可能感兴趣的:(linux,cmd,layout,null,buffer,input)