--- zzzz-none-000/linux-4.19.183/drivers/mtd/ubi/build.c 2021-03-24 10:07:39.000000000 +0000 +++ bcm63-7530ax-756/linux-4.19.183/drivers/mtd/ubi/build.c 2023-06-28 08:54:19.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 @@ -548,6 +553,20 @@ return limit; } +#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 @@ -558,6 +577,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); @@ -565,7 +585,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 } /** @@ -1358,7 +1382,8 @@ * This function returns zero in case of success and a negative error code in * case of error. */ -static int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp) +// AVM/TKL: needs to be callable from AVM mtd parsers +int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp) { int i, len; struct mtd_dev_param *p;