diff options
Diffstat (limited to 'include/mtd/ubi-user.h')
-rw-r--r-- | include/mtd/ubi-user.h | 127 |
1 files changed, 117 insertions, 10 deletions
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h index fe06ded0e6b8..a7421f130cc0 100644 --- a/include/mtd/ubi-user.h +++ b/include/mtd/ubi-user.h | |||
@@ -22,6 +22,21 @@ | |||
22 | #define __UBI_USER_H__ | 22 | #define __UBI_USER_H__ |
23 | 23 | ||
24 | /* | 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 | * | ||
25 | * UBI volume creation | 40 | * UBI volume creation |
26 | * ~~~~~~~~~~~~~~~~~~~ | 41 | * ~~~~~~~~~~~~~~~~~~~ |
27 | * | 42 | * |
@@ -48,7 +63,7 @@ | |||
48 | * | 63 | * |
49 | * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the | 64 | * 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 | 65 | * 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 | 66 | * size should be passed to the IOCTL. After this, UBI expects user to write |
52 | * this number of bytes to the volume character device. The update is finished | 67 | * 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 | 68 | * when the claimed number of bytes is passed. So, the volume update sequence |
54 | * is something like: | 69 | * is something like: |
@@ -57,14 +72,24 @@ | |||
57 | * ioctl(fd, UBI_IOCVOLUP, &image_size); | 72 | * ioctl(fd, UBI_IOCVOLUP, &image_size); |
58 | * write(fd, buf, image_size); | 73 | * write(fd, buf, image_size); |
59 | * close(fd); | 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. | ||
60 | */ | 84 | */ |
61 | 85 | ||
62 | /* | 86 | /* |
63 | * When a new volume is created, users may either specify the volume number they | 87 | * When a new UBI volume or UBI device is created, users may either specify the |
64 | * want to create or to let UBI automatically assign a volume number using this | 88 | * volume/device number they want to create or to let UBI automatically assign |
65 | * constant. | 89 | * the number using these constants. |
66 | */ | 90 | */ |
67 | #define UBI_VOL_NUM_AUTO (-1) | 91 | #define UBI_VOL_NUM_AUTO (-1) |
92 | #define UBI_DEV_NUM_AUTO (-1) | ||
68 | 93 | ||
69 | /* Maximum volume name length */ | 94 | /* Maximum volume name length */ |
70 | #define UBI_MAX_VOLUME_NAME 127 | 95 | #define UBI_MAX_VOLUME_NAME 127 |
@@ -80,6 +105,15 @@ | |||
80 | /* Re-size an UBI volume */ | 105 | /* Re-size an UBI volume */ |
81 | #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req) | 106 | #define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req) |
82 | 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 | |||
83 | /* IOCTL commands of UBI volume character devices */ | 117 | /* IOCTL commands of UBI volume character devices */ |
84 | 118 | ||
85 | #define UBI_VOL_IOC_MAGIC 'O' | 119 | #define UBI_VOL_IOC_MAGIC 'O' |
@@ -88,6 +122,28 @@ | |||
88 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t) | 122 | #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t) |
89 | /* An eraseblock erasure command, used for debugging, disabled by default */ | 123 | /* An eraseblock erasure command, used for debugging, disabled by default */ |
90 | #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t) | 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 | }; | ||
91 | 147 | ||
92 | /* | 148 | /* |
93 | * UBI volume type constants. | 149 | * UBI volume type constants. |
@@ -97,22 +153,58 @@ | |||
97 | */ | 153 | */ |
98 | enum { | 154 | enum { |
99 | UBI_DYNAMIC_VOLUME = 3, | 155 | UBI_DYNAMIC_VOLUME = 3, |
100 | UBI_STATIC_VOLUME = 4 | 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]; | ||
101 | }; | 193 | }; |
102 | 194 | ||
103 | /** | 195 | /** |
104 | * struct ubi_mkvol_req - volume description data structure used in | 196 | * struct ubi_mkvol_req - volume description data structure used in |
105 | * volume creation requests. | 197 | * volume creation requests. |
106 | * @vol_id: volume number | 198 | * @vol_id: volume number |
107 | * @alignment: volume alignment | 199 | * @alignment: volume alignment |
108 | * @bytes: volume size in bytes | 200 | * @bytes: volume size in bytes |
109 | * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) | 201 | * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) |
110 | * @padding1: reserved for future, not used | 202 | * @padding1: reserved for future, not used, has to be zeroed |
111 | * @name_len: volume name length | 203 | * @name_len: volume name length |
112 | * @padding2: reserved for future, not used | 204 | * @padding2: reserved for future, not used, has to be zeroed |
113 | * @name: volume name | 205 | * @name: volume name |
114 | * | 206 | * |
115 | * This structure is used by userspace programs when creating new volumes. The | 207 | * This structure is used by user-space programs when creating new volumes. The |
116 | * @used_bytes field is only necessary when creating static volumes. | 208 | * @used_bytes field is only necessary when creating static volumes. |
117 | * | 209 | * |
118 | * The @alignment field specifies the required alignment of the volume logical | 210 | * The @alignment field specifies the required alignment of the volume logical |
@@ -139,7 +231,7 @@ struct ubi_mkvol_req { | |||
139 | int8_t padding1; | 231 | int8_t padding1; |
140 | int16_t name_len; | 232 | int16_t name_len; |
141 | int8_t padding2[4]; | 233 | int8_t padding2[4]; |
142 | char name[UBI_MAX_VOLUME_NAME+1]; | 234 | char name[UBI_MAX_VOLUME_NAME + 1]; |
143 | } __attribute__ ((packed)); | 235 | } __attribute__ ((packed)); |
144 | 236 | ||
145 | /** | 237 | /** |
@@ -158,4 +250,19 @@ struct ubi_rsvol_req { | |||
158 | int32_t vol_id; | 250 | int32_t vol_id; |
159 | } __attribute__ ((packed)); | 251 | } __attribute__ ((packed)); |
160 | 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 | |||
161 | #endif /* __UBI_USER_H__ */ | 268 | #endif /* __UBI_USER_H__ */ |