四、【s3c2440移植linux-3.5】制作yaffs2镜像和使内核支持yaffs2根文件启动

2019-07-12 22:51发布

(一)制作yaffs2文件系统

1、制作mkyaffs2image

下载mkyaffs2image文件:
链接: https://pan.baidu.com/s/18Sbc2yZd-67Wzrc0Ba0QVQ 密码: 2fzs book@ubuntu:~$ sudo cp mkyaffs2image /usr/local/bin/ book@ubuntu:~$ sudo chmod +x /usr/local/bin/mkyaffs2image

2、制作、烧写yaffs镜像

book@ubuntu:~$ cd /work/s3c2440/nfs/fs book@ubuntu:/work/s3c2440/nfs/fs$ mkyaffs2image fs_mini_mdev fs_mini_mdev.yaffs2 SMDK2440 # nfs 30000000 $serverip:/work/s3c2440/nfs/fs/fs_mini_mdev.yaffs2 SMDK2440 # nand erase.part rootfs SMDK2440 # nand write.yaffs2 30000000 260000 $filesize SMDK2440 # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 SMDK2440 # set bootcmd "nfs 30000000 $serverip:/work/s3c2440/nfs/kernel/uImage_3.5;bootm 30000000" SMDK2440 # save SMDK2440 # reset

3、尝试启动内核

这里写图片描述
挂载yaffs2文件系统失败

(二)内核增加yaffs2根文件

1、下载yaffs2源码并打补丁

book@ubuntu:~$ git clone git://www.aleph1.co.uk/yaffs2 book@ubuntu:~$ cd yaffs2 book@ubuntu:~/yaffs2$ ./patch-ker.sh c m /home/book/linux-3.5 Updating /home/book/linux-3.5/fs/Kconfig Updating /home/book/linux-3.5/fs/Makefile

2、配置内核支持YAFFS2

book@ubuntu:~/yaffs2$ cd ~/linux-3.5 book@ubuntu:~/linux-3.5$ make menuconfig CONFIG_YAFFS_FS: Location: -> File systems -> Miscellaneous filesystems (MISC_FILESYSTEMS [=y]) 这里写图片描述 book@ubuntu:~/linux-3.5$ make uImage 这里写图片描述

(三)内核支持yaffs2根文件

1、修改fs/yaffs2/yaffs_vfs.c

