debug.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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
  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. printk(KERN_DEBUG "Erase counter header dump:\n");
  34. printk(KERN_DEBUG "\tmagic %#08x\n",
  35. be32_to_cpu(ec_hdr->magic));
  36. printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version);
  37. printk(KERN_DEBUG "\tec %llu\n",
  38. (long long)be64_to_cpu(ec_hdr->ec));
  39. printk(KERN_DEBUG "\tvid_hdr_offset %d\n",
  40. be32_to_cpu(ec_hdr->vid_hdr_offset));
  41. printk(KERN_DEBUG "\tdata_offset %d\n",
  42. be32_to_cpu(ec_hdr->data_offset));
  43. printk(KERN_DEBUG "\timage_seq %d\n",
  44. be32_to_cpu(ec_hdr->image_seq));
  45. printk(KERN_DEBUG "\thdr_crc %#08x\n",
  46. be32_to_cpu(ec_hdr->hdr_crc));
  47. printk(KERN_DEBUG "erase counter header hexdump:\n");
  48. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
  49. ec_hdr, UBI_EC_HDR_SIZE, 1);
  50. }
  51. /**
  52. * ubi_dbg_dump_vid_hdr - dump a volume identifier header.
  53. * @vid_hdr: the volume identifier header to dump
  54. */
  55. void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
  56. {
  57. printk(KERN_DEBUG "Volume identifier header dump:\n");
  58. printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
  59. printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version);
  60. printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type);
  61. printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag);
  62. printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat);
  63. printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id));
  64. printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum));
  65. printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size));
  66. printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs));
  67. printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
  68. printk(KERN_DEBUG "\tsqnum %llu\n",
  69. (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
  70. printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
  71. printk(KERN_DEBUG "Volume identifier header hexdump:\n");
  72. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
  73. vid_hdr, UBI_VID_HDR_SIZE, 1);
  74. }
  75. /**
  76. * ubi_dbg_dump_vol_info- dump volume information.
  77. * @vol: UBI volume description object
  78. */
  79. void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
  80. {
  81. printk(KERN_DEBUG "Volume information dump:\n");
  82. printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id);
  83. printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs);
  84. printk(KERN_DEBUG "\talignment %d\n", vol->alignment);
  85. printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad);
  86. printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type);
  87. printk(KERN_DEBUG "\tname_len %d\n", vol->name_len);
  88. printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size);
  89. printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs);
  90. printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes);
  91. printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes);
  92. printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted);
  93. printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker);
  94. if (vol->name_len <= UBI_VOL_NAME_MAX &&
  95. strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
  96. printk(KERN_DEBUG "\tname %s\n", vol->name);
  97. } else {
  98. printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
  99. vol->name[0], vol->name[1], vol->name[2],
  100. vol->name[3], vol->name[4]);
  101. }
  102. }
  103. /**
  104. * ubi_dbg_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
  105. * @r: the object to dump
  106. * @idx: volume table index
  107. */
  108. void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
  109. {
  110. int name_len = be16_to_cpu(r->name_len);
  111. printk(KERN_DEBUG "Volume table record %d dump:\n", idx);
  112. printk(KERN_DEBUG "\treserved_pebs %d\n",
  113. be32_to_cpu(r->reserved_pebs));
  114. printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment));
  115. printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad));
  116. printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type);
  117. printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker);
  118. printk(KERN_DEBUG "\tname_len %d\n", name_len);
  119. if (r->name[0] == '\0') {
  120. printk(KERN_DEBUG "\tname NULL\n");
  121. return;
  122. }
  123. if (name_len <= UBI_VOL_NAME_MAX &&
  124. strnlen(&r->name[0], name_len + 1) == name_len) {
  125. printk(KERN_DEBUG "\tname %s\n", &r->name[0]);
  126. } else {
  127. printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
  128. r->name[0], r->name[1], r->name[2], r->name[3],
  129. r->name[4]);
  130. }
  131. printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc));
  132. }
  133. /**
  134. * ubi_dbg_dump_sv - dump a &struct ubi_scan_volume object.
  135. * @sv: the object to dump
  136. */
  137. void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
  138. {
  139. printk(KERN_DEBUG "Volume scanning information dump:\n");
  140. printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id);
  141. printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum);
  142. printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count);
  143. printk(KERN_DEBUG "\tcompat %d\n", sv->compat);
  144. printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type);
  145. printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs);
  146. printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size);
  147. printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad);
  148. }
  149. /**
  150. * ubi_dbg_dump_seb - dump a &struct ubi_scan_leb object.
  151. * @seb: the object to dump
  152. * @type: object type: 0 - not corrupted, 1 - corrupted
  153. */
  154. void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
  155. {
  156. printk(KERN_DEBUG "eraseblock scanning information dump:\n");
  157. printk(KERN_DEBUG "\tec %d\n", seb->ec);
  158. printk(KERN_DEBUG "\tpnum %d\n", seb->pnum);
  159. if (type == 0) {
  160. printk(KERN_DEBUG "\tlnum %d\n", seb->lnum);
  161. printk(KERN_DEBUG "\tscrub %d\n", seb->scrub);
  162. printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum);
  163. }
  164. }
  165. /**
  166. * ubi_dbg_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
  167. * @req: the object to dump
  168. */
  169. void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
  170. {
  171. char nm[17];
  172. printk(KERN_DEBUG "Volume creation request dump:\n");
  173. printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id);
  174. printk(KERN_DEBUG "\talignment %d\n", req->alignment);
  175. printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes);
  176. printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type);
  177. printk(KERN_DEBUG "\tname_len %d\n", req->name_len);
  178. memcpy(nm, req->name, 16);
  179. nm[16] = 0;
  180. printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
  181. }
  182. /**
  183. * ubi_dbg_dump_flash - dump a region of flash.
  184. * @ubi: UBI device description object
  185. * @pnum: the physical eraseblock number to dump
  186. * @offset: the starting offset within the physical eraseblock to dump
  187. * @len: the length of the region to dump
  188. */
  189. void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
  190. {
  191. int err;
  192. size_t read;
  193. void *buf;
  194. loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
  195. buf = vmalloc(len);
  196. if (!buf)
  197. return;
  198. err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
  199. if (err && err != -EUCLEAN) {
  200. ubi_err("error %d while reading %d bytes from PEB %d:%d, "
  201. "read %zd bytes", err, len, pnum, offset, read);
  202. goto out;
  203. }
  204. dbg_msg("dumping %d bytes of data from PEB %d, offset %d",
  205. len, pnum, offset);
  206. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
  207. out:
  208. vfree(buf);
  209. return;
  210. }
  211. #endif /* CONFIG_MTD_UBI_DEBUG */