From 8beeb3bb9df8caba36ad3e4f226255dff9c92556 Mon Sep 17 00:00:00 2001 From: Shmulik Ladkani Date: Wed, 4 Jul 2012 11:06:00 +0300 Subject: UBI: introduce new bad PEB limit Introduce 'ubi->bad_peb_limit', which specifies an upper limit of PEBs UBI expects to go bad. Currently, it is initialized to a fixed percentage of total PEBs in the UBI device (configurable via CONFIG_MTD_UBI_BEB_LIMIT). The 'bad_peb_limit' is intended to be used for calculating the amount of PEBs UBI needs to reserve for bad eraseblock handling. Artem: minor amendments. Signed-off-by: Shmulik Ladkani Signed-off-by: Artem Bityutskiy --- drivers/mtd/ubi/build.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'drivers/mtd/ubi/build.c') diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 3174dd40095d..ce311aa75a75 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -607,8 +607,18 @@ static int io_init(struct ubi_device *ubi) ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); ubi->flash_size = ubi->mtd->size; - if (mtd_can_have_bb(ubi->mtd)) + if (mtd_can_have_bb(ubi->mtd)) { ubi->bad_allowed = 1; + if (CONFIG_MTD_UBI_BEB_LIMIT > 0) { + int percent = CONFIG_MTD_UBI_BEB_LIMIT; + int limit = mult_frac(ubi->peb_count, percent, 100); + + /* Round it up */ + if (mult_frac(limit, 100, percent) < ubi->peb_count) + limit += 1; + ubi->bad_peb_limit = limit; + } + } if (ubi->mtd->type == MTD_NORFLASH) { ubi_assert(ubi->mtd->writesize == 1); -- cgit v1.2.3