Skip to content

Commit ef7088e

Browse files
committed
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>
1 parent 25886a3 commit ef7088e

4 files changed

Lines changed: 40 additions & 47 deletions

File tree

‎drivers/mtd/ubi/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
obj-$(CONFIG_MTD_UBI) += ubi.o
22

33
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
55

6-
ubi-$(CONFIG_MTD_UBI_DEBUG) += debug.o
76
obj-$(CONFIG_MTD_UBI_GLUEBI) += gluebi.o

‎drivers/mtd/ubi/debug.c‎

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,46 @@
1818
* Author: Artem Bityutskiy (Битюцкий Артём)
1919
*/
2020

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-
2921
#include "ubi.h"
3022
#include <linux/debugfs.h>
3123
#include <linux/uaccess.h>
3224
#include <linux/module.h>
3325

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+
3461
/**
3562
* ubi_dbg_dump_ec_hdr - dump an erase counter header.
3663
* @ec_hdr: the erase counter header to dump
@@ -199,38 +226,6 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
199226
printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
200227
}
201228

202-
/**
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-
234229
/**
235230
* ubi_debugging_init_dev - initialize debugging for an UBI device.
236231
* @ubi: UBI device description object

‎drivers/mtd/ubi/debug.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef __UBI_DEBUG_H__
2222
#define __UBI_DEBUG_H__
2323

24+
void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
25+
2426
#ifdef CONFIG_MTD_UBI_DEBUG
2527
#include <linux/random.h>
2628

@@ -63,7 +65,6 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
6365
void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
6466
void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
6567
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);
6768
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
6869
int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
6970
int offset, int len);
@@ -205,8 +206,6 @@ static inline void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb,
205206
int type) { return; }
206207
static inline void
207208
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; }
210209
static inline void
211210
ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r,
212211
int g, const void *b, size_t len, bool a) { return; }

‎drivers/mtd/ubi/io.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
294294
ubi_err("error %d while writing %d bytes to PEB %d:%d, written "
295295
"%zd bytes", err, len, pnum, offset, written);
296296
dump_stack();
297-
ubi_dbg_dump_flash(ubi, pnum, offset, len);
297+
ubi_dump_flash(ubi, pnum, offset, len);
298298
} else
299299
ubi_assert(written == len);
300300

@@ -563,7 +563,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
563563
*/
564564
ubi_err("cannot invalidate PEB %d, write returned %d read returned %d",
565565
pnum, err, err1);
566-
ubi_dbg_dump_flash(ubi, pnum, 0, ubi->peb_size);
566+
ubi_dump_flash(ubi, pnum, 0, ubi->peb_size);
567567
return -EIO;
568568
}
569569

0 commit comments

Comments
 (0)