Skip to content

Commit e3d2faf

Browse files
juhosgmiquelraynal
authored andcommitted
mtd: core: expose ooblayout information via debugfs
Add two new debugfs files which allows to determine the OOB layout used by a given MTD device. This can be useful to verify the current layout during driver development without adding extra debug code. The exposed information also makes it easier to analyze NAND dumps without the need of crawling out the layout from the driver code. The content of the new debugfs files is similar to this: # cat /sys/kernel/debug/mtd/mtd0/ooblayout_ecc 0 0 49 1 65 63 # cat /sys/kernel/debug/mtd/mtd0/ooblayout_free 0 49 16 Signed-off-by: Gabor Juhos <j4g8y7@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 0ee8d76 commit e3d2faf

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

drivers/mtd/mtdcore.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,64 @@ EXPORT_SYMBOL_GPL(mtd_check_expert_analysis_mode);
384384

385385
static struct dentry *dfs_dir_mtd;
386386

387+
static int mtd_ooblayout_show(struct seq_file *s, void *p,
388+
int (*iter)(struct mtd_info *, int section,
389+
struct mtd_oob_region *region))
390+
{
391+
struct mtd_info *mtd = s->private;
392+
int section;
393+
394+
for (section = 0;; section++) {
395+
struct mtd_oob_region region;
396+
int err;
397+
398+
err = iter(mtd, section, &region);
399+
if (err) {
400+
if (err == -ERANGE)
401+
break;
402+
403+
return err;
404+
}
405+
406+
seq_printf(s, "%-3d %4u %4u\n", section, region.offset,
407+
region.length);
408+
}
409+
410+
return 0;
411+
}
412+
413+
static int mtd_ooblayout_ecc_show(struct seq_file *s, void *p)
414+
{
415+
return mtd_ooblayout_show(s, p, mtd_ooblayout_ecc);
416+
}
417+
DEFINE_SHOW_ATTRIBUTE(mtd_ooblayout_ecc);
418+
419+
static int mtd_ooblayout_free_show(struct seq_file *s, void *p)
420+
{
421+
return mtd_ooblayout_show(s, p, mtd_ooblayout_free);
422+
}
423+
DEFINE_SHOW_ATTRIBUTE(mtd_ooblayout_free);
424+
387425
static void mtd_debugfs_populate(struct mtd_info *mtd)
388426
{
389427
struct device *dev = &mtd->dev;
428+
struct mtd_oob_region region;
390429

391430
if (IS_ERR_OR_NULL(dfs_dir_mtd))
392431
return;
393432

394433
mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(dev), dfs_dir_mtd);
434+
if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir))
435+
return;
436+
437+
/* Create ooblayout files only if at least one region is present. */
438+
if (mtd_ooblayout_ecc(mtd, 0, &region) == 0)
439+
debugfs_create_file("ooblayout_ecc", 0444, mtd->dbg.dfs_dir,
440+
mtd, &mtd_ooblayout_ecc_fops);
441+
442+
if (mtd_ooblayout_free(mtd, 0, &region) == 0)
443+
debugfs_create_file("ooblayout_free", 0444, mtd->dbg.dfs_dir,
444+
mtd, &mtd_ooblayout_free_fops);
395445
}
396446

397447
#ifndef CONFIG_MMU

0 commit comments

Comments
 (0)