diff options
| -rw-r--r-- | drivers/mtd/ubi/build.c | 3 | ||||
| -rw-r--r-- | drivers/mtd/ubi/eba.c | 49 | ||||
| -rw-r--r-- | drivers/mtd/ubi/io.c | 60 | ||||
| -rw-r--r-- | drivers/mtd/ubi/scan.c | 131 | ||||
| -rw-r--r-- | drivers/mtd/ubi/scan.h | 19 | ||||
| -rw-r--r-- | drivers/mtd/ubi/ubi.h | 10 |
6 files changed, 198 insertions, 74 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 13b05cb33b08..78ae89488a4f 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
| @@ -593,6 +593,7 @@ static int attach_by_scanning(struct ubi_device *ubi) | |||
| 593 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; | 593 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; |
| 594 | ubi->max_ec = si->max_ec; | 594 | ubi->max_ec = si->max_ec; |
| 595 | ubi->mean_ec = si->mean_ec; | 595 | ubi->mean_ec = si->mean_ec; |
| 596 | ubi_msg("max. sequence number: %llu", si->max_sqnum); | ||
| 596 | 597 | ||
| 597 | err = ubi_read_volume_table(ubi, si); | 598 | err = ubi_read_volume_table(ubi, si); |
| 598 | if (err) | 599 | if (err) |
| @@ -981,7 +982,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
| 981 | ubi_msg("number of PEBs reserved for bad PEB handling: %d", | 982 | ubi_msg("number of PEBs reserved for bad PEB handling: %d", |
| 982 | ubi->beb_rsvd_pebs); | 983 | ubi->beb_rsvd_pebs); |
| 983 | ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); | 984 | ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); |
| 984 | ubi_msg("image sequence number: %d", ubi->image_seq); | 985 | ubi_msg("image sequence number: %d", ubi->image_seq); |
| 985 | 986 | ||
| 986 | /* | 987 | /* |
| 987 | * The below lock makes sure we do not race with 'ubi_thread()' which | 988 | * The below lock makes sure we do not race with 'ubi_thread()' which |
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 | ||
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 4b979e34b159..332f992f13d9 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
| @@ -150,6 +150,8 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, | |||
| 150 | retry: | 150 | retry: |
| 151 | err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); | 151 | err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); |
| 152 | if (err) { | 152 | if (err) { |
| 153 | const char *errstr = (err == -EBADMSG) ? " (ECC error)" : ""; | ||
| 154 | |||
| 153 | if (err == -EUCLEAN) { | 155 | if (err == -EUCLEAN) { |
| 154 | /* | 156 | /* |
| 155 | * -EUCLEAN is reported if there was a bit-flip which | 157 | * -EUCLEAN is reported if there was a bit-flip which |
| @@ -165,15 +167,15 @@ retry: | |||
| 165 | } | 167 | } |
| 166 | 168 | ||
| 167 | if (read != len && retries++ < UBI_IO_RETRIES) { | 169 | if (read != len && retries++ < UBI_IO_RETRIES) { |
| 168 | dbg_io("error %d while reading %d bytes from PEB %d:%d," | 170 | dbg_io("error %d%s while reading %d bytes from PEB %d:%d," |
| 169 | " read only %zd bytes, retry", | 171 | " read only %zd bytes, retry", |
| 170 | err, len, pnum, offset, read); | 172 | err, errstr, len, pnum, offset, read); |
| 171 | yield(); | 173 | yield(); |
| 172 | goto retry; | 174 | goto retry; |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | 177 | ubi_err("error %d%s while reading %d bytes from PEB %d:%d, " |
| 176 | "read %zd bytes", err, len, pnum, offset, read); | 178 | "read %zd bytes", err, errstr, len, pnum, offset, read); |
| 177 | ubi_dbg_dump_stack(); | 179 | ubi_dbg_dump_stack(); |
| 178 | 180 | ||
| 179 | /* | 181 | /* |
| @@ -515,7 +517,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) | |||
| 515 | * In this case we probably anyway have garbage in this PEB. | 517 | * In this case we probably anyway have garbage in this PEB. |
| 516 | */ | 518 | */ |
| 517 | err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); | 519 | err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); |
| 518 | if (err1 == UBI_IO_BAD_VID_HDR) | 520 | if (err1 == UBI_IO_BAD_HDR_READ || err1 == UBI_IO_BAD_HDR) |
| 519 | /* | 521 | /* |
| 520 | * The VID header is corrupted, so we can safely erase this | 522 | * The VID header is corrupted, so we can safely erase this |
| 521 | * PEB and not afraid that it will be treated as a valid PEB in | 523 | * PEB and not afraid that it will be treated as a valid PEB in |
| @@ -709,7 +711,7 @@ bad: | |||
| 709 | * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected | 711 | * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected |
| 710 | * and corrected by the flash driver; this is harmless but may indicate that | 712 | * and corrected by the flash driver; this is harmless but may indicate that |
| 711 | * this eraseblock may become bad soon (but may be not); | 713 | * this eraseblock may become bad soon (but may be not); |
| 712 | * o %UBI_IO_BAD_EC_HDR if the erase counter header is corrupted (a CRC error); | 714 | * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error); |
| 713 | * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; | 715 | * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; |
| 714 | * o a negative error code in case of failure. | 716 | * o a negative error code in case of failure. |
| 715 | */ | 717 | */ |
| @@ -736,23 +738,21 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
| 736 | * header is still OK, we just report this as there was a | 738 | * header is still OK, we just report this as there was a |
| 737 | * bit-flip. | 739 | * bit-flip. |
| 738 | */ | 740 | */ |
| 739 | read_err = err; | 741 | if (err == -EBADMSG) |
| 742 | read_err = UBI_IO_BAD_HDR_READ; | ||
| 740 | } | 743 | } |
| 741 | 744 | ||
| 742 | magic = be32_to_cpu(ec_hdr->magic); | 745 | magic = be32_to_cpu(ec_hdr->magic); |
| 743 | if (magic != UBI_EC_HDR_MAGIC) { | 746 | if (magic != UBI_EC_HDR_MAGIC) { |
| 747 | if (read_err) | ||
| 748 | return read_err; | ||
| 749 | |||
| 744 | /* | 750 | /* |
| 745 | * The magic field is wrong. Let's check if we have read all | 751 | * The magic field is wrong. Let's check if we have read all |
| 746 | * 0xFF. If yes, this physical eraseblock is assumed to be | 752 | * 0xFF. If yes, this physical eraseblock is assumed to be |
| 747 | * empty. | 753 | * empty. |
| 748 | * | ||
| 749 | * But if there was a read error, we do not test it for all | ||
| 750 | * 0xFFs. Even if it does contain all 0xFFs, this error | ||
| 751 | * indicates that something is still wrong with this physical | ||
| 752 | * eraseblock and we anyway cannot treat it as empty. | ||
| 753 | */ | 754 | */ |
| 754 | if (read_err != -EBADMSG && | 755 | if (check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { |
| 755 | check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { | ||
