]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/mtd/ubi-user.h
Merge branch 'master' of git://git.denx.de/u-boot-mpc83xx
[karo-tx-uboot.git] / include / mtd / ubi-user.h
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 device creation (the same as MTD device attachment)
26  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27  *
28  * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
29  * control device. The caller has to properly fill and pass
30  * &struct ubi_attach_req object - UBI will attach the MTD device specified in
31  * the request and return the newly created UBI device number as the ioctl
32  * return value.
33  *
34  * UBI device deletion (the same as MTD device detachment)
35  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36  *
37  * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI
38  * control device.
39  *
40  * UBI volume creation
41  * ~~~~~~~~~~~~~~~~~~~
42  *
43  * UBI volumes are created via the %UBI_IOCMKVOL IOCTL command of UBI character
44  * device. A &struct ubi_mkvol_req object has to be properly filled and a
45  * pointer to it has to be passed to the IOCTL.
46  *
47  * UBI volume deletion
48  * ~~~~~~~~~~~~~~~~~~~
49  *
50  * To delete a volume, the %UBI_IOCRMVOL IOCTL command of the UBI character
51  * device should be used. A pointer to the 32-bit volume ID hast to be passed
52  * to the IOCTL.
53  *
54  * UBI volume re-size
55  * ~~~~~~~~~~~~~~~~~~
56  *
57  * To re-size a volume, the %UBI_IOCRSVOL IOCTL command of the UBI character
58  * device should be used. A &struct ubi_rsvol_req object has to be properly
59  * filled and a pointer to it has to be passed to the IOCTL.
60  *
61  * UBI volume update
62  * ~~~~~~~~~~~~~~~~~
63  *
64  * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the
65  * corresponding UBI volume character device. A pointer to a 64-bit update
66  * size should be passed to the IOCTL. After this, UBI expects user to write
67  * this number of bytes to the volume character device. The update is finished
68  * when the claimed number of bytes is passed. So, the volume update sequence
69  * is something like:
70  *
71  * fd = open("/dev/my_volume");
72  * ioctl(fd, UBI_IOCVOLUP, &image_size);
73  * write(fd, buf, image_size);
74  * close(fd);
75  *
76  * Atomic eraseblock change
77  * ~~~~~~~~~~~~~~~~~~~~~~~~
78  *
79  * Atomic eraseblock change operation is done via the %UBI_IOCEBCH IOCTL
80  * command of the corresponding UBI volume character device. A pointer to
81  * &struct ubi_leb_change_req has to be passed to the IOCTL. Then the user is
82  * expected to write the requested amount of bytes. This is similar to the
83  * "volume update" IOCTL.
84  */
85
86 /*
87  * When a new UBI volume or UBI device is created, users may either specify the
88  * volume/device number they want to create or to let UBI automatically assign
89  * the number using these constants.
90  */
91 #define UBI_VOL_NUM_AUTO (-1)
92 #define UBI_DEV_NUM_AUTO (-1)
93
94 /* Maximum volume name length */
95 #define UBI_MAX_VOLUME_NAME 127
96
97 /* IOCTL commands of UBI character devices */
98
99 #define UBI_IOC_MAGIC 'o'
100
101 /* Create an UBI volume */
102 #define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
103 /* Remove an UBI volume */
104 #define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t)
105 /* Re-size an UBI volume */
106 #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
107
108 /* IOCTL commands of the UBI control character device */
109
110 #define UBI_CTRL_IOC_MAGIC 'o'
111
112 /* Attach an MTD device */
113 #define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
114 /* Detach an MTD device */
115 #define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, int32_t)
116
117 /* IOCTL commands of UBI volume character devices */
118
119 #define UBI_VOL_IOC_MAGIC 'O'
120
121 /* Start UBI volume update */
122 #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t)
123 /* An eraseblock erasure command, used for debugging, disabled by default */
124 #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t)
125 /* An atomic eraseblock change command */
126 #define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, int32_t)
127
128 /* Maximum MTD device name length supported by UBI */
129 #define MAX_UBI_MTD_NAME_LEN 127
130
131 /*
132  * UBI data type hint constants.
133  *
134  * UBI_LONGTERM: long-term data
135  * UBI_SHORTTERM: short-term data
136  * UBI_UNKNOWN: data persistence is unknown
137  *
138  * These constants are used when data is written to UBI volumes in order to
139  * help the UBI wear-leveling unit to find more appropriate physical
140  * eraseblocks.
141  */
142 enum {
143         UBI_LONGTERM  = 1,
144         UBI_SHORTTERM = 2,
145         UBI_UNKNOWN   = 3,
146 };
147
148 /*
149  * UBI volume type constants.
150  *
151  * @UBI_DYNAMIC_VOLUME: dynamic volume
152  * @UBI_STATIC_VOLUME:  static volume
153  */
154 enum {
155         UBI_DYNAMIC_VOLUME = 3,
156         UBI_STATIC_VOLUME  = 4,
157 };
158
159 /**
160  * struct ubi_attach_req - attach MTD device request.
161  * @ubi_num: UBI device number to create
162  * @mtd_num: MTD device number to attach
163  * @vid_hdr_offset: VID header offset (use defaults if %0)
164  * @padding: reserved for future, not used, has to be zeroed
165  *
166  * This data structure is used to specify MTD device UBI has to attach and the
167  * parameters it has to use. The number which should be assigned to the new UBI
168  * device is passed in @ubi_num. UBI may automatically assign the number if
169  * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
170  * @ubi_num.
171  *
172  * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
173  * offset of the VID header within physical eraseblocks. The default offset is
174  * the next min. I/O unit after the EC header. For example, it will be offset
175  * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or
176  * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.
177  *
178  * But in rare cases, if this optimizes things, the VID header may be placed to
179  * a different offset. For example, the boot-loader might do things faster if the
180  * VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. As
181  * the boot-loader would not normally need to read EC headers (unless it needs
182  * UBI in RW mode), it might be faster to calculate ECC. This is weird example,
183  * but it real-life example. So, in this example, @vid_hdr_offer would be
184  * 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
185  * aligned, which is OK, as UBI is clever enough to realize this is 4th sub-page
186  * of the first page and add needed padding.
187  */
188 struct ubi_attach_req {
189         int32_t ubi_num;
190         int32_t mtd_num;
191         int32_t vid_hdr_offset;
192         uint8_t padding[12];
193 };
194
195 /**
196  * struct ubi_mkvol_req - volume description data structure used in
197  *                        volume creation requests.
198  * @vol_id: volume number
199  * @alignment: volume alignment
200  * @bytes: volume size in bytes
201  * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
202  * @padding1: reserved for future, not used, has to be zeroed
203  * @name_len: volume name length
204  * @padding2: reserved for future, not used, has to be zeroed
205  * @name: volume name
206  *
207  * This structure is used by user-space programs when creating new volumes. The
208  * @used_bytes field is only necessary when creating static volumes.
209  *
210  * The @alignment field specifies the required alignment of the volume logical
211  * eraseblock. This means, that the size of logical eraseblocks will be aligned
212  * to this number, i.e.,
213  *      (UBI device logical eraseblock size) mod (@alignment) = 0.
214  *
215  * To put it differently, the logical eraseblock of this volume may be slightly
216  * shortened in order to make it properly aligned. The alignment has to be
217  * multiple of the flash minimal input/output unit, or %1 to utilize the entire
218  * available space of logical eraseblocks.
219  *
220  * The @alignment field may be useful, for example, when one wants to maintain
221  * a block device on top of an UBI volume. In this case, it is desirable to fit
222  * an integer number of blocks in logical eraseblocks of this UBI volume. With
223  * alignment it is possible to update this volume using plane UBI volume image
224  * BLOBs, without caring about how to properly align them.
225  */
226 struct ubi_mkvol_req {
227         int32_t vol_id;
228         int32_t alignment;
229         int64_t bytes;
230         int8_t vol_type;
231         int8_t padding1;
232         int16_t name_len;
233         int8_t padding2[4];
234         char name[UBI_MAX_VOLUME_NAME + 1];
235 } __attribute__ ((packed));
236
237 /**
238  * struct ubi_rsvol_req - a data structure used in volume re-size requests.
239  * @vol_id: ID of the volume to re-size
240  * @bytes: new size of the volume in bytes
241  *
242  * Re-sizing is possible for both dynamic and static volumes. But while dynamic
243  * volumes may be re-sized arbitrarily, static volumes cannot be made to be
244  * smaller then the number of bytes they bear. To arbitrarily shrink a static
245  * volume, it must be wiped out first (by means of volume update operation with
246  * zero number of bytes).
247  */
248 struct ubi_rsvol_req {
249         int64_t bytes;
250         int32_t vol_id;
251 } __attribute__ ((packed));
252
253 /**
254  * struct ubi_leb_change_req - a data structure used in atomic logical
255  *                             eraseblock change requests.
256  * @lnum: logical eraseblock number to change
257  * @bytes: how many bytes will be written to the logical eraseblock
258  * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
259  * @padding: reserved for future, not used, has to be zeroed
260  */
261 struct ubi_leb_change_req {
262         int32_t lnum;
263         int32_t bytes;
264         uint8_t dtype;
265         uint8_t padding[7];
266 } __attribute__ ((packed));
267
268 #endif /* __UBI_USER_H__ */