一、移植环境
-
主 机:VMWare–Fedora 9
-
开发板:Mini2440–64MB Nand,Kernel:2.6.30.4
-
编译器:arm-linux-gcc-4.3.2.tgz
-
u-boot:u-boot-2009.08.tar.bz2
二、移植过程
Yaffs页结构阐明 |
#gedit include/configs/my2440.h //增加到文件结尾即可 |
#define CONFIG_MTD_NAND_YAFFS2 1//界说一个办理对Yaffs2支撑的宏 //敞开Nand Flash默许分区,留意此处的分区要和你的内核中的分区保持共同 |
②、在本来对Nand操作的指令集列表中增加Yaffs2对Nand的写指令,如下:
接着,在该文件中对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; |
③、在include/linux/mtd/mtd.h头文件的mtd_info结构体中增加上面用到rw_oob和skipfirstblk数据成员,如下:
#gedit include/linux/mtd/mtd.h //在mtd_info结构体中增加 |
#if defined(CONFIG_MTD_NAND_YAFFS2) |
④、在第二步相关的nand_write_skip_bad函数中增加对Nand OOB的相关操作,如下:
#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 rval = nand_write (nand, offset, &write_size, p_buffer); left_to_write -= write_size; #if defined(CONFIG_MTD_NAND_YAFFS2) //add yaffs2 file system support } return 0; |
⑤、在第四步nand_write_skip_bad函数中咱们看到又对nand_write函数进行了拜访,所以这一步是到nand_write函数中增加对yaffs2的支撑,如下:
#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; |
OK,对yaffs2支撑的代码已修正结束,从头编译u-boot并下载到nand中,发动开发板,在u-boot的指令行输入:nand help检查nand的指令,能够看到多了一个nand write[.yaffs2]的指令,这个便是用来下载yaffs2文件体系到nand中的指令了。
⑥、运用nand write[.yaffs2]指令把事前制造好的yaffs2文件体系下载到Nand Flash中(yaffs2文件体系的制造请参阅:Linux-2.6.30.4在2440上的移植之文件体系),下载操作过程和效果图如下:
⑦、结合u-boot和内核来测验发动下载的yaffs2文件体系
设置u-boot发动参数bootargs,留意:这一长串参数要与内核装备里边的Boot options–>Default kernel command string的设置要共同。特别是mtdblock3要根据内核详细的分区来设,在上一篇中讲到了内核中Nand的分区状况,u-boot归于mtdblock0,param归于mtdblock1,kernel归于mtdblock2,root就归于mtdblock3,所以这儿要设置成root=/dev/mtdblock3,不然文件体系无法发动成功,会呈现一些什么I/O之类的过错
好了,最终重启开发板,内核引导成功,yaffs2文件体系也挂载成功,效果图如下:
tftp 0x30000000 root-2.6.30.4.bin //用tftp将yaffs2文件体系下载到内存的0x30000000方位 nand erase 0x250000 0x3dac000 //擦除Nand的文件体系分区 nand write.yaffs2 0x30000000 0x250000 0x658170 //将内存中的yaffs2文件体系写入Nand的文件体系分区,留意这儿的0x658170是yaffs2文件体系的实践巨细(能够在tftp传送完后能够看到),要写正确,不然会构成假坏块 |
#gedit common/cmd_nand.c //在U_BOOT_CMD中增加 |
U_BOOT_CMD(nand, CONFIG_SYS_MAXARGS, 1, do_nand, //留意:这儿只增加了yaffs2的写指令,由于咱们只用u-boot下载(即写)功用,所以咱们没有增加yaffs2读的指令 “nand erase [clean] [off size] – erase size bytes from\n” |