Lines Matching +full:ubi +full:- +full:volume +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 #include "ubi.h"
13 #include <linux/fault-inject.h>
46 * ubi_dump_flash - dump a region of flash. in FAIL_ACTION()
47 * @ubi: UBI device description object in FAIL_ACTION()
52 void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) in FAIL_ACTION()
57 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; in FAIL_ACTION()
62 err = mtd_read(ubi->mtd, addr, len, &read, buf); in FAIL_ACTION()
63 if (err && err != -EUCLEAN) { in FAIL_ACTION()
64 ubi_err(ubi, "err %d while reading %d bytes from PEB %d:%d, read %zd bytes", in FAIL_ACTION()
69 ubi_msg(ubi, "dumping %d bytes of data from PEB %d, offset %d", in FAIL_ACTION()
78 * ubi_dump_ec_hdr - dump an erase counter header.
84 pr_err("\tmagic %#08x\n", be32_to_cpu(ec_hdr->magic)); in ubi_dump_ec_hdr()
85 pr_err("\tversion %d\n", (int)ec_hdr->version); in ubi_dump_ec_hdr()
86 pr_err("\tec %llu\n", (long long)be64_to_cpu(ec_hdr->ec)); in ubi_dump_ec_hdr()
87 pr_err("\tvid_hdr_offset %d\n", be32_to_cpu(ec_hdr->vid_hdr_offset)); in ubi_dump_ec_hdr()
88 pr_err("\tdata_offset %d\n", be32_to_cpu(ec_hdr->data_offset)); in ubi_dump_ec_hdr()
89 pr_err("\timage_seq %d\n", be32_to_cpu(ec_hdr->image_seq)); in ubi_dump_ec_hdr()
90 pr_err("\thdr_crc %#08x\n", be32_to_cpu(ec_hdr->hdr_crc)); in ubi_dump_ec_hdr()
97 * ubi_dump_vid_hdr - dump a volume identifier header.
98 * @vid_hdr: the volume identifier header to dump
102 pr_err("Volume identifier header dump:\n"); in ubi_dump_vid_hdr()
103 pr_err("\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); in ubi_dump_vid_hdr()
104 pr_err("\tversion %d\n", (int)vid_hdr->version); in ubi_dump_vid_hdr()
105 pr_err("\tvol_type %d\n", (int)vid_hdr->vol_type); in ubi_dump_vid_hdr()
106 pr_err("\tcopy_flag %d\n", (int)vid_hdr->copy_flag); in ubi_dump_vid_hdr()
107 pr_err("\tcompat %d\n", (int)vid_hdr->compat); in ubi_dump_vid_hdr()
108 pr_err("\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); in ubi_dump_vid_hdr()
109 pr_err("\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); in ubi_dump_vid_hdr()
110 pr_err("\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); in ubi_dump_vid_hdr()
111 pr_err("\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); in ubi_dump_vid_hdr()
112 pr_err("\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); in ubi_dump_vid_hdr()
114 (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); in ubi_dump_vid_hdr()
115 pr_err("\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc)); in ubi_dump_vid_hdr()
116 pr_err("Volume identifier header hexdump:\n"); in ubi_dump_vid_hdr()
122 * ubi_dump_vol_info - dump volume information.
123 * @vol: UBI volume description object
127 pr_err("Volume information dump:\n"); in ubi_dump_vol_info()
128 pr_err("\tvol_id %d\n", vol->vol_id); in ubi_dump_vol_info()
129 pr_err("\treserved_pebs %d\n", vol->reserved_pebs); in ubi_dump_vol_info()
130 pr_err("\talignment %d\n", vol->alignment); in ubi_dump_vol_info()
131 pr_err("\tdata_pad %d\n", vol->data_pad); in ubi_dump_vol_info()
132 pr_err("\tvol_type %d\n", vol->vol_type); in ubi_dump_vol_info()
133 pr_err("\tname_len %d\n", vol->name_len); in ubi_dump_vol_info()
134 pr_err("\tusable_leb_size %d\n", vol->usable_leb_size); in ubi_dump_vol_info()
135 pr_err("\tused_ebs %d\n", vol->used_ebs); in ubi_dump_vol_info()
136 pr_err("\tused_bytes %lld\n", vol->used_bytes); in ubi_dump_vol_info()
137 pr_err("\tlast_eb_bytes %d\n", vol->last_eb_bytes); in ubi_dump_vol_info()
138 pr_err("\tcorrupted %d\n", vol->corrupted); in ubi_dump_vol_info()
139 pr_err("\tupd_marker %d\n", vol->upd_marker); in ubi_dump_vol_info()
140 pr_err("\tskip_check %d\n", vol->skip_check); in ubi_dump_vol_info()
142 if (vol->name_len <= UBI_VOL_NAME_MAX && in ubi_dump_vol_info()
143 strnlen(vol->name, vol->name_len + 1) == vol->name_len) { in ubi_dump_vol_info()
144 pr_err("\tname %s\n", vol->name); in ubi_dump_vol_info()
147 vol->name[0], vol->name[1], vol->name[2], in ubi_dump_vol_info()
148 vol->name[3], vol->name[4]); in ubi_dump_vol_info()
153 * ubi_dump_vtbl_record - dump a &struct ubi_vtbl_record object.
155 * @idx: volume table index
159 int name_len = be16_to_cpu(r->name_len); in ubi_dump_vtbl_record()
161 pr_err("Volume table record %d dump:\n", idx); in ubi_dump_vtbl_record()
162 pr_err("\treserved_pebs %d\n", be32_to_cpu(r->reserved_pebs)); in ubi_dump_vtbl_record()
163 pr_err("\talignment %d\n", be32_to_cpu(r->alignment)); in ubi_dump_vtbl_record()
164 pr_err("\tdata_pad %d\n", be32_to_cpu(r->data_pad)); in ubi_dump_vtbl_record()
165 pr_err("\tvol_type %d\n", (int)r->vol_type); in ubi_dump_vtbl_record()
166 pr_err("\tupd_marker %d\n", (int)r->upd_marker); in ubi_dump_vtbl_record()
169 if (r->name[0] == '\0') { in ubi_dump_vtbl_record()
175 strnlen(&r->name[0], name_len + 1) == name_len) { in ubi_dump_vtbl_record()
176 pr_err("\tname %s\n", &r->name[0]); in ubi_dump_vtbl_record()
179 r->name[0], r->name[1], r->name[2], r->name[3], in ubi_dump_vtbl_record()
180 r->name[4]); in ubi_dump_vtbl_record()
182 pr_err("\tcrc %#08x\n", be32_to_cpu(r->crc)); in ubi_dump_vtbl_record()
186 * ubi_dump_av - dump a &struct ubi_ainf_volume object.
191 pr_err("Volume attaching information dump:\n"); in ubi_dump_av()
192 pr_err("\tvol_id %d\n", av->vol_id); in ubi_dump_av()
193 pr_err("\thighest_lnum %d\n", av->highest_lnum); in ubi_dump_av()
194 pr_err("\tleb_count %d\n", av->leb_count); in ubi_dump_av()
195 pr_err("\tcompat %d\n", av->compat); in ubi_dump_av()
196 pr_err("\tvol_type %d\n", av->vol_type); in ubi_dump_av()
197 pr_err("\tused_ebs %d\n", av->used_ebs); in ubi_dump_av()
198 pr_err("\tlast_data_size %d\n", av->last_data_size); in ubi_dump_av()
199 pr_err("\tdata_pad %d\n", av->data_pad); in ubi_dump_av()
203 * ubi_dump_aeb - dump a &struct ubi_ainf_peb object.
205 * @type: object type: 0 - not corrupted, 1 - corrupted
210 pr_err("\tec %d\n", aeb->ec); in ubi_dump_aeb()
211 pr_err("\tpnum %d\n", aeb->pnum); in ubi_dump_aeb()
213 pr_err("\tlnum %d\n", aeb->lnum); in ubi_dump_aeb()
214 pr_err("\tscrub %d\n", aeb->scrub); in ubi_dump_aeb()
215 pr_err("\tsqnum %llu\n", aeb->sqnum); in ubi_dump_aeb()
220 * ubi_dump_mkvol_req - dump a &struct ubi_mkvol_req object.
227 pr_err("Volume creation request dump:\n"); in ubi_dump_mkvol_req()
228 pr_err("\tvol_id %d\n", req->vol_id); in ubi_dump_mkvol_req()
229 pr_err("\talignment %d\n", req->alignment); in ubi_dump_mkvol_req()
230 pr_err("\tbytes %lld\n", (long long)req->bytes); in ubi_dump_mkvol_req()
231 pr_err("\tvol_type %d\n", req->vol_type); in ubi_dump_mkvol_req()
232 pr_err("\tname_len %d\n", req->name_len); in ubi_dump_mkvol_req()
234 memcpy(nm, req->name, 16); in ubi_dump_mkvol_req()
240 * Root directory for UBI stuff in debugfs. Contains sub-directories which
241 * contain the stuff specific to particular UBI devices.
252 int err = dir ? PTR_ERR(dir) : -ENODEV; in dfs_create_fault_entry()
254 pr_warn("UBI error: cannot create \"fault_inject\" debugfs directory, error %d\n", in dfs_create_fault_entry()
292 * ubi_debugfs_init - create UBI debugfs directory.
294 * Create UBI debugfs directory. Returns zero in case of success and a negative
302 dfs_rootdir = debugfs_create_dir("ubi", NULL); in ubi_debugfs_init()
304 int err = dfs_rootdir ? PTR_ERR(dfs_rootdir) : -ENODEV; in ubi_debugfs_init()
306 pr_err("UBI error: cannot create \"ubi\" debugfs directory, error %d\n", in ubi_debugfs_init()
319 * ubi_debugfs_exit - remove UBI debugfs directory.
327 /* Read an UBI debugfs file */
331 unsigned long ubi_num = (unsigned long)file->private_data; in dfs_file_read()
332 struct dentry *dent = file->f_path.dentry; in dfs_file_read()
333 struct ubi_device *ubi; in dfs_file_read() local
338 ubi = ubi_get_device(ubi_num); in dfs_file_read()
339 if (!ubi) in dfs_file_read()
340 return -ENODEV; in dfs_file_read()
341 d = &ubi->dbg; in dfs_file_read()
343 if (dent == d->dfs_chk_gen) in dfs_file_read()
344 val = d->chk_gen; in dfs_file_read()
345 else if (dent == d->dfs_chk_io) in dfs_file_read()
346 val = d->chk_io; in dfs_file_read()
347 else if (dent == d->dfs_chk_fastmap) in dfs_file_read()
348 val = d->chk_fastmap; in dfs_file_read()
349 else if (dent == d->dfs_disable_bgt) in dfs_file_read()
350 val = d->disable_bgt; in dfs_file_read()
351 else if (dent == d->dfs_emulate_bitflips) in dfs_file_read()
352 val = d->emulate_bitflips; in dfs_file_read()
353 else if (dent == d->dfs_emulate_io_failures) in dfs_file_read()
354 val = d->emulate_io_failures; in dfs_file_read()
355 else if (dent == d->dfs_emulate_failures) { in dfs_file_read()
356 snprintf(buf, sizeof(buf), "0x%04x\n", d->emulate_failures); in dfs_file_read()
360 } else if (dent == d->dfs_emulate_power_cut) { in dfs_file_read()
361 snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut); in dfs_file_read()
365 } else if (dent == d->dfs_power_cut_min) { in dfs_file_read()
366 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_min); in dfs_file_read()
370 } else if (dent == d->dfs_power_cut_max) { in dfs_file_read()
371 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_max); in dfs_file_read()
376 count = -EINVAL; in dfs_file_read()
390 ubi_put_device(ubi); in dfs_file_read()
394 /* Write an UBI debugfs file */
398 unsigned long ubi_num = (unsigned long)file->private_data; in dfs_file_write()
399 struct dentry *dent = file->f_path.dentry; in dfs_file_write()
400 struct ubi_device *ubi; in dfs_file_write() local
406 ubi = ubi_get_device(ubi_num); in dfs_file_write()
407 if (!ubi) in dfs_file_write()
408 return -ENODEV; in dfs_file_write()
409 d = &ubi->dbg; in dfs_file_write()
411 buf_size = min_t(size_t, count, (sizeof(buf) - 1)); in dfs_file_write()
413 count = -EFAULT; in dfs_file_write()
417 if (dent == d->dfs_emulate_failures) { in dfs_file_write()
418 if (kstrtouint(buf, 0, &d->emulate_failures) != 0) in dfs_file_write()
419 count = -EINVAL; in dfs_file_write()
421 } else if (dent == d->dfs_power_cut_min) { in dfs_file_write()
422 if (kstrtouint(buf, 0, &d->power_cut_min) != 0) in dfs_file_write()
423 count = -EINVAL; in dfs_file_write()
425 } else if (dent == d->dfs_power_cut_max) { in dfs_file_write()
426 if (kstrtouint(buf, 0, &d->power_cut_max) != 0) in dfs_file_write()
427 count = -EINVAL; in dfs_file_write()
429 } else if (dent == d->dfs_emulate_power_cut) { in dfs_file_write()
431 count = -EINVAL; in dfs_file_write()
433 d->emulate_power_cut = val; in dfs_file_write()
442 count = -EINVAL; in dfs_file_write()
446 if (dent == d->dfs_chk_gen) in dfs_file_write()
447 d->chk_gen = val; in dfs_file_write()
448 else if (dent == d->dfs_chk_io) in dfs_file_write()
449 d->chk_io = val; in dfs_file_write()
450 else if (dent == d->dfs_chk_fastmap) in dfs_file_write()
451 d->chk_fastmap = val; in dfs_file_write()
452 else if (dent == d->dfs_disable_bgt) in dfs_file_write()
453 d->disable_bgt = val; in dfs_file_write()
454 else if (dent == d->dfs_emulate_bitflips) in dfs_file_write()
455 d->emulate_bitflips = val; in dfs_file_write()
456 else if (dent == d->dfs_emulate_io_failures) in dfs_file_write()
457 d->emulate_io_failures = val; in dfs_file_write()
459 count = -EINVAL; in dfs_file_write()
462 ubi_put_device(ubi); in dfs_file_write()
466 /* File operations for all UBI debugfs files except
481 struct ubi_device *ubi = s->private; in eraseblk_count_seq_start() local
483 if (*pos < ubi->peb_count) in eraseblk_count_seq_start()
494 struct ubi_device *ubi = s->private; in eraseblk_count_seq_next() local
498 if (*pos < ubi->peb_count) in eraseblk_count_seq_next()
510 struct ubi_device *ubi = s->private; in eraseblk_count_seq_show() local
513 int erase_count = -1; in eraseblk_count_seq_show()
520 err = ubi_io_is_bad(ubi, *block_number); in eraseblk_count_seq_show()
524 spin_lock(&ubi->wl_lock); in eraseblk_count_seq_show()
526 wl = ubi->lookuptbl[*block_number]; in eraseblk_count_seq_show()
528 erase_count = wl->ec; in eraseblk_count_seq_show()
530 spin_unlock(&ubi->wl_lock); in eraseblk_count_seq_show()
535 seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count); in eraseblk_count_seq_show()
556 s = f->private_data; in eraseblk_count_open()
557 s->private = ubi_get_device((unsigned long)inode->i_private); in eraseblk_count_open()
559 if (!s->private) in eraseblk_count_open()
560 return -ENODEV; in eraseblk_count_open()
567 struct seq_file *s = f->private_data; in eraseblk_count_release()
568 struct ubi_device *ubi = s->private; in eraseblk_count_release() local
570 ubi_put_device(ubi); in eraseblk_count_release()
584 * ubi_debugfs_init_dev - initialize debugfs for an UBI device.
585 * @ubi: UBI device description object
587 * This function creates all debugfs files for UBI device @ubi. Returns zero in
590 int ubi_debugfs_init_dev(struct ubi_device *ubi) in ubi_debugfs_init_dev() argument
592 unsigned long ubi_num = ubi->ubi_num; in ubi_debugfs_init_dev()
593 struct ubi_debug_info *d = &ubi->dbg; in ubi_debugfs_init_dev()
600 n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN, UBI_DFS_DIR_NAME, in ubi_debugfs_init_dev()
601 ubi->ubi_num); in ubi_debugfs_init_dev()
604 return -EINVAL; in ubi_debugfs_init_dev()
607 d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir); in ubi_debugfs_init_dev()
609 d->dfs_chk_gen = debugfs_create_file("chk_gen", mode, d->dfs_dir, in ubi_debugfs_init_dev()
612 d->dfs_chk_io = debugfs_create_file("chk_io", mode, d->dfs_dir, in ubi_debugfs_init_dev()
615 d->dfs_chk_fastmap = debugfs_create_file("chk_fastmap", mode, in ubi_debugfs_init_dev()
616 d->dfs_dir, (void *)ubi_num, in ubi_debugfs_init_dev()
619 d->dfs_disable_bgt = debugfs_create_file("tst_disable_bgt", mode, in ubi_debugfs_init_dev()
620 d->dfs_dir, (void *)ubi_num, in ubi_debugfs_init_dev()
623 d->dfs_emulate_bitflips = debugfs_create_file("tst_emulate_bitflips", in ubi_debugfs_init_dev()
624 mode, d->dfs_dir, in ubi_debugfs_init_dev()
628 d->dfs_emulate_io_failures = debugfs_create_file("tst_emulate_io_failures", in ubi_debugfs_init_dev()
629 mode, d->dfs_dir, in ubi_debugfs_init_dev()
633 d->dfs_emulate_power_cut = debugfs_create_file("tst_emulate_power_cut", in ubi_debugfs_init_dev()
634 mode, d->dfs_dir, in ubi_debugfs_init_dev()
638 d->dfs_power_cut_min = debugfs_create_file("tst_emulate_power_cut_min", in ubi_debugfs_init_dev()
639 mode, d->dfs_dir, in ubi_debugfs_init_dev()
642 d->dfs_power_cut_max = debugfs_create_file("tst_emulate_power_cut_max", in ubi_debugfs_init_dev()
643 mode, d->dfs_dir, in ubi_debugfs_init_dev()
646 debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir, in ubi_debugfs_init_dev()
650 d->dfs_emulate_failures = debugfs_create_file("emulate_failures", in ubi_debugfs_init_dev()
651 mode, d->dfs_dir, in ubi_debugfs_init_dev()
659 * ubi_debugfs_exit_dev - free all debugfs files corresponding to device @ubi
660 * @ubi: UBI device description object
662 void ubi_debugfs_exit_dev(struct ubi_device *ubi) in ubi_debugfs_exit_dev() argument
665 debugfs_remove_recursive(ubi->dbg.dfs_dir); in ubi_debugfs_exit_dev()
669 * ubi_dbg_power_cut - emulate a power cut if it is time to do so
670 * @ubi: UBI device description object
673 * Returns non-zero if a power cut was emulated, zero if not.
675 int ubi_dbg_power_cut(struct ubi_device *ubi, int caller) in ubi_dbg_power_cut() argument
679 if ((ubi->dbg.emulate_power_cut & caller) == 0) in ubi_dbg_power_cut()
682 if (ubi->dbg.power_cut_counter == 0) { in ubi_dbg_power_cut()
683 ubi->dbg.power_cut_counter = ubi->dbg.power_cut_min; in ubi_dbg_power_cut()
685 if (ubi->dbg.power_cut_max > ubi->dbg.power_cut_min) { in ubi_dbg_power_cut()
686 range = ubi->dbg.power_cut_max - ubi->dbg.power_cut_min; in ubi_dbg_power_cut()
687 ubi->dbg.power_cut_counter += get_random_u32_below(range); in ubi_dbg_power_cut()
692 ubi->dbg.power_cut_counter--; in ubi_dbg_power_cut()
693 if (ubi->dbg.power_cut_counter) in ubi_dbg_power_cut()