本文主要是介绍TX2440 ARM开发板Uboot移植(五、yaffs2文件系统的支持),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Yaffs/yaffs2文件系统的设计充分考虑到Nand Flash以页为存取单位等的特点,将文件组织成固定大小的段(Chunk)。以528B的页为例,Yaffs/yaffs2文件系统使用前512B存储数据和16B的额外空间存放数据的ECC和文件系统的组织信息等(称为OOB数据)。通过OOB数据,不但能实现错误检测和坏块处理,同时还可以避免加载时对整个存储介质的扫描,加快了文件系统的加载速度。
1、 在原来对Nand操作的命令集列表中添加Yaffs2对Nand的写命令,修改 common/cmd_nand.c 文件,在U_BOOT_CMD约461行处加入读写Yaffs2格式的命令:
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[.yaffs2] - addr off size - read the `size' byte yaffs image starting\n" " at offset `off' to memory address `addr'\n" "nand write[.yaffs2] - 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" ... ... |
2、在该文件中,在对nand操作的do_nand函数中添加yaffs2对nand的操作:
int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) ... ... s = strchr(cmd, '.'); if (s != NULL && (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) { 。。。。。。 } else if ( s != NULL && !strcmp(s, ".yaffs2")){ 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.forceyaffs = 1; */ opts.noecc = 1; opts.writeoob = 1; opts.blockalign = 1; opts.quiet = quiet; opts.skipfirstblk = 1; ret = nand_write_opts(nand, &opts); } }else if (s != NULL && !strcmp(s, ".oob")) { /* read out-of-band data */ |
3、修改 include/nand.h 文件,在nand_write_options增加skipfirstblk成员:
struct nand_write_options { u_char *buffer; /* memory block containing image to write */ ulong length; /* number of bytes to write */ ulong offset; /* start address in NAND */ int quiet; /* don't display progress messages */ int autoplace; /* if true use auto oob layout */ int forcejffs2; /* force jffs2 oob layout */ int forceyaffs; /* force yaffs oob layout */ int noecc; /* write without ecc */ int writeoob; /* image contains oob data */ int pad; /* pad to page size */ int blockalign; /* 1|2|4 set multiple of eraseblocks to align to */ int skipfirstblk; }; |
4、修改drivers/mtd/nand/nand_util.c文件的nand_write_opts函数,增加对skipfirstblk成员的支持:
size_t written; /* skip the first good block when wirte yaffs image*/ |
5、修改drivers/mtd/nand/nand_base.c文件的nand_write_page函数,注释掉因前面设置opts.noecc=1导致烧写Nand Flash过程中出现的提示信息:
case NAND_ECC_NONE: //printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); this->write_buf(mtd, this->data_poi, mtd->oobblock); break; |
这篇关于TX2440 ARM开发板Uboot移植(五、yaffs2文件系统的支持)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!