转:http://www.linux-mtd.infradead.org/faq/general.html#L_mtd_what

Note, you can find Ukranian translation of this page by Alyona Lompar (alyona.lompar@consultant.com) here. We have not assessed the contents, though.

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?

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

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.

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

The sources of this Web-site are available at git://git.infradead.org/mtd-www.git. Just do your modifications and send the patch to the MTD mailing list.

What are the differences between flash devices and block drives?

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.

Block device MTD device
Consists of sectors Consists of eraseblocks
Sectors are small (512, 1024 bytes) Eraseblocks are larger (typically 128KiB)
Maintains 2 main operations: read sector and write sector Maintains 3 main operations: read from eraseblockwrite 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 this Bad 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

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

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 this, and this 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 this 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 calledFlash 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 usingmtdblock in read-write mode. And don't try to use it on NAND flash as it is does not handle bad eraseblocks.

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

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 extramemcpy() is a waste of time, so things can be optimized.

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

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.

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

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.

Some chips that are known to have this behavior:

Manufacturer Part Number
Intel 28FxxxP30
  GE28F256L30T

How do I compile the mtd-utils tree?

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

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

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.ubifsdependencies here. Once you have these satisfied, you should be able to simply type make from the root mtd-utils directory.

How do I report bugs?

First, you need to figure out what you're reporting a bug against. This website (and its accompanying mailing list) supports several related aspects of Linux, from the MTD kernel subsystem to its user-space utilities, including the generic MTD and NAND interface layers, several MTD hardware drivers, the UBI volume management system, several flash filesystems (e.g., JFFS2, UBIFS), and the user-space MTD utils.

Now, bug reports for any of the above areas are more than welcome on the MTD mailing list, provided you include sufficient information for reproducing and debugging your problem. This means:

  • include all kernel 'oopses', stack traces, debug messages, or relevant logs along with a clear description of the problem you're having, what system(s) are affected, and anything else you think might help people understand your issue;
  • include information about flash parameters found from "mtdinfo -a" (or the less useful info from "cat /proc/mtd");
  • specify which kernel version you are using;
  • specify which mtd-utils version you are using, if applicable. In past releases of mtd-utils, different tools had different versions, so be sure to check the relevant tool (e.g., use "nanddump --version" when reporting bugs involving the nanddump tool); newer releases give the same version to most/all the tools.

Please, do not send private e-mails to MTD maintainers; always CC the mailing list!

You may also want to read one of the other related FAQs:

The MTD community may help support the YAFFS/YAFFS2 filesystems; however, YAFFS has its own dedicated website and mailing list, and its code is not kept in the mainstream Linux kernel tree. Thus, any support you receive here will be limited, and you should contact YAFFS maintainers with real YAFFS bug reports.

Is an MTD device a block device or a char device?的更多相关文章

  1. Linux MTD (Memory Technology Device) subsystem analysis -For Atheros char device

    Linux MTD (Memory Technology Device) subsystem analysis For Atheros char device 读了Linux MTD 源代码分析 对这 ...

  2. <<linux device driver,third edition>> Chapter 3:Char Drivers

    The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...

  3. USB Compound Device,USB复合设备 ; USB Composite Device,USB组合设备【转】

    本文转载自:https://blog.csdn.net/autumn20080101/article/details/52776863 科普下USB复合设备和USB组合设备的区别. 关键字 Commu ...

  4. char device

    /** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for f ...

  5. 字符设备 Vs. 块设备 Character Device Vs. Block Device

    字符设备是指驱动发送/接受单个字符(例如字节)的设备. 块设备是指驱动发送/接受整块数据(例如512个字节为一个块)的设备. 常见的字符设备:串口,并口,声卡. 常见的块设备:硬盘(最小读取单位为扇区 ...

  6. VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti

    出现问题的原因: 原因一.出现此问题的原因是Device Guard或Credential Guard与Workstation不兼容. 原因二.Windows系统的Hyper-V不兼容导致. 解决方案 ...

  7. Char device registration

    The kernel uses structures of type struct cdev to represent char devices internally. Include <lin ...

  8. linux kernel系列四:嵌入式系统中的文件系统以及MTD

    本节介绍File System和MTD技术 一 FS 熟知的FS有ext2,3,4.但是这些都是针对磁盘设备的.而ES中一般的存储设备为Flash,由于Flash的特殊性: Flash存储按照Bloc ...

  9. 【转】刚发现一个linux在线文档库。很好很强大。

    原文网址:http://blog.csdn.net/longxibendi/article/details/6048231 1.网址: http://www.mjmwired.net 2.比如查看这个 ...

随机推荐

  1. mysql cluster 名词概念解读

    Node Group [number_of_node_groups] = number_of_data_nodes / NoOfReplicas Partition When using ndbd, ...

  2. 【转】MySQL日期时间函数大全

    MySQL日期时间函数大全 1.DAYOFWEEK(date)  返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)mysql> select DAYOFWEEK( ...

  3. svn's diff command

    [svn's diff command] svn diff 比较的是版本快照, 跟merge的应用diff完全不一样. 缺省情况下,svn diff忽略文件的祖先,只会比较两个文件的内容.如果你使用- ...

  4. C++中使用接口

    面向对象的语言诸如JAVA提供了Interface来实现接口,但C++却没有这样一个东西,尽管C++ 通过纯虚基类实现接口,譬如COM的C++实现就是通过纯虚基类实现的(当然MFC的COM实现用了嵌套 ...

  5. 数据结构——图——最短路径D&F算法

    一.Dijkstra算法(贪心地求最短距离的算法) 在此算法中,我按照自己的理解去命名,理解起来会轻松一些. #define MAXSIZE 100 #define UNVISITED 0 #defi ...

  6. css3 前缀

  7. Gartner: Hype Cycle for Emerging Technologies-2012 (技术成熟度曲线) [转]

      英文稿: The “Hype Cycle for Emerging Technologies” report is the longest-running annual Hype Cycle, p ...

  8. easyui combobox筛选(拼音)

    1.combobox本身的筛选 $('#cc').combobox({ filter: function(q, row){ var opts = $(this).combobox('options') ...

  9. JS获取URL参数 方法

    function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = qu ...

  10. sc7731 Android 5.1 LCD驱动简明笔记之二

    此篇笔记基于sc7731 - android 5.1,对lcd的framebuffer做一个简明笔记. 一共分为两大部分:第一部分,关于LCD的硬件方面的:第二部分,关于lcd核心处理(framebu ...