--- zzzz-none-000/linux-4.1.52/drivers/mtd/ubi/build.c 2018-05-28 02:26:45.000000000 +0000 +++ bcm63-7530ax-731/linux-4.1.52/drivers/mtd/ubi/build.c 2022-03-02 11:37:13.000000000 +0000 @@ -53,6 +53,11 @@ /* Maximum value for the number of bad PEBs per 1024 PEBs */ #define MAX_MTD_UBI_BEB_LIMIT 768 +#if defined(CONFIG_BCM_KF_UBI) +/* Minimum Bad Erase Blocks per MTD partition */ +#define BRCM_MIN_BEB_PER_MTDPART 4 +#endif + #ifdef CONFIG_MTD_UBI_MODULE #define ubi_is_module() 1 #else @@ -599,7 +604,20 @@ if (!max_beb_per1024) return 0; - +#if defined(CONFIG_BCM_KF_UBI) + /* + * Here we are using size of just the MTD partition + * because we believe that it is highly unlikely that + * all of the bad eraseblocks in a chip will end up + * in any one partition. Instead we are saying that the + * larger the partition, the more likely it has a higher + * percentage of bad eraseblocks. We therefore scale the + * reserved peb limit based upon the partition size, + * while enforcing a minimum of BRCM_MIN_BEB_PER_MTDPART + * for smaller partitions. + */ + device_size = ubi->mtd->size; +#else /* * Here we are using size of the entire flash chip and * not just the MTD partition size because the maximum @@ -610,6 +628,7 @@ * the MTD partition we are attaching (ubi->mtd). */ device_size = mtd_get_device_size(ubi->mtd); +#endif device_pebs = mtd_div_by_eb(device_size, ubi->mtd); limit = mult_frac(device_pebs, max_beb_per1024, 1024); @@ -617,7 +636,11 @@ if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs) limit += 1; +#if defined(CONFIG_BCM_KF_UBI) + return max(BRCM_MIN_BEB_PER_MTDPART, limit); +#else return limit; +#endif } /** @@ -1422,7 +1445,9 @@ * This function returns zero in case of success and a negative error code in * case of error. */ -static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) +// AVM/TKL: needs to be callable from AVM mtd parsers +//static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) +int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) { int i, len; struct mtd_dev_param *p;