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