Creating a JFFS2 Filesystem Image
A journaling flash filesystem (JFFS2) can be used to store your target’s root filesystem on flash memory. You must create the JFFS2 image by using the mkfs.jffs2 utility and a directory tree containing the filesystem that you want to load into flash.
The Journaling Flash Filesystem, Version 2, (JFFS2) is a filesystem specially designed for use on embedded devices, though it can also be used in other environments. JFFS2 features automatic compression and decompression as files are written to and read from the filesystem. Journaling means that updates to files and the filesystem itself (known as filesystem metadata) are first stored in a special portion of the filesystem, called a journal or log, before actually being written to the file system. Journaling filesystems generally provide higher performance and require less time at restart than non-journaled filesystems because they minimize the need for the operating system to verify the integrity of its filesystems while the system is rebooting.
In ordinary, non-journaled filesystems, changes are made directly to files and the file system. Applications must typically wait until updates are successfully completed before they can continue execution. This can reduce overall system performance and can also result in incomplete updates if a system crashes while an application is in the middle of updating files.
In journaling filesystems, pending changes to files and filesystem metadata are stored in the journal as transactions. Related sets of changes must all successfully occur before they are deleted from the journal. If you restart the system before a filesystem update transaction completes, the filesystem automatically reexecutes the transaction when the system comes up (sometimes referred to as “replaying the journal”).
The default kernel configuration file on a TimeSys distribution includes support for the JFFS2 filesystem. If you have modified or recreated this file and plan to use a JFFS2 file system with your distribution, you should verify that JFFS2 support is still active in your kernel configuration. This support is activated by selecting filesystem > Journaling Flash filesystem version 2 (EXPERIMENTAL) from the configuration menu.
To use a JFFS2 root filesystem, you first need to create a directory and populate it with the applications you want to include in your JFFS2 root filesystem. You must then copy the contents into a JFFS2 file system image. Creating a JFFS2 filesystem is done by using the mkfs.jffs2 utility. This utility is available in the LinuxLink Repository, or you can download the mkfs.jffs2 utility from ftp://sources.redhat.com/pub/jffs2/.
After you download the mkfs.jffs2 utility (and build it, if necessary), create a directory tree that holds the contents of the filesystem that you want to load into flash. For example, installing this distribution creates an RFS directory tree on the host; to make a JFFS2 image of the installed RFS, use the name of the RFS directory when issuing the command.
The mkfs.jffs2 utility creates a file system and populates it by copying in a set of files from the directory of your choice. You must create and organize this directory before running mkfs.jffs2. Any programs you include must be compiled using the cross-compilers for your target hardware; the programs must be able to run on the target hardware, not on the host where you are creating the filesystem.
Finally, execute mkfs.jffs2 using the general syntax shown here:
mkfs.jffs2 -b -r <source_dir> -o <output_file> -e <blocksize> -p <padsize> -d <image_dir>
Where:
- The -b option causes the output file to be big-endian. The default image has the same endianness as the host platform on which the command runs. Most x86 hosts are little-endian. Some target systems, including some PowerPC-based boards, require big-endian files. An analogous option, -l, forces the resulting image file to be little-endian.
- The -r option causes mkfs.jffs2 to use the filesystem layout in <source_dir>.
- The -o option tells mkfs.jffs2 to write the JFFS2 image to the specified <output_file>.
- The -e option tells mkfs.jffs2 the erase block size of the target, where <blocksize> is a multiple of the erase block size of the flash memory device with which you are working. The erase block size of the flash device is should be included in the device’s documentation, and can also be determined by issuing the cat /proc/mtd command on the target.
- The -p option tells mkfs.jffs2 to pad the output to the given size with 0xFF.
- The -d option tells mkfs.jffs2 to build the filesystem from
the specified directory (<image_dir>). The default
is the current directory.
Your command line should be typed on a single line or continued using the \ character. The spacing and indentation shown in the previous example is used for display purposes only. A more realistic example is the following one:
# cd <linux_dir>/<bsp_name>/rfs/ # mkfs.jffs2 -o ../<bsp_name>-flash.jffs2 -e 00040000
Block size and image size can be specified in decimal, octal, or hexadecimal terms. The manpage provided with the mkfs.jffs2 utility provides additional information.
After you have created a JFFS2 filesystem image as described in the previous section, copy the filesystem image to your TFTP server’s root directory (typically /tftpboot). You can then download the image to your embedded development board via TFTP with your boot monitor.