How to Create YAFFS2 Images

Summary

YAFFS2 is an out-of-tree filesystem that was designed from the ground up to work with NAND flash, but will also work on other solid-state memory devices, like NOR flash. It performs automatic wear-leveling to increase the life of the chip, and can handle bad blocks on NAND flash.

There are two versions of YAFFS: YAFFS and YAFFS2. The YAFFS2 code-base supports functionality provided by the YAFFS code-base as well as being extended with new functionality to provide extra modes of operation, most importantly those required to work with larger and more modern NAND parts. The YAFFS2 code-base supports the YAFFS1 mode of operation through a backward compatibility mode.

YAFFS/YAFFS2 is developed out-of-tree, so it is not included in the vanilla Linux kernel. Many manufacturers incorporate the filesystem into their kernel releases, but there is no "official" version for a particular kernel version. Therefore, the code and options available for YAFFS can differ between manufacturers, if it is integrated at all. However, the YAFFS code can be automatically injected into kernel sources by Factory or with a YAFFS-supplied script, so it does not need to be manually backported like many other filesystems.

The typical method for deploying a YAFFS2 filesystem is to create a YAFFS2 image, integrate and configure YAFFS during kernel compilation, and then burn the image directly to flash using nand_write or flashcp.

Using an externally built image

Prerequisites

Using YAFFS2 with your Linux kernel requires the following:

  • Kernel with YAFFS2 Support, either added by the manufacturer or integrated before compilation
    • CONFIG_YAFFS_FS=m
  • mkyaffs2image
  • Filesystem that will be contained in the image

Procedure

  1. In Factory, enable YAFFS2 image creation under Target Configuration -> Build RFS -> yaffs2
    • This will automatically select mkyaffs2image to be included in your toolchain.
  2. If your kernel includes support for YAFFS2, enable it in your kernel config
    • $ make kernel-menuconfig
  3. Otherwise, Factory can build the YAFFS2 module against your kernel:
    • Select Toolchain Configuration -> YAFFS -> Build target yaffs2 -> Build and include the YAFFS kernel modules
  4. Or, you can download the YAFFS sources, which include a script for integrating into your kernel sources
  5. Burn this image to flash using one of the following methods:
    • For most boards, you can use mtd-utils to burn it to a flash partition. This requires Linux running on the target system, however.
    • On Atmel boards, you can use SAM-BA to burn it to flash from the host machine.
    • Some bootloaders, such as LogicLoader, can copy a file from a flash card (SD or CF) directly to flash.
    • If you have a properly created configuration file, you can also use a debugger such as the BDI2000 to burn it to the board from the host machine.

Mounting a YAFFS2 Filesystem

From the Linux Command Line

You can use the mount command to mount a YAFFS2 filesystem, much like any other partition. Assuming you are using /dev/mtd1 and wish to mount at /mnt, use the following instructions:

mount -t yaffs2 /dev/mtdblock1 /mnt

Using a YAFFS2 Filesystem as RFS

Once the image is created and burned to flash, you can mount it as a root filesystem by specifying certain parameters on the kernel command line. Add the following line to your command line to boot a YAFFS2 filesystem as your RFS:

rootfstype=yaffs2 root=/dev/mtdblockN rw

Where N is the MTD partition containing the RFS. You can determine your MTD partition scheme from the Linux source code for your specific board, or by looking at the console output from the kernel during boot time.

AT91 NAND: 8-bit, Software ECC
Scanning device for bad blocks
Creating 2 MTD partitions on "at91_nand":
0x00000000-0x00400000 : "Bootstrap" 
0x00400000-0x10000000 : "Partition 1" 

This example, taken from the kernel console output, shows that there are two partitions on the NAND flash chip. If there are no other MTD devices on the board, then these will correspond to /dev/mtdblock0 and /dev/mtdblock1, respectively. If you wanted to boot from "Partition 1", you would burn the RFS to /dev/mtd1, or NAND offset 0x00400000, depending on the tool.

Additional Resources

Common NAND Parameters

A list of parameters for common NAND chips can be found on the HOWTO Find NAND Parameters page.

External Links