aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/io.c')
-rw-r--r--drivers/mtd/ubi/io.c60
1 files changed, 33 insertions, 27 deletions
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,
150retry: 150retry:
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)) {
756 /* The physical eraseblock is supposedly empty */ 756 /* The physical eraseblock is supposedly empty */
757 if (verbose) 757 if (verbose)
758 ubi_warn("no EC header found at PEB %d, " 758 ubi_warn("no EC header found at PEB %d, "
@@ -774,7 +774,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
774 } else if (UBI_IO_DEBUG) 774 } else if (UBI_IO_DEBUG)
775 dbg_msg("bad magic number at PEB %d: %08x instead of " 775 dbg_msg("bad magic number at PEB %d: %08x instead of "
776 "%08x", pnum, magic, UBI_EC_HDR_MAGIC); 776 "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
777 return UBI_IO_BAD_EC_HDR; 777 return UBI_IO_BAD_HDR;
778 } 778 }
779 779
780 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 780 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -788,7 +788,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
788 } else if (UBI_IO_DEBUG) 788 } else if (UBI_IO_DEBUG)
789 dbg_msg("bad EC header CRC at PEB %d, calculated " 789 dbg_msg("bad EC header CRC at PEB %d, calculated "
790 "%#08x, read %#08x", pnum, crc, hdr_crc); 790 "%#08x, read %#08x", pnum, crc, hdr_crc);
791 return UBI_IO_BAD_EC_HDR; 791 return read_err ?: UBI_IO_BAD_HDR;
792 } 792 }
793 793
794 /* And of course validate what has just been read from the media */ 794 /* And of course validate what has just been read from the media */
@@ -798,6 +798,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
798 return -EINVAL; 798 return -EINVAL;
799 } 799 }
800 800
801 /*
802 * If there was %-EBADMSG, but the header CRC is still OK, report about
803 * a bit-flip to force scrubbing on this PEB.
804 */
801 return read_err ? UBI_IO_BITFLIPS : 0; 805 return read_err ? UBI_IO_BITFLIPS : 0;
802} 806}
803 807
@@ -977,7 +981,7 @@ bad:
977 * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected 981 * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
978 * and corrected by the flash driver; this is harmless but may indicate that 982 * and corrected by the flash driver; this is harmless but may indicate that
979 * this eraseblock may become bad soon; 983 * this eraseblock may become bad soon;
980 * o %UBI_IO_BAD_VID_HDR if the volume identifier header is corrupted (a CRC 984 * o %UBI_IO_BAD_HDR if the volume identifier header is corrupted (a CRC
981 * error detected); 985 * error detected);
982 * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID 986 * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID
983 * header there); 987 * header there);
@@ -1008,22 +1012,20 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1008 * CRC check-sum and we will identify this. If the VID header is 1012 * CRC check-sum and we will identify this. If the VID header is
1009 * still OK, we just report this as there was a bit-flip. 1013 * still OK, we just report this as there was a bit-flip.
1010 */ 1014 */
1011 read_err = err; 1015 if (err == -EBADMSG)
1016 read_err = UBI_IO_BAD_HDR_READ;
1012 } 1017 }
1013 1018
1014 magic = be32_to_cpu(vid_hdr->magic); 1019 magic = be32_to_cpu(vid_hdr->magic);
1015 if (magic != UBI_VID_HDR_MAGIC) { 1020 if (magic != UBI_VID_HDR_MAGIC) {
1021 if (read_err)
1022 return read_err;
1023
1016 /* 1024 /*
1017 * If we have read all 0xFF bytes, the VID header probably does 1025 * If we have read all 0xFF bytes, the VID header probably does
1018 * not exist and the physical eraseblock is assumed to be free. 1026 * not exist and the physical eraseblock is assumed to be free.
1019 *
1020 * But if there was a read error, we do not test the data for
1021 * 0xFFs. Even if it does contain all 0xFFs, this error
1022 * indicates that something is still wrong with this physical
1023 * eraseblock and it cannot be regarded as free.
1024 */ 1027 */
1025 if (read_err != -EBADMSG && 1028 if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
1026 check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
1027 /* The physical eraseblock is supposedly free */ 1029 /* The physical eraseblock is supposedly free */
1028 if (verbose) 1030 if (verbose)
1029 ubi_warn("no VID header found at PEB %d, " 1031 ubi_warn("no VID header found at PEB %d, "
@@ -1045,7 +1047,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1045 } else if (UBI_IO_DEBUG) 1047 } else if (UBI_IO_DEBUG)
1046 dbg_msg("bad magic number at PEB %d: %08x instead of " 1048 dbg_msg("bad magic number at PEB %d: %08x instead of "
1047 "%08x", pnum, magic, UBI_VID_HDR_MAGIC); 1049 "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
1048 return UBI_IO_BAD_VID_HDR; 1050 return UBI_IO_BAD_HDR;
1049 } 1051 }
1050 1052
1051 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); 1053 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
@@ -1059,7 +1061,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1059 } else if (UBI_IO_DEBUG) 1061 } else if (UBI_IO_DEBUG)
1060 dbg_msg("bad CRC at PEB %d, calculated %#08x, " 1062 dbg_msg("bad CRC at PEB %d, calculated %#08x, "
1061 "read %#08x", pnum, crc, hdr_crc); 1063 "read %#08x", pnum, crc, hdr_crc);
1062 return UBI_IO_BAD_VID_HDR; 1064 return read_err ?: UBI_IO_BAD_HDR;
1063 } 1065 }
1064 1066
1065 /* Validate the VID header that we have just read */ 1067 /* Validate the VID header that we have just read */
@@ -1069,6 +1071,10 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1069 return -EINVAL; 1071 return -EINVAL;
1070 } 1072 }
1071 1073
1074 /*
1075 * If there was a read error (%-EBADMSG), but the header CRC is still
1076 * OK, report about a bit-flip to force scrubbing on this PEB.
1077 */
1072 return read_err ? UBI_IO_BITFLIPS : 0; 1078 return read_err ? UBI_IO_BITFLIPS : 0;
1073} 1079}
1074 1080