Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ubi-media.h
Go to the documentation of this file.
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  * Authors: Artem Bityutskiy (Битюцкий Артём)
19  * Thomas Gleixner
20  * Frank Haverkamp
21  * Oliver Lohmann
22  * Andreas Arnez
23  */
24 
25 /*
26  * This file defines the layout of UBI headers and all the other UBI on-flash
27  * data structures.
28  */
29 
30 #ifndef __UBI_MEDIA_H__
31 #define __UBI_MEDIA_H__
32 
33 #include <asm/byteorder.h>
34 
35 /* The version of UBI images supported by this implementation */
36 #define UBI_VERSION 1
37 
38 /* The highest erase counter value supported by this implementation */
39 #define UBI_MAX_ERASECOUNTER 0x7FFFFFFF
40 
41 /* The initial CRC32 value used when calculating CRC checksums */
42 #define UBI_CRC32_INIT 0xFFFFFFFFU
43 
44 /* Erase counter header magic number (ASCII "UBI#") */
45 #define UBI_EC_HDR_MAGIC 0x55424923
46 /* Volume identifier header magic number (ASCII "UBI!") */
47 #define UBI_VID_HDR_MAGIC 0x55424921
48 
49 /*
50  * Volume type constants used in the volume identifier header.
51  *
52  * @UBI_VID_DYNAMIC: dynamic volume
53  * @UBI_VID_STATIC: static volume
54  */
55 enum {
58 };
59 
60 /*
61  * Volume flags used in the volume table record.
62  *
63  * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume
64  *
65  * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume
66  * table. UBI automatically re-sizes the volume which has this flag and makes
67  * the volume to be of largest possible size. This means that if after the
68  * initialization UBI finds out that there are available physical eraseblocks
69  * present on the device, it automatically appends all of them to the volume
70  * (the physical eraseblocks reserved for bad eraseblocks handling and other
71  * reserved physical eraseblocks are not taken). So, if there is a volume with
72  * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical
73  * eraseblocks will be zero after UBI is loaded, because all of them will be
74  * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared
75  * after the volume had been initialized.
76  *
77  * The auto-resize feature is useful for device production purposes. For
78  * example, different NAND flash chips may have different amount of initial bad
79  * eraseblocks, depending of particular chip instance. Manufacturers of NAND
80  * chips usually guarantee that the amount of initial bad eraseblocks does not
81  * exceed certain percent, e.g. 2%. When one creates an UBI image which will be
82  * flashed to the end devices in production, he does not know the exact amount
83  * of good physical eraseblocks the NAND chip on the device will have, but this
84  * number is required to calculate the volume sized and put them to the volume
85  * table of the UBI image. In this case, one of the volumes (e.g., the one
86  * which will store the root file system) is marked as "auto-resizable", and
87  * UBI will adjust its size on the first boot if needed.
88  *
89  * Note, first UBI reserves some amount of physical eraseblocks for bad
90  * eraseblock handling, and then re-sizes the volume, not vice-versa. This
91  * means that the pool of reserved physical eraseblocks will always be present.
92  */
93 enum {
95 };
96 
97 /*
98  * Compatibility constants used by internal volumes.
99  *
100  * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
101  * to the flash
102  * @UBI_COMPAT_RO: attach this device in read-only mode
103  * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
104  * physical eraseblocks, don't allow the wear-leveling
105  * sub-system to move them
106  * @UBI_COMPAT_REJECT: reject this UBI image
107  */
108 enum {
113 };
114 
115 /* Sizes of UBI headers */
116 #define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)
117 #define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
118 
119 /* Sizes of UBI headers without the ending CRC */
120 #define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32))
121 #define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
122 
157 struct ubi_ec_hdr {
161  __be64 ec; /* Warning: the current limit is 31-bit anyway! */
167 } __packed;
168 
278 struct ubi_vid_hdr {
295 } __packed;
296 
297 /* Internal UBI volumes count */
298 #define UBI_INT_VOL_COUNT 1
299 
300 /*
301  * Starting ID of internal volumes: 0x7fffefff.
302  * There is reserved room for 4096 internal volumes.
303  */
304 #define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
305 
306 /* The layout volume contains the volume table */
307 
308 #define UBI_LAYOUT_VOLUME_ID UBI_INTERNAL_VOL_START
309 #define UBI_LAYOUT_VOLUME_TYPE UBI_VID_DYNAMIC
310 #define UBI_LAYOUT_VOLUME_ALIGN 1
311 #define UBI_LAYOUT_VOLUME_EBS 2
312 #define UBI_LAYOUT_VOLUME_NAME "layout volume"
313 #define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
314 
315 /* The maximum number of volumes per one UBI device */
316 #define UBI_MAX_VOLUMES 128
317 
318 /* The maximum volume name length */
319 #define UBI_VOL_NAME_MAX 127
320 
321 /* Size of the volume table record */
322 #define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
323 
324 /* Size of the volume table record without the ending CRC */
325 #define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
326 
376 } __packed;
377 
378 /* UBI fastmap on-flash data structures */
379 
380 #define UBI_FM_SB_VOLUME_ID (UBI_LAYOUT_VOLUME_ID + 1)
381 #define UBI_FM_DATA_VOLUME_ID (UBI_LAYOUT_VOLUME_ID + 2)
382 
383 /* fastmap on-flash data structure format version */
384 #define UBI_FM_FMT_VERSION 1
385 
386 #define UBI_FM_SB_MAGIC 0x7B11D69F
387 #define UBI_FM_HDR_MAGIC 0xD4B82EF7
388 #define UBI_FM_VHDR_MAGIC 0xFA370ED1
389 #define UBI_FM_POOL_MAGIC 0x67AF4D08
390 #define UBI_FM_EBA_MAGIC 0xf0c040a8
391 
392 /* A fastmap supber block can be located between PEB 0 and
393  * UBI_FM_MAX_START */
394 #define UBI_FM_MAX_START 64
395 
396 /* A fastmap can use up to UBI_FM_MAX_BLOCKS PEBs */
397 #define UBI_FM_MAX_BLOCKS 32
398 
399 /* 5% of the total number of PEBs have to be scanned while attaching
400  * from a fastmap.
401  * But the size of this pool is limited to be between UBI_FM_MIN_POOL_SIZE and
402  * UBI_FM_MAX_POOL_SIZE */
403 #define UBI_FM_MIN_POOL_SIZE 8
404 #define UBI_FM_MAX_POOL_SIZE 256
405 
406 #define UBI_FM_WL_POOL_SIZE 25
407 
419 struct ubi_fm_sb {
429 } __packed;
430 
441 struct ubi_fm_hdr {
450 } __packed;
451 
452 /* struct ubi_fm_hdr is followed by two struct ubi_fm_scan_pool */
453 
467 } __packed;
468 
469 /* ubi_fm_scan_pool is followed by nfree+nused struct ubi_fm_ec records */
470 
476 struct ubi_fm_ec {
479 } __packed;
480 
500 } __packed;
501 
502 /* struct ubi_fm_volhdr is followed by one struct ubi_fm_eba records */
503 
510 struct ubi_fm_eba {
514 } __packed;
515 #endif /* !__UBI_MEDIA_H__ */