aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/debug.c
diff options
context:
space:
mode:
authorArtem B. Bityutskiy <dedekind@linutronix.de>2006-06-27 04:22:22 -0400
committerFrank Haverkamp <haver@vnet.ibm.com>2007-04-27 07:23:33 -0400
commit801c135ce73d5df1caf3eca35b66a10824ae0707 (patch)
treeeaf6e7859650557192533b70746479de686c56e1 /drivers/mtd/ubi/debug.c
parentde46c33745f5e2ad594c72f2cf5f490861b16ce1 (diff)
UBI: Unsorted Block Images
UBI (Latin: "where?") manages multiple logical volumes on a single flash device, specifically supporting NAND flash devices. UBI provides a flexible partitioning concept which still allows for wear-levelling across the whole flash device. In a sense, UBI may be compared to the Logical Volume Manager (LVM). Whereas LVM maps logical sector numbers to physical HDD sector numbers, UBI maps logical eraseblocks to physical eraseblocks. More information may be found at http://www.linux-mtd.infradead.org/doc/ubi.html Partitioning/Re-partitioning An UBI volume occupies a certain number of erase blocks. This is limited by a configured maximum volume size, which could also be viewed as the partition size. Each individual UBI volume's size can be changed independently of the other UBI volumes, provided that the sum of all volume sizes doesn't exceed a certain limit. UBI supports dynamic volumes and static volumes. Static volumes are read-only and their contents are protected by CRC check sums. Bad eraseblocks handling UBI transparently handles bad eraseblocks. When a physical eraseblock becomes bad, it is substituted by a good physical eraseblock, and the user does not even notice this. Scrubbing On a NAND flash bit flips can occur on any write operation, sometimes also on read. If bit flips persist on the device, at first they can still be corrected by ECC, but once they accumulate, correction will become impossible. Thus it is best to actively scrub the affected eraseblock, by first copying it to a free eraseblock and then erasing the original. The UBI layer performs this type of scrubbing under the covers, transparently to the UBI volume users. Erase Counts UBI maintains an erase count header per eraseblock. This frees higher-level layers (like file systems) from doing this and allows for centralized erase count management instead. The erase counts are used by the wear-levelling algorithm in the UBI layer. The algorithm itself is exchangeable. Booting from NAND For booting directly from NAND flash the hardware must at least be capable of fetching and executing a small portion of the NAND flash. Some NAND flash controllers have this kind of support. They usually limit the window to a few kilobytes in erase block 0. This "initial program loader" (IPL) must then contain sufficient logic to load and execute the next boot phase. Due to bad eraseblocks, which may be randomly scattered over the flash device, it is problematic to store the "secondary program loader" (SPL) statically. Also, due to bit-flips it may become corrupted over time. UBI allows to solve this problem gracefully by storing the SPL in a small static UBI volume. UBI volumes vs. static partitions UBI volumes are still very similar to static MTD partitions: * both consist of eraseblocks (logical eraseblocks in case of UBI volumes, and physical eraseblocks in case of static partitions; * both support three basic operations - read, write, erase. But UBI volumes have the following advantages over traditional static MTD partitions: * there are no eraseblock wear-leveling constraints in case of UBI volumes, so the user should not care about this; * there are no bit-flips and bad eraseblocks in case of UBI volumes. So, UBI volumes may be considered as flash devices with relaxed restrictions. Where can it be found? Documentation, kernel code and applications can be found in the MTD gits. What are the applications for? The applications help to create binary flash images for two purposes: pfi files (partial flash images) for in-system update of UBI volumes, and plain binary images, with or without OOB data in case of NAND, for a manufacturing step. Furthermore some tools are/and will be created that allow flash content analysis after a system has crashed.. Who did UBI? The original ideas, where UBI is based on, were developed by Andreas Arnez, Frank Haverkamp and Thomas Gleixner. Josh W. Boyer and some others were involved too. The implementation of the kernel layer was done by Artem B. Bityutskiy. The user-space applications and tools were written by Oliver Lohmann with contributions from Frank Haverkamp, Andreas Arnez, and Artem. Joern Engel contributed a patch which modifies JFFS2 so that it can be run on a UBI volume. Thomas Gleixner did modifications to the NAND layer. Alexander Schmidt made some testing work as well as core functionality improvements. Signed-off-by: Artem B. Bityutskiy <dedekind@linutronix.de> Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
Diffstat (limited to 'drivers/mtd/ubi/debug.c')
-rw-r--r--drivers/mtd/ubi/debug.c224
1 files changed, 224 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
new file mode 100644
index 000000000000..86364221fafe
--- /dev/null
+++ b/drivers/mtd/ubi/debug.c
@@ -0,0 +1,224 @@
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 */
35void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
36{
37 dbg_msg("erase counter header dump:");
38 dbg_msg("magic %#08x", ubi32_to_cpu(ec_hdr->magic));
39 dbg_msg("version %d", (int)ec_hdr->version);
40 dbg_msg("ec %llu", (long long)ubi64_to_cpu(ec_hdr->ec));
41 dbg_msg("vid_hdr_offset %d", ubi32_to_cpu(ec_hdr->vid_hdr_offset));
42 dbg_msg("data_offset %d", ubi32_to_cpu(ec_hdr->data_offset));
43 dbg_msg("hdr_crc %#08x", ubi32_to_cpu(ec_hdr->hdr_crc));
44 dbg_msg("erase counter header hexdump:");
45 ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE);
46}
47
48/**
49 * ubi_dbg_dump_vid_hdr - dump a volume identifier header.
50 * @vid_hdr: the volume identifier header to dump
51 */
52void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
53{
54 dbg_msg("volume identifier header dump:");
55 dbg_msg("magic %08x", ubi32_to_cpu(vid_hdr->magic));
56 dbg_msg("version %d", (int)vid_hdr->version);
57 dbg_msg("vol_type %d", (int)vid_hdr->vol_type);
58 dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag);
59 dbg_msg("compat %d", (int)vid_hdr->compat);
60 dbg_msg("vol_id %d", ubi32_to_cpu(vid_hdr->vol_id));
61 dbg_msg("lnum %d", ubi32_to_cpu(vid_hdr->lnum));
62 dbg_msg("leb_ver %u", ubi32_to_cpu(vid_hdr->leb_ver));
63 dbg_msg("data_size %d", ubi32_to_cpu(vid_hdr->data_size));
64 dbg_msg("used_ebs %d", ubi32_to_cpu(vid_hdr->used_ebs));
65 dbg_msg("data_pad %d", ubi32_to_cpu(vid_hdr->data_pad));
66 dbg_msg("sqnum %llu",
67 (unsigned long long)ubi64_to_cpu(vid_hdr->sqnum));
68 dbg_msg("hdr_crc %08x", ubi32_to_cpu(vid_hdr->hdr_crc));
69 dbg_msg("volume identifier header hexdump:");
70}
71
72/**
73 * ubi_dbg_dump_vol_info- dump volume information.
74 * @vol: UBI volume description object
75 */
76void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
77{
78 dbg_msg("volume information dump:");
79 dbg_msg("vol_id %d", vol->vol_id);
80 dbg_msg("reserved_pebs %d", vol->reserved_pebs);
81 dbg_msg("alignment %d", vol->alignment);
82 dbg_msg("data_pad %d", vol->data_pad);
83 dbg_msg("vol_type %d", vol->vol_type);
84 dbg_msg("name_len %d", vol->name_len);
85 dbg_msg("usable_leb_size %d", vol->usable_leb_size);
86 dbg_msg("used_ebs %d", vol->used_ebs);
87 dbg_msg("used_bytes %lld", vol->used_bytes);
88 dbg_msg("last_eb_bytes %d", vol->last_eb_bytes);
89 dbg_msg("corrupted %d", vol->corrupted);
90 dbg_msg("upd_marker %d", vol->upd_marker);
91
92 if (vol->name_len <= UBI_VOL_NAME_MAX &&
93 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
94 dbg_msg("name %s", vol->name);
95 } else {
96 dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c",
97 vol->name[0], vol->name[1], vol->name[2],
98 vol->name[3], vol->name[4]);
99 }
100}
101
102/**
103 * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
104 * @r: the object to dump
105 * @idx: volume table index
106 */
107void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
108{
109 int name_len = ubi16_to_cpu(r->name_len);
110
111 dbg_msg("volume table record %d dump:", idx);
112 dbg_msg("reserved_pebs %d", ubi32_to_cpu(r->reserved_pebs));
113 dbg_msg("alignment %d", ubi32_to_cpu(r->alignment));
114 dbg_msg("data_pad %d", ubi32_to_cpu(r->data_pad));
115 dbg_msg("vol_type %d", (int)r->vol_type);
116 dbg_msg("upd_marker %d", (int)r->upd_marker);
117 dbg_msg("name_len %d", name_len);
118
119 if (r->name[0] == '\0') {
120 dbg_msg("name NULL");
121 return;
122 }
123
124 if (name_len <= UBI_VOL_NAME_MAX &&
125 strnlen(&r->name[0], name_len + 1) == name_len) {
126 dbg_msg("name %s", &r->name[0]);
127 } else {
128 dbg_msg("1st 5 characters of the name: %c%c%c%c%c",
129 r->name[0], r->name[1], r->name[2], r->name[3],
130 r->name[4]);
131 }
132 dbg_msg("crc %#08x", ubi32_to_cpu(r->crc));
133}
134
135/**
136 * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object.
137 * @sv: the object to dump
138 */
139void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
140{
141 dbg_msg("volume scanning information dump:");
142 dbg_msg("vol_id %d", sv->vol_id);
143 dbg_msg("highest_lnum %d", sv->highest_lnum);
144 dbg_msg("leb_count %d", sv->leb_count);
145 dbg_msg("compat %d", sv->compat);
146 dbg_msg("vol_type %d", sv->vol_type);
147 dbg_msg("used_ebs %d", sv->used_ebs);
148 dbg_msg("last_data_size %d", sv->last_data_size);
149 dbg_msg("data_pad %d", sv->data_pad);
150}
151
152/**
153 * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object.
154 * @seb: the object to dump
155 * @type: object type: 0 - not corrupted, 1 - corrupted
156 */
157void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
158{
159 dbg_msg("eraseblock scanning information dump:");
160 dbg_msg("ec %d", seb->ec);
161 dbg_msg("pnum %d", seb->pnum);
162 if (type == 0) {
163 dbg_msg("lnum %d", seb->lnum);
164 dbg_msg("scrub %d", seb->scrub);
165 dbg_msg("sqnum %llu", seb->sqnum);
166 dbg_msg("leb_ver %u", seb->leb_ver);
167 }
168}
169
170/**
171 * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
172 * @req: the object to dump
173 */
174void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
175{
176 char nm[17];
177
178 dbg_msg("volume creation request dump:");
179 dbg_msg("vol_id %d", req->vol_id);
180 dbg_msg("alignment %d", req->alignment);
181 dbg_msg("bytes %lld", (long long)req->bytes);
182 dbg_msg("vol_type %d", req->vol_type);
183 dbg_msg("name_len %d", req->name_len);
184
185 memcpy(nm, req->name, 16);
186 nm[16] = 0;
187 dbg_msg("the 1st 16 characters of the name: %s", nm);
188}
189
190#define BYTES_PER_LINE 32
191
192/**
193 * ubi_dbg_hexdump - dump a buffer.
194 * @ptr: the buffer to dump
195 * @size: buffer size which must be multiple of 4 bytes
196 */
197void ubi_dbg_hexdump(const void *ptr, int size)
198{
199 int i, k = 0, rows, columns;
200 const uint8_t *p = ptr;
201
202 size = ALIGN(size, 4);
203 rows = size/BYTES_PER_LINE + size % BYTES_PER_LINE;
204 for (i = 0; i < rows; i++) {
205 int j;
206
207 cond_resched();
208 columns = min(size - k, BYTES_PER_LINE) / 4;
209 if (columns == 0)
210 break;
211 printk(KERN_DEBUG "%5d: ", i * BYTES_PER_LINE);
212 for (j = 0; j < columns; j++) {
213 int n, N;
214
215 N = size - k > 4 ? 4 : size - k;
216 for (n = 0; n < N; n++)
217 printk("%02x", p[k++]);
218 printk(" ");
219 }
220 printk("\n");
221 }
222}
223
224#endif /* CONFIG_MTD_UBI_DEBUG_MSG */