咱們進入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的幫助信息:spa
"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函數內部也要修改:code
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宏的定義,orm
#define WITH_YAFFS_OOB (1 << 0)
#define WITH_DROP_FFS (1 << 0)
最後在配置文件裏添加CONFIG_CMD_NAND_YAFFS宏定義,編譯燒寫,成功燒寫yaffs2文件系統並掛載成功,此uboot已經支持yaffs2文件系統的燒寫。blog