mtd设备简介

来源:互联网 发布:淘宝推广员招聘 编辑:程序博客网 时间:2024/05/04 00:27
http://www.linux-mtd.infradead.org/faq/general.html
    
    Unix traditionally only knew block devices and character devices.Character devices were things like keyboards or mice, that you couldread 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 happenedto 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.What are the differences between flash devices and block drives?
The following table describes the differences between block devices andraw flashes. Note, SSD, MMC, eMMC, RS-MMC, SD, mini-SD, micro-SD, USB flashdrive, CompactFlash, MemoryStick, MemoryStick Micro, and other FTL devicesare block devices, not raw flash devices. Of course, hard drives arealso block devices.
Block drivesMTD deviceConsists of sectorsConsists of eraseblocksSectors are small (512, 1024 bytes)Eraseblocks are larger (typically 128KiB)Maintains 2 main operations: read sectorwrite sector andMaintains 3 main operations: read from eraseblock,write to eraseblock, and erase eraseblockBad sectors are re-mapped and hidden by hardware (atleast in modern LBA hard drives); in case of FTLdevices it is the resposibility of FTL to provide thisBad eraseblocks are not hidden and should be dealt within softwareSectors are devoid of the wear-out property (in FTL devicesit is the resposibility of FTL to provide this) Eraseblocks wear-out and become bad and unusable afterabout 103 (for MLC NAND) - 105(NOR, SLC NAND) erase cycles
So as one sees flashes (MTD devices) are somewhat more difficult to workwith. 

    Please, do not be confused by USB stick, MMC, SD, CompactFlash and other popularremovable devices. Although they are also called "flash", they are not MTD devices.They are out of MTD subsystem's scope.
    
    In order to use one of conventional file systems over an MTD device, you need asoftware layer which emulates a block device over the MTD device. These layersare 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 isalso 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 thesystem. The block devices are then accessible via /dev/mtdblockXdevice nodes.

        MTD 驱动程序是专门针对嵌入式Linux的一种驱动程序,相对于常规块设备驱动程序(比如PC中的IDE硬盘)而言,MTD驱动程序能更好的支持和管理闪存设备,因为它本身就是专为闪存设备而设计的。MTD设备是指不同于传统字符设备和块设备的flash存储设备,使得上层的文件系统像访问传统的字符或块设备一样访问flash,为上层软件系统提供一个同一的接口。
    具体地讲,基于MTD的FLASH驱动,承上可以很好地支持cramfs,jffs2和yaffs等文件系统,启下也能对FLASH的擦除,读写,FLASH坏块以及损耗平衡进行很好的管理。所谓损耗平衡,是指对NAND的擦写不能总是集中在某一个或某几个block中,这是由NAND芯片有限的擦写次数的特性决定的。