Skip to content

Commit a904e3f

Browse files
committed
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: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent ef7088e commit a904e3f

4 files changed

Lines changed: 24 additions & 28 deletions

File tree

‎drivers/mtd/ubi/debug.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
5656
return;
5757
}
5858

59-
#ifdef CONFIG_MTD_UBI_DEBUG
60-
6159
/**
62-
* ubi_dbg_dump_ec_hdr - dump an erase counter header.
60+
* ubi_dump_ec_hdr - dump an erase counter header.
6361
* @ec_hdr: the erase counter header to dump
6462
*/
65-
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)
6664
{
6765
printk(KERN_DEBUG "Erase counter header dump:\n");
6866
printk(KERN_DEBUG "\tmagic %#08x\n",
@@ -84,10 +82,10 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
8482
}
8583

8684
/**
87-
* ubi_dbg_dump_vid_hdr - dump a volume identifier header.
85+
* ubi_dump_vid_hdr - dump a volume identifier header.
8886
* @vid_hdr: the volume identifier header to dump
8987
*/
90-
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)
9189
{
9290
printk(KERN_DEBUG "Volume identifier header dump:\n");
9391
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)
108106
vid_hdr, UBI_VID_HDR_SIZE, 1);
109107
}
110108

109+
#ifdef CONFIG_MTD_UBI_DEBUG
110+
111111
/**
112112
* ubi_dbg_dump_vol_info- dump volume information.
113113
* @vol: UBI volume description object

‎drivers/mtd/ubi/debug.h‎

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

2424
void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
25+
void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
26+
void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
2527

2628
#ifdef CONFIG_MTD_UBI_DEBUG
2729
#include <linux/random.h>
@@ -58,8 +60,6 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
5860
/* Initialization and build messages */
5961
#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
6062

61-
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
62-
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
6363
void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
6464
void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
6565
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)
193193
#define dbg_io(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
194194
#define dbg_bld(fmt, ...) ubi_dbg_msg(fmt, ##__VA_ARGS__)
195195

196-
static inline void
197-
ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) { return; }
198-
static inline void
199-
ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) { return; }
200196
static inline void
201197
ubi_dbg_dump_vol_info(const struct ubi_volume *vol) { return; }
202198
static inline void

‎drivers/mtd/ubi/io.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
721721

722722
bad:
723723
ubi_err("bad EC header");
724-
ubi_dbg_dump_ec_hdr(ec_hdr);
724+
ubi_dump_ec_hdr(ec_hdr);
725725
dump_stack();
726726
return 1;
727727
}
@@ -803,7 +803,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
803803
if (verbose) {
804804
ubi_warn("bad magic number at PEB %d: %08x instead of "
805805
"%08x", pnum, magic, UBI_EC_HDR_MAGIC);
806-
ubi_dbg_dump_ec_hdr(ec_hdr);
806+
ubi_dump_ec_hdr(ec_hdr);
807807
}
808808
dbg_bld("bad magic number at PEB %d: %08x instead of "
809809
"%08x", pnum, magic, UBI_EC_HDR_MAGIC);
@@ -817,7 +817,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
817817
if (verbose) {
818818
ubi_warn("bad EC header CRC at PEB %d, calculated "
819819
"%#08x, read %#08x", pnum, crc, hdr_crc);
820-
ubi_dbg_dump_ec_hdr(ec_hdr);
820+
ubi_dump_ec_hdr(ec_hdr);
821821
}
822822
dbg_bld("bad EC header CRC at PEB %d, calculated "
823823
"%#08x, read %#08x", pnum, crc, hdr_crc);
@@ -997,7 +997,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
997997

998998
bad:
999999
ubi_err("bad VID header");
1000-
ubi_dbg_dump_vid_hdr(vid_hdr);
1000+
ubi_dump_vid_hdr(vid_hdr);
10011001
dump_stack();
10021002
return 1;
10031003
}
@@ -1054,7 +1054,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
10541054
if (verbose) {
10551055
ubi_warn("bad magic number at PEB %d: %08x instead of "
10561056
"%08x", pnum, magic, UBI_VID_HDR_MAGIC);
1057-
ubi_dbg_dump_vid_hdr(vid_hdr);
1057+
ubi_dump_vid_hdr(vid_hdr);
10581058
}
10591059
dbg_bld("bad magic number at PEB %d: %08x instead of "
10601060
"%08x", pnum, magic, UBI_VID_HDR_MAGIC);
@@ -1068,7 +1068,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
10681068
if (verbose) {
10691069
ubi_warn("bad CRC at PEB %d, calculated %#08x, "
10701070
"read %#08x", pnum, crc, hdr_crc);
1071-
ubi_dbg_dump_vid_hdr(vid_hdr);
1071+
ubi_dump_vid_hdr(vid_hdr);
10721072
}
10731073
dbg_bld("bad CRC at PEB %d, calculated %#08x, "
10741074
"read %#08x", pnum, crc, hdr_crc);
@@ -1191,7 +1191,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
11911191
return 0;
11921192

