diff options
author | Artem B. Bityutskiy <dedekind@linutronix.de> | 2006-06-27 04:22:22 -0400 |
---|---|---|
committer | Frank Haverkamp <haver@vnet.ibm.com> | 2007-04-27 07:23:33 -0400 |
commit | 801c135ce73d5df1caf3eca35b66a10824ae0707 (patch) | |
tree | eaf6e7859650557192533b70746479de686c56e1 /include/mtd/ubi-user.h | |
parent | de46c33745f5e2ad594c72f2cf5f490861b16ce1 (diff) |
UBI: Unsorted Block Images
UBI (Latin: "where?") manages multiple logical volumes on a single
flash device, specifically supporting NAND flash devices. UBI provides
a flexible partitioning concept which still allows for wear-levelling
across the whole flash device.
In a sense, UBI may be compared to the Logical Volume Manager
(LVM). Whereas LVM maps logical sector numbers to physical HDD sector
numbers, UBI maps logical eraseblocks to physical eraseblocks.
More information may be found at
http://www.linux-mtd.infradead.org/doc/ubi.html
Partitioning/Re-partitioning
An UBI volume occupies a certain number of erase blocks. This is
limited by a configured maximum volume size, which could also be
viewed as the partition size. Each individual UBI volume's size can
be changed independently of the other UBI volumes, provided that the
sum of all volume sizes doesn't exceed a certain limit.
UBI supports dynamic volumes and static volumes. Static volumes are
read-only and their contents are protected by CRC check sums.
Bad eraseblocks handling
UBI transparently handles bad eraseblocks. When a physical
eraseblock becomes bad, it is substituted by a good physical
eraseblock, and the user does not even notice this.
Scrubbing
On a NAND flash bit flips can occur on any write operation,
sometimes also on read. If bit flips persist on the device, at first
they can still be corrected by ECC, but once they accumulate,
correction will become impossible. Thus it is best to actively scrub
the affected eraseblock, by first copying it to a free eraseblock
and then erasing the original. The UBI layer performs this type of
scrubbing under the covers, transparently to the UBI volume users.
Erase Counts
UBI maintains an erase count header per eraseblock. This frees
higher-level layers (like file systems) from doing this and allows
for centralized erase count management instead. The erase counts are
used by the wear-levelling algorithm in the UBI layer. The algorithm
itself is exchangeable.
Booting from NAND
For booting directly from NAND flash the hardware must at least be
capable of fetching and executing a small portion of the NAND
flash. Some NAND flash controllers have this kind of support. They
usually limit the window to a few kilobytes in erase block 0. This
"initial program loader" (IPL) must then contain sufficient logic to
load and execute the next boot phase.
Due to bad eraseblocks, which may be randomly scattered over the
flash device, it is problematic to store the "secondary program
loader" (SPL) statically. Also, due to bit-flips it may become
corrupted over time. UBI allows to solve this problem gracefully by
storing the SPL in a small static UBI volume.
UBI volumes vs. static partitions
UBI volumes are still very similar to static MTD partitions:
* both consist of eraseblocks (logical eraseblocks in case of UBI
volumes, and physical eraseblocks in case of static partitions;
* both support three basic operations - read, write, erase.
But UBI volumes have the following advantages over traditional
static MTD partitions:
* there are no eraseblock wear-leveling constraints in case of UBI
volumes, so the user should not care about this;
* there are no bit-flips and bad eraseblocks in case of UBI volumes.
So, UBI volumes may be considered as flash devices with relaxed
restrictions.
Where can it be found?
Documentation, kernel code and applications can be found in the MTD
gits.
What are the applications for?
The applications help to create binary flash images for two purposes: pfi
files (partial flash images) for in-system update of UBI volumes, and plain
binary images, with or without OOB data in case of NAND, for a manufacturing
step. Furthermore some tools are/and will be created that allow flash content
analysis after a system has crashed..
Who did UBI?
The original ideas, where UBI is based on, were developed by Andreas
Arnez, Frank Haverkamp and Thomas Gleixner. Josh W. Boyer and some others
were involved too. The implementation of the kernel layer was done by Artem
B. Bityutskiy. The user-space applications and tools were written by Oliver
Lohmann with contributions from Frank Haverkamp, Andreas Arnez, and Artem.
Joern Engel contributed a patch which modifies JFFS2 so that it can be run on
a UBI volume. Thomas Gleixner did modifications to the NAND layer. Alexander
Schmidt made some testing work as well as core functionality improvements.
Signed-off-by: Artem B. Bityutskiy <dedekind@linutronix.de>
Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
Diffstat (limited to 'include/mtd/ubi-user.h')
-rw-r--r-- | include/mtd/ubi-user.h | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h new file mode 100644 index 000000000000..fe06ded0e6b8 --- /dev/null +++ b/include/mtd/ubi-user.h | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * Copyright (c) International Business Machines Corp., 2006 | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
12 | * the GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | * | ||
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | ||
19 | */ | ||
20 | |||
21 | #ifndef __UBI_USER_H__ | ||
22 | #define __UBI_USER_H__ | ||
23 | |||
24 | /* | ||
25 | * UBI volume creation | ||
26 | * ~~~~~~~~~~~~~~~~~~~ | ||
27 | * | ||
28 | * UBI volumes are created via the %UBI_IOCMKVOL IOCTL command of UBI character | ||
29 | * device. A &struct ubi_mkvol_req object has to be properly filled and a | ||
30 | * pointer to it has to be passed to the IOCTL. | ||
31 | * | ||
32 | * UBI volume deletion | ||
33 | * ~~~~~~~~~~~~~~~~~~~ | ||
34 | * | ||
35 | * To delete a volume, the %UBI_IOCRMVOL IOCTL command of the UBI character | ||
36 | * device should be used. A pointer to the 32-bit volume ID hast to be passed | ||
37 | * to the IOCTL. | ||
38 | * | ||
39 | * UBI volume re-size | ||
40 | * ~~~~~~~~~~~~~~~~~~ | ||
41 | * | ||
42 | * To re-size a volume, the %UBI_IOCRSVOL IOCTL command of the UBI character | ||
43 | * device should be used. A &struct ubi_rsvol_req object has to be properly | ||
44 | * filled and a pointer to it has to be passed to the IOCTL. | ||
45 | * | ||
46 | * UBI volume update | ||
47 | * ~~~~~~~~~~~~~~~~~ | ||
48 | * | ||
49 | * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the | ||
50 | * corresponding UBI volume character device. A pointer to a 64-bit update | ||
51 | * size should be passed to the IOCTL. After then, UBI expects user to write | ||
52 | * this number of bytes to the volume character device. The update is finished | ||
53 | * when the claimed number of bytes is passed. So, the volume update sequence | ||
54 | * is something like: | ||
55 | * | ||
56 | * fd = open("/dev/my_volume"); | ||
57 | * ioctl(fd, UBI_IOCVOLUP, &image_size); | ||
58 | * write(fd, buf, image_size); | ||
59 | * close(fd); | ||
60 | */ | ||
61 | |||
62 | /* | ||
63 | * When a new volume is created, users may either specify the volume number they | ||
64 | * want to create or to let UBI automatically assign a volume number using this | ||
65 | * constant. | ||
66 | */ | ||
67 | #define UBI_VOL_NUM_AUTO (-1) | ||
68 | |||
69 | /* Maximum volume name length */ | ||
70 | #define UBI_MAX_VOLUME_NAME 127 | ||
71 | |||
72 | /* IOCTL commands of UBI character devices */ | ||
73 | |||
74 | #define UBI_IOC_MAGIC 'o' | ||
75 | |||
76 | /* Create an UBI volume */ | ||
77 | #define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req) | ||
78 | /* Remove an UBI volume */ | ||
79 | #define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t) | ||
80 | /* Re-size an UBI volume */ | ||
81 | #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req) | ||
82 | |||
83 | /* IOCTL commands of UBI volume character devices */ | ||
84 | |||
85 | #define UBI_VOL_IOC_MAGIC 'O' | ||
86 | |||
87 | /* Start UBI volume update */ | ||
88 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t) | ||
89 | /* An eraseblock erasure command, used for debugging, disabled by default */ | ||
90 | #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t) | ||
91 | |||
92 | /* | ||
93 | * UBI volume type constants. | ||
94 | * | ||
95 | * @UBI_DYNAMIC_VOLUME: dynamic volume | ||
96 | * @UBI_STATIC_VOLUME: static volume | ||
97 | */ | ||
98 | enum { | ||
99 | UBI_DYNAMIC_VOLUME = 3, | ||
100 | UBI_STATIC_VOLUME = 4 | ||
101 | }; | ||
102 | |||
103 | /** | ||
104 | * struct ubi_mkvol_req - volume description data structure used in | ||
105 | * volume creation requests. | ||
106 | * @vol_id: volume number | ||
107 | * @alignment: volume alignment | ||
108 | * @bytes: volume size in bytes | ||
109 | * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) | ||
110 | * @padding1: reserved for future, not used | ||
111 | * @name_len: volume name length | ||
112 | * @padding2: reserved for future, not used | ||
113 | * @name: volume name | ||
114 | * | ||
115 | * This structure is used by userspace programs when creating new volumes. The | ||
116 | * @used_bytes field is only necessary when creating static volumes. | ||
117 | * | ||
118 | * The @alignment field specifies the required alignment of the volume logical | ||
119 | * eraseblock. This means, that the size of logical eraseblocks will be aligned | ||
120 | * to this number, i.e., | ||
121 | * (UBI device logical eraseblock size) mod (@alignment) = 0. | ||
122 | * | ||
123 | * To put it differently, the logical eraseblock of this volume may be slightly | ||
124 | * shortened in order to make it properly aligned. The alignment has to be | ||
125 | * multiple of the flash minimal input/output unit, or %1 to utilize the entire | ||
126 | * available space of logical eraseblocks. | ||
127 | * | ||
128 | * The @alignment field may be useful, for example, when one wants to maintain | ||
129 | * a block device on top of an UBI volume. In this case, it is desirable to fit | ||
130 | * an integer number of blocks in logical eraseblocks of this UBI volume. With | ||
131 | * alignment it is possible to update this volume using plane UBI volume image | ||
132 | * BLOBs, without caring about how to properly align them. | ||
133 | */ | ||
134 | struct ubi_mkvol_req { | ||
135 | int32_t vol_id; | ||
136 | int32_t alignment; | ||
137 | int64_t bytes; | ||
138 | int8_t vol_type; | ||
139 | int8_t padding1; | ||
140 | int16_t name_len; | ||
141 | int8_t padding2[4]; | ||
142 | char name[UBI_MAX_VOLUME_NAME+1]; | ||
143 | } __attribute__ ((packed)); | ||
144 | |||
145 | /** | ||
146 | * struct ubi_rsvol_req - a data structure used in volume re-size requests. | ||
147 | * @vol_id: ID of the volume to re-size | ||
148 | * @bytes: new size of the volume in bytes | ||
149 | * | ||
150 | * Re-sizing is possible for both dynamic and static volumes. But while dynamic | ||
151 | * volumes may be re-sized arbitrarily, static volumes cannot be made to be | ||
152 | * smaller then the number of bytes they bear. To arbitrarily shrink a static | ||
153 | * volume, it must be wiped out first (by means of volume update operation with | ||
154 | * zero number of bytes). | ||
155 | */ | ||
156 | struct ubi_rsvol_req { | ||
157 | int64_t bytes; | ||
158 | int32_t vol_id; | ||
159 | } __attribute__ ((packed)); | ||
160 | |||
161 | #endif /* __UBI_USER_H__ */ | ||