Chinaunix首页 | 论坛 | 博客
  • 博客访问: 698557
  • 博文数量: 130
  • 博客积分: 2192
  • 博客等级: 大尉
  • 技术积分: 1410
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-31 15:37
文章分类

全部博文(130)

文章存档

2013年(1)

2012年(4)

2011年(27)

2010年(97)

2009年(1)

分类: 嵌入式

2010-11-21 14:50:38

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.

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.


载自 :


//===================================================

NAND vs. NOR

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 ByteFast Slow
Program Time multi ByteSlow 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 NoAllowed

载自:
//======================================================

NOR & NAND

物理结构:
●NAND Flash把整个memory分成若干个Block,一个Block包含若干个Page,一个Page又包含512(+16)Byte或 2048(+64)Byte. 以Toshiba的TC58NWM9S3B NAND flash为例,它的容量是512Mbits,它总共有512个Block, 一个Block包含64个Page,而一个page是(2048+64)Byte.
查看更多精彩图片

查看更多精彩图片


●NOR Flash把整个memory分成若干个Sector.

Program & Erase:
●NOR和NAND flash的program都只能将数据位从1写到0,而不能将0写成1,所以在对flash进行写入之前必须对flash进行erase操作。
●NOR 和NAND flash的erase操作就是将某一擦除块的内容都写成1,擦写操作的最小单位是一个区块(NAND:block, NOR:sector或block),而不能是单个字节。NOR flash的erase通常包括两种,sector/block erase(块擦除), chip erase(芯片擦除);块擦除就是把某一擦除块的内容写成1,而芯片擦除则是把整个flash的内容都变成1。

操作指令:
●NOR Flash 除了读,其它的操作都不能像RAM那样直接对目标地址进行总线操作, 而是必须输入一串特殊的指令才能擦除或将数据写入到NOR Flash中.
●NAND Flash 的所有操作也是需要输入特定的命令(command)才能完成的.还是以Toshiba的TC58NWM9S3B NAND flash为例,
Page Program:     80h(CMD),     Column Address M(页内偏移地址), Page Address N, Data, 1    0h(CMD)
block erase:         60h(CMD),     Block address input:2cycle,     D0h(erase start cmd)
read:                    00h(CMD),     Column Address M, Page Address N,     30h(CMD)
ID read :              90h(ID Read CMD),     00h(Address 00)
status read:          70h(CMD)
Reset:                  FF(CMD)

NOR flash spec 摘要

if a program/erase operation fails, the device remains in the programming/erasing state and does not automatically return to Read Mode, In this case, either a software reset or a hardware reset is required to return the device to Read Mode.
   
DQ7(Data#Polling)
during program operation, DQ7 outputs the complement of the data.
when program operation completed, DQ7 outputs the data.
during erase operation, DQ7 outputs 0.
when erase operation completed, DQ7 outputs 1.
if program or erase operation fails, DQ7 outputs the data.

DQ6 (Toggle bit 1)


DQ5 (time-out)
if program or erase operates normally, DQ5 outputs 0.
if the internal timer times out during program or erase operation (indicates that the operation

has not been completed ), DQ5 outputs 1.
any attempt to program a 1 into a cell containing a 0 will fail (only erase operation can

change 0 back to 1), DQ5 outputs 1.

NOTE: In the case of internal time-out, reset command is required to return the device to Read 
mode.

DQ3 (Sector/Block Erase)
if sector/block erase operation starts, DQ3 outputs 1.

DQ2 (Toggle bit 2)


载自: http://blog.chinaunix.net/u2/70445/showart_1674219.html
//======================================================
从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(raw flash, DOC/DOM/CF)------

载自:http://hi.baidu.com/hilyjiang/blog/item/804165e73d857b2fb8382067.html
//======================================================

FLASH MEMORY wiki
载自:
阅读(5797) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

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