在linux的PC上挂载jffs2根文件系统映像
因为jffs2是构建于MTD设备上的文件系统,所以无法通过loop设备来挂载,但是可以通过mtdram设备来挂载。mtdram是在用RAM实现的MTD设备,可以通过mtdblock设备来访问。使用mtdram设备很简单,只要加载mtdram和mtdblock两个内核模块即可。这两个内核模块一般的linux内核发行版都有编译好的,直接用modprobe命令加载。
下面是具体步骤:
(1).加载mtdblock内核模块
modprobe mtdblock
(2).加载mtdram内核模块,将该设备的大小指定为jffs2根文件系统映像的大小,块擦除大小(即flash的块大小)指定为制作该jffs2根文件系统时“-e”参数指定的大小,缺省为64KB。下面两个参数的单位都是KB。
modprobe mtdram total_size=5120 erase_size=256
(3).这时将出现MTD设备/dev/mtdblock0,使用dd命令将jffs2根文件系统拷贝到/dev/mtdblock0设备中。
dd if=jffs2.img of=/dev/mtdblock0
(4).将保存了jffs2根文件系统的MTD设备挂载到指定的目录上。
mount -t jffs2 /dev/mtdblock0 /mnt/mtd
root@gpl-vm:/gplt/PX-4854/fw/rootfs# hexdump -C rootfs|more
00000000 73 68 73 71 8f 03 00 00 00 00 00 74 8f 0d 05 00 |shsq.......t....|
00000010 00 00 00 00 00 00 00 00 78 5a fe d4 03 00 00 00 |........xZ......|
So, ‘shsq’ is one of those other variants, according to Armijn Hemel ever suggested, change ‘shsq’ to ‘hsqs’ (it is little endian). Then try again.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# unsquashfs rootfschanged
Parallel unsquashfs: Using 1 processor
gzip uncompress failed with error code -3
read_block: failed to read block @0x4997ff
read_fragment_table: failed to read fragment table block
FATAL ERROR aborting: failed to read fragment table
This is the second issue we encounter, I guess it was caused by incompatible unsquashfs. Let’s check the version of unsquashfs.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# unsquashfs -v
unsquashfs version 4.2 (2011/02/28)
Finally, try other version of unsquashfs, there are lots of unsquashfs provide by BAT.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# bat-unsquashfs
bat-unsquashfs42 bat-unsquashfs-atheros2 bat-unsquashfs-broadcom bat-unsquashfs-ddwrt bat-unsquashfs-ralink
bat-unsquashfs-atheros bat-unsquashfs-atheros40 bat-unsquashfs-broadcom40 bat-unsquashfs-openwrt bat-unsquashfs-realtek
after tried some of them, bat-unsquashfs-broadcom40 extracted the rootfs successfully.
CPIO
因为jffs2是构建于MTD设备上的文件系统,所以无法通过loop设备来挂载,但是可以通过mtdram设备来挂载。mtdram是在用RAM实现的MTD设备,可以通过mtdblock设备来访问。使用mtdram设备很简单,只要加载mtdram和mtdblock两个内核模块即可。这两个内核模块一般的linux内核发行版都有编译好的,直接用modprobe命令加载。
下面是具体步骤:
(1).加载mtdblock内核模块
modprobe mtdblock
(2).加载mtdram内核模块,将该设备的大小指定为jffs2根文件系统映像的大小,块擦除大小(即flash的块大小)指定为制作该jffs2根文件系统时“-e”参数指定的大小,缺省为64KB。下面两个参数的单位都是KB。
modprobe mtdram total_size=5120 erase_size=256
(3).这时将出现MTD设备/dev/mtdblock0,使用dd命令将jffs2根文件系统拷贝到/dev/mtdblock0设备中。
dd if=jffs2.img of=/dev/mtdblock0
(4).将保存了jffs2根文件系统的MTD设备挂载到指定的目录上。
mount -t jffs2 /dev/mtdblock0 /mnt/mtd
root@gpl-vm:/gplt/PX-4854/fw/rootfs# hexdump -C rootfs|more
00000000 73 68 73 71 8f 03 00 00 00 00 00 74 8f 0d 05 00 |shsq.......t....|
00000010 00 00 00 00 00 00 00 00 78 5a fe d4 03 00 00 00 |........xZ......|
So, ‘shsq’ is one of those other variants, according to Armijn Hemel ever suggested, change ‘shsq’ to ‘hsqs’ (it is little endian). Then try again.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# unsquashfs rootfschanged
Parallel unsquashfs: Using 1 processor
gzip uncompress failed with error code -3
read_block: failed to read block @0x4997ff
read_fragment_table: failed to read fragment table block
FATAL ERROR aborting: failed to read fragment table
This is the second issue we encounter, I guess it was caused by incompatible unsquashfs. Let’s check the version of unsquashfs.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# unsquashfs -v
unsquashfs version 4.2 (2011/02/28)
Finally, try other version of unsquashfs, there are lots of unsquashfs provide by BAT.
root@gpl-vm:/gplt/PX-4854/fw/rootfs# bat-unsquashfs
bat-unsquashfs42 bat-unsquashfs-atheros2 bat-unsquashfs-broadcom bat-unsquashfs-ddwrt bat-unsquashfs-ralink
bat-unsquashfs-atheros bat-unsquashfs-atheros40 bat-unsquashfs-broadcom40 bat-unsquashfs-openwrt bat-unsquashfs-realtek
after tried some of them, bat-unsquashfs-broadcom40 extracted the rootfs successfully.
CPIO
cpio -id --no-absolute-filenames < output~
http://forum.xda-developers.com/galaxy-s2/general/ref-unpacking-repacking-stock-rom-img-t1081239
[REF] Unpacking and repacking stock rom .img files