嵌入式Linux开发之在PC上挂载jffs2文件
May 28, 2009 (Thursday) 21:34 CST+0800
我发现一个问题:我老是忘事。这不,今天倒腾手机就忘了怎么挂jffs2镜像了。。。
算了,多谢Google Web History,我又找到了mount的方法。发过来,备忘,也为大家方便下。
先决条件:
alex-laptop# apt-get install mtd-tools
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不再被使用了:
libibus-gtk0
使用'apt-get autoremove'来删除它们
将会安装下列额外的软件包:
mtd-utils
下列【新】软件包将被安装:
mtd-tools mtd-utils
突然发现我笔记本上没有mtdblock这个module,懒得解决了,ssh到我的服务器上。
alex-laptop% ssh [email protected] -pXXXX #端口就免了
alex-home-server# modprobe mtdblock
alex-home-server# modprobe mtd
alex-home-server# modprobe jffs2
alex-home-server# modprobe block2mtd
alex-home-server# dmesg|tail
[836625.444865] JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
很好,可以干活了
alex-home-server# file *|grep jffs2
CG35_0x001A0000.smg: Linux jffs2 filesystem data little endian
CG41_0x019E0000.smg: Linux jffs2 filesystem data little endian
找准目标干活。
losetup /dev/loop0 `pwd`/CG35_0x001A0000.smg
alex-home-server# echo "/dev/loop0" >/sys/module/block2mtd/parameters/block2mtd alex-home-server# modprobe mtdblock
alex-home-server# file /dev/mtdblock0
/dev/mtdblock0: block special
alex-home-server#
到这里,各位看官都知道怎么办了。
alex-home-server# mount -t jffs2 /dev/mtdblock0 /mnt
另外,重要的一点在这里:请在挂载后先看看dmesg信息!如果dmesg|tail形如下文,那么请umount后重新设置挂载,不要轻易进行文件读写操作,这会导致文件的损坏,直接导致嵌入式设备引导失败!
alex-home-server# dmesg|tail
[859194.689349] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #68 to 93708 bytes failed because it only had 90112 bytes to start with!
[859194.692156] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #23 to 634016 bytes failed because it only had 630784 bytes to start with!
[859194.699443] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #1245 to 27428 bytes failed because it only had 24576 bytes to start with!
[859194.720251] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #791 to 18516 bytes failed because it only had 16384 bytes to start with!
[859194.722075] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #787 to 1808332 bytes failed because it only had 1806336 bytes to start with!
[859194.741411] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #765 to 724796 bytes failed because it only had 720896 bytes to start with!
[859194.747256] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #761 to 440728 bytes failed because it only had 438272 bytes to start with!
[859194.749780] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #755 to 122236 bytes failed because it only had 118784 bytes to start with!
[859194.753370] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #717 to 80860 bytes failed because it only had 77824 bytes to start with!
[859194.754985] JFFS2 warning: (22716) jffs2_do_read_inode_internal: Truncating ino #706 to 94028 bytes failed because it only had 90112 bytes to start with!
出现这种情况的解决办法在这里:
alex-home-server# umount /dev/mtdblock0
alex-home-server# modprobe -r block2mtd
alex-home-server# modprobe block2mtd block2mtd=/dev/loop0,131072 #131072 is the block_size of this image. this was set when creating the image.
alex-home-server# mount -t jffs2 /dev/mtdblock0 /mnt
modprobe block2mtd block2mtd=device_name,[block_size] 请注意,block_size是在创建镜像文件的时候设定的。131072=128*1024,这里是block_size=128KiB的情况,其他情况自己更正,不要在看到错误信息以后随便写文件!
到这里,这篇东西写完了,希望给搞嵌入式的兄弟们有点帮助,不过现在大部分都去做yaffs了吧。
另外说下,我在做的工作是刷我的手机,Motorola ROCK E6,折腾的不成样子了,键盘用双面胶勉强粘上了,后盖用502粘上的,屏幕也有点小问题(不大,划伤很多而已),进水了没坏,别的没什么了,这样还能天天为我服务真不容易。。。不知道什么别的手机能经我这样用法,还不到两年。。。
另外,告诉大家下,screen(1)真的很好用!


and Solaris 11.