1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef __UBI_DEBUG_H__
22#define __UBI_DEBUG_H__
23
24#ifdef CONFIG_MTD_UBI_DEBUG
25#ifdef UBI_LINUX
26#include <linux/random.h>
27#endif
28
29#define ubi_assert(expr) BUG_ON(!(expr))
30#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
31#else
32#define ubi_assert(expr) ({})
33#define dbg_err(fmt, ...) ({})
34#endif
35
36#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
37#define DBG_DISABLE_BGT 1
38#else
39#define DBG_DISABLE_BGT 0
40#endif
41
42#ifdef CONFIG_MTD_UBI_DEBUG_MSG
43
44#define dbg_msg(fmt, ...) \
45 printk(KERN_DEBUG "UBI DBG: %s: " fmt "\n", \
46 __FUNCTION__, ##__VA_ARGS__)
47
48#define ubi_dbg_dump_stack() dump_stack()
49
50struct ubi_ec_hdr;
51struct ubi_vid_hdr;
52struct ubi_volume;
53struct ubi_vtbl_record;
54struct ubi_scan_volume;
55struct ubi_scan_leb;
56struct ubi_mkvol_req;
57
58void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
59void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
60void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
61void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx);
62void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
63void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
64void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
65
66#else
67
68#define dbg_msg(fmt, ...) ({})
69#define ubi_dbg_dump_stack() ({})
70#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
71#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
72#define ubi_dbg_dump_vol_info(vol) ({})
73#define ubi_dbg_dump_vtbl_record(r, idx) ({})
74#define ubi_dbg_dump_sv(sv) ({})
75#define ubi_dbg_dump_seb(seb, type) ({})
76#define ubi_dbg_dump_mkvol_req(req) ({})
77
78#endif
79
80#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
81
82#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
83#else
84#define dbg_eba(fmt, ...) ({})
85#endif
86
87#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
88
89#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
90#else
91#define dbg_wl(fmt, ...) ({})
92#endif
93
94#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
95
96#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
97#else
98#define dbg_io(fmt, ...) ({})
99#endif
100
101#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
102
103#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
104#else
105#define dbg_bld(fmt, ...) ({})
106#endif
107
108#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
109
110
111
112
113
114static inline int ubi_dbg_is_bitflip(void)
115{
116 return !(random32() % 200);
117}
118#else
119#define ubi_dbg_is_bitflip() 0
120#endif
121
122#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES
123
124
125
126
127
128
129static inline int ubi_dbg_is_write_failure(void)
130{
131 return !(random32() % 500);
132}
133#else
134#define ubi_dbg_is_write_failure() 0
135#endif
136
137#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES
138
139
140
141
142
143
144static inline int ubi_dbg_is_erase_failure(void)
145{
146 return !(random32() % 400);
147}
148#else
149#define ubi_dbg_is_erase_failure() 0
150#endif
151
152#endif
153