aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-07-24 08:31:33 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-08-14 13:02:20 -0400
commit867996b15c1f0a98d2c405bada907e97499ba8c2 (patch)
tree3ca5bfb6e74ef5697bb89d29365f6c4df7ab4c03 /drivers/mtd
parent758d8e46347aee199e7025b8c571bab75d2de63f (diff)
UBI: introduce flash dump helper
Useful for debugging problems, compiled in only if UBI debugging is enabled. This patch also makes the UBI writing function dump the flash if it fails to write. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/ubi/debug.c32
-rw-r--r--drivers/mtd/ubi/debug.h2
-rw-r--r--drivers/mtd/ubi/io.c1
3 files changed, 35 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 54b0186915fb..4876977e52cb 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -196,4 +196,36 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
196 printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm); 196 printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
197} 197}
198 198
199/**
200 * ubi_dbg_dump_flash - dump a region of flash.
201 * @ubi: UBI device description object
202 * @pnum: the physical eraseblock number to dump
203 * @offset: the starting offset within the physical eraseblock to dump
204 * @len: the length of the region to dump
205 */
206void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
207{
208 int err;
209 size_t read;
210 void *buf;
211 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
212
213 buf = vmalloc(len);
214 if (!buf)
215 return;
216 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
217 if (err && err != -EUCLEAN) {
218 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
219 "read %zd bytes", err, len, pnum, offset, read);
220 goto out;
221 }
222
223 dbg_msg("dumping %d bytes of data from PEB %d, offset %d",
224 len, pnum, offset);
225 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
226out:
227 vfree(buf);
228 return;
229}
230
199#endif /* CONFIG_MTD_UBI_DEBUG */ 231#endif /* CONFIG_MTD_UBI_DEBUG */
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index a4da7a09b949..f30bcb372c05 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -55,6 +55,7 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
55void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); 55void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
56void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); 56void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
57void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); 57void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
58void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
58 59
59#ifdef CONFIG_MTD_UBI_DEBUG_MSG 60#ifdef CONFIG_MTD_UBI_DEBUG_MSG
60/* General debugging messages */ 61/* General debugging messages */
@@ -167,6 +168,7 @@ static inline int ubi_dbg_is_erase_failure(void)
167#define ubi_dbg_dump_sv(sv) ({}) 168#define ubi_dbg_dump_sv(sv) ({})
168#define ubi_dbg_dump_seb(seb, type) ({}) 169#define ubi_dbg_dump_seb(seb, type) ({})
169#define ubi_dbg_dump_mkvol_req(req) ({}) 170#define ubi_dbg_dump_mkvol_req(req) ({})
171#define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({})
170 172
171#define UBI_IO_DEBUG 0 173#define UBI_IO_DEBUG 0
172#define DBG_DISABLE_BGT 0 174#define DBG_DISABLE_BGT 0
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 4e7bcb215075..b693138fc519 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -269,6 +269,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
269 ubi_err("error %d while writing %d bytes to PEB %d:%d, written " 269 ubi_err("error %d while writing %d bytes to PEB %d:%d, written "
270 "%zd bytes", err, len, pnum, offset, written); 270 "%zd bytes", err, len, pnum, offset, written);
271 ubi_dbg_dump_stack(); 271 ubi_dbg_dump_stack();
272 ubi_dbg_dump_flash(ubi, pnum, offset, len);
272 } else 273 } else
273 ubi_assert(written == len); 274 ubi_assert(written == len);
274 275