对技术执着
分类: 嵌入式
2015-03-14 14:59:18
一、移植环境
二、移植步骤
|
|
|
②、在原来对Nand操作的命令集列表中添加Yaffs2对Nand的写命令,如下:
U_BOOT_CMD(nand, CONFIG_SYS_MAXARGS, 1, do_nand, //注意:这里只添加了yaffs2的写命令,因为我们只用u-boot下载(即写)功能,所以我们没有添加yaffs2读的命令
#gedit common/cmd_nand.c //在U_BOOT_CMD中添加
"NAND sub-system",
"info - show available NAND devices\n"
"nand device [dev] - show or set current device\n"
"nand read - addr off|partition size\n"
"nand write - addr off|partition size\n"
" read/write 'size' bytes starting at offset 'off'\n"
" to/from memory address 'addr', skipping bad blocks.\n"
#if defined(CONFIG_MTD_NAND_YAFFS2)
"nand write[.yaffs2] - addr off|partition size - write `size' byte yaffs image\n"
" starting at offset off' from memory address addr' (.yaffs2 for 512+16 NAND)\n"
#endif
"nand erase [clean] [off size] - erase 'size' bytes from\n"
" offset 'off' (entire device if not specified)\n"
"nand bad - show bad blocks\n"
"nand dump[.oob] off - dump page\n"
"nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
"nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
"nand biterr off - make a bit error at offset (UNSAFE)"
#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
"\n"
"nand lock [tight] [status]\n"
" bring nand to lock state or display locked pages\n"
"nand unlock [offset] [size] - unlock section"
#endif
);
接着,在该文件中对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; |
|
|
|
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; |
|
|
⑥、使用nand write[.yaffs2]命令把事前制作好的yaffs2文件系统下载到Nand Flash中(yaffs2文件系统的制作请参考:Linux-2.6.30.4在2440上的移植之文件系统),下载操作步骤和效果图如下:
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传送完后可以看到),要写正确,否则会形成假坏块
⑦、结合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文件系统也挂载成功,效果图如下: