debug.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. * Here we keep all the UBI debugging stuff which should normally be disabled
  22. * and compiled-out, but it is extremely helpful when hunting bugs or doing big
  23. * changes.
  24. */
  25. #ifdef CONFIG_MTD_UBI_DEBUG_MSG
  26. #include "ubi.h"
  27. /**
  28. * ubi_dbg_dump_ec_hdr - dump an erase counter header.
  29. * @ec_hdr: the erase counter header to dump
  30. */
  31. void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
  32. {
  33. dbg_msg("erase counter header dump:");
  34. dbg_msg("magic %#08x", ubi32_to_cpu(ec_hdr->magic));
  35. dbg_msg("version %d", (int)ec_hdr->version);
  36. dbg_msg("ec %llu", (long long)ubi64_to_cpu(ec_hdr->ec));
  37. dbg_msg("vid_hdr_offset %d", ubi32_to_cpu(ec_hdr->vid_hdr_offset));
  38. dbg_msg("data_offset %d", ubi32_to_cpu(ec_hdr->data_offset));
  39. dbg_msg("hdr_crc %#08x", ubi32_to_cpu(ec_hdr->hdr_crc));
  40. dbg_msg("erase counter header hexdump:");
  41. ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE);
  42. }
  43. /**
  44. * ubi_dbg_dump_vid_hdr - dump a volume identifier header.
  45. * @vid_hdr: the volume identifier header to dump
  46. */
  47. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
  48. {
  49. dbg_msg("volume identifier header dump:");
  50. dbg_msg("magic %08x", ubi32_to_cpu(vid_hdr->magic));
  51. dbg_msg("version %d", (int)vid_hdr->version);
  52. dbg_msg("vol_type %d", (int)vid_hdr->vol_type);
  53. dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag);
  54. dbg_msg("compat %d", (int)vid_hdr->compat);
  55. dbg_msg("vol_id %d", ubi32_to_cpu(vid_hdr->vol_id));
  56. dbg_msg("lnum %d", ubi32_to_cpu(vid_hdr->lnum));
  57. dbg_msg("leb_ver %u", ubi32_to_cpu(vid_hdr->leb_ver));
  58. dbg_msg("data_size %d", ubi32_to_cpu(vid_hdr->data_size));
  59. dbg_msg("used_ebs %d", ubi32_to_cpu(vid_hdr->used_ebs));
  60. dbg_msg("data_pad %d", ubi32_to_cpu(vid_hdr->data_pad));
  61. dbg_msg("sqnum %llu",
  62. (unsigned long long)ubi64_to_cpu(vid_hdr->sqnum));
  63. dbg_msg("hdr_crc %08x", ubi32_to_cpu(vid_hdr->hdr_crc));
  64. dbg_msg("volume identifier header hexdump:");
  65. }
  66. /**
  67. * ubi_dbg_dump_vol_info- dump volume information.
  68. * @vol: UBI volume description object
  69. */
  70. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
  71. {
  72. dbg_msg("volume information dump:");
  73. dbg_msg("vol_id %d", vol->vol_id);
  74. dbg_msg("reserved_pebs %d", vol->reserved_pebs);
  75. dbg_msg("alignment %d", vol->alignment);
  76. dbg_msg("data_pad %d", vol->data_pad);
  77. dbg_msg("vol_type %d", vol->vol_type);
  78. dbg_msg("name_len %d", vol->name_len);
  79. dbg_msg("usable_leb_size %d", vol->usable_leb_size);
  80. dbg_msg("used_ebs %d", vol->used_ebs);
  81. dbg_msg("used_bytes %lld", vol->used_bytes);
  82. dbg_msg("last_eb_bytes %d", vol->last_eb_bytes);
  83. dbg_msg("corrupted %d", vol->corrupted);
  84. dbg_msg("upd_marker %d", vol->upd_marker);
  85. if (vol->name_len <= UBI_VOL_NAME_MAX &&
  86. strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
  87. dbg_msg("name %s", vol->name);
  88. } else {
  89. dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c",
  90. vol->name[0], vol->name[1], vol->name[2],
  91. vol->name[3], vol->name[4]);
  92. }
  93. }
  94. /**
  95. * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
  96. * @r: the object to dump
  97. * @idx: volume table index
  98. */
  99. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
  100. {
  101. int name_len = ubi16_to_cpu(r->name_len);
  102. dbg_msg("volume table record %d dump:", idx);
  103. dbg_msg("reserved_pebs %d", ubi32_to_cpu(r->reserved_pebs));
  104. dbg_msg("alignment %d", ubi32_to_cpu(r->alignment));
  105. dbg_msg("data_pad %d", ubi32_to_cpu(r->data_pad));
  106. dbg_msg("vol_type %d", (int)r->vol_type);
  107. dbg_msg("upd_marker %d", (int)r->upd_marker);
  108. dbg_msg("name_len %d", name_len);
  109. if (r->name[0] == '\0') {
  110. dbg_msg("name NULL");
  111. return;
  112. }
  113. if (name_len <= UBI_VOL_NAME_MAX &&
  114. strnlen(&r->name[0], name_len + 1) == name_len) {
  115. dbg_msg("name %s", &r->name[0]);
  116. } else {
  117. dbg_msg("1st 5 characters of the name: %c%c%c%c%c",
  118. r->name[0], r->name[1], r->name[2], r->name[3],
  119. r->name[4]);
  120. }
  121. dbg_msg("crc %#08x", ubi32_to_cpu(r->crc));
  122. }
  123. /**
  124. * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object.
  125. * @sv: the object to dump
  126. */
  127. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
  128. {
  129. dbg_msg("volume scanning information dump:");
  130. dbg_msg("vol_id %d", sv->vol_id);
  131. dbg_msg("highest_lnum %d", sv->highest_lnum);
  132. dbg_msg("leb_count %d", sv->leb_count);
  133. dbg_msg("compat %d", sv->compat);
  134. dbg_msg("vol_type %d", sv->vol_type);
  135. dbg_msg("used_ebs %d", sv->used_ebs);
  136. dbg_msg("last_data_size %d", sv->last_data_size);
  137. dbg_msg("data_pad %d", sv->data_pad);
  138. }
  139. /**
  140. * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object.
  141. * @seb: the object to dump
  142. * @type: object type: 0 - not corrupted, 1 - corrupted
  143. */
  144. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
  145. {
  146. dbg_msg("eraseblock scanning information dump:");
  147. dbg_msg("ec %d", seb->ec);
  148. dbg_msg("pnum %d", seb->pnum);
  149. if (type == 0) {
  150. dbg_msg("lnum %d", seb->lnum);
  151. dbg_msg("scrub %d", seb->scrub);
  152. dbg_msg("sqnum %llu", seb->sqnum);
  153. dbg_msg("leb_ver %u", seb->leb_ver);
  154. }
  155. }
  156. /**
  157. * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
  158. * @req: the object to dump
  159. */
  160. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
  161. {
  162. char nm[17];
  163. dbg_msg("volume creation request dump:");
  164. dbg_msg("vol_id %d", req->vol_id);
  165. dbg_msg("alignment %d", req->alignment);
  166. dbg_msg("bytes %lld", (long long)req->bytes);
  167. dbg_msg("vol_type %d", req->vol_type);
  168. dbg_msg("name_len %d", req->name_len);
  169. memcpy(nm, req->name, 16);
  170. nm[16] = 0;
  171. dbg_msg("the 1st 16 characters of the name: %s", nm);
  172. }
  173. #define BYTES_PER_LINE 32
  174. /**
  175. * ubi_dbg_hexdump - dump a buffer.
  176. * @ptr: the buffer to dump
  177. * @size: buffer size which must be multiple of 4 bytes
  178. */
  179. void ubi_dbg_hexdump(const void *ptr, int size)
  180. {
  181. int i, k = 0, rows, columns;
  182. const uint8_t *p = ptr;
  183. size = ALIGN(size, 4);
  184. rows = size/BYTES_PER_LINE + size % BYTES_PER_LINE;
  185. for (i = 0; i < rows; i++) {
  186. int j;
  187. cond_resched();
  188. columns = min(size - k, BYTES_PER_LINE) / 4;
  189. if (columns == 0)
  190. break;
  191. printk(KERN_DEBUG "%5d: ", i * BYTES_PER_LINE);
  192. for (j = 0; j < columns; j++) {
  193. int n, N;
  194. N = size - k > 4 ? 4 : size - k;
  195. for (n = 0; n < N; n++)
  196. printk("%02x", p[k++]);
  197. printk(" ");
  198. }
  199. printk("\n");
  200. }
  201. }
  202. #endif /* CONFIG_MTD_UBI_DEBUG_MSG */