2 * Copyright (c) International Business Machines Corp., 2006
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.
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.
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
18 * Author: Artem Bityutskiy (Битюцкий Артём)
21 #ifndef __UBI_USER_H__
22 #define __UBI_USER_H__
25 * UBI device creation (the same as MTD device attachment)
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
34 * UBI device deletion (the same as MTD device detachment)
35 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI
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.
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
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.
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 then, 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
71 * fd = open("/dev/my_volume");
72 * ioctl(fd, UBI_IOCVOLUP, &image_size);
73 * write(fd, buf, image_size);
78 * When a new UBI volume or UBI device is created, users may either specify the
79 * volume/device number they want to create or to let UBI automatically assign
80 * the number using these constants.
82 #define UBI_VOL_NUM_AUTO (-1)
83 #define UBI_DEV_NUM_AUTO (-1)
85 /* Maximum volume name length */
86 #define UBI_MAX_VOLUME_NAME 127
88 /* IOCTL commands of UBI character devices */
90 #define UBI_IOC_MAGIC 'o'
92 /* Create an UBI volume */
93 #define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
94 /* Remove an UBI volume */
95 #define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, int32_t)
96 /* Re-size an UBI volume */
97 #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
99 /* IOCTL commands of the UBI control character device */
101 #define UBI_CTRL_IOC_MAGIC 'o'
103 /* Attach an MTD device */
104 #define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
105 /* Detach an MTD device */
106 #define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, int32_t)
108 /* IOCTL commands of UBI volume character devices */
110 #define UBI_VOL_IOC_MAGIC 'O'
112 /* Start UBI volume update */
113 #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t)
114 /* An eraseblock erasure command, used for debugging, disabled by default */
115 #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t)
117 /* Maximum MTD device name length supported by UBI */
118 #define MAX_UBI_MTD_NAME_LEN 127
121 * UBI volume type constants.
123 * @UBI_DYNAMIC_VOLUME: dynamic volume
124 * @UBI_STATIC_VOLUME: static volume
127 UBI_DYNAMIC_VOLUME
= 3,
128 UBI_STATIC_VOLUME
= 4,
132 * struct ubi_attach_req - attach MTD device request.
133 * @ubi_num: UBI device number to create
134 * @mtd_num: MTD device number to attach
135 * @vid_hdr_offset: VID header offset (use defaults if %0)
136 * @padding: reserved for future, not used, has to be zeroed
138 * This data structure is used to specify MTD device UBI has to attach and the
139 * parameters it has to use. The number which should be assigned to the new UBI
140 * device is passed in @ubi_num. UBI may automatically assing the number if
141 * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
144 * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
145 * offset of the VID header within physical eraseblocks. The default offset is
146 * the next min. I/O unit after the EC header. For example, it will be offset
147 * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or
148 * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.
150 * But in rare cases, if this optimizes things, the VID header may be placed to
151 * a different offset. For example, the boot-loader might do things faster if the
152 * VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. As
153 * the boot-loader would not normally need to read EC headers (unless it needs
154 * UBI in RW mode), it might be faster to calculate ECC. This is weird example,
155 * but it real-life example. So, in this example, @vid_hdr_offer would be
156 * 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
157 * aligned, which is OK, as UBI is clever enough to realize this is 4th sub-page
158 * of the first page and add needed padding.
160 struct ubi_attach_req
{
163 int32_t vid_hdr_offset
;
168 * struct ubi_mkvol_req - volume description data structure used in
169 * volume creation requests.
170 * @vol_id: volume number
171 * @alignment: volume alignment
172 * @bytes: volume size in bytes
173 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
174 * @padding1: reserved for future, not used, has to be zeroed
175 * @name_len: volume name length
176 * @padding2: reserved for future, not used, has to be zeroed
179 * This structure is used by userspace programs when creating new volumes. The
180 * @used_bytes field is only necessary when creating static volumes.
182 * The @alignment field specifies the required alignment of the volume logical
183 * eraseblock. This means, that the size of logical eraseblocks will be aligned
184 * to this number, i.e.,
185 * (UBI device logical eraseblock size) mod (@alignment) = 0.
187 * To put it differently, the logical eraseblock of this volume may be slightly
188 * shortened in order to make it properly aligned. The alignment has to be
189 * multiple of the flash minimal input/output unit, or %1 to utilize the entire
190 * available space of logical eraseblocks.
192 * The @alignment field may be useful, for example, when one wants to maintain
193 * a block device on top of an UBI volume. In this case, it is desirable to fit
194 * an integer number of blocks in logical eraseblocks of this UBI volume. With
195 * alignment it is possible to update this volume using plane UBI volume image
196 * BLOBs, without caring about how to properly align them.
198 struct ubi_mkvol_req
{
206 char name
[UBI_MAX_VOLUME_NAME
+ 1];
207 } __attribute__ ((packed
));
210 * struct ubi_rsvol_req - a data structure used in volume re-size requests.
211 * @vol_id: ID of the volume to re-size
212 * @bytes: new size of the volume in bytes
214 * Re-sizing is possible for both dynamic and static volumes. But while dynamic
215 * volumes may be re-sized arbitrarily, static volumes cannot be made to be
216 * smaller then the number of bytes they bear. To arbitrarily shrink a static
217 * volume, it must be wiped out first (by means of volume update operation with
218 * zero number of bytes).
220 struct ubi_rsvol_req
{
223 } __attribute__ ((packed
));
225 #endif /* __UBI_USER_H__ */