1
2
3
4
5
6
7
8#ifndef __UBI_DEBUG_H__
9#define __UBI_DEBUG_H__
10
11void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
12void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
13void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
14
15#ifndef __UBOOT__
16#include <linux/random.h>
17#endif
18
19#include <hexdump.h>
20
21#ifndef __UBOOT__
22#define ubi_assert(expr) do { \
23 if (unlikely(!(expr))) { \
24 pr_crit("UBI assert failed in %s at %u (pid %d)\n", \
25 __func__, __LINE__, current->pid); \
26 dump_stack(); \
27 } \
28} while (0)
29#else
30#define ubi_assert(expr) do { \
31 if (unlikely(!(expr))) { \
32 pr_debug("UBI assert failed in %s at %u\n", \
33 __func__, __LINE__); \
34 dump_stack(); \
35 } \
36} while (0)
37#endif
38
39#define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \
40 print_hex_dump(ps, pt, r, g, b, len, a)
41
42#define ubi_dbg_msg(type, fmt, ...) \
43 pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \
44 ##__VA_ARGS__)
45
46
47#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
48
49#define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__)
50
51#define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__)
52
53#define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__)
54
55#define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__)
56
57void ubi_dump_vol_info(const struct ubi_volume *vol);
58void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
59void ubi_dump_av(const struct ubi_ainf_volume *av);
60void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
61void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
62int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
63 int len);
64int ubi_debugfs_init(void);
65void ubi_debugfs_exit(void);
66int ubi_debugfs_init_dev(struct ubi_device *ubi);
67void ubi_debugfs_exit_dev(struct ubi_device *ubi);
68
69
70
71
72
73
74
75
76static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
77{
78 return ubi->dbg.disable_bgt;
79}
80
81
82
83
84
85
86
87static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
88{
89 if (ubi->dbg.emulate_bitflips)
90 return !(prandom_u32() % 200);
91 return 0;
92}
93
94
95
96
97
98
99
100
101static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
102{
103 if (ubi->dbg.emulate_io_failures)
104 return !(prandom_u32() % 500);
105 return 0;
106}
107
108
109
110
111
112
113
114
115static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
116{
117 if (ubi->dbg.emulate_io_failures)
118 return !(prandom_u32() % 400);
119 return 0;
120}
121
122static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
123{
124 return ubi->dbg.chk_io;
125}
126
127static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
128{
129 return ubi->dbg.chk_gen;
130}
131
132static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi)
133{
134 return ubi->dbg.chk_fastmap;
135}
136
137static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
138{
139 ubi->dbg.chk_fastmap = 1;
140}
141
142int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
143#endif
144