diff options
Diffstat (limited to 'drivers/mtd/ubi/debug.c')
-rw-r--r-- | drivers/mtd/ubi/debug.c | 137 |
1 files changed, 64 insertions, 73 deletions
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index 61af9bb560ab..9f957c2d48e9 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -18,24 +18,49 @@ | |||
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | 18 | * Author: Artem Bityutskiy (Битюцкий Артём) |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | ||
22 | * Here we keep all the UBI debugging stuff which should normally be disabled | ||
23 | * and compiled-out, but it is extremely helpful when hunting bugs or doing big | ||
24 | * changes. | ||
25 | */ | ||
26 | |||
27 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
28 | |||
29 | #include "ubi.h" | 21 | #include "ubi.h" |
30 | #include <linux/debugfs.h> | 22 | #include <linux/debugfs.h> |
31 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
32 | #include <linux/module.h> | 24 | #include <linux/module.h> |
33 | 25 | ||
26 | |||
27 | /** | ||
28 | * ubi_dump_flash - dump a region of flash. | ||
29 | * @ubi: UBI device description object | ||
30 | * @pnum: the physical eraseblock number to dump | ||
31 | * @offset: the starting offset within the physical eraseblock to dump | ||
32 | * @len: the length of the region to dump | ||
33 | */ | ||
34 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) | ||
35 | { | ||
36 | int err; | ||
37 | size_t read; | ||
38 | void *buf; | ||
39 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | ||
40 | |||
41 | buf = vmalloc(len); | ||
42 | if (!buf) | ||
43 | return; | ||
44 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | ||
45 | if (err && err != -EUCLEAN) { | ||
46 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | ||
47 | "read %zd bytes", err, len, pnum, offset, read); | ||
48 | goto out; | ||
49 | } | ||
50 | |||
51 | ubi_msg("dumping %d bytes of data from PEB %d, offset %d", | ||
52 | len, pnum, offset); | ||
53 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | ||
54 | out: | ||
55 | vfree(buf); | ||
56 | return; | ||
57 | } | ||
58 | |||
34 | /** | 59 | /** |
35 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. | 60 | * ubi_dump_ec_hdr - dump an erase counter header. |
36 | * @ec_hdr: the erase counter header to dump | 61 | * @ec_hdr: the erase counter header to dump |
37 | */ | 62 | */ |
38 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | 63 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) |
39 | { | 64 | { |
40 | printk(KERN_DEBUG "Erase counter header dump:\n"); | 65 | printk(KERN_DEBUG "Erase counter header dump:\n"); |
41 | printk(KERN_DEBUG "\tmagic %#08x\n", | 66 | printk(KERN_DEBUG "\tmagic %#08x\n", |
@@ -57,10 +82,10 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | |||
57 | } | 82 | } |
58 | 83 | ||
59 | /** | 84 | /** |
60 | * ubi_dbg_dump_vid_hdr - dump a volume identifier header. | 85 | * ubi_dump_vid_hdr - dump a volume identifier header. |
61 | * @vid_hdr: the volume identifier header to dump | 86 | * @vid_hdr: the volume identifier header to dump |
62 | */ | 87 | */ |
63 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | 88 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) |
64 | { | 89 | { |
65 | printk(KERN_DEBUG "Volume identifier header dump:\n"); | 90 | printk(KERN_DEBUG "Volume identifier header dump:\n"); |
66 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); | 91 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); |
@@ -82,10 +107,10 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | |||
82 | } | 107 | } |
83 | 108 | ||
84 | /** | 109 | /** |
85 | * ubi_dbg_dump_vol_info- dump volume information. | 110 | * ubi_dump_vol_info - dump volume information. |
86 | * @vol: UBI volume description object | 111 | * @vol: UBI volume description object |
87 | */ | 112 | */ |
88 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) | 113 | void ubi_dump_vol_info(const struct ubi_volume *vol) |
89 | { | 114 | { |
90 | printk(KERN_DEBUG "Volume information dump:\n"); | 115 | printk(KERN_DEBUG "Volume information dump:\n"); |
91 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); | 116 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); |
@@ -112,11 +137,11 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) | |||
112 | } | 137 | } |
113 | 138 | ||
114 | /** | 139 | /** |
115 | * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object. | 140 | * ubi_dump_vtbl_record - dump a &struct ubi_vtbl_record object. |
116 | * @r: the object to dump | 141 | * @r: the object to dump |
117 | * @idx: volume table index | 142 | * @idx: volume table index |
118 | */ | 143 | */ |
119 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | 144 | void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) |
120 | { | 145 | { |
121 | int name_len = be16_to_cpu(r->name_len); | 146 | int name_len = be16_to_cpu(r->name_len); |
122 | 147 | ||
@@ -146,44 +171,44 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | |||
146 | } | 171 | } |
147 | 172 | ||
148 | /** | 173 | /** |
149 | * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object. | 174 | * ubi_dump_av - dump a &struct ubi_ainf_volume object. |
150 | * @sv: the object to dump | 175 | * @av: the object to dump |
151 | */ | 176 | */ |
152 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) | 177 | void ubi_dump_av(const struct ubi_ainf_volume *av) |
153 | { | 178 | { |
154 | printk(KERN_DEBUG "Volume scanning information dump:\n"); | 179 | printk(KERN_DEBUG "Volume attaching information dump:\n"); |
155 | printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id); | 180 | printk(KERN_DEBUG "\tvol_id %d\n", av->vol_id); |
156 | printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum); | 181 | printk(KERN_DEBUG "\thighest_lnum %d\n", av->highest_lnum); |
157 | printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count); | 182 | printk(KERN_DEBUG "\tleb_count %d\n", av->leb_count); |
158 | printk(KERN_DEBUG "\tcompat %d\n", sv->compat); | 183 | printk(KERN_DEBUG "\tcompat %d\n", av->compat); |
159 | printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type); | 184 | printk(KERN_DEBUG "\tvol_type %d\n", av->vol_type); |
160 | printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs); | 185 | printk(KERN_DEBUG "\tused_ebs %d\n", av->used_ebs); |
161 | printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size); | 186 | printk(KERN_DEBUG "\tlast_data_size %d\n", av->last_data_size); |
162 | printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad); | 187 | printk(KERN_DEBUG "\tdata_pad %d\n", av->data_pad); |
163 | } | 188 | } |
164 | 189 | ||
165 | /** | 190 | /** |
166 | * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object. | 191 | * ubi_dump_aeb - dump a &struct ubi_ainf_peb object. |
167 | * @seb: the object to dump | 192 | * @aeb: the object to dump |
168 | * @type: object type: 0 - not corrupted, 1 - corrupted | 193 | * @type: object type: 0 - not corrupted, 1 - corrupted |
169 | */ | 194 | */ |
170 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) | 195 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type) |
171 | { | 196 | { |
172 | printk(KERN_DEBUG "eraseblock scanning information dump:\n"); | 197 | printk(KERN_DEBUG "eraseblock attaching information dump:\n"); |
173 | printk(KERN_DEBUG "\tec %d\n", seb->ec); | 198 | printk(KERN_DEBUG "\tec %d\n", aeb->ec); |
174 | printk(KERN_DEBUG "\tpnum %d\n", seb->pnum); | 199 | printk(KERN_DEBUG "\tpnum %d\n", aeb->pnum); |
175 | if (type == 0) { | 200 | if (type == 0) { |
176 | printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); | 201 | printk(KERN_DEBUG "\tlnum %d\n", aeb->lnum); |
177 | printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); | 202 | printk(KERN_DEBUG "\tscrub %d\n", aeb->scrub); |
178 | printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); | 203 | printk(KERN_DEBUG "\tsqnum %llu\n", aeb->sqnum); |
179 | } | 204 | } |
180 | } | 205 | } |
181 | 206 | ||
182 | /** | 207 | /** |
183 | * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object. | 208 | * ubi_dump_mkvol_req - dump a &struct ubi_mkvol_req object. |
184 | * @req: the object to dump | 209 | * @req: the object to dump |
185 | */ | 210 | */ |
186 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | 211 | void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req) |
187 | { | 212 | { |
188 | char nm[17]; | 213 | char nm[17]; |
189 | 214 | ||
@@ -200,38 +225,6 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | |||
200 | } | 225 | } |
201 | 226 | ||
202 | /** | 227 | /** |
203 | * ubi_dbg_dump_flash - dump a region of flash. | ||
204 | * @ubi: UBI device description object | ||
205 | * @pnum: the physical eraseblock number to dump | ||
206 | * @offset: the starting offset within the physical eraseblock to dump | ||
207 | * @len: the length of the region to dump | ||
208 | */ | ||
209 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) | ||
210 | { | ||
211 | int err; | ||
212 | size_t read; | ||
213 | void *buf; | ||
214 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | ||
215 | |||
216 | buf = vmalloc(len); | ||
217 | if (!buf) | ||
218 | return; | ||
219 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | ||
220 | if (err && err != -EUCLEAN) { | ||
221 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | ||
222 | "read %zd bytes", err, len, pnum, offset, read); | ||
223 | goto out; | ||
224 | } | ||
225 | |||
226 | dbg_msg("dumping %d bytes of data from PEB %d, offset %d", | ||
227 | len, pnum, offset); | ||
228 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | ||
229 | out: | ||
230 | vfree(buf); | ||
231 | return; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * ubi_debugging_init_dev - initialize debugging for an UBI device. | 228 | * ubi_debugging_init_dev - initialize debugging for an UBI device. |
236 | * @ubi: UBI device description object | 229 | * @ubi: UBI device description object |
237 | * | 230 | * |
@@ -479,5 +472,3 @@ void ubi_debugfs_exit_dev(struct ubi_device *ubi) | |||
479 | { | 472 | { |
480 | debugfs_remove_recursive(ubi->dbg->dfs_dir); | 473 | debugfs_remove_recursive(ubi->dbg->dfs_dir); |
481 | } | 474 | } |
482 | |||
483 | #endif /* CONFIG_MTD_UBI_DEBUG */ | ||