Difference between revisions of "Memory Tecnology Device (MTD)"

From DAVE Developer's Wiki
Jump to: navigation, search
(JFFS2)
Line 5: Line 5:
 
{{WorkInProgress}}
 
{{WorkInProgress}}
  
=== Introduction ===
+
= Introduction =
  
=== MTD Partitions ===
+
= MTD Partitions =
  
=== UBI ===
+
== UBI ==
  
=== File system on MTD ===
+
== File system on MTD ==
  
==== JFFS2 ====
+
=== JFFS2 ===
  
 
The Journaled Flash File System v.2 provides non-volatile storing and compression of data on flash devices. For more details about is please see ....
 
The Journaled Flash File System v.2 provides non-volatile storing and compression of data on flash devices. For more details about is please see ....
Line 115: Line 115:
 
</pre>
 
</pre>
  
==== UBIFS ====
+
=== UBIFS ===
  
 
UBIFS can be considered as the next-generation of the JFFS2 file system. It is a new journaled flash file system which works on top of the UBI (Unsorted Block Images) subsystem, a wear-leveling and volume management system for raw flash devices. UBI volumes are higher level entities than MTD devices, which represents the raw flash devices (/dev/mtdX) and provide the interface to access flash chips. The following figure shows the involved subsystems:
 
UBIFS can be considered as the next-generation of the JFFS2 file system. It is a new journaled flash file system which works on top of the UBI (Unsorted Block Images) subsystem, a wear-leveling and volume management system for raw flash devices. UBI volumes are higher level entities than MTD devices, which represents the raw flash devices (/dev/mtdX) and provide the interface to access flash chips. The following figure shows the involved subsystems:

Revision as of 16:49, 11 May 2012

Info Box
Tux.png Applies to Linux


WorkInProgress.gif

Introduction[edit | edit source]

MTD Partitions[edit | edit source]

UBI[edit | edit source]

File system on MTD[edit | edit source]

JFFS2[edit | edit source]

The Journaled Flash File System v.2 provides non-volatile storing and compression of data on flash devices. For more details about is please see ....

The default MTD partition associated to the NAND flash is mapped as number .... Please note that the same technique can be used with the NOR Flash partitions.

Let’s assume we run the kernel by using the net_nfs configuration as described ... From the target shell, run

cat /proc/mtd

This command lists all the MTD partitions. For example, the mtd4 partition can be used.

eraseall /dev/mtd4
bash-2.05b# eraseall /dev/mtd5
Erasing 16 Kibyte @ nand_erase: attempt to erase a bad block at page 0x0000a740
Erasing 16 Kibyte @ 14e8000 -- 65 % complete.
eraseall: /dev/mtd5: MTD Erase failure: Input/output error
Erased 32768 Kibyte @ 0 -- 100% complete.

This operation is a sort of formatting. The error shown above refers to a bad block found in the device. These bad block are common for NAND flashes. They resemble somehow bad block of hard disk.

mkdir /mnt/nand
mount -t jffs2 /dev/mtdblock4 /mnt/nand
mount

Linux should print something like this:

/dev/nfs on / type nfs (rw)
none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
/dev/mtdblock4 on /mnt/nand type jffs2 (rw)

This means than the device is correctly mounted on /mnt/nand.

To see how much space is left on the device please run the df command:

bash-2.05b# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/nfs              99077740  44983688  54094052  46% /
 /dev/mtdblock4           32768       912     31856   3% /mnt/nand

Now it is possibile to create create files and directories in /mnt/nand. This stuff will be permanently stored in the NAND flash chip.


Mount root filesystem from MTD JFFS2 partition[edit | edit source]

First of all it is necessary to have the root file system available on a directory, for example /mnt/rfs (user can mount it throug NFS or loop-mount an ext2 image). Then:

cd /mnt/rfs/
cp -aRv . /mnt/nand/

You should see something like this:

bash-2.05b# cp -aRv . /mnt/nand/
`./bin' -> `/mnt/nand/./bin'
`./bin/login' -> `/mnt/nand/./bin/login'
`./bin/application' -> `/mnt/nand/./bin/application'
`./bin/busybox' -> `/mnt/nand/./bin/busybox'
...
`./var/run' -> `/mnt/nand/./var/run'
bash-2.05b#

Now reboot the system in order to access the U-Boot shell and modify the root and rootfstype kernel command line parameters on the nandargs environment variable:

setenv nandargs 'setenv bootargs root=/dev/mtdblock4 rw rootflags=noatime rootfstype=jffs2'

Now run the kernel with this command:

run flash_nand

When kernel completed boot process, you can verify that the root file system is the one stored in the NAND flash:

# mount
rootfs on / type rootfs (rw)
/dev/mtdblock4 on / type jffs2 (rw,noatime)
/proc on /proc type proc (rw,nodiratime)

UBIFS[edit | edit source]

UBIFS can be considered as the next-generation of the JFFS2 file system. It is a new journaled flash file system which works on top of the UBI (Unsorted Block Images) subsystem, a wear-leveling and volume management system for raw flash devices. UBI volumes are higher level entities than MTD devices, which represents the raw flash devices (/dev/mtdX) and provide the interface to access flash chips. The following figure shows the involved subsystems:

Ubifs stack.png

The default MTD partition associated to the NAND flash is mapped as number 4. Let’s assume we run the kernel by using the net_nfs configuration. Since using UBIFS shares some points with using JFFS2, please refer to ... for further details.

To access and use UBIFS:

  • Add the ubi.mtd=X parameter to the kernel command line, where X is the number of the mtd partition
  • Erase the MTD partition:
flash_eraseall /dev/mtdX 
  • As an alternative to point 1, launch the following command:
ubiattach /dev/ubi_ctrl -m X 
  • The device /dev/ubi0 is now available. To create the UBI volume, launch the following command (-N sets the name and -s sets the size of the volume):
ubimkvol /dev/ubi0 -N rootfs -s 128MiB
  • The device /dev/ubi0_0 is now available and can be mounted with one of the following comands:
mount -t ubifs ubi0_0 /mnt/ubifs
mount -t ubifs ubi0:rootfs /mnt/ubifs
  • To mount the UBI file system as root file system, the binding between MTD and UBI must be specified from the kernel command line, adding the following parameters:
ubi.mtd=6 root=ubi0_0 rootfstype=ubifs rw

Please note that

  1. the file system is formatted automatically the first time it is mounted
  2. the mount command don't use the /dev/ prefix before ubi0_0 device