Overview: Linux Filesystems for Flash and Compact Flash Memory

Updateable static memory, known as flash memory, is a common storage medium found on embedded hardware today. Most of the embedded boards that provide flash memory divide that memory into a number of separately-addressable regions, known as partitions. Onboard flash is typically partitioned into at least three regions: one to store the bootloader and its configuration information, another to store the Linux kernel, and a third containing a filesystem that contains system and user applications and startup files.

Under Linux, flash memory is handled by the Linux MTD (Memory Technology Device) kernel subsystem.

In addition to general flash support, Linux supports a number of different filesystems that are especially designed for use on flash memory devices, such as cramfs or JFFS2. Because flash memory can only be reliably written to a certain number of times, filesystems designed for use with flash memory are usually either read-only or writable.

  • Read-only filesystems cannot be updated other than by updating the entire filesystem at once, by rewriting the partition that holds the filesystem. For more information on read-only filesystems, refer to Read-Only Filesystems.

    The most popular read-only filesystem for use with flash is cramfs, the compressed ROM filesystem. Cramfs simplifies the metadata that is stored for files and the filesystem itself in order to minimize its footprint. The tools for creating and working with cramfs filesystems is available at http://sourceforge.net/projects/cramfs/. TimeSys’ LinuxLink Repository also includes cramfs in the Embedded Development Utilities.

  • Writable flash filesystems provide internal support for mechanisms such as wear-leveling, which attempts to ensure that filesystem updates are evenly distributed across the portions of the flash that contains filesystem data. This is designed to prevent dead spots from appearing in the flash, because a specific portion of the filesystem has been written to the maximum number of times, while others may be far from reaching their write limit.

    The most popular writable filesystem for use on flash devices is JFFS2, the Journaling Flash File System, Version 2. JFFS2 is an enhanced version of the JFFS flash filesystem, which was originally developed by Axis Communications, AB. Detailed information about JFFS2 is available at http://sources.redhat.com/jffs2/. The source code for JFFS2 filesystem creation utilities is part of the MTD package, which you can find at http://www.linux-mtd.infradead.org. TimeSys’ LinuxLink Repository also includes JFFS2 in the Embedded Development Utilities MTD package.

Both cramfs and JFFS2 filesystems are created by utilities that convert an existing Linux directory hierarchy into a filesystem image, which you can then either bundle into the kernel as an initial RAM disk or write to a portion of your hardware’s flash and access as a filesystem. The Linux kernel provides internal support for both ROM filesystems and JFFS2.

Tools such as Factory provide integrated support for creating cramfs and JFFS2 filesystems without requiring that you build a specific set of filesystem creation utilities and learn the intricacies of their command structure.

Tip

One common misconception about flash memory on Linux systems is that flash memory and compact flash memory are handled in the same way. As mentioned earlier, flash memory is supported by the MTD subsystem, while compact flash memory is supported by the kernel’s IDE (Integrated Drive Electronics) subsystem. The filesystems that you can use on compact flash are therefore the same as those that you would use with any IDE storage device: ext2, ext3, FAT16, JFS, reiserfs, vfat, XFS, and so on. You would rarely, if ever, use a filesystem such as JFFS2 on compact flash, because the wear-leveling algorithm would conflict with the way that data is read from and written to IDE devices, and would therefore introduce additional system overhead and wear and tear on the device.