Mounting JFFS2 Images on a Linux PC

From wiki.emacinc.com
Revision as of 07:10, 26 April 2013 by Tstratman (talk | contribs) (adding content)
Jump to: navigation, search

It is possible to mount a binary JFFS2 image on a Linux PC without a flash device. This can be useful for examining the contents of the image, making required changes, and creating a new image in any format. When a JFFS2 image is copied directly from a JFFS2 flash partition, the resulting image is the size of the source partition, regardless of how much space is actually used for storage. Mounting the filesystem and using the mkfs.jffs2 utility to create a new image will result in a JFFS2 image without blank nodes. This can also be used to create multiple images for flashes with different characteristics, such as erase block sizes. This page describes two different methods of mounting JFFS2 images on a Linux PC.

Mounting JFFS2 Images using RAM

One method of mounting JFFS2 images uses the mtdram module to emulate an MTD device using system RAM. This works well for smaller JFFS2 images less than approximately 32 MB but will not work for larger images since it requires allocating a large amount of system RAM. The basic steps of this process are as follows:

  1. Load mtdram and mtdblock modules.
  2. Use dd to copy the JFFS2 image to /dev/mtdblock0.
  3. Mount /dev/mtdblock0 as a JFFS2 filesytem.

In order to simplify this process, EMAC has created a script which takes the JFFS2 image, mount point, and the erase block size of the image as parameters. The default erase block size for this script is 128 KiB, which is the correct value for most NOR flashes used on EMAC products and some NAND flashes. The eraseblock size can be determined from the contents of /proc/mtd from the system that the image was copied from or created for. For example, if the value of the "erasesize" parameter is 00040000, the erase block size for the device is 256 KiB (0x40000 = 262144, 262144 / 1024 = 256). The jffs2_mount_mtdram.sh script is shown below.