debug.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) International Business Machines Corp., 2006
  4. *
  5. * Author: Artem Bityutskiy (Битюцкий Артём)
  6. */
  7. #include "ubi.h"
  8. #include <linux/debugfs.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/module.h>
  11. #include <linux/seq_file.h>
  12. /**
  13. * ubi_dump_flash - dump a region of flash.
  14. * @ubi: UBI device description object
  15. * @pnum: the physical eraseblock number to dump
  16. * @offset: the starting offset within the physical eraseblock to dump
  17. * @len: the length of the region to dump
  18. */
  19. void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
  20. {
  21. int err;
  22. size_t read;
  23. void *buf;
  24. loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
  25. buf = vmalloc(len);
  26. if (!buf)
  27. return;
  28. err = mtd_read(ubi->mtd, addr, len, &read, buf);
  29. if (err && err != -EUCLEAN) {
  30. ubi_err(ubi, "err %d while reading %d bytes from PEB %d:%d, read %zd bytes",
  31. err, len, pnum, offset, read);
  32. goto out;
  33. }
  34. ubi_msg(ubi, "dumping %d bytes of data from PEB %d, offset %d",
  35. len, pnum, offset);
  36. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
  37. out:
  38. vfree(buf);
  39. return;
  40. }
  41. /**
  42. * ubi_dump_ec_hdr - dump an erase counter header.
  43. * @ec_hdr: the erase counter header to dump
  44. */
  45. void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
  46. {
  47. pr_err("Erase counter header dump:\n");
  48. pr_err("\tmagic %#08x\n", be32_to_cpu(ec_hdr->magic));
  49. pr_err("\tversion %d\n", (int)ec_hdr->version);
  50. pr_err("\tec %llu\n", (long long)be64_to_cpu(ec_hdr->ec));
  51. pr_err("\tvid_hdr_offset %d\n", be32_to_cpu(ec_hdr->vid_hdr_offset));
  52. pr_err("\tdata_offset %d\n", be32_to_cpu(ec_hdr->data_offset));
  53. pr_err("\timage_seq %d\n", be32_to_cpu(ec_hdr->image_seq));
  54. pr_err("\thdr_crc %#08x\n", be32_to_cpu(ec_hdr->hdr_crc));
  55. pr_err("erase counter header hexdump:\n");
  56. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
  57. ec_hdr, UBI_EC_HDR_SIZE, 1);
  58. }
  59. /**
  60. * ubi_dump_vid_hdr - dump a volume identifier header.
  61. * @vid_hdr: the volume identifier header to dump
  62. */
  63. void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
  64. {
  65. pr_err("Volume identifier header dump:\n");
  66. pr_err("\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
  67. pr_err("\tversion %d\n", (int)vid_hdr->version);
  68. pr_err("\tvol_type %d\n", (int)vid_hdr->vol_type);
  69. pr_err("\tcopy_flag %d\n", (int)vid_hdr->copy_flag);
  70. pr_err("\tcompat %d\n", (int)vid_hdr->compat);
  71. pr_err("\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id));
  72. pr_err("\tlnum %d\n", be32_to_cpu(vid_hdr->lnum));
  73. pr_err("\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size));
  74. pr_err("\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs));
  75. pr_err("\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
  76. pr_err("\tsqnum %llu\n",
  77. (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
  78. pr_err("\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
  79. pr_err("Volume identifier header hexdump:\n");
  80. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
  81. vid_hdr, UBI_VID_HDR_SIZE, 1);
  82. }
  83. /**
  84. * ubi_dump_vol_info - dump volume information.
  85. * @vol: UBI volume description object
  86. */
  87. void ubi_dump_vol_info(const struct ubi_volume *vol)
  88. {
  89. pr_err("Volume information dump:\n");
  90. pr_err("\tvol_id %d\n", vol->vol_id);
  91. pr_err("\treserved_pebs %d\n", vol->reserved_pebs);
  92. pr_err("\talignment %d\n", vol->alignment);
  93. pr_err("\tdata_pad %d\n", vol->data_pad);
  94. pr_err("\tvol_type %d\n", vol->vol_type);
  95. pr_err("\tname_len %d\n", vol->name_len);
  96. pr_err("\tusable_leb_size %d\n", vol->usable_leb_size);
  97. pr_err("\tused_ebs %d\n", vol->used_ebs);
  98. pr_err("\tused_bytes %lld\n", vol->used_bytes);
  99. pr_err("\tlast_eb_bytes %d\n", vol->last_eb_bytes);
  100. pr_err("\tcorrupted %d\n", vol->corrupted);
  101. pr_err("\tupd_marker %d\n", vol->upd_marker);
  102. pr_err("\tskip_check %d\n", vol->skip_check);
  103. if (vol->name_len <= UBI_VOL_NAME_MAX &&
  104. strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
  105. pr_err("\tname %s\n", vol->name);
  106. } else {
  107. pr_err("\t1st 5 characters of name: %c%c%c%c%c\n",
  108. vol->name[0], vol->name[1], vol->name[2],
  109. vol->name[3], vol->name[4]);
  110. }
  111. }
  112. /**
  113. * ubi_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
  114. * @r: the object to dump
  115. * @idx: volume table index
  116. */
  117. void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
  118. {
  119. int name_len = be16_to_cpu(r->name_len);
  120. pr_err("Volume table record %d dump:\n", idx);
  121. pr_err("\treserved_pebs %d\n", be32_to_cpu(r->reserved_pebs));
  122. pr_err("\talignment %d\n", be32_to_cpu(r->alignment));
  123. pr_err("\tdata_pad %d\n", be32_to_cpu(r->data_pad));
  124. pr_err("\tvol_type %d\n", (int)r->vol_type);
  125. pr_err("\tupd_marker %d\n", (int)r->upd_marker);
  126. pr_err("\tname_len %d\n", name_len);
  127. if (r->name[0] == '\0') {
  128. pr_err("\tname NULL\n");
  129. return;
  130. }
  131. if (name_len <= UBI_VOL_NAME_MAX &&
  132. strnlen(&r->name[0], name_len + 1) == name_len) {
  133. pr_err("\tname %s\n", &r->name[0]);
  134. } else {
  135. pr_err("\t1st 5 characters of name: %c%c%c%c%c\n",
  136. r->name[0], r->name[1], r->name[2], r->name[3],
  137. r->name[4]);
  138. }
  139. pr_err("\tcrc %#08x\n", be32_to_cpu(r->crc));
  140. }
  141. /**
  142. * ubi_dump_av - dump a &struct ubi_ainf_volume object.
  143. * @av: the object to dump
  144. */
  145. void ubi_dump_av(const struct ubi_ainf_volume *av)
  146. {
  147. pr_err("Volume attaching information dump:\n");
  148. pr_err("\tvol_id %d\n", av->vol_id);
  149. pr_err("\thighest_lnum %d\n", av->highest_lnum);
  150. pr_err("\tleb_count %d\n", av->leb_count);
  151. pr_err("\tcompat %d\n", av->compat);
  152. pr_err("\tvol_type %d\n", av->vol_type);
  153. pr_err("\tused_ebs %d\n", av->used_ebs);
  154. pr_err("\tlast_data_size %d\n", av->last_data_size);
  155. pr_err("\tdata_pad %d\n", av->data_pad);
  156. }
  157. /**
  158. * ubi_dump_aeb - dump a &struct ubi_ainf_peb object.
  159. * @aeb: the object to dump
  160. * @type: object type: 0 - not corrupted, 1 - corrupted
  161. */
  162. void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type)
  163. {
  164. pr_err("eraseblock attaching information dump:\n");
  165. pr_err("\tec %d\n", aeb->ec);
  166. pr_err("\tpnum %d\n", aeb->pnum);
  167. if (type == 0) {
  168. pr_err("\tlnum %d\n", aeb->lnum);
  169. pr_err("\tscrub %d\n", aeb->scrub);
  170. pr_err("\tsqnum %llu\n", aeb->sqnum);
  171. }
  172. }
  173. /**
  174. * ubi_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
  175. * @req: the object to dump
  176. */
  177. void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
  178. {
  179. char nm[17];
  180. pr_err("Volume creation request dump:\n");
  181. pr_err("\tvol_id %d\n", req->vol_id);
  182. pr_err("\talignment %d\n", req->alignment);
  183. pr_err("\tbytes %lld\n", (long long)req->bytes);
  184. pr_err("\tvol_type %d\n", req->vol_type);
  185. pr_err("\tname_len %d\n", req->name_len);
  186. memcpy(nm, req->name, 16);
  187. nm[16] = 0;
  188. pr_err("\t1st 16 characters of name: %s\n", nm);
  189. }
  190. /*
  191. * Root directory for UBI stuff in debugfs. Contains sub-directories which
  192. * contain the stuff specific to particular UBI devices.
  193. */
  194. static struct dentry *dfs_rootdir;
  195. /**
  196. * ubi_debugfs_init - create UBI debugfs directory.
  197. *
  198. * Create UBI debugfs directory. Returns zero in case of success and a negative
  199. * error code in case of failure.
  200. */
  201. int ubi_debugfs_init(void)
  202. {
  203. if (!IS_ENABLED(CONFIG_DEBUG_FS))
  204. return 0;
  205. dfs_rootdir = debugfs_create_dir("ubi", NULL);
  206. if (IS_ERR_OR_NULL(dfs_rootdir)) {
  207. int err = dfs_rootdir ? PTR_ERR(dfs_rootdir) : -ENODEV;
  208. pr_err("UBI error: cannot create \"ubi\" debugfs directory, error %d\n",
  209. err);
  210. return err;
  211. }
  212. return 0;
  213. }
  214. /**
  215. * ubi_debugfs_exit - remove UBI debugfs directory.
  216. */
  217. void ubi_debugfs_exit(void)
  218. {
  219. if (IS_ENABLED(CONFIG_DEBUG_FS))
  220. debugfs_remove(dfs_rootdir);
  221. }
  222. /* Read an UBI debugfs file */
  223. static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
  224. size_t count, loff_t *ppos)
  225. {
  226. unsigned long ubi_num = (unsigned long)file->private_data;
  227. struct dentry *dent = file->f_path.dentry;
  228. struct ubi_device *ubi;
  229. struct ubi_debug_info *d;
  230. char buf[8];
  231. int val;
  232. ubi = ubi_get_device(ubi_num);
  233. if (!ubi)
  234. return -ENODEV;
  235. d = &ubi->dbg;
  236. if (dent == d->dfs_chk_gen)
  237. val = d->chk_gen;
  238. else if (dent == d->dfs_chk_io)
  239. val = d->chk_io;
  240. else if (dent == d->dfs_chk_fastmap)
  241. val = d->chk_fastmap;
  242. else if (dent == d->dfs_disable_bgt)
  243. val = d->disable_bgt;
  244. else if (dent == d->dfs_emulate_bitflips)
  245. val = d->emulate_bitflips;
  246. else if (dent == d->dfs_emulate_io_failures)
  247. val = d->emulate_io_failures;
  248. else if (dent == d->dfs_emulate_power_cut) {
  249. snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut);
  250. count = simple_read_from_buffer(user_buf, count, ppos,
  251. buf, strlen(buf));
  252. goto out;
  253. } else if (dent == d->dfs_power_cut_min) {
  254. snprintf(buf, sizeof(buf), "%u\n", d->power_cut_min);
  255. count = simple_read_from_buffer(user_buf, count, ppos,
  256. buf, strlen(buf));
  257. goto out;
  258. } else if (dent == d->dfs_power_cut_max) {
  259. snprintf(buf, sizeof(buf), "%u\n", d->power_cut_max);
  260. count = simple_read_from_buffer(user_buf, count, ppos,
  261. buf, strlen(buf));
  262. goto out;
  263. }
  264. else {
  265. count = -EINVAL;
  266. goto out;
  267. }
  268. if (val)
  269. buf[0] = '1';
  270. else
  271. buf[0] = '0';
  272. buf[1] = '\n';
  273. buf[2] = 0x00;
  274. count = simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  275. out:
  276. ubi_put_device(ubi);
  277. return count;
  278. }
  279. /* Write an UBI debugfs file */
  280. static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
  281. size_t count, loff_t *ppos)
  282. {
  283. unsigned long ubi_num = (unsigned long)file->private_data;
  284. struct dentry *dent = file->f_path.dentry;
  285. struct ubi_device *ubi;
  286. struct ubi_debug_info *d;
  287. size_t buf_size;
  288. char buf[8] = {0};
  289. int val;
  290. ubi = ubi_get_device(ubi_num);
  291. if (!ubi)
  292. return -ENODEV;
  293. d = &ubi->dbg;
  294. buf_size = min_t(size_t, count, (sizeof(buf) - 1));
  295. if (copy_from_user(buf, user_buf, buf_size)) {
  296. count = -EFAULT;
  297. goto out;
  298. }
  299. if (dent == d->dfs_power_cut_min) {
  300. if (kstrtouint(buf, 0, &d->power_cut_min) != 0)
  301. count = -EINVAL;
  302. goto out;
  303. } else if (dent == d->dfs_power_cut_max) {
  304. if (kstrtouint(buf, 0, &d->power_cut_max) != 0)
  305. count = -EINVAL;
  306. goto out;
  307. } else if (dent == d->dfs_emulate_power_cut) {
  308. if (kstrtoint(buf, 0, &val) != 0)
  309. count = -EINVAL;
  310. else
  311. d->emulate_power_cut = val;
  312. goto out;
  313. }
  314. if (buf[0] == '1')
  315. val = 1;
  316. else if (buf[0] == '0')
  317. val = 0;
  318. else {
  319. count = -EINVAL;
  320. goto out;
  321. }
  322. if (dent == d->dfs_chk_gen)
  323. d->chk_gen = val;
  324. else if (dent == d->dfs_chk_io)
  325. d->chk_io = val;
  326. else if (dent == d->dfs_chk_fastmap)
  327. d->chk_fastmap = val;
  328. else if (dent == d->dfs_disable_bgt)
  329. d->disable_bgt = val;
  330. else if (dent == d->dfs_emulate_bitflips)
  331. d->emulate_bitflips = val;
  332. else if (dent == d->dfs_emulate_io_failures)
  333. d->emulate_io_failures = val;
  334. else
  335. count = -EINVAL;
  336. out:
  337. ubi_put_device(ubi);
  338. return count;
  339. }
  340. /* File operations for all UBI debugfs files except
  341. * detailed_erase_block_info
  342. */
  343. static const struct file_operations dfs_fops = {
  344. .read = dfs_file_read,
  345. .write = dfs_file_write,
  346. .open = simple_open,
  347. .llseek = no_llseek,
  348. .owner = THIS_MODULE,
  349. };
  350. /* As long as the position is less then that total number of erase blocks,
  351. * we still have more to print.
  352. */
  353. static void *eraseblk_count_seq_start(struct seq_file *s, loff_t *pos)
  354. {
  355. struct ubi_device *ubi = s->private;
  356. if (*pos < ubi->peb_count)
  357. return pos;
  358. return NULL;
  359. }
  360. /* Since we are using the position as the iterator, we just need to check if we
  361. * are done and increment the position.
  362. */
  363. static void *eraseblk_count_seq_next(struct seq_file *s, void *v, loff_t *pos)
  364. {
  365. struct ubi_device *ubi = s->private;
  366. (*pos)++;
  367. if (*pos < ubi->peb_count)
  368. return pos;
  369. return NULL;
  370. }
  371. static void eraseblk_count_seq_stop(struct seq_file *s, void *v)
  372. {
  373. }
  374. static int eraseblk_count_seq_show(struct seq_file *s, void *iter)
  375. {
  376. struct ubi_device *ubi = s->private;
  377. struct ubi_wl_entry *wl;
  378. int *block_number = iter;
  379. int erase_count = -1;
  380. int err;
  381. /* If this is the start, print a header */
  382. if (*block_number == 0)
  383. seq_puts(s, "physical_block_number\terase_count\n");
  384. err = ubi_io_is_bad(ubi, *block_number);
  385. if (err)
  386. return err;
  387. spin_lock(&ubi->wl_lock);
  388. wl = ubi->lookuptbl[*block_number];
  389. if (wl)
  390. erase_count = wl->ec;
  391. spin_unlock(&ubi->wl_lock);
  392. if (erase_count < 0)
  393. return 0;
  394. seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count);
  395. return 0;
  396. }
  397. static const struct seq_operations eraseblk_count_seq_ops = {
  398. .start = eraseblk_count_seq_start,
  399. .next = eraseblk_count_seq_next,
  400. .stop = eraseblk_count_seq_stop,
  401. .show = eraseblk_count_seq_show
  402. };
  403. static int eraseblk_count_open(struct inode *inode, struct file *f)
  404. {
  405. struct seq_file *s;
  406. int err;
  407. err = seq_open(f, &eraseblk_count_seq_ops);
  408. if (err)
  409. return err;
  410. s = f->private_data;
  411. s->private = ubi_get_device((unsigned long)inode->i_private);
  412. if (!s->private)
  413. return -ENODEV;
  414. else
  415. return 0;
  416. }
  417. static int eraseblk_count_release(struct inode *inode, struct file *f)
  418. {
  419. struct seq_file *s = f->private_data;
  420. struct ubi_device *ubi = s->private;
  421. ubi_put_device(ubi);
  422. return seq_release(inode, f);
  423. }
  424. static const struct file_operations eraseblk_count_fops = {
  425. .owner = THIS_MODULE,
  426. .open = eraseblk_count_open,
  427. .read = seq_read,
  428. .llseek = seq_lseek,
  429. .release = eraseblk_count_release,
  430. };
  431. /**
  432. * ubi_debugfs_init_dev - initialize debugfs for an UBI device.
  433. * @ubi: UBI device description object
  434. *
  435. * This function creates all debugfs files for UBI device @ubi. Returns zero in
  436. * case of success and a negative error code in case of failure.
  437. */
  438. int ubi_debugfs_init_dev(struct ubi_device *ubi)
  439. {
  440. unsigned long ubi_num = ubi->ubi_num;
  441. struct ubi_debug_info *d = &ubi->dbg;
  442. int n;
  443. if (!IS_ENABLED(CONFIG_DEBUG_FS))
  444. return 0;
  445. n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME,
  446. ubi->ubi_num);
  447. if (n > UBI_DFS_DIR_LEN) {
  448. /* The array size is too small */
  449. return -EINVAL;
  450. }
  451. d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir);
  452. d->dfs_chk_gen = debugfs_create_file("chk_gen", S_IWUSR, d->dfs_dir,
  453. (void *)ubi_num, &dfs_fops);
  454. d->dfs_chk_io = debugfs_create_file("chk_io", S_IWUSR, d->dfs_dir,
  455. (void *)ubi_num, &dfs_fops);
  456. d->dfs_chk_fastmap = debugfs_create_file("chk_fastmap", S_IWUSR,
  457. d->dfs_dir, (void *)ubi_num,
  458. &dfs_fops);
  459. d->dfs_disable_bgt = debugfs_create_file("tst_disable_bgt", S_IWUSR,
  460. d->dfs_dir, (void *)ubi_num,
  461. &dfs_fops);
  462. d->dfs_emulate_bitflips = debugfs_create_file("tst_emulate_bitflips",
  463. S_IWUSR, d->dfs_dir,
  464. (void *)ubi_num,
  465. &dfs_fops);
  466. d->dfs_emulate_io_failures = debugfs_create_file("tst_emulate_io_failures",
  467. S_IWUSR, d->dfs_dir,
  468. (void *)ubi_num,
  469. &dfs_fops);
  470. d->dfs_emulate_power_cut = debugfs_create_file("tst_emulate_power_cut",
  471. S_IWUSR, d->dfs_dir,
  472. (void *)ubi_num,
  473. &dfs_fops);
  474. d->dfs_power_cut_min = debugfs_create_file("tst_emulate_power_cut_min",
  475. S_IWUSR, d->dfs_dir,
  476. (void *)ubi_num, &dfs_fops);
  477. d->dfs_power_cut_max = debugfs_create_file("tst_emulate_power_cut_max",
  478. S_IWUSR, d->dfs_dir,
  479. (void *)ubi_num, &dfs_fops);
  480. debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir,
  481. (void *)ubi_num, &eraseblk_count_fops);
  482. return 0;
  483. }
  484. /**
  485. * ubi_debugfs_exit_dev - free all debugfs files corresponding to device @ubi
  486. * @ubi: UBI device description object
  487. */
  488. void ubi_debugfs_exit_dev(struct ubi_device *ubi)
  489. {
  490. if (IS_ENABLED(CONFIG_DEBUG_FS))
  491. debugfs_remove_recursive(ubi->dbg.dfs_dir);
  492. }
  493. /**
  494. * ubi_dbg_power_cut - emulate a power cut if it is time to do so
  495. * @ubi: UBI device description object
  496. * @caller: Flags set to indicate from where the function is being called
  497. *
  498. * Returns non-zero if a power cut was emulated, zero if not.
  499. */
  500. int ubi_dbg_power_cut(struct ubi_device *ubi, int caller)
  501. {
  502. unsigned int range;
  503. if ((ubi->dbg.emulate_power_cut & caller) == 0)
  504. return 0;
  505. if (ubi->dbg.power_cut_counter == 0) {
  506. ubi->dbg.power_cut_counter = ubi->dbg.power_cut_min;
  507. if (ubi->dbg.power_cut_max > ubi->dbg.power_cut_min) {
  508. range = ubi->dbg.power_cut_max - ubi->dbg.power_cut_min;
  509. ubi->dbg.power_cut_counter += prandom_u32_max(range);
  510. }
  511. return 0;
  512. }
  513. ubi->dbg.power_cut_counter--;
  514. if (ubi->dbg.power_cut_counter)
  515. return 0;
  516. ubi_msg(ubi, "XXXXXXXXXXXXXXX emulating a power cut XXXXXXXXXXXXXXXX");
  517. ubi_ro_mode(ubi);
  518. return 1;
  519. }