diff options
Diffstat (limited to 'drivers/mtd/ubi/eba.c')
-rw-r--r-- | drivers/mtd/ubi/eba.c | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 9f87c99189a9..fe74749e0dae 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -418,7 +418,8 @@ retry: | |||
418 | * may try to recover data. FIXME: but this is | 418 | * may try to recover data. FIXME: but this is |
419 | * not implemented. | 419 | * not implemented. |
420 | */ | 420 | */ |
421 | if (err == UBI_IO_BAD_VID_HDR) { | 421 | if (err == UBI_IO_BAD_HDR_READ || |
422 | err == UBI_IO_BAD_HDR) { | ||
422 | ubi_warn("corrupted VID header at PEB " | 423 | ubi_warn("corrupted VID header at PEB " |
423 | "%d, LEB %d:%d", pnum, vol_id, | 424 | "%d, LEB %d:%d", pnum, vol_id, |
424 | lnum); | 425 | lnum); |
@@ -961,8 +962,8 @@ write_error: | |||
961 | */ | 962 | */ |
962 | static int is_error_sane(int err) | 963 | static int is_error_sane(int err) |
963 | { | 964 | { |
964 | if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_VID_HDR || | 965 | if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_HDR || |
965 | err == -ETIMEDOUT) | 966 | err == UBI_IO_BAD_HDR_READ || err == -ETIMEDOUT) |
966 | return 0; | 967 | return 0; |
967 | return 1; | 968 | return 1; |
968 | } | 969 | } |
@@ -1165,6 +1166,44 @@ out_unlock_leb: | |||
1165 | } | 1166 | } |
1166 | 1167 | ||
1167 | /** | 1168 | /** |
1169 | * print_rsvd_warning - warn about not having enough reserved PEBs. | ||
1170 | * @ubi: UBI device description object | ||
1171 | * | ||
1172 | * This is a helper function for 'ubi_eba_init_scan()' which is called when UBI | ||
1173 | * cannot reserve enough PEBs for bad block handling. This function makes a | ||
1174 | * decision whether we have to print a warning or not. The algorithm is as | ||
1175 | * follows: | ||
1176 | * o if this is a new UBI image, then just print the warning | ||
1177 | * o if this is an UBI image which has already been used for some time, print | ||
1178 | * a warning only if we can reserve less than 10% of the expected amount of | ||
1179 | * the reserved PEB. | ||
1180 | * | ||
1181 | * The idea is that when UBI is used, PEBs become bad, and the reserved pool | ||
1182 | * of PEBs becomes smaller, which is normal and we do not want to scare users | ||
1183 | * with a warning every time they attach the MTD device. This was an issue | ||
1184 | * reported by real users. | ||
1185 | */ | ||
1186 | static void print_rsvd_warning(struct ubi_device *ubi, | ||
1187 | struct ubi_scan_info *si) | ||
1188 | { | ||
1189 | /* | ||
1190 | * The 1 << 18 (256KiB) number is picked randomly, just a reasonably | ||
1191 | * large number to distinguish between newly flashed and used images. | ||
1192 | */ | ||
1193 | if (si->max_sqnum > (1 << 18)) { | ||
1194 | int min = ubi->beb_rsvd_level / 10; | ||
1195 | |||
1196 | if (!min) | ||
1197 | min = 1; | ||
1198 | if (ubi->beb_rsvd_pebs > min) | ||
1199 | return; | ||
1200 | } | ||
1201 | |||
1202 | ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d," | ||
1203 | " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); | ||
1204 | } | ||
1205 | |||
1206 | /** | ||
1168 | * ubi_eba_init_scan - initialize the EBA sub-system using scanning information. | 1207 | * ubi_eba_init_scan - initialize the EBA sub-system using scanning information. |
1169 | * @ubi: UBI device description object | 1208 | * @ubi: UBI device description object |
1170 | * @si: scanning information | 1209 | * @si: scanning information |
@@ -1236,9 +1275,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1236 | if (ubi->avail_pebs < ubi->beb_rsvd_level) { | 1275 | if (ubi->avail_pebs < ubi->beb_rsvd_level) { |
1237 | /* No enough free physical eraseblocks */ | 1276 | /* No enough free physical eraseblocks */ |
1238 | ubi->beb_rsvd_pebs = ubi->avail_pebs; | 1277 | ubi->beb_rsvd_pebs = ubi->avail_pebs; |
1239 | ubi_warn("cannot reserve enough PEBs for bad PEB " | 1278 | print_rsvd_warning(ubi, si); |
1240 | "handling, reserved %d, need %d", | ||
1241 | ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); | ||
1242 | } else | 1279 | } else |
1243 | ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; | 1280 | ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; |
1244 | 1281 | ||