Open main menu

DAVE Developer's Wiki β

Changes

Memory Tecnology Device (MTD)

5,679 bytes added, 15:33, 4 May 2015
m
UBIFS
{{InfoBoxBottom}}
{{WorkInProgress}}
=== Introduction ==Memory Technology Devices (MTD) =
=== MTD Partitions ===subsystem (Memory Technology Devices) provides an abstraction layer for raw flash devices. It makes it possible to use the same API when working with different flash types and technologies (NOR and NAND in particular). Please refer to the [http://www.linux-mtd.infradead.org/doc/general.html official documentation] for detailed information.
==MTD Partitions = = The mapping driver can either specify a hard-coded partition layout or read the partition layout from the kernel command line passed in from the boot loader. With partition support, each MTD partition will be exported as a separate MTD device. Each device has a descriptive name which can be viewed using the following command: <pre>cat /proc/mtd</pre> === Command line configured MTD partitions === == MTD Utils == You can interact with the MTD subsystem using the MTD Utilities, a collection of tools that can be used to perform operations on Flash devices. For further information on this package, plese refer to http://processors.wiki.ti.com/index.php/MTD_Utilities Usually the mtd-utils collection is provided as a pre-built binary package. Anyway, it can also be [http://processors.wiki.ti.com/index.php/MTD_Utilities#Target cross-compiled] for the specific target. == UBI == UBI (Unsorted Block Images) is a volume management system for raw flash devices which manages multiple logical volumes on a single physical flash device and spreads the I/O load (i.e, wear-leveling) across whole flash chip. UBI/UBIFS is the recommended solution when using large flash partitions. For further information on UBI, plase refer to http://www.linux-mtd.infradead.org/doc/ubi.html == File systems on MTD == Because of the particular characteristics of flash memory, it is best used with a specifically designed flash file systems, which handles the read/write/erase operations and the wear-leveling algorithms. At the moment there are only a few filesystems which support NAND:* JFFS2 and YAFFS for bare NAND Flash and SmartMediaCards* NTFL for DiskOnChip devices* TRUEFFS from M-Systems for DiskOnChip devices* SmartMedia DOS-FAT as defined by the SSFDC Forum* UBIFS for bare NAND flash The most common solutions are JFFS2 and UBI /UBIFS.  === 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 http://www.linux-mtd.infradead.org/doc/jffs2.html. It can be a good choice for not too big flash partitions (as a reference, not bigger than 128 MByte). Let's assume the MTD partition associated to the NAND flash is mapped as number 5. Please note that the same technique can be used with the NOR Flash partitions. Let’s assume we run the kernel by using the [[Booting_Linux_Kernel#Configuration_net_nfs|net_nfs configuration]]. From the target shell, run<pre class="board-terminal">cat /proc/mtd</pre> This command lists all the MTD partitions. For example, the mtd4 partition can be used. <pre class="board-terminal">eraseall /dev/mtd5</pre> <pre class="board-terminal">bash-2.05b# eraseall /dev/mtd5Erasing 16 Kibyte @ nand_erase: attempt to erase a bad block at page 0x0000a740Erasing 16 Kibyte @ 14e8000 -- 65 % complete.eraseall: /dev/mtd5: MTD Erase failure: Input/output errorErased 32768 Kibyte @ 0 -- 100% complete.</pre> 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.<pre class="board-terminal">mkdir /mnt/nand</pre> <pre class="board-terminal">mount -t jffs2 /dev/mtdblock5 /mnt/nand</pre> <pre class="board-terminal">mount</pre> Linux should print something like this: <pre class="board-terminal">/dev/nfs on / type nfs (rw)none on /proc type proc (rw)usbdevfs on /proc/bus/usb type usbdevfs (rw)/dev/mtdblock5 on /mnt/nand type jffs2 (rw)</pre> 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: <pre class="board-terminal">bash-2.05b# dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/nfs 99077740 44983688 54094052 46% / /dev/mtdblock5 32768 912 31856 3% /mnt/nand</pre> 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 ==== 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: <pre class="board-terminal">cd /mnt/rfs/cp -aRv . /mnt/nand/</pre> You should see something like this:<pre class="board-terminal">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#</pre> 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: <pre class="board-terminal">setenv nandargs 'setenv bootargs root=/dev/mtdblock5 rw rootflags=noatime rootfstype=jffs2'</pre> Now run the kernel with this command: <pre class="board-terminal">run flash_nand</pre> When kernel completed boot process, you can verify that the root file system is the one stored in the NAND flash:<pre class="board-terminal"># mountrootfs on / type rootfs (rw)/dev/mtdblock5 on / type jffs2 (rw,noatime)/proc on /proc type proc (rw,nodiratime)</pre> === 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:
[[File: Ubifs stack.png]]
The default For more information on UBIFS, please refer to http://www.linux-mtd.infradead.org/doc/ubifs.html Let's assume the MTD partition associated to the NAND flash is mapped as number 4. Let’s assume X and that we run the kernel by using the [[Booting_Linux_Kernel#Configuration_net_nfs|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:
<pre class="board-terminal">
flash_eraseall /dev/mtdX
</pre>
* As an alternative to point 1, launch Launch the following commandto create the UBI volume:
<pre class="board-terminal">
ubiattach /dev/ubi_ctrl -m X
* 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:
<pre class="board-terminal">
ubi.mtd=6 X root=ubi0_0 rootfstype=ubifs rw
</pre>
# the mount command don't use the /dev/ prefix before ubi0_0 device
=== File system on MTD === ==== JFFS2 ==Additional information ==
==== UBIFS ====* http://free-electrons.com/blog/managing-flash-storage-with-linux/