aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/io.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-09-03 07:22:17 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-10-19 10:19:56 -0400
commit92e1a7d9e7e07fb1cf0cbbcdf202938d0819b54d (patch)
tree48930121fa2f1cf9ebd36f85118fe433d1ecd01f /drivers/mtd/ubi/io.c
parent74d82d2660058e32644f0c673656b2a1d01d3688 (diff)
UBI: handle bit-flips when no header found
Currently UBI has one small flaw - when we read EC or VID header, but find only 0xFF bytes, we return UBI_IO_FF and do not report whether we had bit-flips or not. In case of the VID header, the scanning code adds this PEB to the free list, even though there were bit-flips. Imagine the following situation: we start writing VID header to a PEB and have a power cut, so the PEB becomes unstable. When we scan and read the PEB, we get a bit-flip. Currently, UBI would just ignore this and treat the PEB as free. This patch changes UBI behavior and now UBI will schedule this PEB for erasure. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi/io.c')
-rw-r--r--drivers/mtd/ubi/io.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 1677a215af64..b76252465c87 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -720,16 +720,16 @@ bad:
720int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, 720int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
721 struct ubi_ec_hdr *ec_hdr, int verbose) 721 struct ubi_ec_hdr *ec_hdr, int verbose)
722{ 722{
723 int err, read_err = 0; 723 int err, read_err;
724 uint32_t crc, magic, hdr_crc; 724 uint32_t crc, magic, hdr_crc;
725 725
726 dbg_io("read EC header from PEB %d", pnum); 726 dbg_io("read EC header from PEB %d", pnum);
727 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 727 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
728 728
729 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 729 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
730 if (err) { 730 if (read_err) {
731 if (err != UBI_IO_BITFLIPS && err != -EBADMSG) 731 if (read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG)
732 return err; 732 return read_err;
733 733
734 /* 734 /*
735 * We read all the data, but either a correctable bit-flip 735 * We read all the data, but either a correctable bit-flip
@@ -740,14 +740,12 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
740 * this. If the EC header is still OK, we just report this as 740 * this. If the EC header is still OK, we just report this as
741 * there was a bit-flip, to force scrubbing. 741 * there was a bit-flip, to force scrubbing.
742 */ 742 */
743 if (err == -EBADMSG)
744 read_err = UBI_IO_BAD_HDR_EBADMSG;
745 } 743 }
746 744
747 magic = be32_to_cpu(ec_hdr->magic); 745 magic = be32_to_cpu(ec_hdr->magic);
748 if (magic != UBI_EC_HDR_MAGIC) { 746 if (magic != UBI_EC_HDR_MAGIC) {
749 if (read_err) 747 if (read_err == -EBADMSG)
750 return read_err; 748 return UBI_IO_BAD_HDR_EBADMSG;
751 749
752 /* 750 /*
753 * 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
@@ -762,7 +760,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
762 else if (UBI_IO_DEBUG) 760 else if (UBI_IO_DEBUG)
763 dbg_msg("no EC header found at PEB %d, " 761 dbg_msg("no EC header found at PEB %d, "
764 "only 0xFF bytes", pnum); 762 "only 0xFF bytes", pnum);
765 return UBI_IO_FF; 763 if (!read_err)
764 return UBI_IO_FF;
765 else
766 return UBI_IO_FF_BITFLIPS;
766 } 767 }
767 768
768 /* 769 /*
@@ -790,7 +791,11 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
790 } else if (UBI_IO_DEBUG) 791 } else if (UBI_IO_DEBUG)
791 dbg_msg("bad EC header CRC at PEB %d, calculated " 792 dbg_msg("bad EC header CRC at PEB %d, calculated "
792 "%#08x, read %#08x", pnum, crc, hdr_crc); 793 "%#08x, read %#08x", pnum, crc, hdr_crc);
793 return read_err ?: UBI_IO_BAD_HDR; 794
795 if (!read_err)
796 return UBI_IO_BAD_HDR;
797 else
798 return UBI_IO_BAD_HDR_EBADMSG;
794 } 799 }
795 800
796 /* And of course validate what has just been read from the media */ 801 /* And of course validate what has just been read from the media */
@@ -986,7 +991,7 @@ bad:
986int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, 991int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
987 struct ubi_vid_hdr *vid_hdr, int verbose) 992 struct ubi_vid_hdr *vid_hdr, int verbose)
988{ 993{
989 int err, read_err = 0; 994 int err, read_err;
990 uint32_t crc, magic, hdr_crc; 995 uint32_t crc, magic, hdr_crc;
991 void *p; 996 void *p;
992 997
@@ -994,20 +999,15 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
994 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 999 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
995 1000
996 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1001 p = (char *)vid_hdr - ubi->vid_hdr_shift;
997 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 1002 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
998 ubi->vid_hdr_alsize); 1003 ubi->vid_hdr_alsize);
999 if (err) { 1004 if (read_err && read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG)
1000 if (err != UBI_IO_BITFLIPS && err != -EBADMSG) 1005 return read_err;
1001 return err;
1002
1003 if (err == -EBADMSG)
1004 read_err = UBI_IO_BAD_HDR_EBADMSG;
1005 }
1006 1006
1007 magic = be32_to_cpu(vid_hdr->magic); 1007 magic = be32_to_cpu(vid_hdr->magic);
1008 if (magic != UBI_VID_HDR_MAGIC) { 1008 if (magic != UBI_VID_HDR_MAGIC) {
1009 if (read_err) 1009 if (read_err == -EBADMSG)
1010 return read_err; 1010 return UBI_IO_BAD_HDR_EBADMSG;
1011 1011
1012 if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 1012 if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
1013 if (verbose) 1013 if (verbose)
@@ -1016,7 +1016,10 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1016 else if (UBI_IO_DEBUG) 1016 else if (UBI_IO_DEBUG)
1017 dbg_msg("no VID header found at PEB %d, " 1017 dbg_msg("no VID header found at PEB %d, "
1018 "only 0xFF bytes", pnum); 1018 "only 0xFF bytes", pnum);
1019 return UBI_IO_FF; 1019 if (!read_err)
1020 return UBI_IO_FF;
1021 else
1022 return UBI_IO_FF_BITFLIPS;
1020 } 1023 }
1021 1024
1022 if (verbose) { 1025 if (verbose) {
@@ -1040,7 +1043,10 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1040 } else if (UBI_IO_DEBUG) 1043 } else if (UBI_IO_DEBUG)
1041 dbg_msg("bad CRC at PEB %d, calculated %#08x, " 1044 dbg_msg("bad CRC at PEB %d, calculated %#08x, "
1042 "read %#08x", pnum, crc, hdr_crc); 1045 "read %#08x", pnum, crc, hdr_crc);
1043 return read_err ?: UBI_IO_BAD_HDR; 1046 if (!read_err)
1047 return UBI_IO_BAD_HDR;
1048 else
1049 return UBI_IO_BAD_HDR_EBADMSG;
1044 } 1050 }
1045 1051
1046 err = validate_vid_hdr(ubi, vid_hdr); 1052 err = validate_vid_hdr(ubi, vid_hdr);