aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/debug.c
diff options
context:
space:
mode:
authordavid.oberhollenzer@sigma-star.at <david.oberhollenzer@sigma-star.at>2015-03-26 18:59:50 -0400
committerRichard Weinberger <richard@nod.at>2015-04-13 15:05:17 -0400
commit502690674281a047abd45f81e64c498bc23a8bb3 (patch)
tree5aa08ca80d7de94bf0b3050a7f458ad0ed25d004 /drivers/mtd/ubi/debug.c
parent1a7e985dd1bf5939af0f56bbd6d13d2caf48dd63 (diff)
UBI: power cut emulation for testing
Emulate random power cuts by switching device to ro after a number of writes to allow simple power cut testing with nand-sim. Maximum and minimum number of successful writes before power cut and what kind of writes (EC header, VID header or none) to interrupt configurable via debugfs. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'drivers/mtd/ubi/debug.c')
-rw-r--r--drivers/mtd/ubi/debug.c89
1 files changed, 87 insertions, 2 deletions
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 224fed085102..b077e43b5ba9 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -263,7 +263,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
263 struct dentry *dent = file->f_path.dentry; 263 struct dentry *dent = file->f_path.dentry;
264 struct ubi_device *ubi; 264 struct ubi_device *ubi;
265 struct ubi_debug_info *d; 265 struct ubi_debug_info *d;
266 char buf[3]; 266 char buf[8];
267 int val; 267 int val;
268 268
269 ubi = ubi_get_device(ubi_num); 269 ubi = ubi_get_device(ubi_num);
@@ -283,6 +283,22 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
283 val = d->emulate_bitflips; 283 val = d->emulate_bitflips;
284 else if (dent == d->dfs_emulate_io_failures) 284 else if (dent == d->dfs_emulate_io_failures)
285 val = d->emulate_io_failures; 285 val = d->emulate_io_failures;
286 else if (dent == d->dfs_emulate_power_cut) {
287 snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut);
288 count = simple_read_from_buffer(user_buf, count, ppos,
289 buf, strlen(buf));
290 goto out;
291 } else if (dent == d->dfs_power_cut_min) {
292 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_min);
293 count = simple_read_from_buffer(user_buf, count, ppos,
294 buf, strlen(buf));
295 goto out;
296 } else if (dent == d->dfs_power_cut_max) {
297 snprintf(buf, sizeof(buf), "%u\n", d->power_cut_max);
298 count = simple_read_from_buffer(user_buf, count, ppos,
299 buf, strlen(buf));
300 goto out;
301 }
286 else { 302 else {
287 count = -EINVAL; 303 count = -EINVAL;
288 goto out; 304 goto out;
@@ -311,7 +327,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
311 struct ubi_device *ubi; 327 struct ubi_device *ubi;
312 struct ubi_debug_info *d; 328 struct ubi_debug_info *d;
313 size_t buf_size; 329 size_t buf_size;
314 char buf[8]; 330 char buf[8] = {0};
315 int val; 331 int val;
316 332
317 ubi = ubi_get_device(ubi_num); 333 ubi = ubi_get_device(ubi_num);
@@ -325,6 +341,21 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
325 goto out; 341 goto out;
326 } 342 }
327 343
344 if (dent == d->dfs_power_cut_min) {
345 if (kstrtouint(buf, 0, &d->power_cut_min) != 0)
346 count = -EINVAL;
347 goto out;
348 } else if (dent == d->dfs_power_cut_max) {
349 if (kstrtouint(buf, 0, &d->power_cut_max) != 0)
350 count = -EINVAL;
351 goto out;
352 } else if (dent == d->dfs_emulate_power_cut) {
353 if (kstrtoint(buf, 0, &val) != 0)
354 count = -EINVAL;
355 d->emulate_power_cut = val;
356 goto out;
357 }
358
328 if (buf[0] == '1') 359 if (buf[0] == '1')
329 val = 1; 360 val = 1;
330 else if (buf[0] == '0') 361 else if (buf[0] == '0')
@@ -438,6 +469,27 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
438 goto out_remove; 469 goto out_remove;
439 d->dfs_emulate_io_failures = dent; 470 d->dfs_emulate_io_failures = dent;
440 471
472 fname = "tst_emulate_power_cut";
473 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
474 &dfs_fops);
475 if (IS_ERR_OR_NULL(dent))
476 goto out_remove;
477 d->dfs_emulate_power_cut = dent;
478
479 fname = "tst_emulate_power_cut_min";
480 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
481 &dfs_fops);
482 if (IS_ERR_OR_NULL(dent))
483 goto out_remove;
484 d->dfs_power_cut_min = dent;
485
486 fname = "tst_emulate_power_cut_max";
487 dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
488 &dfs_fops);
489 if (IS_ERR_OR_NULL(dent))
490 goto out_remove;
491 d->dfs_power_cut_max = dent;
492
441 return 0; 493 return 0;
442 494
443out_remove: 495out_remove:
@@ -458,3 +510,36 @@ void ubi_debugfs_exit_dev(struct ubi_device *ubi)
458 if (IS_ENABLED(CONFIG_DEBUG_FS)) 510 if (IS_ENABLED(CONFIG_DEBUG_FS))
459 debugfs_remove_recursive(ubi->dbg.dfs_dir); 511 debugfs_remove_recursive(ubi->dbg.dfs_dir);
460} 512}
513
514/**
515 * ubi_dbg_power_cut - emulate a power cut if it is time to do so
516 * @ubi: UBI device description object
517 * @caller: Flags set to indicate from where the function is being called
518 *
519 * Returns non-zero if a power cut was emulated, zero if not.
520 */
521int ubi_dbg_power_cut(struct ubi_device *ubi, int caller)
522{
523 unsigned int range;
524
525 if ((ubi->dbg.emulate_power_cut & caller) == 0)
526 return 0;
527
528 if (ubi->dbg.power_cut_counter == 0) {
529 ubi->dbg.power_cut_counter = ubi->dbg.power_cut_min;
530
531 if (ubi->dbg.power_cut_max > ubi->dbg.power_cut_min) {
532 range = ubi->dbg.power_cut_max - ubi->dbg.power_cut_min;
533 ubi->dbg.power_cut_counter += prandom_u32() % range;
534 }
535 return 0;
536 }
537
538 ubi->dbg.power_cut_counter--;
539 if (ubi->dbg.power_cut_counter)
540 return 0;
541
542 ubi_msg(ubi, "XXXXXXXXXXXXXXX emulating a power cut XXXXXXXXXXXXXXXX");
543 ubi_ro_mode(ubi);
544 return 1;
545}