11931193
fail:
1194-
ubi_dbg_dump_ec_hdr(ec_hdr);
1194+
ubi_dump_ec_hdr(ec_hdr);
11951195
dump_stack();
11961196
return -EINVAL;
11971197
}
@@ -1226,7 +1226,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
12261226
if (hdr_crc != crc) {
12271227
ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc);
12281228
ubi_err("paranoid check failed for PEB %d", pnum);
1229-
ubi_dbg_dump_ec_hdr(ec_hdr);
1229+
ubi_dump_ec_hdr(ec_hdr);
12301230
dump_stack();
12311231
err = -EINVAL;
12321232
goto exit;
@@ -1274,7 +1274,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
12741274

12751275
fail:
12761276
ubi_err("paranoid check failed for PEB %d", pnum);
1277-
ubi_dbg_dump_vid_hdr(vid_hdr);
1277+
ubi_dump_vid_hdr(vid_hdr);
12781278
dump_stack();
12791279
return -EINVAL;
12801280

@@ -1314,7 +1314,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
13141314
ubi_err("bad VID header CRC at PEB %d, calculated %#08x, "
13151315
"read %#08x", pnum, crc, hdr_crc);
13161316
ubi_err("paranoid check failed for PEB %d", pnum);
1317-
ubi_dbg_dump_vid_hdr(vid_hdr);
1317+
ubi_dump_vid_hdr(vid_hdr);
13181318
dump_stack();
13191319
err = -EINVAL;
13201320
goto exit;

‎drivers/mtd/ubi/scan.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
230230

231231
bad:
232232
ubi_err("inconsistent VID header at PEB %d", pnum);
233-
ubi_dbg_dump_vid_hdr(vid_hdr);
233+
ubi_dump_vid_hdr(vid_hdr);
234234
ubi_dbg_dump_sv(sv);
235235
return -EINVAL;
236236
}
@@ -511,7 +511,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
511511
ubi_err("two LEBs with same sequence number %llu",
512512
sqnum);
513513
ubi_dbg_dump_seb(seb, 0);
514-
ubi_dbg_dump_vid_hdr(vid_hdr);
514+
ubi_dump_vid_hdr(vid_hdr);
515515
return -EINVAL;
516516
}
517517

@@ -814,7 +814,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
814814
ubi_err("PEB %d contains corrupted VID header, and the data does not "
815815
"contain all 0xFF, this may be a non-UBI PEB or a severe VID "
816816
"header corruption which requires manual inspection", pnum);
817-
ubi_dbg_dump_vid_hdr(vid_hdr);
817+
ubi_dump_vid_hdr(vid_hdr);
818818
dbg_msg("hexdump of PEB %d offset %d, length %d",
819819
pnum, ubi->leb_start, ubi->leb_size);
820820
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,
911911
*/
912912
ubi_err("erase counter overflow, max is %d",
913913
UBI_MAX_ERASECOUNTER);
914-
ubi_dbg_dump_ec_hdr(ech);
914+
ubi_dump_ec_hdr(ech);
915915
return -EINVAL;
916916
}
917917

@@ -933,7 +933,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
933933
ubi->image_seq != image_seq) {
934934
ubi_err("bad image sequence number %d in PEB %d, "
935935
"expected %d", image_seq, pnum, ubi->image_seq);
936-
ubi_dbg_dump_ec_hdr(ech);
936+
ubi_dump_ec_hdr(ech);
937937
return -EINVAL;
938938
}
939939
}
@@ -1595,7 +1595,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
15951595
bad_vid_hdr:
15961596
ubi_err("bad scanning information about volume %d", sv->vol_id);
15971597
ubi_dbg_dump_sv(sv);
1598-
ubi_dbg_dump_vid_hdr(vidh);
1598+
ubi_dump_vid_hdr(vidh);
15991599

16001600
out:
16011601
dump_stack();

0 commit comments

Comments
 (0)