diff options
author | Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com> | 2012-04-24 00:10:33 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-05-20 13:25:58 -0400 |
commit | ef7088e7f84ba550b276bc4a74f2732ee5618fb8 (patch) | |
tree | d78e5c018a29241b05e14b946b9f29e008fa6042 /drivers/mtd/ubi | |
parent | 25886a368d58edd9bb0f63d4417d2f73592b9dba (diff) |
UBI: always dump flash contents in case of errors
UBI (and UBIFS) are a bit over-engineered WRT debugging. The idea was to
link as few as possible when debugging is disabled, but the downside is
that most people produce bug reports which are difficult to understand.
Always dump the flash contents in case of errors, not only when debugging is
enabled.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/Makefile | 3 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.c | 75 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.h | 5 | ||||
-rw-r--r-- | drivers/mtd/ubi/io.c | 4 |
4 files changed, 40 insertions, 47 deletions
diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile index c9302a5452b0..da71655e42db 100644 --- a/drivers/mtd/ubi/Makefile +++ b/drivers/mtd/ubi/Makefile | |||
@@ -1,7 +1,6 @@ | |||
1 | obj-$(CONFIG_MTD_UBI) += ubi.o | 1 | obj-$(CONFIG_MTD_UBI) += ubi.o |
2 | 2 | ||
3 | ubi-y += vtbl.o vmt.o upd.o build.o cdev.o kapi.o eba.o io.o wl.o scan.o | 3 | ubi-y += vtbl.o vmt.o upd.o build.o cdev.o kapi.o eba.o io.o wl.o scan.o |
4 | ubi-y += misc.o | 4 | ubi-y += misc.o debug.o |
5 | 5 | ||
6 | ubi-$(CONFIG_MTD_UBI_DEBUG) += debug.o | ||
7 | obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o | 6 | obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o |
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index 61af9bb560ab..30aa9c440834 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -18,19 +18,46 @@ | |||
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 | |||
59 | #ifdef CONFIG_MTD_UBI_DEBUG | ||
60 | |||
34 | /** | 61 | /** |
35 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. | 62 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. |
36 | * @ec_hdr: the erase counter header to dump | 63 | * @ec_hdr: the erase counter header to dump |
@@ -200,38 +227,6 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | |||
200 | } | 227 | } |
201 | 228 | ||
202 | /** | 229 | /** |
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. | 230 | * ubi_debugging_init_dev - initialize debugging for an UBI device. |
236 | * @ubi: UBI device description object | 231 | * @ubi: UBI device description object |
237 | * | 232 | * |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index aff6499cde47..4bce78dc5226 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -21,6 +21,8 @@ | |||
21 | #ifndef __UBI_DEBUG_H__ | 21 | #ifndef __UBI_DEBUG_H__ |
22 | #define __UBI_DEBUG_H__ | 22 | #define __UBI_DEBUG_H__ |
23 | 23 | ||
24 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | ||
25 | |||
24 | #ifdef CONFIG_MTD_UBI_DEBUG | 26 | #ifdef CONFIG_MTD_UBI_DEBUG |
25 | #include <linux/random.h> | 27 | #include <linux/random.h> |
26 | 28 | ||
@@ -63,7 +65,6 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); | |||
63 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); | 65 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); |
64 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); | 66 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); |
65 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | 67 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); |
66 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | ||
67 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); | 68 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); |
68 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | 69 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, |
69 | int offset, int len); | 70 | int offset, int len); |
@@ -205,8 +206,6 @@ static inline void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, | |||
205 | int type) { return; } | 206 | int type) { return; } |
206 | static inline void | 207 | static inline void |
207 | ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) { return; } | 208 | ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) { return; } |
208 | static inline void ubi_dbg_dump_flash(struct ubi_device *ubi, | ||
209 | int pnum, int offset, int len) { return; } | ||
210 | static inline void | 209 | static inline void |
211 | ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r, | 210 | ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r, |
212 | int g, const void *b, size_t len, bool a) { return; } | 211 | int g, const void *b, size_t len, bool a) { return; } |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 507e0c6113c3..9658ac80890c 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -294,7 +294,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
294 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written " | 294 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written " |
295 | "%zd bytes", err, len, pnum, offset, written); | 295 | "%zd bytes", err, len, pnum, offset, written); |
296 | dump_stack(); | 296 | dump_stack(); |
297 | ubi_dbg_dump_flash(ubi, pnum, offset, len); | 297 | ubi_dump_flash(ubi, pnum, offset, len); |
298 | } else | 298 | } else |
299 | ubi_assert(written == len); | 299 | ubi_assert(written == len); |
300 | 300 | ||
@@ -563,7 +563,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) | |||
563 | */ | 563 | */ |
564 | ubi_err("cannot invalidate PEB %d, write returned %d read returned %d", | 564 | ubi_err("cannot invalidate PEB %d, write returned %d read returned %d", |
565 | pnum, err, err1); | 565 | pnum, err, err1); |
566 | ubi_dbg_dump_flash(ubi, pnum, 0, ubi->peb_size); | 566 | ubi_dump_flash(ubi, pnum, 0, ubi->peb_size); |
567 | return -EIO; | 567 | return -EIO; |
568 | } | 568 | } |
569 | 569 | ||