--- zzzz-none-000/linux-4.4.271/drivers/mtd/mtdcore.c 2021-06-03 06:22:09.000000000 +0000 +++ dakota-7530ac-750/linux-4.4.271/drivers/mtd/mtdcore.c 2023-01-11 09:25:42.000000000 +0000 @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -464,6 +465,15 @@ of this try_ nonsense, and no bitching about it either. :) */ __module_get(THIS_MODULE); + + if (!strcmp(mtd->name, "rootfs") && + config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV) && + ROOT_DEV == 0) { + pr_notice("mtd: device %d (%s) set to be root filesystem\n", + mtd->index, mtd->name); + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index); + } + return 0; fail_added: @@ -1278,6 +1288,42 @@ .llseek = seq_lseek, .release = single_release, }; + +#if defined(CONFIG_AVM_ENHANCED) +static struct proc_dir_entry *proc_bbt_mtd; +static int mtd_bbt_proc_show(struct seq_file *m, void *v) +{ + struct mtd_info *mtd; + + mutex_lock(&mtd_table_mutex); + mtd_for_each_device(mtd) { + if (mtd->_block_isbad) { + uint64_t i; + unsigned int badblocks=0; + for (i = 0; i < mtd->size; i += mtd->erasesize) { + if (mtd->_block_isbad(mtd, i) && ((badblocks+1)>badblocks) ) + badblocks++; + } + seq_printf(m, "mtd%d: %u bad blocks\n", mtd->index, badblocks); + } + } + mutex_unlock(&mtd_table_mutex); + return 0; +} + +static int mtd_bbt_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, mtd_bbt_proc_show, NULL); +} + +static const struct file_operations mtd_bbt_proc_ops = { + .open = mtd_bbt_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif /*--- #if #defined(CONFIG_AVM_ENHANCED) ---*/ + #endif /* CONFIG_PROC_FS */ /*====================================================================*/ @@ -1313,6 +1359,10 @@ proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); +#if defined(CONFIG_AVM_ENHANCED) + proc_bbt_mtd = proc_create("avm/mtd_bbt", 0, NULL, &mtd_bbt_proc_ops); +#endif + ret = init_mtdchar(); if (ret) goto out_procfs; @@ -1322,6 +1372,12 @@ out_procfs: if (proc_mtd) remove_proc_entry("mtd", NULL); + +#if defined(CONFIG_AVM_ENHANCED) + if (proc_bbt_mtd) + remove_proc_entry("mtd_bbt", NULL); +#endif + err_bdi: class_unregister(&mtd_class); err_reg: @@ -1334,6 +1390,12 @@ cleanup_mtdchar(); if (proc_mtd) remove_proc_entry("mtd", NULL); + +#if defined(CONFIG_AVM_ENHANCED) + if (proc_bbt_mtd) + remove_proc_entry("mtd_bbt", NULL); +#endif + class_unregister(&mtd_class); bdi_destroy(&mtd_bdi); idr_destroy(&mtd_idr);