diff options
| author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2009-06-30 09:11:59 -0400 |
|---|---|---|
| committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2009-07-05 11:47:08 -0400 |
| commit | fe96efc1a3c049f0a1bcd9b65e0faeb751ce5ec6 (patch) | |
| tree | 5c750ab134bb1037eeaf5baa8d9eee6196566226 | |
| parent | 0c6c7fa1313fcb69cae35e34168d2e83b8da854a (diff) | |
UBI: nicify image sequence number handling
Move the image seq. number handling from I/O level to the scanning
lever, where it really belongs to. Move the @image_seq_set variable
to the @struct ubi_scan_info structure, which exists only during
scanning.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
| -rw-r--r-- | drivers/mtd/ubi/io.c | 14 | ||||
| -rw-r--r-- | drivers/mtd/ubi/scan.c | 16 | ||||
| -rw-r--r-- | drivers/mtd/ubi/scan.h | 2 | ||||
| -rw-r--r-- | drivers/mtd/ubi/ubi.h | 2 |
4 files changed, 18 insertions, 16 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index b58714011091..1ea14218de02 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
| @@ -563,16 +563,15 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum) | |||
| 563 | * This function returns zero if the erase counter header is OK, and %1 if | 563 | * This function returns zero if the erase counter header is OK, and %1 if |
| 564 | * not. | 564 | * not. |
| 565 | */ | 565 | */ |
| 566 | static int validate_ec_hdr(struct ubi_device *ubi, | 566 | static int validate_ec_hdr(const struct ubi_device *ubi, |
| 567 | const struct ubi_ec_hdr *ec_hdr) | 567 | const struct ubi_ec_hdr *ec_hdr) |
| 568 | { | 568 | { |
| 569 | long long ec; | 569 | long long ec; |
| 570 | int vid_hdr_offset, leb_start, image_seq; | 570 | int vid_hdr_offset, leb_start; |
| 571 | 571 | ||
| 572 | ec = be64_to_cpu(ec_hdr->ec); | 572 | ec = be64_to_cpu(ec_hdr->ec); |
| 573 | vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset); | 573 | vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset); |
| 574 | leb_start = be32_to_cpu(ec_hdr->data_offset); | 574 | leb_start = be32_to_cpu(ec_hdr->data_offset); |
| 575 | image_seq = be32_to_cpu(ec_hdr->image_seq); | ||
| 576 | 575 | ||
| 577 | if (ec_hdr->version != UBI_VERSION) { | 576 | if (ec_hdr->version != UBI_VERSION) { |
| 578 | ubi_err("node with incompatible UBI version found: " | 577 | ubi_err("node with incompatible UBI version found: " |
| @@ -598,15 +597,6 @@ static int validate_ec_hdr(struct ubi_device *ubi, | |||
| 598 | goto bad; | 597 | goto bad; |
| 599 | } | 598 | } |
| 600 | 599 | ||
| 601 | if (!ubi->image_seq_set) { | ||
| 602 | ubi->image_seq = image_seq; | ||
| 603 | ubi->image_seq_set = 1; | ||
| 604 | } else if (ubi->image_seq != image_seq) { | ||
| 605 | ubi_err("bad image sequence number %d, expected %d", | ||
| 606 | image_seq, ubi->image_seq); | ||
| 607 | goto bad; | ||
| 608 | } | ||
| 609 | |||
| 610 | return 0; | 600 | return 0; |
| 611 | 601 | ||
| 612 | bad: | 602 | bad: |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 72570ed7d33f..f60895ee0aeb 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
| @@ -757,6 +757,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
| 757 | si->is_empty = 0; | 757 | si->is_empty = 0; |
| 758 | 758 | ||
| 759 | if (!ec_corr) { | 759 | if (!ec_corr) { |
| 760 | int image_seq; | ||
| 761 | |||
| 760 | /* Make sure UBI version is OK */ | 762 | /* Make sure UBI version is OK */ |
| 761 | if (ech->version != UBI_VERSION) { | 763 | if (ech->version != UBI_VERSION) { |
| 762 | ubi_err("this UBI version is %d, image version is %d", | 764 | ubi_err("this UBI version is %d, image version is %d", |
| @@ -778,6 +780,18 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
| 778 | ubi_dbg_dump_ec_hdr(ech); | 780 | ubi_dbg_dump_ec_hdr(ech); |
| 779 | return -EINVAL; | 781 | return -EINVAL; |
| 780 | } | 782 | } |
| 783 | |||
| 784 | image_seq = be32_to_cpu(ech->ec); | ||
| 785 | if (!si->image_seq_set) { | ||
| 786 | ubi->image_seq = image_seq; | ||
| 787 | si->image_seq_set = 1; | ||
| 788 | } else if (ubi->image_seq != image_seq) { | ||
| 789 | ubi_err("bad image sequence number %d in PEB %d, " | ||
| 790 | "expected %d", image_seq, pnum, ubi->image_seq); | ||
| 791 | ubi_dbg_dump_ec_hdr(ech); | ||
| 792 | return -EINVAL; | ||
| 793 | } | ||
| 794 | |||
| 781 | } | 795 | } |
| 782 | 796 | ||
| 783 | /* OK, we've done with the EC header, let's look at the VID header */ | 797 | /* OK, we've done with the EC header, let's look at the VID header */ |
| @@ -910,8 +924,6 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
| 910 | if (si->is_empty) | 924 | if (si->is_empty) |
| 911 | ubi_msg("empty MTD device detected"); | 925 | ubi_msg("empty MTD device detected"); |
| 912 | 926 | ||
| 913 | ubi->image_seq_set = 1; | ||
| 914 | |||
| 915 | /* | 927 | /* |
| 916 | * In case of unknown erase counter we use the mean erase counter | 928 | * In case of unknown erase counter we use the mean erase counter |
| 917 | * value. | 929 | * value. |
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h index 61df208e2f20..1017cf12def5 100644 --- a/drivers/mtd/ubi/scan.h +++ b/drivers/mtd/ubi/scan.h | |||
| @@ -102,6 +102,7 @@ struct ubi_scan_volume { | |||
| 102 | * @mean_ec: mean erase counter value | 102 | * @mean_ec: mean erase counter value |
| 103 | * @ec_sum: a temporary variable used when calculating @mean_ec | 103 | * @ec_sum: a temporary variable used when calculating @mean_ec |
| 104 | * @ec_count: a temporary variable used when calculating @mean_ec | 104 | * @ec_count: a temporary variable used when calculating @mean_ec |
| 105 | * @image_seq_set: indicates @ubi->image_seq is known | ||
| 105 | * | 106 | * |
| 106 | * This data structure contains the result of scanning and may be used by other | 107 | * This data structure contains the result of scanning and may be used by other |
| 107 | * UBI sub-systems to build final UBI data structures, further error-recovery | 108 | * UBI sub-systems to build final UBI data structures, further error-recovery |
| @@ -124,6 +125,7 @@ struct ubi_scan_info { | |||
| 124 | int mean_ec; | 125 | int mean_ec; |
| 125 | uint64_t ec_sum; | 126 | uint64_t ec_sum; |
| 126 | int ec_count; | 127 | int ec_count; |
| 128 | int image_seq_set; | ||
| 127 | }; | 129 | }; |
| 128 | 130 | ||
| 129 | struct ubi_device; | 131 | struct ubi_device; |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index bb372c4222b7..64604e8809ec 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
| @@ -302,7 +302,6 @@ struct ubi_wl_entry; | |||
| 302 | * @vol->ref_count, @vol->mapping and @vol->eba_tbl. | 302 | * @vol->ref_count, @vol->mapping and @vol->eba_tbl. |
| 303 | * @ref_count: count of references on the UBI device | 303 | * @ref_count: count of references on the UBI device |
| 304 | * @image_seq: image sequence number recorded on EC headers | 304 | * @image_seq: image sequence number recorded on EC headers |
| 305 | * @image_seq_set: indicates @image_seq is known | ||
| 306 | * | 305 | * |
| 307 | * @rsvd_pebs: count of reserved physical eraseblocks | 306 | * @rsvd_pebs: count of reserved physical eraseblocks |
| 308 | * @avail_pebs: count of available physical eraseblocks | 307 | * @avail_pebs: count of available physical eraseblocks |
| @@ -393,7 +392,6 @@ struct ubi_device { | |||
| 393 | spinlock_t volumes_lock; | 392 | spinlock_t volumes_lock; |
| 394 | int ref_count; | 393 | int ref_count; |
| 395 | int image_seq; | 394 | int image_seq; |
| 396 | int image_seq_set; | ||
| 397 | 395 | ||
| 398 | int rsvd_pebs; | 396 | int rsvd_pebs; |
| 399 | int avail_pebs; | 397 | int avail_pebs; |
