You are on page 1of 2

MTD First off, an MTD is a "Memory Technology Device", so it's just "MTD". An "MTD device" is a pleonasm.

Unix traditionally only knew block devices and character devices. Character devices were things like keyboards or mice, that you could read current data from, but couldn't be seek-ed and didn't have a size. Block devices had a fixed size and could be seek-ed. They also happened to be organized in blocks of multiple bytes, usually 512. Flash doesn't match the description of either block or character devices. They behave similar to block device, but have differences. For example, block devices don't distinguish between write and erase operations. Therefore, a special device type to match flash characteristics was created: MTD.So MTD is neither a block nor a char device.

Block device Consists of sectors Sectors are small (512, 1024 bytes) Maintains 2 main operations: read sector and write sector

MTD device Consists of eraseblocks Eraseblocks are larger (typically 128KiB) Maintains 3 main operations: read from eraseblock, write to eraseblock, and erase eraseblock

Bad sectors are re-mapped and hidden by hardware (at Bad eraseblocks are not hidden and should least in modern LBA hard drives); in case of FTL be dealt with in software devices it is the responsibility of FTL to provide this Sectors are devoid of the wear-out property (in FTL devices it is the responsibility of FTL to provide this) Eraseblocks wear-out and become bad and unusable after about 103 (for MLC NAND) 105 (NOR, SLC NAND) erase cycles

In order to use one of conventional file systems over an MTD device,  you need a software layer which emulates a block device over the MTD  device.   These   layers   are   often   called  Flash   Translation   Layers  (FTLs).  There is an extremely simple FTL layer in Linux MTD subsystem - mtdblock. It emulates block devices over MTD devices. There is also an mtdblock_ro module which emulates read-only block devices. When you load this module, it creates a block device for each MTD device in the system. The block devices are then accessible via /dev/mtdblockX device nodes. But in many cases using mtdblock is a very bad idea because what it basically does if you change any sector of your mtdblockX device, it reads the whole corresponding eraseblock into the memory, erases the eraseblock, changes the sector in RAM, and writes the whole eraseblock back. This is very straightforward. If you have a power failure when the eraseblock is being erased, you lose all the block device sectors in it. The flash will likely decay soon because you will wear few eraseblocks out - most

It makes sense to use mtdblock_ro for read-only file systems or read-only mounts.probably those ones which contain FAT/bitmap/inode table/etc. And don't try to use it on NAND flash as it is does not handle bad eraseblocks. But now when we have UBI (see here) it is much easier to do it on top of UBI. But think twice before using mtdblock in read-write mode. . Unfortunately it is a rather difficult task to create a good FTL layer and nobody still managed to implement one for Linux. one may use SquashFS as it compresses data quite well. For example.