blob: 6c22301d932cc47d5e702a388e507b0f0518d9c7 [file] [log] [blame]
Kyungmin Park961df832008-11-19 16:25:44 +01001/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kyungmin Park961df832008-11-19 16:25:44 +01005 *
6 * Author: Artem Bityutskiy (Битюцкий Артём)
7 */
8
9/*
10 * Here we keep all the UBI debugging stuff which should normally be disabled
11 * and compiled-out, but it is extremely helpful when hunting bugs or doing big
12 * changes.
13 */
14#include <ubi_uboot.h>
15
16#ifdef CONFIG_MTD_UBI_DEBUG_MSG
17
18#include "ubi.h"
19
20/**
21 * ubi_dbg_dump_ec_hdr - dump an erase counter header.
22 * @ec_hdr: the erase counter header to dump
23 */
24void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
25{
26 dbg_msg("erase counter header dump:");
27 dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic));
28 dbg_msg("version %d", (int)ec_hdr->version);
29 dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec));
30 dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset));
31 dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset));
32 dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc));
33 dbg_msg("erase counter header hexdump:");
34 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
35 ec_hdr, UBI_EC_HDR_SIZE, 1);
36}
37
38/**
39 * ubi_dbg_dump_vid_hdr - dump a volume identifier header.
40 * @vid_hdr: the volume identifier header to dump
41 */
42void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
43{
44 dbg_msg("volume identifier header dump:");
45 dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic));
46 dbg_msg("version %d", (int)vid_hdr->version);
47 dbg_msg("vol_type %d", (int)vid_hdr->vol_type);
48 dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag);
49 dbg_msg("compat %d", (int)vid_hdr->compat);
50 dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id));
51 dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum));
52 dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver));
53 dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size));
54 dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs));
55 dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad));
56 dbg_msg("sqnum %llu",
57 (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
58 dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc));
59 dbg_msg("volume identifier header hexdump:");
60}
61
62/**
63 * ubi_dbg_dump_vol_info- dump volume information.
64 * @vol: UBI volume description object
65 */
66void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
67{
68 dbg_msg("volume information dump:");
69 dbg_msg("vol_id %d", vol->vol_id);
70 dbg_msg("reserved_pebs %d", vol->reserved_pebs);
71 dbg_msg("alignment %d", vol->alignment);
72 dbg_msg("data_pad %d", vol->data_pad);
73 dbg_msg("vol_type %d", vol->vol_type);
74 dbg_msg("name_len %d", vol->name_len);
75 dbg_msg("usable_leb_size %d", vol->usable_leb_size);
76 dbg_msg("used_ebs %d", vol->used_ebs);
77 dbg_msg("used_bytes %lld", vol->used_bytes);
78 dbg_msg("last_eb_bytes %d", vol->last_eb_bytes);
79 dbg_msg("corrupted %d", vol->corrupted);
80 dbg_msg("upd_marker %d", vol->upd_marker);
81
82 if (vol->name_len <= UBI_VOL_NAME_MAX &&
83 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
84 dbg_msg("name %s", vol->name);
85 } else {
86 dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c",
87 vol->name[0], vol->name[1], vol->name[2],
88 vol->name[3], vol->name[4]);
89 }
90}
91
92/**
93 * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
94 * @r: the object to dump
95 * @idx: volume table index
96 */
97void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
98{
99 int name_len = be16_to_cpu(r->name_len);
100
101 dbg_msg("volume table record %d dump:", idx);
102 dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs));
103 dbg_msg("alignment %d", be32_to_cpu(r->alignment));
104 dbg_msg("data_pad %d", be32_to_cpu(r->data_pad));
105 dbg_msg("vol_type %d", (int)r->vol_type);
106 dbg_msg("upd_marker %d", (int)r->upd_marker);
107 dbg_msg("name_len %d", name_len);
108
109 if (r->name[0] == '\0') {
110 dbg_msg("name NULL");
111 return;
112 }
113
114 if (name_len <= UBI_VOL_NAME_MAX &&
115 strnlen(&r->name[0], name_len + 1) == name_len) {
116 dbg_msg("name %s", &r->name[0]);
117 } else {
118 dbg_msg("1st 5 characters of the name: %c%c%c%c%c",
119 r->name[0], r->name[1], r->name[2], r->name[3],
120 r->name[4]);
121 }
122 dbg_msg("crc %#08x", be32_to_cpu(r->crc));
123}
124
125/**
126 * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object.
127 * @sv: the object to dump
128 */
129void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
130{
131 dbg_msg("volume scanning information dump:");
132 dbg_msg("vol_id %d", sv->vol_id);
133 dbg_msg("highest_lnum %d", sv->highest_lnum);
134 dbg_msg("leb_count %d", sv->leb_count);
135 dbg_msg("compat %d", sv->compat);
136 dbg_msg("vol_type %d", sv->vol_type);
137 dbg_msg("used_ebs %d", sv->used_ebs);
138 dbg_msg("last_data_size %d", sv->last_data_size);
139 dbg_msg("data_pad %d", sv->data_pad);
140}
141
142/**
143 * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object.
144 * @seb: the object to dump
145 * @type: object type: 0 - not corrupted, 1 - corrupted
146 */
147void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
148{
149 dbg_msg("eraseblock scanning information dump:");
150 dbg_msg("ec %d", seb->ec);
151 dbg_msg("pnum %d", seb->pnum);
152 if (type == 0) {
153 dbg_msg("lnum %d", seb->lnum);
154 dbg_msg("scrub %d", seb->scrub);
155 dbg_msg("sqnum %llu", seb->sqnum);
156 dbg_msg("leb_ver %u", seb->leb_ver);
157 }
158}
159
160/**
161 * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
162 * @req: the object to dump
163 */
164void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
165{
166 char nm[17];
167
168 dbg_msg("volume creation request dump:");
169 dbg_msg("vol_id %d", req->vol_id);
170 dbg_msg("alignment %d", req->alignment);
171 dbg_msg("bytes %lld", (long long)req->bytes);
172 dbg_msg("vol_type %d", req->vol_type);
173 dbg_msg("name_len %d", req->name_len);
174
175 memcpy(nm, req->name, 16);
176 nm[16] = 0;
177 dbg_msg("the 1st 16 characters of the name: %s", nm);
178}
179
180#endif /* CONFIG_MTD_UBI_DEBUG_MSG */