分类: LINUX
2015-01-27 21:16:58
Yaffs页结构说明 |
#gedit include/configs/my2440.h //添加到文件末尾即可 |
#define CONFIG_MTD_NAND_YAFFS2 1 //定义一个管理对Yaffs2支持的宏
//开启Nand Flash默认分区,注意此处的分区要和你的内核中的分区保持一致 |
②、在原来对Nand操作的命令集列表中添加Yaffs2对Nand的写命令,如下:
#gedit common/cmd_nand.c //在U_BOOT_CMD中添加 |
U_BOOT_CMD(nand, CONFIG_SYS_MAXARGS, 1, do_nand,
//注意:这里只添加了yaffs2的写命令,因为我们只用u-boot下载(即写)功能,所以我们没有添加yaffs2读的命令
|
接着,在该文件中对nand操作的do_nand函数中添加yaffs2对nand的操作,如下:
if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0)
if (argc < 4) addr = (ulong)simple_strtoul(argv[2], NULL, 16);
read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
s = strchr(cmd, '.'); //添加yaffs2相关操作,注意该处又关联到nand_write_skip_bad函数
#if defined(CONFIG_MTD_NAND_YAFFS2)
else if (!strcmp(s, ".oob"))
if (read) printf(" %zu bytes %s: %s\n", size, read ? "read" : "written", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1; |
#gedit include/linux/mtd/mtd.h //在mtd_info结构体中添加 |
#if defined(CONFIG_MTD_NAND_YAFFS2) |
#gedit drivers/mtd/nand/nand_util.c //在nand_write_skip_bad函数中添加 |
int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, u_char *buffer)
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support
if (((*length)%(nand->oobsize+nand->writesize)) != 0)
datapages = *length/(datasize+oobsize);
/* Reject writes, which are not page aligned */ len_incl_bad = get_len_incl_bad (nand, offset, *length);
if ((offset + len_incl_bad) >= nand->size) {
#if !defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support
return rval;
while (left_to_write > 0) { WATCHDOG_RESET ();
if (nand_block_isbad (nand, offset & ~(nand->erasesize - 1))) {
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support
if (left_to_write < (nand->erasesize - block_offset)) printf("\rWriting at 0x%llx -- ",offset); //add yaffs2 file system support
left_to_write -= write_size;
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support }
return 0; |
#gedit drivers/mtd/nand/nand_base.c //在nand_write函数中添加 |
static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const uint8_t *buf)
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support int oldopsmode = 0;
if(mtd->rw_oob==1)
size_t oobsize = mtd->oobsize;
uint8_t oobtemp[oobsize];
for(i = 0; i < (datapages); i++)
/* Do not allow reads past end of device */ nand_get_device(chip, mtd, FL_WRITING);
chip->ops.len = len;
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support
if(mtd->rw_oob!=1)
ret = nand_do_write_ops(mtd, to, &chip->ops); *retlen = chip->ops.retlen; nand_release_device(mtd);
#if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support
chip->ops.mode = oldopsmode;
return ret; |
⑥、使用nand write[.yaffs2]命令把事前制作好的yaffs2文件系统下载到Nand Flash中(yaffs2文件系统的制作请参考:Linux-2.6.30.4在2440上的移植之文件系统),下载操作步骤和效果图如下:
tftp 0x30000000 root-2.6.30.4.bin //用tftp将yaffs2文件系统下载到内存的0x30000000位置 |