分类: 嵌入式
2010-11-21 14:50:38
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. There are translations to
use them, as if they were. But those translations are nowhere near the
original, just like translated Chinese poems.
Can I mount ext2 over an MTD device?
Ext2, ext3, XFS, JFS, FAT and other "conventional" file systems work with block devices. They are designed this way. Flashes are not block devices, they are very different beasts. Please, read , and FAQ entries.
Please, do not be confused by USB stick, MMC, SD, CompactFlash and other popular removable devices. Although they are also called "flash", they are not MTD devices. They are out of MTD subsystem's scope. Please, read FAQ entry.
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 ) 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.
载自 :
//===================================================
Beside the different silicon cell design, the most important difference between NAND and NOR Flash is the bus interface. NOR Flash is connected to a address / data bus direct like other memory devices as SRAM etc. NAND Flash uses a multiplexed I/O Interface with some additional control pins. NAND flash is a sequential access device appropriate for mass storage applications, while NOR flash is a random access device appropriate for code storage application. NOR Flash can be used for code storage and code execution. Code stored on NAND Flash can't be executed from there. It must be loaded into RAM memory and executed from there.
NOR | NAND | |
Interface | Bus | I/O |
Cell Size | Large | Small |
Cell Cost | High | Low |
Read Time | Fast | Slow |
Program Time single Byte | Fast | Slow |
Program Time multi Byte | Slow | Fast |
Erase Time | Slow | Fast |
Power consumption | High | Low, but requires additional RAM |
Can execute code | Yes | No, but newer chips can execute a small loader out of the first page |
Bit twiddling | nearly unrestricted | 1-3 times, also known as "partial page program restriction" |
Bad blocks at ship time | No | Allowed |
mikujiang2018-01-29 14:35:32
hi 这个层次关系是不是画的有问题?
从linux软件的角度看FLASH:??
------C runtime(glibc 2.x)------------------------------
------kernel inte**ce(system call)---------------------
------Filesystem(ext2, FAT, JFFS/JFFS2)-----------------
------MTD(/dev/fla?, block device)----------------------
------MTD(/dev/mtd?, char device)-----------------------
------Translation Layer(CFI, FTL, NFTL)-----------------
------NAND, NOR, AND------------------------------------
------Hardware level, FLASH