debug.c 8.9 KB

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