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

时间:2014-04-18 12:39:11   收藏:0   阅读:837

本节介绍File System和MTD技术

一 FS

熟知的FS有ext2,3,4.但是这些都是针对磁盘设备的。而ES中一般的存储设备为Flash,由于Flash的特殊性:

所以,针对FLASH的特性,整出了一个Journaling Flash File System(JFFS2,第二版)。它的特点就是:

(apt-get install mtd-tools,下载不少好工具,另外,可见往flash设备写log,可能会导致flash短命喔)

一些伪文件系统:proc/sysfs,systool工具用来分析sysfs。

ES中常用的FS还有ramfs/rootfs/tmpfs,都是基于内存的FS。这个和前面讲的initramfs有什么关系?实际上这些是基于Initramfs的。

这里要解释一下几个比如容易混淆的东西:

下面介绍一下如何利用mount loop创建一个虚拟的基于文件的BLOCK设备。

二 MTD技术

MTD全称是Memory Technology Device,内存技术设备?实际上是一个虚拟设备驱动层,类似Virtual File System。它提供标准API给那些操作Raw Flash的device driver。那么Flash device和普通的Block device的区别是什么呢?

这里要重点指出的是:

SD/MMC卡、CF(Compact Flash)卡、USB Flash等并不是MTD设备,因为这些设备中已经有一个内置的Flash Translation Layer,这个layer处理erase、wear leveling事情了(这个TL应该是固件中支持的)。所以这些设备直接当做普通的Block Device使用

(上面的描述还是没能说清楚MTD到底是怎么用的,以后会结合源码分析一下)

2.1 内核中启用MTD支持

这个很简单,make menuconfig的时候打开就行了,有好几个选项。

bubuko.com,布布扣

图1 LK中MTD支持的配置选项

其中:

ES中又如何配置MTD及其相关的东西呢?

下面先看看分区的设置

可对Flash分区,这里有一些稍微重要的内容:如何把Flash分区的信息传递给LK呢?有两种方法:

图2

再看看Driver的Mapping,也就是将MTD和对应的Flash Driver配对...

kernel/drivers/mtd/maps......,以后要分析

Flash芯片本身的Driver呢?

kernel/drivers/mtd/chips,目前比较流行的是CFI接口

三 一些参考资料和补充知识

http://www.linux-mtd.infradead.org/

MTD的本意是:

We‘re working on a generic Linux subsystem for memory devices, especially Flash devices.
The aim of the system is to make it simple to provide a driver for new hardware, by providing a generic interface between the hardware drivers and the upper layers of the system.
Hardware drivers need to know nothing about the storage formats used, such as FTL, FFS2, etc., but will only need to provide simple routines for read, write and erase. Presentation of the device‘s contents to the user in an appropriate form will be handled by the upper layers of the system.

MTD overview
MTD subsystem (stands for Memory Technology Devices) provides an abstraction layer for raw flash devices. It makes it possible to use the same API when working with different flash types and technologies, e.g. NAND, OneNAND, NOR, AG-AND, ECC‘d NOR, etc.
MTD subsystem does not deal with block devices like MMC, eMMC, SD, CompactFlash, etc. These devices are not raw flashes but they have a Flash Translation layer inside, which makes them look like block devices. These devices are the subject of the Linux block subsystem, not MTD. Please, refer to this FAQ section for a short list of the main differences between block and MTD devices. And the raw flash vs. FTL devices UBIFS section discusses this in more details.
MTD subsystem has the following interfaces.

Additionally, MTD supports legacy FTL/NFTL "translation layers", M-Systems‘ DiskOnChip 2000 and Millennium chips, and PCMCIA flashes (pcmciamtd driver). But the corresponding drivers are very old and not maintained very much.

MTD Block Driver:

The mtdblock driver available in the MTD is an archaic tool which emulates block devices on top of MTD devices. It does not even have bad eraseblock handling, so it is not really usable with NAND flashes. And it works by caching a whole flash erase block in RAM, modifying it as requested, then erasing the whole block and writing back the modified. This means that mtdblock does not try to do any optimizations, and that you will lose lots of data in case of power cuts. And last, but not least, mtdblock does not do any wear-leveling.
Often people consider mtdblock as general FTL layer and try to use block-based file systems on top of bare flashes using mtdblock. This is wrong in most cases. In other words, please, do not use mtdblock unless you know exactly what you are doing.
There is also a read-only version of this driver which doesn‘t have the capacity to do the caching and erase/writeback, mainly for use with uCLinux where the extra RAM requirement was considered too large

These are the modules which provide interfaces that can be used directly from userspace. The user modules currently planned include:

这里牵扯到NOR和NAND,那么二者有啥区别呢?

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.

linux kernel系列四:嵌入式系统中的文件系统以及MTD,布布扣,bubuko.com

原文:http://www.cnblogs.com/xmphoenix/p/3672031.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!