原文参考: http://www.linux-mtd.infradead.org/doc/ubi.html
Note:
People are often confused about what UBI is, which was the reason for creating this section. Please, realize that:
MMC
, RS-MMC
, eMMC
, SD
, mini-SD
, micro-SD
, CompactFlash
, MemoryStick
, USB flash drive
, etc; instead, UBI works with raw flash devices, which are mostly found in embedded devices like mobile phones, etc.人们经常对UBI到底是什么感到迷惑, 这是本说明存在的原因, 你需要知道:
1. Overview
UBI (Latin: "where?") stands for "Unsorted Block Images". It is a volume management system for raw flash devices which manages multiple logical volumes on a single physical flash device and spreads the I/O load (i.e, wear-leveling) across whole flash chip.
UBI 代表 "Unsorted Block Images", 它是一个为flash裸设备设计的卷管理系统,该系统管理单个flash设备上的多个逻辑卷, 在整个设备范围内平衡I/O负载。
In a sense, UBI may be compared to the Logical Volume Manager (LVM). Whereas LVM maps logical sectors to physical sectors, UBI maps logical eraseblocks to physical eraseblocks. But besides the mapping, UBI implements global wear-leveling and transparent I/O errors handling.
在某种意义上, UBI类似我们熟悉的 Logical Volume Manager(LVM). LVM 管理硬盘这类块设备, 映射逻辑扇区到物理扇区; 而 UBI 映射逻辑擦除块到物理擦除块。 但是, 由于flash设备自身的特点, UBI 还实现了全局耗损平均功能和对用户透明的 I/O 错误处理功能。
An UBI volume is a set of consecutive logical eraseblocks (LEBs). Each logical eraseblock may be mapped to any physical eraseblock (PEB). This mapping is managed by UBI, it is hidden from users and it is the base mechanism to provide global wear-leveling (along with per-physical eraseblock erase counters and the ability to transparently move data from more worn-out physical eraseblocks to less worn-out ones).
UBI卷是一组连续的逻辑擦除块(LEB), 每一个LEB都可以映射到任何物理擦除块(PEB), 这种映射由 UBI 管理, 这一点是对用户隐藏的, 也是提供耗损平均功能的基本机制。 (耗损平均主要是对物理擦除块的擦除次数计数, 并透明的把数据从过度使用擦除块移动到较少使用的擦除块, 从而使在整个flash全局范围内擦除块的损耗比较接近, 提高寿命)
UBI volume size is specified when the volume is created and may later be changed (volumes are dynamically re-sizable). There are user-space tools which may be used to manipulate UBI volumes.
UBI 卷尺寸在卷创建时指定, 需要时可以重新调整, 有对应的用户空间工具可以用来操作 UBI 卷。
There are 2 types of UBI volumes - dynamic volumes and static volumes. Static volumes are read-only and their contents are protected by CRC-32
checksums, while dynamic volumes are read-write and the upper layers (e.g., a file-system) are responsible for ensuring data integrity.
有两种类型的UBI卷: 动态卷和静态卷。 静态卷是只读的, 存储的内容使用 CRC32 保护; 动态卷是可读写的, 由卷上建立的文件系统保证数据的完整性。
UBI is aware of bad eraseblocks (e.g., NAND flash may have them) and frees the upper layers from any bad block handling. UBI has a pool of reserved physical eraseblocks, and when a physical eraseblock becomes bad, it transparently substitutes it with a good physical eraseblock. UBI moves good data from the newly appeared bad physical eraseblocks to good ones. The result is that users of UBI volumes do not notice I/O errors as UBI takes care of them.
UBI 能够检测坏的擦除块 (例如, Nand flash 可能存在), 可使上层的文件系统免于处理坏块。 UBI 有一个预留的块池, 当发现坏块之后, 就对用户透明的使用好的块替换, 把好的数据从坏块搬运到这些好块中。 这样, UBI 卷的用户不会收到I/O错误, 因为UBI已经处理了。
NAND flashes may have bit-flips which occur on read and write operations. Bit-flips are corrected by ECC checksums, but they may accumulate over time and cause data loss. UBI handles this by moving data from physical eraseblocks which have bit-flips to other physical eraseblocks. This process is called scrubbing. Scrubbing is done transparently in background and is hidden from upper layers.
NAND flash 在进行读写操作时可能出现 bit-flips, 这种错误使用ECC校验进行纠正, 但由于过度累积而引起数据丢失。 针对这个问题, UBI 把出现bit-flips的擦除块中的数据移动到其它物理块中,这种处理称为scrubbing. Scrubbing 是在后台进行的, 对上层用户隐藏。
Here is a short list of the main UBI features:
下面是UBI 主要特性的列表:
Here is a comparison of MTD partitions and UBI volumes. They are somewhat because:
下面会给出 MTD 分区 与 UBI 卷的对比, 它们有可比性, 是因为:
But UBI volumes have the following advantages over MTD partitions:
但是, UBI 比 MTD分区有下列优势:
There is an additional driver called gluebi
which emulates MTD devices on top of UBI volumes. This looks a little strange, because UBI works on top of an MTD device, then gluebi
emulates other MTD devices on top, but this actually works and makes it possible for existing software (e.g., JFFS2) to run on top of UBI volumes. However, new software may benefit from the advanced UBI features and let UBI solve many issues which the flash technology imposes.
UBI 还提供一个额外的驱动, 称为gluebi, 用于在UBI卷之上模拟 MTD设备。 这看起来比较奇怪, 因为 UBI 工作在 MTD 设备上, gluebi 却在其上模拟其它MTD设备, 但这对于现有的软件运行在UBI卷上是有用的, 比如 JFFS2。 而新软件则可以从 高级 UBI 特性中受益, 由 UBI 解决flash技术存在问题。
2. Source Code
2.6.22
. But it is recommended to use the latest UBI, because we have fixed many bugs since that time, made many improvements and added new features. The UBI git tree may be found at:
git://git.infradead.org/ubi-2.6.git
UBI 从 Linux Kernel 2.6.22开始加入到 linux 主线分支, 但推荐使用最新的UBI, 因为从那时以来我们已经解决了很多bug, 做了很多改善, 添加了新特性。 UBI git 源参见: git://git.infradead.org/ubi-2.6.git
The git tree has 2 branches - the master
branch and linux-next
branches. The master
branch contains the most recent stuff which is often incomplete, buggy, or has not been tested very well. This branch is re-based from time to time. Please, do not use it unless you are an UBI developer. The linux-next
branch contains stable UBI changes which are going to be merged upstream soon. This branch is included to the linux-next git tree. Please, use this branch unless you are an UBI developer.
UBI Git 库中有两个分支: master分支和 linux-next 分支。
master分支含有大部分最近的最新成果, 但经常不完整, 有bug, 甚至没有充分测试; 该分支随时会更改, 所以请不要使用该分支, 除非你是 UBI 开发者。
linux-next 分支含有稳定的代码, 这个是可以合并到linux中的, 推荐使用该分支。