blob: 0cd5beabe9c903518e6d0e7b05ac1ad13c43784e [file] [log] [blame]
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +04001/*
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 Bityutskiyc8566352008-07-16 17:40:22 +030027#ifdef CONFIG_MTD_UBI_DEBUG
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040028
29#include "ubi.h"
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020030#include <linux/module.h>
31#include <linux/moduleparam.h>
32
33unsigned int ubi_msg_flags;
Artem Bityutskiy92d124f2011-03-14 18:17:40 +020034unsigned int ubi_chk_flags;
Artem Bityutskiy28237e42011-03-15 10:30:40 +020035unsigned int ubi_tst_flags;
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020036
37module_param_named(debug_msgs, ubi_msg_flags, uint, S_IRUGO | S_IWUSR);
Artem Bityutskiy92d124f2011-03-14 18:17:40 +020038module_param_named(debug_chks, ubi_chk_flags, uint, S_IRUGO | S_IWUSR);
Artem Bityutskiy28237e42011-03-15 10:30:40 +020039module_param_named(debug_tsts, ubi_chk_flags, uint, S_IRUGO | S_IWUSR);
Artem Bityutskiyb342efd2011-03-11 14:33:23 +020040
41MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
Artem Bityutskiy92d124f2011-03-14 18:17:40 +020042MODULE_PARM_DESC(debug_chks, "Debug check flags");
Artem Bityutskiy28237e42011-03-15 10:30:40 +020043MODULE_PARM_DESC(debug_tsts, "Debug special test flags");
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040044
45/**
46 * ubi_dbg_dump_ec_hdr - dump an erase counter header.
47 * @ec_hdr: the erase counter header to dump
48 */
49void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
50{
Artem Bityutskiyc8566352008-07-16 17:40:22 +030051 printk(KERN_DEBUG "Erase counter header dump:\n");
52 printk(KERN_DEBUG "\tmagic %#08x\n",
53 be32_to_cpu(ec_hdr->magic));
54 printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version);
55 printk(KERN_DEBUG "\tec %llu\n",
56 (long long)be64_to_cpu(ec_hdr->ec));
57 printk(KERN_DEBUG "\tvid_hdr_offset %d\n",
58 be32_to_cpu(ec_hdr->vid_hdr_offset));
59 printk(KERN_DEBUG "\tdata_offset %d\n",
60 be32_to_cpu(ec_hdr->data_offset));
Adrian Hunter0c6c7fa2009-06-26 14:58:01 +030061 printk(KERN_DEBUG "\timage_seq %d\n",
62 be32_to_cpu(ec_hdr->image_seq));
Artem Bityutskiyc8566352008-07-16 17:40:22 +030063 printk(KERN_DEBUG "\thdr_crc %#08x\n",
64 be32_to_cpu(ec_hdr->hdr_crc));
65 printk(KERN_DEBUG "erase counter header hexdump:\n");
Artem Bityutskiy69866462007-08-29 14:56:20 +030066 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
67 ec_hdr, UBI_EC_HDR_SIZE, 1);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040068}
69
70/**
71 * ubi_dbg_dump_vid_hdr - dump a volume identifier header.
72 * @vid_hdr: the volume identifier header to dump
73 */
74void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
75{
Artem Bityutskiyc8566352008-07-16 17:40:22 +030076 printk(KERN_DEBUG "Volume identifier header dump:\n");
77 printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
Artem Bityutskiyfeddbb32011-03-28 10:12:25 +030078 printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version);
79 printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type);
80 printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag);
81 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat);
82 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id));
83 printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum));
84 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size));
85 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs));
86 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
Artem Bityutskiyc8566352008-07-16 17:40:22 +030087 printk(KERN_DEBUG "\tsqnum %llu\n",
Christoph Hellwig3261ebd2007-05-21 17:41:46 +030088 (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
Artem Bityutskiyc8566352008-07-16 17:40:22 +030089 printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
90 printk(KERN_DEBUG "Volume identifier header hexdump:\n");
91 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
92 vid_hdr, UBI_VID_HDR_SIZE, 1);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +040093}
94
95/**
96 * ubi_dbg_dump_vol_info- dump volume information.
97 * @vol: UBI volume description object
98 */
99void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
100{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300101 printk(KERN_DEBUG "Volume information dump:\n");
102 printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id);
103 printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs);
104 printk(KERN_DEBUG "\talignment %d\n", vol->alignment);
105 printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad);
106 printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type);
107 printk(KERN_DEBUG "\tname_len %d\n", vol->name_len);
108 printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size);
109 printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs);
110 printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes);
111 printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes);
112 printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted);
113 printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400114
115 if (vol->name_len <= UBI_VOL_NAME_MAX &&
116 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300117 printk(KERN_DEBUG "\tname %s\n", vol->name);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400118 } else {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300119 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
120 vol->name[0], vol->name[1], vol->name[2],
121 vol->name[3], vol->name[4]);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400122 }
123}
124
125/**
126 * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
127 * @r: the object to dump
128 * @idx: volume table index
129 */
130void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
131{
Christoph Hellwig3261ebd2007-05-21 17:41:46 +0300132 int name_len = be16_to_cpu(r->name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400133
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300134 printk(KERN_DEBUG "Volume table record %d dump:\n", idx);
135 printk(KERN_DEBUG "\treserved_pebs %d\n",
136 be32_to_cpu(r->reserved_pebs));
137 printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment));
138 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad));
139 printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type);
140 printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker);
141 printk(KERN_DEBUG "\tname_len %d\n", name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400142
143 if (r->name[0] == '\0') {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300144 printk(KERN_DEBUG "\tname NULL\n");
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400145 return;
146 }
147
148 if (name_len <= UBI_VOL_NAME_MAX &&
149 strnlen(&r->name[0], name_len + 1) == name_len) {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300150 printk(KERN_DEBUG "\tname %s\n", &r->name[0]);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400151 } else {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300152 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400153 r->name[0], r->name[1], r->name[2], r->name[3],
154 r->name[4]);
155 }
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300156 printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc));
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400157}
158
159/**
160 * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object.
161 * @sv: the object to dump
162 */
163void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
164{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300165 printk(KERN_DEBUG "Volume scanning information dump:\n");
166 printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id);
167 printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum);
168 printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count);
169 printk(KERN_DEBUG "\tcompat %d\n", sv->compat);
170 printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type);
171 printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs);
172 printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size);
173 printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400174}
175
176/**
177 * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object.
178 * @seb: the object to dump
179 * @type: object type: 0 - not corrupted, 1 - corrupted
180 */
181void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
182{
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300183 printk(KERN_DEBUG "eraseblock scanning information dump:\n");
184 printk(KERN_DEBUG "\tec %d\n", seb->ec);
185 printk(KERN_DEBUG "\tpnum %d\n", seb->pnum);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400186 if (type == 0) {
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300187 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum);
188 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub);
189 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400190 }
191}
192
193/**
194 * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
195 * @req: the object to dump
196 */
197void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
198{
199 char nm[17];
200
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300201 printk(KERN_DEBUG "Volume creation request dump:\n");
202 printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id);
203 printk(KERN_DEBUG "\talignment %d\n", req->alignment);
204 printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes);
205 printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type);
206 printk(KERN_DEBUG "\tname_len %d\n", req->name_len);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400207
208 memcpy(nm, req->name, 16);
209 nm[16] = 0;
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300210 printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
Artem B. Bityutskiy801c1352006-06-27 12:22:22 +0400211}
212
Artem Bityutskiy867996b2009-07-24 15:31:33 +0300213/**
214 * ubi_dbg_dump_flash - dump a region of flash.
215 * @ubi: UBI device description object
216 * @pnum: the physical eraseblock number to dump
217 * @offset: the starting offset within the physical eraseblock to dump
218 * @len: the length of the region to dump
219 */
220void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
221{
222 int err;
223 size_t read;
224 void *buf;
225 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
226
227 buf = vmalloc(len);
228 if (!buf)
229 return;
230 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
231 if (err && err != -EUCLEAN) {
232 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
233 "read %zd bytes", err, len, pnum, offset, read);
234 goto out;
235 }
236
237 dbg_msg("dumping %d bytes of data from PEB %d, offset %d",
238 len, pnum, offset);
239 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
240out:
241 vfree(buf);
242 return;
243}
244
Artem Bityutskiyc8566352008-07-16 17:40:22 +0300245#endif /* CONFIG_MTD_UBI_DEBUG */