diff -urN linux-3.5/fs/yaffs2/yaffs_vfs.c linux-3.5_s3c2440/fs/yaffs2/yaffs_vfs.c --- linux-3.5/fs/yaffs2/yaffs_vfs.c 2018-06-19 00:06:55.449511510 +0800 +++ linux-3.5_s3c2440/fs/yaffs2/yaffs_vfs.c 2018-06-19 00:20:48.025511510 +0800 @@ -872,7 +872,7 @@ if (!inode->i_nlink && !is_bad_inode(inode)) deleteme = 1; truncate_inode_pages(&inode->i_data, 0); - end_writeback(inode); + clear_inode(inode); if (deleteme && obj) { dev = obj->my_dev; @@ -2511,8 +2511,8 @@ { struct mtd_info *mtd = yaffs_dev_to_mtd(yaffs_super_to_dev(sb)); - if (mtd->sync) - mtd->sync(mtd); + if (mtd->_sync) + mtd->_sync(mtd); put_mtd_device(mtd); } @@ -2699,13 +2699,13 @@ return NULL; } - yaffs_trace(YAFFS_TRACE_OS, " erase %p", mtd->erase); - yaffs_trace(YAFFS_TRACE_OS, " read %p", mtd->read); - yaffs_trace(YAFFS_TRACE_OS, " write %p", mtd->write); - yaffs_trace(YAFFS_TRACE_OS, " readoob %p", mtd->read_oob); - yaffs_trace(YAFFS_TRACE_OS, " writeoob %p", mtd->write_oob); - yaffs_trace(YAFFS_TRACE_OS, " block_isbad %p", mtd->block_isbad); - yaffs_trace(YAFFS_TRACE_OS, " block_markbad %p", mtd->block_markbad); + yaffs_trace(YAFFS_TRACE_OS, " erase %p", mtd->_erase); + yaffs_trace(YAFFS_TRACE_OS, " read %p", mtd->_read); + yaffs_trace(YAFFS_TRACE_OS, " write %p", mtd->_write); + yaffs_trace(YAFFS_TRACE_OS, " readoob %p", mtd->_read_oob); + yaffs_trace(YAFFS_TRACE_OS, " writeoob %p", mtd->_write_oob); + yaffs_trace(YAFFS_TRACE_OS, " block_isbad %p", mtd->_block_isbad); + yaffs_trace(YAFFS_TRACE_OS, " block_markbad %p", mtd->_block_markbad); yaffs_trace(YAFFS_TRACE_OS, " %s %d", WRITE_SIZE_STR, WRITE_SIZE(mtd)); yaffs_trace(YAFFS_TRACE_OS, " oobsize %d", mtd->oobsize); yaffs_trace(YAFFS_TRACE_OS, " erasesize %d", mtd->erasesize); @@ -2729,11 +2729,11 @@ if (yaffs_version == 2) { /* Check for version 2 style functions */ - if (!mtd->erase || - !mtd->block_isbad || - !mtd->block_markbad || !mtd->read || !mtd->write || + if (!mtd->_erase || + !mtd->_block_isbad || + !mtd->_block_markbad || !mtd->_read || !mtd->_write || #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) - !mtd->read_oob || !mtd->write_oob) { + !mtd->_read_oob || !mtd->_write_oob) { #else !mtd->write_ecc || !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) { @@ -2754,9 +2754,9 @@ } } else { /* Check for V1 style functions */ - if (!mtd->erase || !mtd->read || !mtd->write || + if (!mtd->_erase || !mtd->_read || !mtd->_write || #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) - !mtd->read_oob || !mtd->write_oob) { + !mtd->_read_oob || !mtd->_write_oob) { #else !mtd->write_ecc || !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) { @@ -2964,7 +2964,7 @@ yaffs_trace(YAFFS_TRACE_OS, "yaffs_read_super: got root inode"); - root = d_alloc_root(inode); + root = d_make_root(inode); yaffs_trace(YAFFS_TRACE_OS, "yaffs_read_super: d_alloc_root done");

2、fs/yaffs2/yaffs_mtdif.c

diff -urN linux-3.5/fs/yaffs2/yaffs_mtdif.c linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif.c --- linux-3.5/fs/yaffs2/yaffs_mtdif.c 2018-06-19 00:06:55.445511510 +0800 +++ linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif.c 2018-06-19 00:21:44.669511510 +0800 @@ -39,7 +39,7 @@ ei.callback = NULL; ei.priv = (u_long) dev; - retval = mtd->erase(mtd, &ei); + retval = mtd->_erase(mtd, &ei); if (retval == 0) return YAFFS_OK;

3、fs/yaffs2/yaffs_mtdif1.c

diff -urN linux-3.5/fs/yaffs2/yaffs_mtdif1.c linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif1.c --- linux-3.5/fs/yaffs2/yaffs_mtdif1.c 2018-06-19 00:06:55.445511510 +0800 +++ linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif1.c 2018-06-19 00:23:42.237511510 +0800 @@ -135,7 +135,7 @@ ops.datbuf = (u8 *) data; ops.oobbuf = (u8 *) &pt1; - retval = mtd->write_oob(mtd, addr, &ops); + retval = mtd->_write_oob(mtd, addr, &ops); if (retval) { yaffs_trace(YAFFS_TRACE_MTD, "write_oob failed, chunk %d, mtd error %d", @@ -197,7 +197,7 @@ /* Read page and oob using MTD. * Check status and determine ECC result. */ - retval = mtd->read_oob(mtd, addr, &ops); + retval = mtd->_read_oob(mtd, addr, &ops); if (retval) yaffs_trace(YAFFS_TRACE_MTD, "read_oob failed, chunk %d, mtd error %d", @@ -220,7 +220,7 @@ /* fall into... */ default: rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); - etags->block_bad = (mtd->block_isbad) (mtd, addr); + etags->block_bad = (mtd->_block_isbad) (mtd, addr); return YAFFS_FAIL; } @@ -288,7 +288,7 @@ yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", block_no); - retval = mtd->block_markbad(mtd, (loff_t) blocksize * block_no); + retval = mtd->_block_markbad(mtd, (loff_t) blocksize * block_no); return (retval) ? YAFFS_FAIL : YAFFS_OK; } @@ -338,7 +338,7 @@ return YAFFS_FAIL; retval = nandmtd1_read_chunk_tags(dev, chunk_num, NULL, &etags); - etags.block_bad = (mtd->block_isbad) (mtd, addr); + etags.block_bad = (mtd->_block_isbad) (mtd, addr); if (etags.block_bad) { yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "block %d is marked bad",

4、fs/yaffs2/yaffs_mtdif2.c

diff -urN linux-3.5/fs/yaffs2/yaffs_mtdif2.c linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif2.c --- linux-3.5/fs/yaffs2/yaffs_mtdif2.c 2018-06-19 00:06:55.445511510 +0800 +++ linux-3.5_s3c2440/fs/yaffs2/yaffs_mtdif2.c 2018-06-19 00:24:49.849511510 +0800 @@ -87,7 +87,7 @@ ops.ooboffs = 0; ops.datbuf = (u8 *) data; ops.oobbuf = (dev->param.inband_tags) ? NULL : packed_tags_ptr; - retval = mtd->write_oob(mtd, addr, &ops); + retval = mtd->_write_oob(mtd, addr, &ops); #else if (!dev->param.inband_tags) { @@ -142,7 +142,7 @@ #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) if (dev->param.inband_tags || (data && !tags)) - retval = mtd->read(mtd, addr, dev->param.total_bytes_per_chunk, + retval = mtd->_read(mtd, addr, dev->param.total_bytes_per_chunk, &dummy, data); else if (tags) { ops.mode = MTD_OPS_AUTO_OOB; @@ -151,7 +151,7 @@ ops.ooboffs = 0; ops.datbuf = data; ops.oobbuf = yaffs_dev_to_lc(dev)->spare_buffer; - retval = mtd->read_oob(mtd, addr, &ops); + retval = mtd->_read_oob(mtd, addr, &ops); } #else if (!dev->param.inband_tags && data && tags) { @@ -215,7 +215,7 @@ block_no); retval = - mtd->block_markbad(mtd, + mtd->_block_markbad(mtd, block_no * dev->param.chunks_per_block * dev->param.total_bytes_per_chunk); @@ -234,7 +234,7 @@ yaffs_trace(YAFFS_TRACE_MTD, "nandmtd2_query_block %d", block_no); retval = - mtd->block_isbad(mtd, + mtd->_block_isbad(mtd, block_no * dev->param.chunks_per_block * dev->param.total_bytes_per_chunk);

5、使用新内核启动

book@ubuntu:~/linux-3.5$ make uImage 这里写图片描述
至此挂载yaffs2文件系统成功