u-boot-2016.03 支持yaffs2文件系统烧写之添加nand write.yaffs2命令
我们进入nand的命令文件cmd/nand.c,在do_nand函数里,有nand read或write的代码,而其中有对jffs2的支持,却并没有对yaffs2的支持。以前的老版本uboot是有对yaffs文件系统烧写的支持的,于是我们参考老版本的uboot代码,在do_nand函数里的nand write/read部分加上一段代码,如下:
1 #ifdef CONFIG_CMD_NAND_TRIMFFS
2 } else if (!strcmp(s, ".trimffs")) {
3 if (read) {
4 printf("Unknown nand command suffix ‘%s‘\n", s);
5 return 1;
6 }
7 ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
8 maxsize, (u_char *)addr,
9 WITH_DROP_FFS | WITH_WR_VERIFY);
10 #endif
11 #ifdef CONFIG_CMD_NAND_YAFFS
12 } else if (!strcmp(s, ".yaffs2")) {
13 if (read) {
14 printf("Unknown nand command suffix ‘%s‘.\n", s);
15 return 1;
16 }
17 ret = nand_write_skip_bad(nand, off, &rwsize,NULL,//这里参数和老版比要修改下
18 maxsize,(u_char *)addr,
19 WITH_YAFFS_OOB);
20 #endif
在nand_help_text[]里添加nand write.yaffs的帮助信息:
"nand read.raw - addr off|partition [count]\n"
"nand write.raw - addr off|partition [count]\n"
" Use read.raw/write.raw to avoid ECC and access the flash as-is.\n"
#ifdef CONFIG_CMD_NAND_YAFFS
"nand write.yaffs2 - addr off|partition size\n"
" write ‘size‘ bytes starting at offset ‘off‘ with yaffs format\n"
" from memory address ‘addr‘, skipping bad blocks.\n"
#endif
nand_write_skip_bad函数内部也要修改:
1 if (actual) 2 *actual = 0; 3 #ifdef CONFIG_CMD_NAND_YAFFS 4 if (flags & WITH_YAFFS_OOB) { 5 if (flags & ~WITH_YAFFS_OOB) 6 return -EINVAL; 7 8 int pages; 9 pages = nand->erasesize / nand->writesize; 10 blocksize = (pages * nand->oobsize) + nand->erasesize; 11 if (*length % (nand->writesize + nand->oobsize)) { 12 printf ("Attempt to write incomplete page" 13 " in yaffs mode\n"); 14 return -EINVAL; 15 } 16 } else 17 #endif 18 { 19 blocksize = nand->erasesize; 20 } 21 22 ... 23 24 if (left_to_write < (blocksize - block_offset)) 25 write_size = left_to_write; 26 else 27 write_size = blocksize - block_offset; 28 #ifdef CONFIG_CMD_NAND_YAFFS 29 if (flags & WITH_YAFFS_OOB) { 30 int page, pages; 31 size_t pagesize = nand->writesize; 32 size_t pagesize_oob = pagesize + nand->oobsize; 33 struct mtd_oob_ops ops; 34 35 ops.len = pagesize; 36 ops.ooblen = nand->oobsize; 37 ops.mode = MTD_OPS_RAW; //这里要改为RAW 38 ops.ooboffs = 0; 39 40 pages = write_size / pagesize_oob; 41 for (page = 0; page < pages; page++) { 42 WATCHDOG_RESET(); 43 44 ops.datbuf = p_buffer; 45 ops.oobbuf = ops.datbuf + pagesize; 46 47 rval = nand->_write_oob(nand, offset, &ops); 48 if (rval != 0) 49 break; 50 51 offset += pagesize; 52 p_buffer += pagesize_oob; 53 } 54 } 55 else 56 #endif 57 { //这里要加个左大括号 58 truncated_write_size = write_size; 59 #ifdef CONFIG_CMD_NAND_TRIMFFS 60 if (flags & WITH_DROP_FFS) 61 truncated_write_size = drop_ffs(nand, p_buffer, 62 &write_size); 63 #endif 64 65 rval = nand_write(nand, offset, &truncated_write_size, 66 p_buffer); 67 68 if ((flags & WITH_WR_VERIFY) && !rval) 69 rval = nand_verify(nand, offset, 70 truncated_write_size, p_buffer); 71 72 offset += write_size; 73 p_buffer += write_size; 74 } //这里要加个右大括号 75 if (rval != 0) {
同时,在include/nand.h中添加WITH_YAFFS_OOB宏的定义,
#define WITH_YAFFS_OOB (1 << 0)
#define WITH_DROP_FFS (1 << 0)
最后在配置文件里添加CONFIG_CMD_NAND_YAFFS宏定义,编译烧写,成功烧写yaffs2文件系统并挂载成功,此uboot已经支持yaffs2文件系统的烧写。