Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 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 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 27 | #ifdef CONFIG_MTD_UBI_DEBUG |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 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 | { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 37 | printk(KERN_DEBUG "Erase counter header dump:\n"); |
| 38 | printk(KERN_DEBUG "\tmagic %#08x\n", |
| 39 | be32_to_cpu(ec_hdr->magic)); |
| 40 | printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version); |
| 41 | printk(KERN_DEBUG "\tec %llu\n", |
| 42 | (long long)be64_to_cpu(ec_hdr->ec)); |
| 43 | printk(KERN_DEBUG "\tvid_hdr_offset %d\n", |
| 44 | be32_to_cpu(ec_hdr->vid_hdr_offset)); |
| 45 | printk(KERN_DEBUG "\tdata_offset %d\n", |
| 46 | be32_to_cpu(ec_hdr->data_offset)); |
| 47 | printk(KERN_DEBUG "\thdr_crc %#08x\n", |
| 48 | be32_to_cpu(ec_hdr->hdr_crc)); |
| 49 | printk(KERN_DEBUG "erase counter header hexdump:\n"); |
Artem Bityutskiy | 6986646 | 2007-08-29 14:56:20 +0300 | [diff] [blame] | 50 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
| 51 | ec_hdr, UBI_EC_HDR_SIZE, 1); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * ubi_dbg_dump_vid_hdr - dump a volume identifier header. |
| 56 | * @vid_hdr: the volume identifier header to dump |
| 57 | */ |
| 58 | void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) |
| 59 | { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 60 | printk(KERN_DEBUG "Volume identifier header dump:\n"); |
| 61 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); |
| 62 | printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version); |
| 63 | printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type); |
| 64 | printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag); |
| 65 | printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); |
| 66 | printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); |
| 67 | printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 68 | printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); |
| 69 | printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); |
| 70 | printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); |
| 71 | printk(KERN_DEBUG "\tsqnum %llu\n", |
Christoph Hellwig | 3261ebd | 2007-05-21 17:41:46 +0300 | [diff] [blame] | 72 | (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 73 | printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc)); |
| 74 | printk(KERN_DEBUG "Volume identifier header hexdump:\n"); |
| 75 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
| 76 | vid_hdr, UBI_VID_HDR_SIZE, 1); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * ubi_dbg_dump_vol_info- dump volume information. |
| 81 | * @vol: UBI volume description object |
| 82 | */ |
| 83 | void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) |
| 84 | { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 85 | printk(KERN_DEBUG "Volume information dump:\n"); |
| 86 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); |
| 87 | printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs); |
| 88 | printk(KERN_DEBUG "\talignment %d\n", vol->alignment); |
| 89 | printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad); |
| 90 | printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type); |
| 91 | printk(KERN_DEBUG "\tname_len %d\n", vol->name_len); |
| 92 | printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size); |
| 93 | printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs); |
| 94 | printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes); |
| 95 | printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes); |
| 96 | printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted); |
| 97 | printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 98 | |
| 99 | if (vol->name_len <= UBI_VOL_NAME_MAX && |
| 100 | strnlen(vol->name, vol->name_len + 1) == vol->name_len) { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 101 | printk(KERN_DEBUG "\tname %s\n", vol->name); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 102 | } else { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 103 | printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", |
| 104 | vol->name[0], vol->name[1], vol->name[2], |
| 105 | vol->name[3], vol->name[4]); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object. |
| 111 | * @r: the object to dump |
| 112 | * @idx: volume table index |
| 113 | */ |
| 114 | void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) |
| 115 | { |
Christoph Hellwig | 3261ebd | 2007-05-21 17:41:46 +0300 | [diff] [blame] | 116 | int name_len = be16_to_cpu(r->name_len); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 117 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 118 | printk(KERN_DEBUG "Volume table record %d dump:\n", idx); |
| 119 | printk(KERN_DEBUG "\treserved_pebs %d\n", |
| 120 | be32_to_cpu(r->reserved_pebs)); |
| 121 | printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment)); |
| 122 | printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad)); |
| 123 | printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type); |
| 124 | printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker); |
| 125 | printk(KERN_DEBUG "\tname_len %d\n", name_len); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 126 | |
| 127 | if (r->name[0] == '\0') { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 128 | printk(KERN_DEBUG "\tname NULL\n"); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 129 | return; |
| 130 | } |
| 131 | |
| 132 | if (name_len <= UBI_VOL_NAME_MAX && |
| 133 | strnlen(&r->name[0], name_len + 1) == name_len) { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 134 | printk(KERN_DEBUG "\tname %s\n", &r->name[0]); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 135 | } else { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 136 | printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 137 | r->name[0], r->name[1], r->name[2], r->name[3], |
| 138 | r->name[4]); |
| 139 | } |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 140 | printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc)); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
| 144 | * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object. |
| 145 | * @sv: the object to dump |
| 146 | */ |
| 147 | void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) |
| 148 | { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 149 | printk(KERN_DEBUG "Volume scanning information dump:\n"); |
| 150 | printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id); |
| 151 | printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum); |
| 152 | printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count); |
| 153 | printk(KERN_DEBUG "\tcompat %d\n", sv->compat); |
| 154 | printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type); |
| 155 | printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs); |
| 156 | printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size); |
| 157 | printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** |
| 161 | * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object. |
| 162 | * @seb: the object to dump |
| 163 | * @type: object type: 0 - not corrupted, 1 - corrupted |
| 164 | */ |
| 165 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) |
| 166 | { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 167 | printk(KERN_DEBUG "eraseblock scanning information dump:\n"); |
| 168 | printk(KERN_DEBUG "\tec %d\n", seb->ec); |
| 169 | printk(KERN_DEBUG "\tpnum %d\n", seb->pnum); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 170 | if (type == 0) { |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 171 | printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); |
| 172 | printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); |
| 173 | printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object. |
| 179 | * @req: the object to dump |
| 180 | */ |
| 181 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req) |
| 182 | { |
| 183 | char nm[17]; |
| 184 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 185 | printk(KERN_DEBUG "Volume creation request dump:\n"); |
| 186 | printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id); |
| 187 | printk(KERN_DEBUG "\talignment %d\n", req->alignment); |
| 188 | printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes); |
| 189 | printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type); |
| 190 | printk(KERN_DEBUG "\tname_len %d\n", req->name_len); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 191 | |
| 192 | memcpy(nm, req->name, 16); |
| 193 | nm[16] = 0; |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 194 | printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm); |
Artem B. Bityutskiy | 801c135 | 2006-06-27 12:22:22 +0400 | [diff] [blame] | 195 | } |
| 196 | |
Artem Bityutskiy | c856635 | 2008-07-16 17:40:22 +0300 | [diff] [blame] | 197 | #endif /* CONFIG_MTD_UBI_DEBUG */ |