Is an MTD device a block device or a char device?
转: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
- Is an MTD device a block device or a char device?
- I'd like to add/change/fix information on this Web-site - how?
- What are the differences between flash devices and block drives?
- Can I mount ext2 over an MTD device?
- What are the point() and unpoint() functions used for?
- Why do I keep getting errors whenever I try to write to or erase my MTD device?
- How do I compile the mtd-utils tree?
- 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 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 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.ubifs
dependencies 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 thenanddump
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?的更多相关文章
- Linux MTD (Memory Technology Device) subsystem analysis -For Atheros char device
Linux MTD (Memory Technology Device) subsystem analysis For Atheros char device 读了Linux MTD 源代码分析 对这 ...
- <<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 ...
- USB Compound Device,USB复合设备 ; USB Composite Device,USB组合设备【转】
本文转载自:https://blog.csdn.net/autumn20080101/article/details/52776863 科普下USB复合设备和USB组合设备的区别. 关键字 Commu ...
- char device
/** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for f ...
- 字符设备 Vs. 块设备 Character Device Vs. Block Device
字符设备是指驱动发送/接受单个字符(例如字节)的设备. 块设备是指驱动发送/接受整块数据(例如512个字节为一个块)的设备. 常见的字符设备:串口,并口,声卡. 常见的块设备:硬盘(最小读取单位为扇区 ...
- VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti
出现问题的原因: 原因一.出现此问题的原因是Device Guard或Credential Guard与Workstation不兼容. 原因二.Windows系统的Hyper-V不兼容导致. 解决方案 ...
- Char device registration
The kernel uses structures of type struct cdev to represent char devices internally. Include <lin ...
- linux kernel系列四:嵌入式系统中的文件系统以及MTD
本节介绍File System和MTD技术 一 FS 熟知的FS有ext2,3,4.但是这些都是针对磁盘设备的.而ES中一般的存储设备为Flash,由于Flash的特殊性: Flash存储按照Bloc ...
- 【转】刚发现一个linux在线文档库。很好很强大。
原文网址:http://blog.csdn.net/longxibendi/article/details/6048231 1.网址: http://www.mjmwired.net 2.比如查看这个 ...
随机推荐
- Supports BorlandIDEServices
Delphi: procedure SetKeystrokeDebugging(Debugging: Boolean); var Dialog: IOTAKeyboardDiagnostics beg ...
- CentOS(RedHat) 6.2 Samba share权限拒绝访问
在实现<CentOS(RedHat) 6.2下Samba配置>的过程中,发现CentOS 6.2的Samba share总是没有权限写文件,已经试过在Windows XP/Windows ...
- POJ 2653 Pick-up sticks(判断线段相交)
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7699 Accepted: 2843 De ...
- Liunx更新源
不同的网络状况连接以下源的速度不同, 建议在添加前手动验证以下源的连接速度(ping下就行),选择最快的源可以节省大批下载时间. 首先备份源列表: sudo cp /etc/apt/sources.l ...
- 关于缺省路由传递问题的探讨(下)[ip default-network、ip default-gateway等]
之前文章介绍的是没有路由协议的环境下,那么在有路由协议的环境下: ip default-network IGRP/EIGRP: IP Default-Network所指定的网络必须在EIGRP进程中通 ...
- svn如何回滚到之前版本
第一种情况:改动没有被提交(commit). 这种情况下,使用svn revert就能取消之前的修改. svn revert用法如下: # svn revert [-R] something 其中so ...
- 在ASP.NET MVC中验证checkbox 必须选中 (Validation of required checkbox in Asp.Net MVC)
转载自 http://blog.degree.no/2012/03/validation-of-required-checkbox-in-asp-net-mvc/ Why would you want ...
- Remove Duplicates from Sorted List @LeetCode
/** * Remove Duplicates from Sorted List * * Given a sorted linked list, delete all duplicates such ...
- spring中文乱码过滤器
中文乱码过滤器 在您通过表单向服务器提交数据时,一个经典的问题就是中文乱码问题.虽然我们所有的 JSP 文件和页面编码格式都采用 UTF-8,但这个问题还是会出现.解决的办法很简单,我们只需要在 we ...
- M站 confirm 插件
/*弹出提示*/.pop-error{position:absolute; left:25%; top:50%; width:200px; FILTER: progid:DXImageTransfor ...