Commit a904e3f1 authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: always dump VID and EC headers 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 VID and EC headers' contents in case of errors when it
is helpful.
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
parent ef7088e7
...@@ -56,13 +56,11 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) ...@@ -56,13 +56,11 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
return; return;
} }
#ifdef CONFIG_MTD_UBI_DEBUG
/** /**
* ubi_dbg_dump_ec_hdr - dump an erase counter header. * ubi_dump_ec_hdr - dump an erase counter header.
* @ec_hdr: the erase counter header to dump * @ec_hdr: the erase counter header to dump
*/ */
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
{ {
printk(KERN_DEBUG "Erase counter header dump:\n"); printk(KERN_DEBUG "Erase counter header dump:\n");
printk(KERN_DEBUG "\tmagic %#08x\n", printk(KERN_DEBUG "\tmagic %#08x\n",
...@@ -84,10 +82,10 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) ...@@ -84,10 +82,10 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
} }
/** /**
* ubi_dbg_dump_vid_hdr - dump a volume identifier header. * ubi_dump_vid_hdr - dump a volume identifier header.
* @vid_hdr: the volume identifier header to dump * @vid_hdr: the volume identifier header to dump
*/ */
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
{ {
printk(KERN_DEBUG "Volume identifier header dump:\n"); printk(KERN_DEBUG "Volume identifier header dump:\n");
printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
...@@ -108,6 +106,8 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) ...@@ -108,6 +106,8 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
vid_hdr, UBI_VID_HDR_SIZE, 1); vid_hdr, UBI_VID_HDR_SIZE, 1);
} }
#ifdef CONFIG_MTD_UBI_DEBUG
/** /**
* ubi_dbg_dump_vol_info- dump volume information. * ubi_dbg_dump_vol_info- dump volume information.
* @vol: UBI volume description object * @vol: UBI volume description object
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define __UBI_DEBUG_H__ #define __UBI_DEBUG_H__
void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
#ifdef CONFIG_MTD_UBI_DEBUG #ifdef CONFIG_MTD_UBI_DEBUG
#include <linux/random.h> #include <linux/random.h>
...@@ -58,8 +60,6 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); ...@@ -58,8 +60,6 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
/* Initialization and build messages */ /* Initialization and build messages */
#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
void ubi_dbg_dump_vol_info(const struct ubi_volume *vol); void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
...@@ -193,10 +193,6 @@ static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) ...@@ -193,10 +193,6 @@ static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
#define dbg_io(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) #define dbg_io(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
#define dbg_bld(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__) #define dbg_bld(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
static inline void
ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) { return; }
static inline void
ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) { return; }
static inline void static inline void
ubi_dbg_dump_vol_info(const struct ubi_volume *vol) { return; } ubi_dbg_dump_vol_info(const struct ubi_volume *vol) { return; }
static inline void static inline void
......
...@@ -721,7 +721,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi, ...@@ -721,7 +721,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
bad: bad:
ubi_err("bad EC header"); ubi_err("bad EC header");
ubi_dbg_dump_ec_hdr(ec_hdr); ubi_dump_ec_hdr(ec_hdr);
dump_stack(); dump_stack();
return 1; return 1;
} }
...@@ -803,7 +803,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, ...@@ -803,7 +803,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
if (verbose) { if (verbose) {
ubi_warn("bad magic number at PEB %d: %08x instead of " ubi_warn("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_EC_HDR_MAGIC); "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
ubi_dbg_dump_ec_hdr(ec_hdr); ubi_dump_ec_hdr(ec_hdr);
} }
dbg_bld("bad magic number at PEB %d: %08x instead of " dbg_bld("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_EC_HDR_MAGIC); "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
...@@ -817,7 +817,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, ...@@ -817,7 +817,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
if (verbose) { if (verbose) {
ubi_warn("bad EC header CRC at PEB %d, calculated " ubi_warn("bad EC header CRC at PEB %d, calculated "
"%#08x, read %#08x", pnum, crc, hdr_crc); "%#08x, read %#08x", pnum, crc, hdr_crc);
ubi_dbg_dump_ec_hdr(ec_hdr); ubi_dump_ec_hdr(ec_hdr);
} }
dbg_bld("bad EC header CRC at PEB %d, calculated " dbg_bld("bad EC header CRC at PEB %d, calculated "
"%#08x, read %#08x", pnum, crc, hdr_crc); "%#08x, read %#08x", pnum, crc, hdr_crc);
...@@ -997,7 +997,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi, ...@@ -997,7 +997,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
bad: bad:
ubi_err("bad VID header"); ubi_err("bad VID header");
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
dump_stack(); dump_stack();
return 1; return 1;
} }
...@@ -1054,7 +1054,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, ...@@ -1054,7 +1054,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
if (verbose) { if (verbose) {
ubi_warn("bad magic number at PEB %d: %08x instead of " ubi_warn("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_VID_HDR_MAGIC); "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
} }
dbg_bld("bad magic number at PEB %d: %08x instead of " dbg_bld("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_VID_HDR_MAGIC); "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
...@@ -1068,7 +1068,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, ...@@ -1068,7 +1068,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
if (verbose) { if (verbose) {
ubi_warn("bad CRC at PEB %d, calculated %#08x, " ubi_warn("bad CRC at PEB %d, calculated %#08x, "
"read %#08x", pnum, crc, hdr_crc); "read %#08x", pnum, crc, hdr_crc);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
} }
dbg_bld("bad CRC at PEB %d, calculated %#08x, " dbg_bld("bad CRC at PEB %d, calculated %#08x, "
"read %#08x", pnum, crc, hdr_crc); "read %#08x", pnum, crc, hdr_crc);
...@@ -1191,7 +1191,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, ...@@ -1191,7 +1191,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
return 0; return 0;
fail: fail:
ubi_dbg_dump_ec_hdr(ec_hdr); ubi_dump_ec_hdr(ec_hdr);
dump_stack(); dump_stack();
return -EINVAL; return -EINVAL;
} }
...@@ -1226,7 +1226,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) ...@@ -1226,7 +1226,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
if (hdr_crc != crc) { if (hdr_crc != crc) {
ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc);
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
ubi_dbg_dump_ec_hdr(ec_hdr); ubi_dump_ec_hdr(ec_hdr);
dump_stack(); dump_stack();
err = -EINVAL; err = -EINVAL;
goto exit; goto exit;
...@@ -1274,7 +1274,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, ...@@ -1274,7 +1274,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
fail: fail:
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
dump_stack(); dump_stack();
return -EINVAL; return -EINVAL;
...@@ -1314,7 +1314,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) ...@@ -1314,7 +1314,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " ubi_err("bad VID header CRC at PEB %d, calculated %#08x, "
"read %#08x", pnum, crc, hdr_crc); "read %#08x", pnum, crc, hdr_crc);
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
dump_stack(); dump_stack();
err = -EINVAL; err = -EINVAL;
goto exit; goto exit;
......
...@@ -230,7 +230,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, ...@@ -230,7 +230,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
bad: bad:
ubi_err("inconsistent VID header at PEB %d", pnum); ubi_err("inconsistent VID header at PEB %d", pnum);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
ubi_dbg_dump_sv(sv); ubi_dbg_dump_sv(sv);
return -EINVAL; return -EINVAL;
} }
...@@ -511,7 +511,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -511,7 +511,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
ubi_err("two LEBs with same sequence number %llu", ubi_err("two LEBs with same sequence number %llu",
sqnum); sqnum);
ubi_dbg_dump_seb(seb, 0); ubi_dbg_dump_seb(seb, 0);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
return -EINVAL; return -EINVAL;
} }
...@@ -814,7 +814,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, ...@@ -814,7 +814,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
ubi_err("PEB %d contains corrupted VID header, and the data does not " ubi_err("PEB %d contains corrupted VID header, and the data does not "
"contain all 0xFF, this may be a non-UBI PEB or a severe VID " "contain all 0xFF, this may be a non-UBI PEB or a severe VID "
"header corruption which requires manual inspection", pnum); "header corruption which requires manual inspection", pnum);
ubi_dbg_dump_vid_hdr(vid_hdr); ubi_dump_vid_hdr(vid_hdr);
dbg_msg("hexdump of PEB %d offset %d, length %d", dbg_msg("hexdump of PEB %d offset %d, length %d",
pnum, ubi->leb_start, ubi->leb_size); pnum, ubi->leb_start, ubi->leb_size);
ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
...@@ -911,7 +911,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -911,7 +911,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
*/ */
ubi_err("erase counter overflow, max is %d", ubi_err("erase counter overflow, max is %d",
UBI_MAX_ERASECOUNTER); UBI_MAX_ERASECOUNTER);
ubi_dbg_dump_ec_hdr(ech); ubi_dump_ec_hdr(ech);
return -EINVAL; return -EINVAL;
} }
...@@ -933,7 +933,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -933,7 +933,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
ubi->image_seq != image_seq) { ubi->image_seq != image_seq) {
ubi_err("bad image sequence number %d in PEB %d, " ubi_err("bad image sequence number %d in PEB %d, "
"expected %d", image_seq, pnum, ubi->image_seq); "expected %d", image_seq, pnum, ubi->image_seq);
ubi_dbg_dump_ec_hdr(ech); ubi_dump_ec_hdr(ech);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -1595,7 +1595,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) ...@@ -1595,7 +1595,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
bad_vid_hdr: bad_vid_hdr:
ubi_err("bad scanning information about volume %d", sv->vol_id); ubi_err("bad scanning information about volume %d", sv->vol_id);
ubi_dbg_dump_sv(sv); ubi_dbg_dump_sv(sv);
ubi_dbg_dump_vid_hdr(vidh); ubi_dump_vid_hdr(vidh);
out: out:
dump_stack(); dump_stack();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment