General

 

Table of contents

  1. Is an MTD device a block device or a char device?
  2. I'd like to add/change/fix information on this Web-site - how?
  3. What are the differences between flash devices and block drives?
  4. Can I mount ext2 over an MTD device?
  5. What are the point() and unpoint() functions used for?
  6. Why do I keep getting errors whenever I try to write to or erase my MTD device?
  7. How do I compile the mtd-utils tree?
  8. How do I report bugs?

Is an MTD device a block device or a char device?

一个MTD设备是一个字符设备还是一个块设备?

First off, an MTD is a "Memory Technology Device", so it's just "MTD". An "MTD device" is a pleonasm. Of course, at the time of this edit (Thu Aug 4 15:36:10 PDT 2011) "MTD device" was found at least 520 times in the Linux source tree, 189 times in the mtd-utils source, and even 119 times in the source for this website...

首先,一个MTD是一个“存储技术设备”,因此它只是一个简单的“MTD”。一个“MTD设备”是一个赘述。当然,在编辑该文章时,“MTD设备”这个词在Linux源代码树上至少出现了520次,在mtd-utils 源上至少出现了189次,甚至在本网站的源代码中出现了119次...

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.

Unix传统上只知道块设备和字符类设备。字符类设备就是例如键盘和鼠标这样的设备,你可以从这些设备上读取当前数据,但是不支持搜索,也没有大小。块设备有一个固定的容量并且支持检索。它们是由许多块组成的,每个块由许多字节组成,通常是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.

闪存没有匹配块或字符类设备的描述。它与块设备类似,但是仍有许多不同之处。例如,块设备不区分写入和擦除操作。因此,一个用来匹配flash特性的特殊设备被创造出来: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.

所以,MTD既不是块设备,也不是字符类设备。有一些翻译可以使用它们,好像它们是。但是这些翻译与原作相去甚远,就好像是翻译中国诗歌一样。

I'd like to add/change/fix information on this Web-site - how?

我想要增加/改变/修改这个网站上的信息,要怎么做?

What are the differences between flash devices and block drives?

flash设备和块设备之间有什么不同?

The following table describes the differences between block devices and raw flashes. Note, SSD, MMC, eMMC, RS-MMC, SD, mini-SD, micro-SD, USB flash drive, CompactFlash, MemoryStick, MemoryStick Micro, and other FTL devices are block devices, not raw flash devices. Of course, hard drives are also block devices.

下面的表格描述了块设备和单纯的flash之间的不同。注意,SSD,MMC,eMMC,RS-MMC,SD,mini-SD,micro-SD,USB flash驱动,CompactFlash,MemoryStick,MemoryStick Micro, 以及其他FTL设备都是块设备,而不是单纯的闪存设备。当然,硬件驱动也是块设备。

Block deviceMTD device
Consists of sectorsConsists of eraseblocks
Sectors are small (512, 1024 bytes)Eraseblocks are larger (typically 128KiB)
Maintains 2 main operations: read sector and write sectorMaintains 3 main operations: read from eraseblock, write to eraseblock, and erase eraseblock
Bad sectors are re-mapped and hidden by hardware (at least in modern LBA hard drives); in case of FTL devices it is the responsibility of FTL to provide thisBad eraseblocks are not hidden and should be dealt with in software
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
块设备MTD设备
由扇区(sector)组成由可擦除块组成
扇区很小(512,1024字节)可擦除块很大(典型值128KiB)
主要维护两个操作:读扇区和写扇区主要维护三个操作:读可擦除块,写可擦除块和擦可擦除块
坏的扇区被硬件重映射和隐藏(至少在现代LBA硬盘中是这样的);对于FTL设备,FTL有责任提供该功能坏块没有被隐藏,需要软件来处理
扇区缺乏负载均衡功能(对于FTL设备,FTL有责任提供该功能)可擦除块在大约103(用于MLC NAND)-105(NOR,SLC NAND)擦除周期后磨损、损坏且不可用

So as one sees flashes (MTD devices) are somewhat more difficult to work with.

因此,正如一些人看到的闪存(MTD设备)在某种程度上更难使用。

Can I mount ext2 over an MTD device?

我可以在MTD设备上挂载ext2吗?

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 this, and this FAQ entries.

Ext2, ext3, XFS, JFS, FAT和其他“传统的”文件系统可以与块设备一起工作。它们被设计成这样。flash不是块设备,它们是非常不同的类型。参见上一节。

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 this FAQ entry.

请不要对U盘,MMC,SD,CompactFlash和其他受欢迎的可移动设备感到困惑。虽然它们都被叫做“flash”,但它们并不是MTD设备。它们超出了MTD子系统的范畴。

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).

