Creating JFFS2 Images

From EMAC Wiki
Jump to: navigation, search
TODO: {{#todo:SEOKWREV (11.26.13-22:20->MD+)(12.10.13-12:00->MG+)(12.17.13-12:35->KY+)(02.26.14-15:30->MW+)(03.06.14-15:00->BS-);(04.11.14-10:45->BS+)|Mike Dean|oe 4,oe 5,md,SEOKWREV,mg,ky,bs}}

Background

JFFS2 (Journalling Flash File System version 2) was created to provide a better filesystem for flash memory devices. It is a log-structured filesystem, which provides for wear-leveling of the flash. JFFS2 supports NAND flash devices (used on all newer EMAC products), hard links, compression and garbage collection.


This page describes the process of creating new images from existing JFFS2 images in order to resize, modify, or change parameters of the image. Please follow the steps in Mounting JFFS2 Images to mount an existing JFFS2 image. The mounted directory structure will be used as the root directory for creating the new image.


Mkfs.jffs2 Usage

The mkfs.jffs2 application is used to create JFFS2 images. The parameters used to create the image will depend on the target system, including the flash type, erase block size, and partition size. Once the parameters have been determined, the JFFS2 image will be created by running mkfs.jffs2 and specifying the directory tree to use for making the image using the --root option. The following sections discuss the system variables affecting JFFS2 images. More information can be obtained by running mkfs.jffs2 --help and man mkfs.jffs2.

Erase Block Size

The erase block size of the flash must be determined before creating the JFFS2 image. This can be found through the contents of /proc/mtd on a running system or through the system documentation. All NOR flashes currently used on EMAC products utilize 128 KiB erase blocks. NAND flashes use a variety of configurations, 128 KiB and 256 KiB are the most common.

To determine the erase block size of a NAND flash from U-Boot run the following:

U-Boot> nand info

The sector size reported corresponds to the erase block size.


For example, 256 KiB erase block is reported as follows:

Device 0: NAND 1GiB 3,3V 8-bit, sector size 256 KiB

Endianess

Currently, all EMAC products that use JFFS2 filesystems are configured as little endian by default. Custom configurations or future products may result in the need for a big endian image. Contact EMAC if you are unsure which endianness to use.

Cleanmarkers

By default, JFFS2 writes cleanmarker nodes to the beginning of each erase block. While this is desired on NOR flash, it should not be used for NAND flash devices. If the target system uses a NAND flash, cleanmarkers will be disabled with the --no-cleanmarkers option.

Padding

Padding is extra space left for the creation of inodes, which are essentially pointers to files. The filesystem will automatically allocate space for the inodes needed for the files which are put into the filesystem at the time of creation. On NOR devices, padding needs to be added to allow additional files to be stored on the filesystem after the time of creation. On NAND flash, this is not needed due to the strictly sequential interface of NAND devices.

For NOR flash, padding is typically added to the end of the last erase block by specifying the --pad option with no size parameter. However, when using RedBoot as the bootloader the image should be padded to the full size of the JFFS2 partition.

Examples

After determining what parameters to use for the target system, the image can be created. The following are examples for different common system types. These examples assume that the root directory is located at /tmp/rootfs and the image in the output file is emac-oe-rootfs.jffs2.

NAND Flash with 128 KiB Erase Blocks
developer@ldc:~$ sudo mkfs.jffs2 --root=/tmp/rootfs --output=emac-oe-rootfs.jffs2 \
--eraseblock=0x20000 --little-endian --no-cleanmarkers
NAND Flash with 256 KiB Erase Blocks
developer@ldc~$ sudo mkfs.jffs2 --root=/tmp/rootfs --output=emac-oe-rootfs.jffs2 \
--eraseblock=0x40000 --little-endian --no-cleanmarkers
NOR Flash with 128 KiB Erase Blocks for U-Boot
developer@ldc~$ sudo mkfs.jffs2 --root=/tmp/rootfs --output=emac-oe-rootfs.jffs2 \
--eraseblock=0x20000 --little-endian --pad
NOR Flash with 128 KiB Erase Blocks for RedBoot with 28 MiB Partition Size
developer@ldc:~$ sudo mkfs.jffs2 --root=/tmp/rootfs --output=emac-oe-rootfs.jffs2 \
--eraseblock=0x20000 --little-endian --pad=0x1C00000

Sumtool

Sumtool is a utility that creates JFFS2 erase block summary images. Summary information is an improvement to the original JFFS2 design that can speed up the mount process of JFFS2 filesystems by reducing the amount of the filesystem that must be scanned. JFFS2 summary support is included in default EMAC kernel configurations.

Summary JFFS2 images are created using an existing JFFS2 filesystem created with mkfs.jffs2. Typically, the only options required to use sumtool are the eraseblock size, input file, output file, and whether cleanmarkers should be used. Other options may be listed by running sumtool --help. To create a summary image from the oe-rootfs.jffs2 file created in the examples above, the following commands should be used for a NAND flash with 128 KiB erase blocks:

developer@ldc:~$ sudo sumtool --input=emac-oe-rootfs.jffs2 --output=emac-oe-rootfs-summary.jffs2 \
--eraseblock=0x20000 --no-cleanmarkers

For a NOR flash with 128 KiB erase blocks, the no-cleanmarkers option is replaced by the pad option. There is no way to specify the padded size of the final image with sumtool, so summary images are not generally used on EMAC products with RedBoot. The command below will create a summary image for the NOR flash:

developer@ldc:~$ sudo sumtool --input=emac-oe-rootfs.jffs2 --output=emac-oe-rootfs-summary.jffs2 \
--eraseblock=0x20000 --pad

Using the Images

The JFFS2 file created above will need to be made available on a TFTP server for programming onto boards. The Loading JFFS2 Images Onto a Board page describes how to load the image onto a board from a TFTP server.

Navigation menu