Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) International Business Machines Corp., 2006 |
| 4 | * |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 5 | * Author: Artem Bityutskiy (Битюцкий Артём) |
| 6 | */ |
| 7 | |
| 8 | #ifndef __UBI_DEBUG_H__ |
| 9 | #define __UBI_DEBUG_H__ |
| 10 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 11 | void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
| 12 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr); |
| 13 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); |
| 14 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 15 | #ifndef __UBOOT__ |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 16 | #include <linux/random.h> |
| 17 | #endif |
| 18 | |
Alexey Brodkin | f8c987f | 2018-06-05 17:17:57 +0300 | [diff] [blame] | 19 | #include <hexdump.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 20 | #include <linux/printk.h> |
Alexey Brodkin | f8c987f | 2018-06-05 17:17:57 +0300 | [diff] [blame] | 21 | |
Eran Matityahu | 66e78fc | 2019-02-13 20:55:43 +0200 | [diff] [blame] | 22 | #ifndef __UBOOT__ |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 23 | #define ubi_assert(expr) do { \ |
| 24 | if (unlikely(!(expr))) { \ |
| 25 | pr_crit("UBI assert failed in %s at %u (pid %d)\n", \ |
| 26 | __func__, __LINE__, current->pid); \ |
| 27 | dump_stack(); \ |
| 28 | } \ |
| 29 | } while (0) |
Eran Matityahu | 66e78fc | 2019-02-13 20:55:43 +0200 | [diff] [blame] | 30 | #else |
Pali Rohár | e2e6caa | 2022-07-10 13:38:07 +0200 | [diff] [blame] | 31 | #include <log.h> |
| 32 | #define ubi_assert(expr) assert(expr) |
Eran Matityahu | 66e78fc | 2019-02-13 20:55:43 +0200 | [diff] [blame] | 33 | #endif |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 34 | |
Alexey Brodkin | f8c987f | 2018-06-05 17:17:57 +0300 | [diff] [blame] | 35 | #define ubi_dbg_print_hex_dump(ps, pt, r, g, b, len, a) \ |
| 36 | print_hex_dump(ps, pt, r, g, b, len, a) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 37 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 38 | #define ubi_dbg_msg(type, fmt, ...) \ |
| 39 | pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \ |
| 40 | ##__VA_ARGS__) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 41 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 42 | /* General debugging messages */ |
| 43 | #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) |
| 44 | /* Messages from the eraseblock association sub-system */ |
| 45 | #define dbg_eba(fmt, ...) ubi_dbg_msg("eba", fmt, ##__VA_ARGS__) |
| 46 | /* Messages from the wear-leveling sub-system */ |
| 47 | #define dbg_wl(fmt, ...) ubi_dbg_msg("wl", fmt, ##__VA_ARGS__) |
| 48 | /* Messages from the input/output sub-system */ |
| 49 | #define dbg_io(fmt, ...) ubi_dbg_msg("io", fmt, ##__VA_ARGS__) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 50 | /* Initialization and build messages */ |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 51 | #define dbg_bld(fmt, ...) ubi_dbg_msg("bld", fmt, ##__VA_ARGS__) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 52 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 53 | void ubi_dump_vol_info(const struct ubi_volume *vol); |
| 54 | void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx); |
| 55 | void ubi_dump_av(const struct ubi_ainf_volume *av); |
| 56 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type); |
| 57 | void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); |
| 58 | int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, |
| 59 | int len); |
| 60 | int ubi_debugfs_init(void); |
| 61 | void ubi_debugfs_exit(void); |
| 62 | int ubi_debugfs_init_dev(struct ubi_device *ubi); |
| 63 | void ubi_debugfs_exit_dev(struct ubi_device *ubi); |
| 64 | |
| 65 | /** |
| 66 | * ubi_dbg_is_bgt_disabled - if the background thread is disabled. |
| 67 | * @ubi: UBI device description object |
| 68 | * |
| 69 | * Returns non-zero if the UBI background thread is disabled for testing |
| 70 | * purposes. |
| 71 | */ |
| 72 | static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) |
| 73 | { |
| 74 | return ubi->dbg.disable_bgt; |
| 75 | } |
| 76 | |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 77 | /** |
| 78 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 79 | * @ubi: UBI device description object |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 80 | * |
| 81 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. |
| 82 | */ |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 83 | static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 84 | { |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 85 | if (ubi->dbg.emulate_bitflips) |
| 86 | return !(prandom_u32() % 200); |
| 87 | return 0; |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 88 | } |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 89 | |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 90 | /** |
| 91 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 92 | * @ubi: UBI device description object |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 93 | * |
| 94 | * Returns non-zero if a write failure should be emulated, otherwise returns |
| 95 | * zero. |
| 96 | */ |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 97 | static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 98 | { |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 99 | if (ubi->dbg.emulate_io_failures) |
| 100 | return !(prandom_u32() % 500); |
| 101 | return 0; |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 102 | } |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 103 | |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 104 | /** |
| 105 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 106 | * @ubi: UBI device description object |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 107 | * |
| 108 | * Returns non-zero if an erase failure should be emulated, otherwise returns |
| 109 | * zero. |
| 110 | */ |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 111 | static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 112 | { |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 113 | if (ubi->dbg.emulate_io_failures) |
| 114 | return !(prandom_u32() % 400); |
| 115 | return 0; |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 116 | } |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 117 | |
Heiko Schocher | ff94bc4 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 118 | static inline int ubi_dbg_chk_io(const struct ubi_device *ubi) |
| 119 | { |
| 120 | return ubi->dbg.chk_io; |
| 121 | } |
| 122 | |
| 123 | static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) |
| 124 | { |
| 125 | return ubi->dbg.chk_gen; |
| 126 | } |
Heiko Schocher | 0195a7b | 2015-10-22 06:19:21 +0200 | [diff] [blame] | 127 | |
| 128 | static inline int ubi_dbg_chk_fastmap(const struct ubi_device *ubi) |
| 129 | { |
| 130 | return ubi->dbg.chk_fastmap; |
| 131 | } |
| 132 | |
| 133 | static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi) |
| 134 | { |
| 135 | ubi->dbg.chk_fastmap = 1; |
| 136 | } |
| 137 | |
| 138 | int ubi_dbg_power_cut(struct ubi_device *ubi, int caller); |
Kyungmin Park | 961df83 | 2008-11-19 16:25:44 +0100 | [diff] [blame] | 139 | #endif /* !__UBI_DEBUG_H__ */ |