Commit | Line | Data |
---|---|---|
801c135c AB |
1 | /* |
2 | * Copyright (c) International Business Machines Corp., 2006 | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
12 | * the GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | * | |
18 | * Author: Artem Bityutskiy (Битюцкий Артём) | |
19 | */ | |
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_MSG | |
28 | ||
29 | #include "ubi.h" | |
30 | ||
31 | /** | |
32 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. | |
33 | * @ec_hdr: the erase counter header to dump | |
34 | */ | |
35 | void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | |
36 | { | |
37 | dbg_msg("erase counter header dump:"); | |
3261ebd7 | 38 | dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic)); |
801c135c | 39 | dbg_msg("version %d", (int)ec_hdr->version); |
3261ebd7 CH |
40 | dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec)); |
41 | dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset)); | |
42 | dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset)); | |
43 | dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc)); | |
801c135c | 44 | dbg_msg("erase counter header hexdump:"); |
6986646b AB |
45 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
46 | ec_hdr, UBI_EC_HDR_SIZE, 1); | |
801c135c AB |
47 | } |
48 | ||
49 | /** | |
50 | * ubi_dbg_dump_vid_hdr - dump a volume identifier header. | |
51 | * @vid_hdr: the volume identifier header to dump | |
52 | */ | |
53 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | |
54 | { | |
55 | dbg_msg("volume identifier header dump:"); | |
3261ebd7 | 56 | dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic)); |
801c135c AB |
57 | dbg_msg("version %d", (int)vid_hdr->version); |
58 | dbg_msg("vol_type %d", (int)vid_hdr->vol_type); | |
59 | dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag); | |
60 | dbg_msg("compat %d", (int)vid_hdr->compat); | |
3261ebd7 CH |
61 | dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id)); |
62 | dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum)); | |
63 | dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver)); | |
64 | dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size)); | |
65 | dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs)); | |
66 | dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad)); | |
801c135c | 67 | dbg_msg("sqnum %llu", |
3261ebd7 CH |
68 | (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); |
69 | dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc)); | |
801c135c AB |
70 | dbg_msg("volume identifier header hexdump:"); |
71 | } | |
72 | ||
73 | /** | |
74 | * ubi_dbg_dump_vol_info- dump volume information. | |
75 | * @vol: UBI volume description object | |
76 | */ | |
77 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) | |
78 | { | |
79 | dbg_msg("volume information dump:"); | |
80 | dbg_msg("vol_id %d", vol->vol_id); | |
81 | dbg_msg("reserved_pebs %d", vol->reserved_pebs); | |
82 | dbg_msg("alignment %d", vol->alignment); | |
83 | dbg_msg("data_pad %d", vol->data_pad); | |
84 | dbg_msg("vol_type %d", vol->vol_type); | |
85 | dbg_msg("name_len %d", vol->name_len); | |
86 | dbg_msg("usable_leb_size %d", vol->usable_leb_size); | |
87 | dbg_msg("used_ebs %d", vol->used_ebs); | |
88 | dbg_msg("used_bytes %lld", vol->used_bytes); | |
89 | dbg_msg("last_eb_bytes %d", vol->last_eb_bytes); | |
90 | dbg_msg("corrupted %d", vol->corrupted); | |
91 | dbg_msg("upd_marker %d", vol->upd_marker); | |
92 | ||
93 | if (vol->name_len <= UBI_VOL_NAME_MAX && | |
94 | strnlen(vol->name, vol->name_len + 1) == vol->name_len) { | |
94784d91 | 95 | dbg_msg("name %s", vol->name); |
801c135c AB |
96 | } else { |
97 | dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c", | |
98 | vol->name[0], vol->name[1], vol->name[2], | |
99 | vol->name[3], vol->name[4]); | |
100 | } | |
101 | } | |
102 | ||
103 | /** | |
104 | * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object. | |
105 | * @r: the object to dump | |
106 | * @idx: volume table index | |
107 | */ | |
108 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | |
109 | { | |
3261ebd7 | 110 | int name_len = be16_to_cpu(r->name_len); |
801c135c AB |
111 | |
112 | dbg_msg("volume table record %d dump:", idx); | |
3261ebd7 CH |
113 | dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs)); |
114 | dbg_msg("alignment %d", be32_to_cpu(r->alignment)); | |
115 | dbg_msg("data_pad %d", be32_to_cpu(r->data_pad)); | |
801c135c AB |
116 | dbg_msg("vol_type %d", (int)r->vol_type); |
117 | dbg_msg("upd_marker %d", (int)r->upd_marker); | |
118 | dbg_msg("name_len %d", name_len); | |
119 | ||
120 | if (r->name[0] == '\0') { | |
94784d91 | 121 | dbg_msg("name NULL"); |
801c135c AB |
122 | return; |
123 | } | |
124 | ||
125 | if (name_len <= UBI_VOL_NAME_MAX && | |
126 | strnlen(&r->name[0], name_len + 1) == name_len) { | |
94784d91 | 127 | dbg_msg("name %s", &r->name[0]); |
801c135c AB |
128 | } else { |
129 | dbg_msg("1st 5 characters of the name: %c%c%c%c%c", | |
130 | r->name[0], r->name[1], r->name[2], r->name[3], | |
131 | r->name[4]); | |
132 | } | |
3261ebd7 | 133 | dbg_msg("crc %#08x", be32_to_cpu(r->crc)); |
801c135c AB |
134 | } |
135 | ||
136 | /** | |
137 | * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object. | |
138 | * @sv: the object to dump | |
139 | */ | |
140 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) | |
141 | { | |
142 | dbg_msg("volume scanning information dump:"); | |
143 | dbg_msg("vol_id %d", sv->vol_id); | |
144 | dbg_msg("highest_lnum %d", sv->highest_lnum); | |
145 | dbg_msg("leb_count %d", sv->leb_count); | |
146 | dbg_msg("compat %d", sv->compat); | |
147 | dbg_msg("vol_type %d", sv->vol_type); | |
148 | dbg_msg("used_ebs %d", sv->used_ebs); | |
149 | dbg_msg("last_data_size %d", sv->last_data_size); | |
150 | dbg_msg("data_pad %d", sv->data_pad); | |
151 | } | |
152 | ||
153 | /** | |
154 | * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object. | |
155 | * @seb: the object to dump | |
156 | * @type: object type: 0 - not corrupted, 1 - corrupted | |
157 | */ | |
158 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) | |
159 | { | |
160 | dbg_msg("eraseblock scanning information dump:"); | |
161 | dbg_msg("ec %d", seb->ec); | |
162 | dbg_msg("pnum %d", seb->pnum); | |
163 | if (type == 0) { | |
164 | dbg_msg("lnum %d", seb->lnum); | |
165 | dbg_msg("scrub %d", seb->scrub); | |
166 | dbg_msg("sqnum %llu", seb->sqnum); | |
167 | dbg_msg("leb_ver %u", seb->leb_ver); | |
168 | } | |
169 | } | |
170 | ||
171 | /** | |
172 | * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object. | |
173 | * @req: the object to dump | |
174 | */ | |
175 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) | |
176 | { | |
177 | char nm[17]; | |
178 | ||
179 | dbg_msg("volume creation request dump:"); | |
180 | dbg_msg("vol_id %d", req->vol_id); | |
181 | dbg_msg("alignment %d", req->alignment); | |
182 | dbg_msg("bytes %lld", (long long)req->bytes); | |
183 | dbg_msg("vol_type %d", req->vol_type); | |
184 | dbg_msg("name_len %d", req->name_len); | |
185 | ||
186 | memcpy(nm, req->name, 16); | |
187 | nm[16] = 0; | |
188 | dbg_msg("the 1st 16 characters of the name: %s", nm); | |
189 | } | |
190 | ||
801c135c | 191 | #endif /* CONFIG_MTD_UBI_DEBUG_MSG */ |