为了在MTD设备上使用传统文件系统之一,你需要在软件层上,模拟MTD设备上的块设备。这一层通常被叫做“Flash翻译层”(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.

Linux MTD子系统上有一个非常简单的FTL层-mtdblock。它在MTD设备上模拟了块设备。还有一个mtdblock_ro模块,它用来模仿只读的块设备。当你加载这个模块,它为系统中的每一个MTD设备都创建了一个块设备。然后这些块设备就可以通过/dev/mtdblockX设备节点来连接。

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.

但是在许多情况下使用mtdblock是一个非常坏的注意,因为如果你改变了你的mtdblockX设备的任意一页,它会将整个可擦除块都读入内存,擦除可擦除块,改变RAM中对应的页,然后再将数据写会到可擦除块中去。很显然。如果在擦除可擦除块时断电,你就会失去该块的所有数据。flash很可能会很快的衰退,因为你会磨损很少的擦除块(意思是频繁的擦除相同的擦除块,导致这些擦除块很快耗尽了寿命)-很可能是那些包含了FAT/位图/索引节点表等等的擦除块。

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.

但是,创造一个好用的FTL层是一件十分困难的任务,而且还没有人为linux实现这个。但是现在我们有了UBI,在UBI上做这件事情就方便很多了。(see here:http://www.linux-mtd.infradead.org/doc/ubi.html

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.

将mtdblock_ro用于只读文件系统或只读装载是有意义的。比如,你可以使用SquashFS,因为它可以很好的压缩数据。但是在使用mtdblock的读-写模式前要想清楚。而且不要试图在NAND Flash上使用它,因为它不会处理坏块。

What are the point() and unpoint() functions used for?

point()和unpoint()函数用来做什么?

Mainly for NOR flash. As long as the flash is only read, it behaves just like normal memory. The read() function for NOR chips is essentially a memcpy(). For some purposes the extra memcpy() is a waste of time, so things can be optimized.

主要是NOR flash。只要这个flash是只读的,它就表现得像普通的内存。对于NOR芯片来说,read()函数就是memcpy()。处于某些原因,多余的memcpy()是浪费时间,因此可以对其进行优化。

So the point() function does just that, it returns a pointer to the raw flash, so callers can operate directly on the flash.

因此这个point()函数就是这样做的,它返回一个指向原始闪存的指针,因此调用者可以直接对闪存进行操作。

But of course, things are a little more complicated than that. NOR flash chips can be in several different modes and only when in read mode will the above work. Therefore point() also locks the flash chip in addition to returning a pointer. And while locked, writes to the same flash chips have to wait. So callers have to call unpoint() soon after to release the chip again.

当然,实际上会比说的更复杂一些。NOR Flash芯片会处在许多不同的模式,而且只有当处在读模式下时,上述的这些工作才可以展开。因此,point()函数除了返回指针,也会将flash芯片锁住。当芯片被锁住时,写相同的flash芯片就要等待。因此调用者必须在不久之后调用unpoint()来再次释放芯片。

Why do I keep getting errors whenever I try to write to or erase my MTD device?

为什么每次我尝试写/擦除MTD设备都会出现错误?

Some NOR chips power on with all of the eraseblocks in a locked state. The MTD layer doesn't unlock these devices by default. If you are accessing these devices from user-space, you can use the flash_unlock tool to unlock the MTD device(s). If you are using the MTD device as a write-able root file-system you will either need to have the boot loader unlock the eraseblocks before booting the kernel, or add code to the MTD map driver for your board to unlock them.

一些NOR芯片在所有可擦除块处于锁定状态时通电。默认状态下MTD层不锁定这些设备。如果你从用户控件存取这些设备,你可以使用flash_unlock工具来解锁MTD设备。如果你将MTD设备当做可以写的根文件系统,则需要在引导内核之前让引导加载程序解锁擦除块,或者向MTD映射驱动程序添加代码,以便于你的主板解锁擦除块。

Some chips that are known to have this behavior:

一些已知具有此行为的芯片:

ManufacturerPart Number
Intel28FxxxP30
GE28F256L30T

How do I compile the mtd-utils tree?

我要怎么编译mtd-utils树?

The MTD and UBI user-space tools are available from the the following git repository:

从以下的git库可以得到MTD和UBI用户空间工具:

git://git.infradead.org/mtd-utils.git

Source tar balls of the release versions are available from the following ftp directory:

从以下ftp目录可以得到发布版本的源tar ball:

ftp://ftp.infradead.org/pub/mtd-utils/

To compile, first you have to install libraries the tools depend on. You can find the information about mkfs.jffs2 dependencies here and the the information about mkfs.ubifs dependencies here.

想要编译,首先要安装这些工具依赖的库。你可以在这里(http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mkfs_jffs2_comp)找到关于mkfs.jffs2依赖关系的信息,也可以在这里(http://www.linux-mtd.infradead.org/faq/ubifs.html#L_mkfs_ubifs_comp)找到mkfs.ubis依赖关系的信息。

The mtd-utils use an autotools based build system. For the release tar balls, simply run the configure script from the mtd-utils root directory followed by make to build the mtd-utils.

mtd-utils使用基于自动工具的构建系统。对于发行版的tar ball,只需从mtd-utils根目录运行配置脚本,然后运行make来构建mtd-utils。

If you are working on the mtd-utils git-tree, you have to generate the configure script by running the autogen.sh script first.

如果你正在使用mtd-utils git-tree,则必须首先运行autogen.sh脚本来生成配置脚本。

How do I report bugs?

我要怎么报告bugs?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值