yaffs2在am335x上实施
一.yaffs2文件烧写(通过网口)
uboot下输入如下命令:
setenv ipaddr 192.168.2.110;setenv serverip 192.168.2.222;saveenv
nandecc hw 2
nand erase 0 0x80000
tftp 81000000 MLO
nand write 81000000 0 8f5b; nand write 81000000 20000 8f5b; nand write 81000000 40000 8f5b; nand write 81000000 60000 8f5b
nand erase 0x80000 0x200000
tftp 81000000 u-boot.img
nand write 81000000 80000 3e1cc
nand erase 700000 0x80000
tftp 81000000 logo.bmp
nand write 81000000 700000 12f96
run erase_kernel
tftp 81000000 uImage
nand write 81000000 280000 2ca930
run erase_rootfs
tftp 81000000 rootfs_yaffs2;
nand write.yaffs 81000000 780000 406bc0
nandecc hw 0
nand erase 700000 0x80000
tftp 81000000 logo.bmp
nand write 81000000 700000 12f96
setenv bootargs noinitrd root=/dev/mtdblock7 init=/linuxrc console=ttyO0,115200n8 rootfstype=yaffs2 mem=253M;setenv bootcmd nandecc hw 2\; nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz}\;nandecc hw 0\; nand read.i ${logoaddr} ${splashimage} 0x80000\; bootm ${kloadaddr};saveenv
简单方法:借助SD卡,将镜像拷贝到SD中,最后uboot执行如下命令:
setenv ipaddr 192.168.2.110;setenv serverip 192.168.2.222;saveenv;
run erase_rootfs;tftp 81000000 rootfs_yaffs2;nand write.yaffs 81000000 780000 406bc0
setenv bootargs noinitrd root=/dev/mtdblock7 init=/linuxrc console=ttyO0,115200n8 rootfstype=yaffs2 mem=253M;setenv bootcmd nandecc hw 2\; nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz}\;nandecc hw 0\; nand read.i ${logoaddr} ${splashimage} 0x80000\; bootm ${kloadaddr};saveenv
注:通过原来u-boot可知,在烧写MLO时,nandecc hw 2,此后MLO,u-boot.img,uImage,ubi.img都是该ECC校验;在烧写logo.bmp时又修改ECC,nandecc hw 0。uboot的ENV也是nandecc hw 0。
注:nand dump 0x780000显示nand内容包含oob,从而可了解yaffs烧写时oob内容;刚开始按照yaffs2中mkyaffs2img工具制作的yaffs2在烧写后,再次u-boot启动时提示均为坏块,是因为oob的ECC布局不对(默认oob的前两个字节保留为坏块标识,不应被占用,好块标识为0xFF 0xFF)。可通过scrube命令擦除坏块后重新烧写。
二.烧写应用程序
烧写应用程序与原来完全相同。
三.yaffs文件系统修改及制作
文件系统内容修改
1)配置文件/etc/setup.sh和/etc/mount.sh已修改,修改了与803相关的挂测内容。
/etc/setup.sh
146 elif [ $product = 803s -o $product = 803e ];then
147 # mount -t ubifs ubi0:app /usr/app_install/
148 # sync
149 flash_eraseall /dev/mtd8
150 flash_eraseall /dev/mtd9
151
152 mount -t yaffs2 /dev/mtdblock8 /usr/app_install/
153 fi
/etc/mount.sh
6 echo "mount app partition..."
7 if [ "${HW_PLATFORM}" = "803s" -o "${HW_PLATFORM}" = "803e" ];then
8 # mount -t ubifs ubi0:app ${APP_INSTALL_DIR}/
9 mount -t yaffs2 /dev/mtdblock8 ${APP_INSTALL_DIR}/
26 #mount database partiton
27 echo "mount database partition..."
28 if [ "${HW_PLATFORM}" = "803s" -o "${HW_PLATFORM}" = "803e" ];then
29 # mount -t ubifs ubi0:db ${APP_INSTALL_DIR}/db/database
30 # sync
31 mount -t yaffs2 /dev/mtdblock9 ${APP_INSTALL_DIR}/db/database
2)增加分区设备文件mtd7-9,mtdblock7-9
crw-r--r-- 1 root root 90, 14 Sep 22 20:02 mtd7
crw-r--r-- 1 root root 90, 16 Sep 22 20:02 mtd8
crw-r--r-- 1 root root 90, 18 Sep 22 20:03 mtd9
brw-r--r-- 1 root root 31, 7 Sep 7 17:01 mtdblock7
brw-r--r-- 1 root root 31, 8 Sep 7 17:01 mtdblock8
brw-r--r-- 1 root root 31, 9 Sep 7 17:02 mtdblock9
3) 文件系统制作
仅需要使用一条命令:
./mkyaffs2image-128M rootfs_yaffs2 rootfs_yaffs2_20160923
四.uboot修改(详情可参考git)
修改内容在yaffs文件烧写的实现部分,修改处在nand_write_skip_bad()如下:
drivers/mtd/nand/nand_util.c
531 #ifndef CONFIG_CMD_NAND_YAFFS //wqh add
532 if (!need_skip && !(flags & WITH_DROP_FFS)) {
533 rval = nand_write (nand, offset, length, buffer);
534 if (rval == 0)
535 return 0;
536
537 *length = 0;
538 printf ("NAND write to offset %llx failed %d\n",
539 offset, rval);
540 return rval;
541 }
542 #endif
563 #ifdef CONFIG_CMD_NAND_YAFFS
564 if (flags & WITH_YAFFS_OOB) {
565 int page, pages;
566 size_t pagesize = nand->writesize;
567 size_t pagesize_oob = pagesize + nand->oobsize;
568 struct mtd_oob_ops ops;
569
570 ops.len = pagesize;
571 ops.ooblen = nand->oobsize;
572 // ops.mode = MTD_OOB_AUTO; //wqh add
573 ops.mode = MTD_OOB_RAW;
574 ops.ooboffs = 0;
575
576 pages = write_size / pagesize_oob;
577 for (page = 0; page < pages; page++) {
578 WATCHDOG_RESET();
579
580 ops.datbuf = p_buffer;
581 ops.oobbuf = ops.datbuf + pagesize;
582
583 printf("----write at offset 0x%08llx.\n", offset);
584 rval = nand->write_oob(nand, offset, &ops);
585 // if (rval) //wqh mod
586 // break; //wqh mod
587
588 offset += pagesize;
589 p_buffer += pagesize_oob;
590 }
591
592 printf("write %d bytes end offset 0x%08llx\n", write_s ize, offset);
593 }
五.内核修改(详情可参考git)
内核中主要修改Nand的ECC校验,现在修改为“无校验”,为更好扩展,主要修改内容如下:
>>arch/arm/mach-omap2/board-am335xevm.c中修改evm_nand_init()中ECC选项
2016 //pdata->ecc_opt =OMAP_ECC_BCH8_CODE_HW;
2017 pdata->ecc_opt =OMAP_ECC_NONE; //wqh fix for yaffs2
2018 pdata->elm_used = true;
2019 gpmc_device[0].pdata = pdata;
2020 gpmc_device[0].flag = GPMC_DEVICE_NAND;
>>arch/arm/plat-omap/include/plat/gpmc.h中增加OMAP_ECC_NONE选项
89 enum omap_ecc {
90 /* 1-bit ecc: stored at end of spare area */
91 OMAP_ECC_HAMMING_CODE_DEFAULT = 0, /* Default, s/w method */
92 OMAP_ECC_HAMMING_CODE_HW, /* gpmc to detect the error */
93 /* 1-bit ecc: stored at beginning of spare area as romcode */
94 OMAP_ECC_HAMMING_CODE_HW_ROMCODE, /* gpmc method & romcode lay out */
95 OMAP_ECC_BCH4_CODE_HW, /* gpmc bch detection & s/w method corr ection */
96 OMAP_ECC_BCH8_CODE_HW, /* gpmc bch detection & s/w method corr ection */
97 OMAP_ECC_NONE, /*wqh add for NAND_ECC_NONE */
98 };
>>drivers/mtd/nand/omap2.c中修改选项的驱动omap_nand_probe()
1201 /* selsect the ecc type */
1202 if(pdata->ecc_opt == OMAP_ECC_NONE) /* wqh add for NADN_ECC _NONE */
1203 info->nand.ecc.mode = NAND_ECC_NONE;
1204 else if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_DEFAULT)
1205 info->nand.ecc.mode = NAND_ECC_SOFT;
1236 /* select ecc lyout */
1237 /* wqh add for NADN_ECC_NONE */
1238 if (info->nand.ecc.mode == NAND_ECC_NONE)
1239 {
1240 // nothing for NAND_ECC_NONE
1241 }
1242 else if (info->nand.ecc.mode != NAND_ECC_SOFT) {
六.文件系统启动参数修改
yaffs文件系统作为linux根文件系统时需要配置bootargs和bootcmd参数。
setenv bootargs noinitrd root=/dev/mtdblock7 init=/linuxrc console=ttyO0,115200n8 rootfstype=yaffs2 mem=253M;setenv bootcmd nandecc hw 2\; nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz}\;nandecc hw 0\; nand read.i ${logoaddr} ${splashimage} 0x80000\; bootm ${kloadaddr};
注:实际测试中发现如下事项
》》bootargs必须包含mem选项,mem=253M;若不包含,终端信息显示到内核解压处,之后无其他信息。
》》bootargs应制定文件系统类型,否则VFS挂载不了文件系统yaffs2。
》》无论烧写不烧写文件系统,都提示“Failed to execute /linuxrc”(找不到根文件也提示这个)。
七.linux支持最新的yaffs(详情参考git)
将最新yaffs文件从官网下载后,整合到内核中。从官网下载的内核支持yaffs所有操作,但编译完成的制作工具mkyaffs2image仍不能很好制作根文件系统,该工具需要修改。
从友善之臂下载的mkyaffs2image-128M可很好完成yaffs2文件制作。
版本备注:
u-boot-2011.09-psp04.06.00.07
linux-3.2-psp04.06.00.07.sdk
yaffs2_20160708