diff options
-rw-r--r-- | Documentation/ABI/stable/sysfs-class-ubi | 212 | ||||
-rw-r--r-- | drivers/mtd/ubi/Kconfig | 9 | ||||
-rw-r--r-- | drivers/mtd/ubi/build.c | 37 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.h | 2 | ||||
-rw-r--r-- | drivers/mtd/ubi/gluebi.c | 5 | ||||
-rw-r--r-- | drivers/mtd/ubi/io.c | 4 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.c | 41 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.h | 2 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi-media.h (renamed from include/mtd/ubi-header.h) | 8 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 3 | ||||
-rw-r--r-- | include/mtd/Kbuild | 1 |
11 files changed, 260 insertions, 64 deletions
diff --git a/Documentation/ABI/stable/sysfs-class-ubi b/Documentation/ABI/stable/sysfs-class-ubi new file mode 100644 index 000000000000..18d471d9faea --- /dev/null +++ b/Documentation/ABI/stable/sysfs-class-ubi | |||
@@ -0,0 +1,212 @@ | |||
1 | What: /sys/class/ubi/ | ||
2 | Date: July 2006 | ||
3 | KernelVersion: 2.6.22 | ||
4 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
5 | Description: | ||
6 | The ubi/ class sub-directory belongs to the UBI subsystem and | ||
7 | provides general UBI information, per-UBI device information | ||
8 | and per-UBI volume information. | ||
9 | |||
10 | What: /sys/class/ubi/version | ||
11 | Date: July 2006 | ||
12 | KernelVersion: 2.6.22 | ||
13 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
14 | Description: | ||
15 | This file contains version of the latest supported UBI on-media | ||
16 | format. Currently it is 1, and there is no plan to change this. | ||
17 | However, if in the future UBI needs on-flash format changes | ||
18 | which cannot be done in a compatible manner, a new format | ||
19 | version will be added. So this is a mechanism for possible | ||
20 | future backward-compatible (but forward-incompatible) | ||
21 | improvements. | ||
22 | |||
23 | What: /sys/class/ubiX/ | ||
24 | Date: July 2006 | ||
25 | KernelVersion: 2.6.22 | ||
26 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
27 | Description: | ||
28 | The /sys/class/ubi0, /sys/class/ubi1, etc directories describe | ||
29 | UBI devices (UBI device 0, 1, etc). They contain general UBI | ||
30 | device information and per UBI volume information (each UBI | ||
31 | device may have many UBI volumes) | ||
32 | |||
33 | What: /sys/class/ubi/ubiX/avail_eraseblocks | ||
34 | Date: July 2006 | ||
35 | KernelVersion: 2.6.22 | ||
36 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
37 | Description: | ||
38 | Amount of available logical eraseblock. For example, one may | ||
39 | create a new UBI volume which has this amount of logical | ||
40 | eraseblocks. | ||
41 | |||
42 | What: /sys/class/ubi/ubiX/bad_peb_count | ||
43 | Date: July 2006 | ||
44 | KernelVersion: 2.6.22 | ||
45 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
46 | Description: | ||
47 | Count of bad physical eraseblocks on the underlying MTD device. | ||
48 | |||
49 | What: /sys/class/ubi/ubiX/bgt_enabled | ||
50 | Date: July 2006 | ||
51 | KernelVersion: 2.6.22 | ||
52 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
53 | Description: | ||
54 | Contains ASCII "0\n" if the UBI background thread is disabled, | ||
55 | and ASCII "1\n" if it is enabled. | ||
56 | |||
57 | What: /sys/class/ubi/ubiX/dev | ||
58 | Date: July 2006 | ||
59 | KernelVersion: 2.6.22 | ||
60 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
61 | Description: | ||
62 | Major and minor numbers of the character device corresponding | ||
63 | to this UBI device (in <major>:<minor> format). | ||
64 | |||
65 | What: /sys/class/ubi/ubiX/eraseblock_size | ||
66 | Date: July 2006 | ||
67 | KernelVersion: 2.6.22 | ||
68 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
69 | Description: | ||
70 | Maximum logical eraseblock size this UBI device may provide. UBI | ||
71 | volumes may have smaller logical eraseblock size because of their | ||
72 | alignment. | ||
73 | |||
74 | What: /sys/class/ubi/ubiX/max_ec | ||
75 | Date: July 2006 | ||
76 | KernelVersion: 2.6.22 | ||
77 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
78 | Description: | ||
79 | Maximum physical eraseblock erase counter value. | ||
80 | |||
81 | What: /sys/class/ubi/ubiX/max_vol_count | ||
82 | Date: July 2006 | ||
83 | KernelVersion: 2.6.22 | ||
84 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
85 | Description: | ||
86 | Maximum number of volumes which this UBI device may have. | ||
87 | |||
88 | What: /sys/class/ubi/ubiX/min_io_size | ||
89 | Date: July 2006 | ||
90 | KernelVersion: 2.6.22 | ||
91 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
92 | Description: | ||
93 | Minimum input/output unit size. All the I/O may only be done | ||
94 | in fractions of the contained number. | ||
95 | |||
96 | What: /sys/class/ubi/ubiX/mtd_num | ||
97 | Date: January 2008 | ||
98 | KernelVersion: 2.6.25 | ||
99 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
100 | Description: | ||
101 | Number of the underlying MTD device. | ||
102 | |||
103 | What: /sys/class/ubi/ubiX/reserved_for_bad | ||
104 | Date: July 2006 | ||
105 | KernelVersion: 2.6.22 | ||
106 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
107 | Description: | ||
108 | Number of physical eraseblocks reserved for bad block handling. | ||
109 | |||
110 | What: /sys/class/ubi/ubiX/total_eraseblocks | ||
111 | Date: July 2006 | ||
112 | KernelVersion: 2.6.22 | ||
113 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
114 | Description: | ||
115 | Total number of good (not marked as bad) physical eraseblocks on | ||
116 | the underlying MTD device. | ||
117 | |||
118 | What: /sys/class/ubi/ubiX/volumes_count | ||
119 | Date: July 2006 | ||
120 | KernelVersion: 2.6.22 | ||
121 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
122 | Description: | ||
123 | Count of volumes on this UBI device. | ||
124 | |||
125 | What: /sys/class/ubi/ubiX/ubiX_Y/ | ||
126 | Date: July 2006 | ||
127 | KernelVersion: 2.6.22 | ||
128 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
129 | Description: | ||
130 | The /sys/class/ubi/ubiX/ubiX_0/, /sys/class/ubi/ubiX/ubiX_1/, | ||
131 | etc directories describe UBI volumes on UBI device X (volumes | ||
132 | 0, 1, etc). | ||
133 | |||
134 | What: /sys/class/ubi/ubiX/ubiX_Y/alignment | ||
135 | Date: July 2006 | ||
136 | KernelVersion: 2.6.22 | ||
137 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
138 | Description: | ||
139 | Volume alignment - the value the logical eraseblock size of | ||
140 | this volume has to be aligned on. For example, 2048 means that | ||
141 | logical eraseblock size is multiple of 2048. In other words, | ||
142 | volume logical eraseblock size is UBI device logical eraseblock | ||
143 | size aligned to the alignment value. | ||
144 | |||
145 | What: /sys/class/ubi/ubiX/ubiX_Y/corrupted | ||
146 | Date: July 2006 | ||
147 | KernelVersion: 2.6.22 | ||
148 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
149 | Description: | ||
150 | Contains ASCII "0\n" if the UBI volume is OK, and ASCII "1\n" | ||
151 | if it is corrupted (e.g., due to an interrupted volume update). | ||
152 | |||
153 | What: /sys/class/ubi/ubiX/ubiX_Y/data_bytes | ||
154 | Date: July 2006 | ||
155 | KernelVersion: 2.6.22 | ||
156 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
157 | Description: | ||
158 | The amount of data this volume contains. This value makes sense | ||
159 | only for static volumes, and for dynamic volume it equivalent | ||
160 | to the total volume size in bytes. | ||
161 | |||
162 | What: /sys/class/ubi/ubiX/ubiX_Y/dev | ||
163 | Date: July 2006 | ||
164 | KernelVersion: 2.6.22 | ||
165 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
166 | Description: | ||
167 | Major and minor numbers of the character device corresponding | ||
168 | to this UBI volume (in <major>:<minor> format). | ||
169 | |||
170 | What: /sys/class/ubi/ubiX/ubiX_Y/name | ||
171 | Date: July 2006 | ||
172 | KernelVersion: 2.6.22 | ||
173 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
174 | Description: | ||
175 | Volume name. | ||
176 | |||
177 | What: /sys/class/ubi/ubiX/ubiX_Y/reserved_ebs | ||
178 | Date: July 2006 | ||
179 | KernelVersion: 2.6.22 | ||
180 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
181 | Description: | ||
182 | Count of physical eraseblock reserved for this volume. | ||
183 | Equivalent to the volume size in logical eraseblocks. | ||
184 | |||
185 | What: /sys/class/ubi/ubiX/ubiX_Y/type | ||
186 | Date: July 2006 | ||
187 | KernelVersion: 2.6.22 | ||
188 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
189 | Description: | ||
190 | Volume type. Contains ASCII "dynamic\n" for dynamic volumes and | ||
191 | "static\n" for static volumes. | ||
192 | |||
193 | What: /sys/class/ubi/ubiX/ubiX_Y/upd_marker | ||
194 | Date: July 2006 | ||
195 | KernelVersion: 2.6.22 | ||
196 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
197 | Description: | ||
198 | Contains ASCII "0\n" if the update marker is not set for this | ||
199 | volume, and "1\n" if it is set. The update marker is set when | ||
200 | volume update starts, and cleaned when it ends. So the presence | ||
201 | of the update marker indicates that the volume is being updated | ||
202 | at the moment of the update was interrupted. The later may be | ||
203 | checked using the "corrupted" sysfs file. | ||
204 | |||
205 | What: /sys/class/ubi/ubiX/ubiX_Y/usable_eb_size | ||
206 | Date: July 2006 | ||
207 | KernelVersion: 2.6.22 | ||
208 | Contact: Artem Bityutskiy <dedekind@infradead.org> | ||
209 | Description: | ||
210 | Logical eraseblock size of this volume. Equivalent to logical | ||
211 | eraseblock size of the device aligned on the volume alignment | ||
212 | value. | ||
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index b9daf159a4a7..3f063108e95f 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig | |||
@@ -24,8 +24,13 @@ config MTD_UBI_WL_THRESHOLD | |||
24 | erase counter value and the lowest erase counter value of eraseblocks | 24 | erase counter value and the lowest erase counter value of eraseblocks |
25 | of UBI devices. When this threshold is exceeded, UBI starts performing | 25 | of UBI devices. When this threshold is exceeded, UBI starts performing |
26 | wear leveling by means of moving data from eraseblock with low erase | 26 | wear leveling by means of moving data from eraseblock with low erase |
27 | counter to eraseblocks with high erase counter. Leave the default | 27 | counter to eraseblocks with high erase counter. |
28 | value if unsure. | 28 | |
29 | The default value should be OK for SLC NAND flashes, NOR flashes and | ||
30 | other flashes which have eraseblock life-cycle 100000 or more. | ||
31 | However, in case of MLC NAND flashes which typically have eraseblock | ||
32 | life-cycle less then 10000, the threshold should be lessened (e.g., | ||
33 | to 128 or 256, although it does not have to be power of 2). | ||
29 | 34 | ||
30 | config MTD_UBI_BEB_RESERVE | 35 | config MTD_UBI_BEB_RESERVE |
31 | int "Percentage of reserved eraseblocks for bad eraseblocks handling" | 36 | int "Percentage of reserved eraseblocks for bad eraseblocks handling" |
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 275960462970..e8578ca422ff 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -606,8 +606,16 @@ static int io_init(struct ubi_device *ubi) | |||
606 | ubi->ro_mode = 1; | 606 | ubi->ro_mode = 1; |
607 | } | 607 | } |
608 | 608 | ||
609 | dbg_msg("leb_size %d", ubi->leb_size); | 609 | ubi_msg("physical eraseblock size: %d bytes (%d KiB)", |
610 | dbg_msg("ro_mode %d", ubi->ro_mode); | 610 | ubi->peb_size, ubi->peb_size >> 10); |
611 | ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size); | ||
612 | ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size); | ||
613 | if (ubi->hdrs_min_io_size != ubi->min_io_size) | ||
614 | ubi_msg("sub-page size: %d", | ||
615 | ubi->hdrs_min_io_size); | ||
616 | ubi_msg("VID header offset: %d (aligned %d)", | ||
617 | ubi->vid_hdr_offset, ubi->vid_hdr_aloffset); | ||
618 | ubi_msg("data offset: %d", ubi->leb_start); | ||
611 | 619 | ||
612 | /* | 620 | /* |
613 | * Note, ideally, we have to initialize ubi->bad_peb_count here. But | 621 | * Note, ideally, we have to initialize ubi->bad_peb_count here. But |
@@ -804,15 +812,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
804 | ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); | 812 | ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); |
805 | ubi_msg("MTD device name: \"%s\"", mtd->name); | 813 | ubi_msg("MTD device name: \"%s\"", mtd->name); |
806 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); | 814 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); |
807 | ubi_msg("physical eraseblock size: %d bytes (%d KiB)", | ||
808 | ubi->peb_size, ubi->peb_size >> 10); | ||
809 | ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size); | ||
810 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); | 815 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); |
811 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); | 816 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); |
812 | ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size); | ||
813 | ubi_msg("VID header offset: %d (aligned %d)", | ||
814 | ubi->vid_hdr_offset, ubi->vid_hdr_aloffset); | ||
815 | ubi_msg("data offset: %d", ubi->leb_start); | ||
816 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); | 817 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); |
817 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); | 818 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); |
818 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); | 819 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); |
@@ -950,8 +951,7 @@ static int __init ubi_init(void) | |||
950 | BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); | 951 | BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); |
951 | 952 | ||
952 | if (mtd_devs > UBI_MAX_DEVICES) { | 953 | if (mtd_devs > UBI_MAX_DEVICES) { |
953 | printk(KERN_ERR "UBI error: too many MTD devices, " | 954 | ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES); |
954 | "maximum is %d\n", UBI_MAX_DEVICES); | ||
955 | return -EINVAL; | 955 | return -EINVAL; |
956 | } | 956 | } |
957 | 957 | ||
@@ -959,25 +959,25 @@ static int __init ubi_init(void) | |||
959 | ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); | 959 | ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); |
960 | if (IS_ERR(ubi_class)) { | 960 | if (IS_ERR(ubi_class)) { |
961 | err = PTR_ERR(ubi_class); | 961 | err = PTR_ERR(ubi_class); |
962 | printk(KERN_ERR "UBI error: cannot create UBI class\n"); | 962 | ubi_err("cannot create UBI class"); |
963 | goto out; | 963 | goto out; |
964 | } | 964 | } |
965 | 965 | ||
966 | err = class_create_file(ubi_class, &ubi_version); | 966 | err = class_create_file(ubi_class, &ubi_version); |
967 | if (err) { | 967 | if (err) { |
968 | printk(KERN_ERR "UBI error: cannot create sysfs file\n"); | 968 | ubi_err("cannot create sysfs file"); |
969 | goto out_class; | 969 | goto out_class; |
970 | } | 970 | } |
971 | 971 | ||
972 | err = misc_register(&ubi_ctrl_cdev); | 972 | err = misc_register(&ubi_ctrl_cdev); |
973 | if (err) { | 973 | if (err) { |
974 | printk(KERN_ERR "UBI error: cannot register device\n"); | 974 | ubi_err("cannot register device"); |
975 | goto out_version; | 975 | goto out_version; |
976 | } | 976 | } |
977 | 977 | ||
978 | ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", | 978 | ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", |
979 | sizeof(struct ubi_wl_entry), | 979 | sizeof(struct ubi_wl_entry), |
980 | 0, 0, NULL); | 980 | 0, 0, NULL); |
981 | if (!ubi_wl_entry_slab) | 981 | if (!ubi_wl_entry_slab) |
982 | goto out_dev_unreg; | 982 | goto out_dev_unreg; |
983 | 983 | ||
@@ -1000,8 +1000,7 @@ static int __init ubi_init(void) | |||
1000 | mutex_unlock(&ubi_devices_mutex); | 1000 | mutex_unlock(&ubi_devices_mutex); |
1001 | if (err < 0) { | 1001 | if (err < 0) { |
1002 | put_mtd_device(mtd); | 1002 | put_mtd_device(mtd); |
1003 | printk(KERN_ERR "UBI error: cannot attach mtd%d\n", | 1003 | ubi_err("cannot attach mtd%d", mtd->index); |
1004 | mtd->index); | ||
1005 | goto out_detach; | 1004 | goto out_detach; |
1006 | } | 1005 | } |
1007 | } | 1006 | } |
@@ -1023,7 +1022,7 @@ out_version: | |||
1023 | out_class: | 1022 | out_class: |
1024 | class_destroy(ubi_class); | 1023 | class_destroy(ubi_class); |
1025 | out: | 1024 | out: |
1026 | printk(KERN_ERR "UBI error: cannot initialize UBI, error %d\n", err); | 1025 | ubi_err("UBI error: cannot initialize UBI, error %d", err); |
1027 | return err; | 1026 | return err; |
1028 | } | 1027 | } |
1029 | module_init(ubi_init); | 1028 | module_init(ubi_init); |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index 8ac7d87dc85b..8ea99d8c9e1f 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -99,8 +99,10 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | |||
99 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD | 99 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD |
100 | /* Initialization and build messages */ | 100 | /* Initialization and build messages */ |
101 | #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | 101 | #define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
102 | #define UBI_IO_DEBUG 1 | ||
102 | #else | 103 | #else |
103 | #define dbg_bld(fmt, ...) ({}) | 104 | #define dbg_bld(fmt, ...) ({}) |
105 | #define UBI_IO_DEBUG 0 | ||
104 | #endif | 106 | #endif |
105 | 107 | ||
106 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS | 108 | #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS |
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c index d397219238d3..e909b390069a 100644 --- a/drivers/mtd/ubi/gluebi.c +++ b/drivers/mtd/ubi/gluebi.c | |||
@@ -291,11 +291,12 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol) | |||
291 | /* | 291 | /* |
292 | * In case of dynamic volume, MTD device size is just volume size. In | 292 | * In case of dynamic volume, MTD device size is just volume size. In |
293 | * case of a static volume the size is equivalent to the amount of data | 293 | * case of a static volume the size is equivalent to the amount of data |
294 | * bytes, which is zero at this moment and will be changed after volume | 294 | * bytes. |
295 | * update. | ||
296 | */ | 295 | */ |
297 | if (vol->vol_type == UBI_DYNAMIC_VOLUME) | 296 | if (vol->vol_type == UBI_DYNAMIC_VOLUME) |
298 | mtd->size = vol->usable_leb_size * vol->reserved_pebs; | 297 | mtd->size = vol->usable_leb_size * vol->reserved_pebs; |
298 | else | ||
299 | mtd->size = vol->used_bytes; | ||
299 | 300 | ||
300 | if (add_mtd_device(mtd)) { | 301 | if (add_mtd_device(mtd)) { |
301 | ubi_err("cannot not add MTD device\n"); | 302 | ubi_err("cannot not add MTD device\n"); |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index db3efdef2433..4ac11df7b048 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -631,6 +631,8 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
631 | 631 | ||
632 | dbg_io("read EC header from PEB %d", pnum); | 632 | dbg_io("read EC header from PEB %d", pnum); |
633 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 633 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
634 | if (UBI_IO_DEBUG) | ||
635 | verbose = 1; | ||
634 | 636 | ||
635 | err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); | 637 | err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); |
636 | if (err) { | 638 | if (err) { |
@@ -904,6 +906,8 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
904 | 906 | ||
905 | dbg_io("read VID header from PEB %d", pnum); | 907 | dbg_io("read VID header from PEB %d", pnum); |
906 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 908 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
909 | if (UBI_IO_DEBUG) | ||
910 | verbose = 1; | ||
907 | 911 | ||
908 | p = (char *)vid_hdr - ubi->vid_hdr_shift; | 912 | p = (char *)vid_hdr - ubi->vid_hdr_shift; |
909 | err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, | 913 | err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 05aa3e7daba1..96d410e106ab 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -42,6 +42,7 @@ | |||
42 | 42 | ||
43 | #include <linux/err.h> | 43 | #include <linux/err.h> |
44 | #include <linux/crc32.h> | 44 | #include <linux/crc32.h> |
45 | #include <asm/div64.h> | ||
45 | #include "ubi.h" | 46 | #include "ubi.h" |
46 | 47 | ||
47 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 48 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
@@ -92,27 +93,6 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, | |||
92 | } | 93 | } |
93 | 94 | ||
94 | /** | 95 | /** |
95 | * commit_to_mean_value - commit intermediate results to the final mean erase | ||
96 | * counter value. | ||
97 | * @si: scanning information | ||
98 | * | ||
99 | * This is a helper function which calculates partial mean erase counter mean | ||
100 | * value and adds it to the resulting mean value. As we can work only in | ||
101 | * integer arithmetic and we want to calculate the mean value of erase counter | ||
102 | * accurately, we first sum erase counter values in @si->ec_sum variable and | ||
103 | * count these components in @si->ec_count. If this temporary @si->ec_sum is | ||
104 | * going to overflow, we calculate the partial mean value | ||
105 | * (@si->ec_sum/@si->ec_count) and add it to @si->mean_ec. | ||
106 | */ | ||
107 | static void commit_to_mean_value(struct ubi_scan_info *si) | ||
108 | { | ||
109 | si->ec_sum /= si->ec_count; | ||
110 | if (si->ec_sum % si->ec_count >= si->ec_count / 2) | ||
111 | si->mean_ec += 1; | ||
112 | si->mean_ec += si->ec_sum; | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * validate_vid_hdr - check that volume identifier header is correct and | 96 | * validate_vid_hdr - check that volume identifier header is correct and |
117 | * consistent. | 97 | * consistent. |
118 | * @vid_hdr: the volume identifier header to check | 98 | * @vid_hdr: the volume identifier header to check |
@@ -901,15 +881,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum | |||
901 | 881 | ||
902 | adjust_mean_ec: | 882 | adjust_mean_ec: |
903 | if (!ec_corr) { | 883 | if (!ec_corr) { |
904 | if (si->ec_sum + ec < ec) { | 884 | si->ec_sum += ec; |
905 | commit_to_mean_value(si); | 885 | si->ec_count += 1; |
906 | si->ec_sum = 0; | ||
907 | si->ec_count = 0; | ||
908 | } else { | ||
909 | si->ec_sum += ec; | ||
910 | si->ec_count += 1; | ||
911 | } | ||
912 | |||
913 | if (ec > si->max_ec) | 886 | if (ec > si->max_ec) |
914 | si->max_ec = ec; | 887 | si->max_ec = ec; |
915 | if (ec < si->min_ec) | 888 | if (ec < si->min_ec) |
@@ -965,9 +938,11 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
965 | 938 | ||
966 | dbg_msg("scanning is finished"); | 939 | dbg_msg("scanning is finished"); |
967 | 940 | ||
968 | /* Finish mean erase counter calculations */ | 941 | /* Calculate mean erase counter */ |
969 | if (si->ec_count) | 942 | if (si->ec_count) { |
970 | commit_to_mean_value(si); | 943 | do_div(si->ec_sum, si->ec_count); |
944 | si->mean_ec = si->ec_sum; | ||
945 | } | ||
971 | 946 | ||
972 | if (si->is_empty) | 947 | if (si->is_empty) |
973 | ubi_msg("empty MTD device detected"); | 948 | ubi_msg("empty MTD device detected"); |
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h index 46d444af471a..966b9b682a42 100644 --- a/drivers/mtd/ubi/scan.h +++ b/drivers/mtd/ubi/scan.h | |||
@@ -124,7 +124,7 @@ struct ubi_scan_info { | |||
124 | int max_ec; | 124 | int max_ec; |
125 | unsigned long long max_sqnum; | 125 | unsigned long long max_sqnum; |
126 | int mean_ec; | 126 | int mean_ec; |
127 | int ec_sum; | 127 | uint64_t ec_sum; |
128 | int ec_count; | 128 | int ec_count; |
129 | }; | 129 | }; |
130 | 130 | ||
diff --git a/include/mtd/ubi-header.h b/drivers/mtd/ubi/ubi-media.h index 292f916ea564..c3185d9fd048 100644 --- a/include/mtd/ubi-header.h +++ b/drivers/mtd/ubi/ubi-media.h | |||
@@ -24,11 +24,11 @@ | |||
24 | 24 | ||
25 | /* | 25 | /* |
26 | * This file defines the layout of UBI headers and all the other UBI on-flash | 26 | * This file defines the layout of UBI headers and all the other UBI on-flash |
27 | * data structures. May be included by user-space. | 27 | * data structures. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef __UBI_HEADER_H__ | 30 | #ifndef __UBI_MEDIA_H__ |
31 | #define __UBI_HEADER_H__ | 31 | #define __UBI_MEDIA_H__ |
32 | 32 | ||
33 | #include <asm/byteorder.h> | 33 | #include <asm/byteorder.h> |
34 | 34 | ||
@@ -369,4 +369,4 @@ struct ubi_vtbl_record { | |||
369 | __be32 crc; | 369 | __be32 crc; |
370 | } __attribute__ ((packed)); | 370 | } __attribute__ ((packed)); |
371 | 371 | ||
372 | #endif /* !__UBI_HEADER_H__ */ | 372 | #endif /* !__UBI_MEDIA_H__ */ |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 8f095cb87108..67dcbd11c15c 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -37,10 +37,9 @@ | |||
37 | #include <linux/string.h> | 37 | #include <linux/string.h> |
38 | #include <linux/vmalloc.h> | 38 | #include <linux/vmalloc.h> |
39 | #include <linux/mtd/mtd.h> | 39 | #include <linux/mtd/mtd.h> |
40 | |||
41 | #include <mtd/ubi-header.h> | ||
42 | #include <linux/mtd/ubi.h> | 40 | #include <linux/mtd/ubi.h> |
43 | 41 | ||
42 | #include "ubi-media.h" | ||
44 | #include "scan.h" | 43 | #include "scan.h" |
45 | #include "debug.h" | 44 | #include "debug.h" |
46 | 45 | ||
diff --git a/include/mtd/Kbuild b/include/mtd/Kbuild index 4d46b3bdebd8..8eb018f96002 100644 --- a/include/mtd/Kbuild +++ b/include/mtd/Kbuild | |||
@@ -3,5 +3,4 @@ header-y += jffs2-user.h | |||
3 | header-y += mtd-abi.h | 3 | header-y += mtd-abi.h |
4 | header-y += mtd-user.h | 4 | header-y += mtd-user.h |
5 | header-y += nftl-user.h | 5 | header-y += nftl-user.h |
6 | header-y += ubi-header.h | ||
7 | header-y += ubi-user.h | 6 | header-y += ubi-user.h |