Put YAFFS Image to Flash

From Texas Instruments Embedded Processors Wiki

Jump to: navigation, search
Translate this page to   

Often times it is useful to write the file system for you device into a permanent storage media such as NAND flash. Below you will find steps on how to write a YAFFS/YAFFS2 file system into NAND Flash on the DVEVM boards.

Contents

Prerequisites

Writing Flash from Linux

It is possible to use the Linux MTD subsystem to write the YAFFS/YAFFS2 file system. While this method requires the use of an intermediate file system it has the benefit of not requiring calculation of the start of the file system partition and allows the DaVinci NAND driver to place the contents of the file system in the desired format. This example can be used with a .tar.gz file.

When using Linux, interaction with the Flash device is controlled through the MTD subsystem. The MTD subsystem exports two device nodes per Flash partition. These are:

  1. /dev/mtd# - A character device that is used to access the raw Flash device
  2. /dev/mtdblock# - A block device used to access the disk/block established in the raw Flash

In the above device nodes the '#' sign represents the partition number. For example partition 0 would have the device nodes /dev/mtd0 and /dev/mtdblock0

Writing a Tarball Image

To write a YAFFS/YAFFS2 image you will use the MTD utilities to erase and copy the file system image into the Flash. The utility that will be used is:

  • flash_eraseall - Erases an entire MTD device, which in this case is a partition

The steps to write the YAFFS/YAFFS2 image are:

NOTE: The Sample output below is for the DM6446 EVM. You should see similar output when using other EVMs.

   target$ cat /proc/mtd

You should see output similar to:

   target$ cat /proc/mtd
   dev:    size   erasesize  name
   mtd0: 00040000 00004000 "bootloader"
   mtd1: 00020000 00004000 "params"
   mtd2: 00400000 00004000 "kernel"
   mtd3: 03ba0000 00004000 "filesystem"

In this example the file system partition of the flash device is /dev/mtd3

NOTE: For some devices such as the DM355 you may have more than 1 file system partition. This is done to help speed boot times by mounting the root file system from a smaller Flash partition and then allowing the larger second Flash partition to be mounted after boot.

   target$ flash_eraseall /dev/mtd3

You should see output similar to:

   target$ flash_eraseall /dev/mtd3
   Erasing 16 Kibyte @ 3b9c000 -- 99 % complete.

NOTE: For small block NAND devices (i.e. DM6446) you must mount the file system as a YAFFS file system. For large block NAND devices (i.e. DM355) the file system should be mounted as YAFFS2. Using the wrong version of YAFFS will result in error messages similar to:

   target$ mount -t yaffs2 /dev/mtdblock3 /mnt
   yaffs: dev is 32505859 name is "mtdblock3"
   yaffs: Attempting MTD mount on 31.3, "mtdblock3"
   yaffs: MTD device does not support have the right page sizes
   mount: wrong fs type, bad option, bad superblock on /dev/mtdblock3,
          or too many mounted file systems
   target$ mount -t yaffs /dev/mtdblock3 /mnt
   target$ mount -t yaffs2 /dev/mtdblock3 /mnt
   target$ cd /mnt
   target$ date MMDDhhmmCCYY (this is month,day,hour,minute,century,year format.  i.e. for May 22 10:15 2008 this would be "date 052210152008")
   target$ tar xzf <imagedir>/rootfs.tar.gz

NOTE: The date command is used to avoid warnings about time differences

   target$ cd /
   target$ umount /mnt

Setting the Kernel to Boot Using YAFFS/YAFFS2

This section covers setting the kernel bootargs in U-Boot to boot from a Flash partition populated with a YAFFS/YAFFS2 file system image.

Requirements

Command Line Parameters

In order to boot the YAFFS/YAFFS2 file system in Flash you must add the following kernel parameters to the kernel boot arguments defined in the "bootargs" environment variable in U-Boot:

For YAFFS

   "... root=/dev/mtdblock3 rw rootfstype=yaffs ..."

The above bootargs tell the kernel that the root file system is on MTD partition 3 and that the file system type is YAFFS.

For YAFFS2

   "... root=/dev/mtdblock3 rw rootfstype=yaffs2 ..."

The above bootargs tell the kernel that the root file system is on MTD partition 3 and that the file system type is YAFFS.

Conclusion

You should now have a kernel which boot using a YAFFS/YAFFS2 root file system in Flash.

Leave a Comment

Comments

it seems has some problems when I try to create yaffs2 in mtdblock3. I erased mtd3 and mount mtdblokc3 to /mnt/nand, then copied a file to /mnt/nand , umount it and mount it again. but the file lost. I test it on EVM board, EVM can't save file, too. what's wrong? my log as blow:

================================================================================

root@192.168.1.7:~# flash_eraseall /dev/mtd3 Erasing 128 Kibyte @ 1fe0000 -- 99 % complete.

root@192.168.1.7:~# mount -t yaffs2 /dev/mtdblock3 /mnt/nand

yaffs: dev is 32505859 name is "mtdblock3" yaffs: Attempting MTD mount on 31.3, "mtdblock3"

root@192.168.1.7:~# cd /mnt/nand/

root@192.168.1.7:/mnt/nand# ls lost+found

root@192.168.1.7:/mnt/nand# cp /root/cif.bmp ./

root@192.168.1.7:/mnt/nand# ls

cif.bmp lost+found /*cif.bmp can be listed here*/

root@192.168.1.7:/mnt/nand# cd

root@192.168.1.7:~# umount /mnt/nand/

root@192.168.1.7:~# mount -t yaffs2 /dev/mtdblock3 /mnt/nand

yaffs: dev is 32505859 name is "mtdblock3" yaffs: Attempting MTD mount on 31.3, "mtdblock3"

root@192.168.1.7:~# ls /mnt/nand/ lost+found /*cif.bmp lost*/ root@192.168.1.7:~#

Dog0138 said ...

the mount-time of yaffs2 is so long that when i boot the dm355 evm i must spent 8 seconds on mounting the root filesystem ,i have reduce the patition to 64M,but do nothing better for that.dose anyone have good advice?

--Dog0138 15:39, 22 March 2009 (UTC)

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox