Contents

Introduction to YAFFS/YAFFS2

What is YAFFS

YAFFS/YAFFS2 (Yet Another Flash File System) is a file system designed for use on NAND flash devices such as those commonly found in embedded systems. Unlike some other file systems which may be stored on the Flash device and then copied to RAM during boot (i.e. ramdisk) YAFFS/YAFFS2 actually resides on the Flash device and allows the user to read/write data to Flash. This is particularly useful in embedded devices that wish to save some persistent data between reboots. For more information on YAFFS/YAFFS2 please see the YAFFS wikipedia page as well as the YAFFS home page.

YAFFS/YAFFS2 is mainly designed for use with NAND Flash. While YAFFS/YAFFS2 can be used with NOR Flash devices it does not fit very well (because YAFFS does not use erase suspend). Generally if you are using a small flash device (less that 64MB) JFFS2 may be the better file system to use.

Benefits of YAFFS

There are several reasons why YAFFS is useful in an embedded system. Some of the more common ones are

  1. YAFFS allows data to be written back to Flash for persistent storage
  2. YAFFS is optimized for NAND FLash memory which must be erased in block size segments
  3. YAFFS provides wear leveling for longer Flash memory life
  4. YAFFS file systems do not need to be copied from Flash to RAM to be used
  5. YAFFS uses less run-time RAM to hold its state, so YAFFS/YAFFS2 scales better than JFFS2 on large devices
  6. YAFFS garbage collection is simpler and faster, typically making for better performance under hard writing than JFFS2

Benefits of YAFFS2 vs. YAFFS

YAFFS2 supports all of the features of YAFFS and is backwards compatible with YAFFS but also has some additional features added.

  1. YAFFS2 support large block NAND devices
  2. YAFFS2 meets the "write once" requirement of modern NAND Flash
  3. YAFFS2 supports "shrink headers" to handle how to resize an existing file to a smaller size
  4. YAFFS2 uses a more abstract definition of NAND which allows it to be used with a wider variety of devices which may have different geometries as well as using auto-placement of OOB (Out of Band) data
  5. YAFFS2 supports "checkpointing" to bypass normal mount scanning to reduce boot time

Limitations of YAFFS/YAFFS2

While YAFFS/YAFFS2 can be of use in embedded systems there are some limitations that users should be aware of. The most common are

  1. YAFFS/YAFFS2 scans the entire file system during mount to check for valid data and recreate the file system tree. This can result in longer boot times, particularly for large flash devices
  2. YAFFS/YAFFS2 does not provide compression
  3. YAFFS/YAFFS2 is included in the TI kernel but may not be included in mainline kernels

Methods for Creating the File System Image

While there do exist utilities for creating a YAFFS/YAFFS2 file system image file they do not appear to be fully cooked and are not covered in this document. If you have used these utilities please feel free to add your input.

The method covered in this document for creating a YAFFS/YAFFS2 file system image is to create a tarball archive of the file system and use Linux to write that image to the file system partition. This requires the use of an intermediate file system (i.e. ramdisk, NFS, or hard drive file system) with the target version (ARM) of MTD Utilities installed in order to use the MTD subsystem to write the contents of the tarball archive to the Flash device.

Prerequisites

To create a YAFFS/YAFFS2 image in this example you will need a target (ARM) root file system which you want to create a tarball image of (i.e. the content of a ramdisk or NFS share). For this example we will be using the sample ramdisk file system provided with the DVSDK software. For newer versions of the DVSDK (DVSDK 1.30 and greater) the sample ramdisk file system can be found at <DVSDK install dir>/<PSP directory>/bin. In older versions of the DVSDK (DVSDK 1.20 and earlier) the sample ramdisk file system can be found in the MontaVista installation directory at <MV install dir>/montavista/pro/devkit/arm/v5t_le/var/www/vhosts/mytiwiki.com/subdomains/wiki/httpdocs/images//.

Making the File System Image

As already mentioned it is possible to create a YAFFS/YAFFS2 file system image using the mkyaffsimage utility. However, it this document we will only cover creating a tarball image of a file system. The section below details how to create the tarball image.

Making a Tarball Image

This section will detail how to create a tarball file system image on a Linux development host. For this example I will be using the sample ramdisk.gz file shipped with the DVSDK. For information on locating the ramdisk.gz file please see the Prerequisites section.

   host$ mkdir -p /home/user/workdir
   host$ cd /home/user/workdir
   host$ cp <ramdisk path>/ramdisk.gz .
   host$ mkdir ram
   host$ gunzip ramdisk.gz
   host$ mount ramdisk ram -o loop

NOTE: At this point you can add any additional files or applications you wish to the file system image at /home/user/workdir/ram before creating the tarball file system image.

   host$ cd ram
   host$ tar czf ../rootfs.tar.gz *

The tarball rootfs.tar.gz located at /home/user/workdir is now ready to be used to populate the YAFFS/YAFFS2 file system.

Conclusion

By following this example you should now have created a file system image that you can use to populate the YAFFS/YAFFS2 file system. For more information on how to write this image to NAND plase see the Put YAFFS Image to Flash Page.

Further reading

The Filesystem_in_NOR_or_NAND article has some more useful pointers as well.