aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mtd/ubi.h
diff options
context:
space:
mode:
authorArtem B. Bityutskiy <dedekind@linutronix.de>2006-06-27 04:22:22 -0400
committerFrank Haverkamp <haver@vnet.ibm.com>2007-04-27 07:23:33 -0400
commit801c135ce73d5df1caf3eca35b66a10824ae0707 (patch)
treeeaf6e7859650557192533b70746479de686c56e1 /include/linux/mtd/ubi.h
parentde46c33745f5e2ad594c72f2cf5f490861b16ce1 (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/linux/mtd/ubi.h')
-rw-r--r--include/linux/mtd/ubi.h202
1 files changed, 202 insertions, 0 deletions
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
new file mode 100644
index 000000000000..3d967b6b120a
--- /dev/null
+++ b/include/linux/mtd/ubi.h
@@ -0,0 +1,202 @@
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 __LINUX_UBI_H__
22#define __LINUX_UBI_H__
23
24#include <asm/ioctl.h>
25#include <linux/types.h>
26#include <mtd/ubi-user.h>
27
28/*
29 * UBI data type hint constants.
30 *
31 * UBI_LONGTERM: long-term data
32 * UBI_SHORTTERM: short-term data
33 * UBI_UNKNOWN: data persistence is unknown
34 *
35 * These constants are used when data is written to UBI volumes in order to
36 * help the UBI wear-leveling unit to find more appropriate physical
37 * eraseblocks.
38 */
39enum {
40 UBI_LONGTERM = 1,
41 UBI_SHORTTERM,
42 UBI_UNKNOWN
43};
44
45/*
46 * enum ubi_open_mode - UBI volume open mode constants.
47 *
48 * UBI_READONLY: read-only mode
49 * UBI_READWRITE: read-write mode
50 * UBI_EXCLUSIVE: exclusive mode
51 */
52enum {
53 UBI_READONLY = 1,
54 UBI_READWRITE,
55 UBI_EXCLUSIVE
56};
57
58/**
59 * struct ubi_volume_info - UBI volume description data structure.
60 * @vol_id: volume ID
61 * @ubi_num: UBI device number this volume belongs to
62 * @size: how many physical eraseblocks are reserved for this volume
63 * @used_bytes: how many bytes of data this volume contains
64 * @used_ebs: how many physical eraseblocks of this volume actually contain any
65 * data
66 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
67 * @corrupted: non-zero if the volume is corrupted (static volumes only)
68 * @upd_marker: non-zero if the volume has update marker set
69 * @alignment: volume alignment
70 * @usable_leb_size: how many bytes are available in logical eraseblocks of
71 * this volume
72 * @name_len: volume name length
73 * @name: volume name
74 * @cdev: UBI volume character device major and minor numbers
75 *
76 * The @corrupted flag is only relevant to static volumes and is always zero
77 * for dynamic ones. This is because UBI does not care about dynamic volume
78 * data protection and only cares about protecting static volume data.
79 *
80 * The @upd_marker flag is set if the volume update operation was interrupted.
81 * Before touching the volume data during the update operation, UBI first sets
82 * the update marker flag for this volume. If the volume update operation was
83 * further interrupted, the update marker indicates this. If the update marker
84 * is set, the contents of the volume is certainly damaged and a new volume
85 * update operation has to be started.
86 *
87 * To put it differently, @corrupted and @upd_marker fields have different
88 * semantics:
89 * o the @corrupted flag means that this static volume is corrupted for some
90 * reasons, but not because an interrupted volume update
91 * o the @upd_marker field means that the volume is damaged because of an
92 * interrupted update operation.
93 *
94 * I.e., the @corrupted flag is never set if the @upd_marker flag is set.
95 *
96 * The @used_bytes and @used_ebs fields are only really needed for static
97 * volumes and contain the number of bytes stored in this static volume and how
98 * many eraseblock this data occupies. In case of dynamic volumes, the
99 * @used_bytes field is equivalent to @size*@usable_leb_size, and the @used_ebs
100 * field is equivalent to @size.
101 *
102 * In general, logical eraseblock size is a property of the UBI device, not
103 * of the UBI volume. Indeed, the logical eraseblock size depends on the
104 * physical eraseblock size and on how much bytes UBI headers consume. But
105 * because of the volume alignment (@alignment), the usable size of logical
106 * eraseblocks if a volume may be less. The following equation is true:
107 * @usable_leb_size = LEB size - (LEB size mod @alignment),
108 * where LEB size is the logical eraseblock size defined by the UBI device.
109 *
110 * The alignment is multiple to the minimal flash input/output unit size or %1
111 * if all the available space is used.
112 *
113 * To put this differently, alignment may be considered is a way to change
114 * volume logical eraseblock sizes.
115 */
116struct ubi_volume_info {
117 int ubi_num;
118 int vol_id;
119 int size;
120 long long used_bytes;
121 int used_ebs;
122 int vol_type;
123 int corrupted;
124 int upd_marker;
125 int alignment;
126 int usable_leb_size;
127 int name_len;
128 const char *name;
129 dev_t cdev;
130};
131
132/**
133 * struct ubi_device_info - UBI device description data structure.
134 * @ubi_num: ubi device number
135 * @leb_size: logical eraseblock size on this UBI device
136 * @min_io_size: minimal I/O unit size
137 * @ro_mode: if this device is in read-only mode
138 * @cdev: UBI character device major and minor numbers
139 *
140 * Note, @leb_size is the logical eraseblock size offered by the UBI device.
141 * Volumes of this UBI device may have smaller logical eraseblock size if their
142 * alignment is not equivalent to %1.
143 */
144struct ubi_device_info {
145 int ubi_num;
146 int leb_size;
147 int min_io_size;
148 int ro_mode;
149 dev_t cdev;
150};
151
152/* UBI descriptor given to users when they open UBI volumes */
153struct ubi_volume_desc;
154
155int ubi_get_device_info(int ubi_num, struct ubi_device_info *di);
156void ubi_get_volume_info(struct ubi_volume_desc *desc,
157 struct ubi_volume_info *vi);
158struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
159struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
160 int mode);
161void ubi_close_volume(struct ubi_volume_desc *desc);
162int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
163 int len, int check);
164int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
165 int offset, int len, int dtype);
166int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
167 int len, int dtype);
168int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum);
169int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum);
170int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum);
171
172/*
173 * This function is the same as the 'ubi_leb_read()' function, but it does not
174 * provide the checking capability.
175 */
176static inline int ubi_read(struct ubi_volume_desc *desc, int lnum, char *buf,
177 int offset, int len)
178{
179 return ubi_leb_read(desc, lnum, buf, offset, len, 0);
180}
181
182/*
183 * This function is the same as the 'ubi_leb_write()' functions, but it does
184 * not have the data type argument.
185 */
186static inline int ubi_write(struct ubi_volume_desc *desc, int lnum,
187 const void *buf, int offset, int len)
188{
189 return ubi_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
190}
191
192/*
193 * This function is the same as the 'ubi_leb_change()' functions, but it does
194 * not have the data type argument.
195 */
196static inline int ubi_change(struct ubi_volume_desc *desc, int lnum,
197 const void *buf, int len)
198{
199 return ubi_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
200}
201
202#endif /* !__LINUX_UBI_H__ */