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.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index c8edbfd09b64..b58714011091 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -563,15 +563,16 @@ 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 */
566static int validate_ec_hdr(const struct ubi_device *ubi, 566static int validate_ec_hdr(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; 570 int vid_hdr_offset, leb_start, image_seq;
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);
575 576
576 if (ec_hdr->version != UBI_VERSION) { 577 if (ec_hdr->version != UBI_VERSION) {
577 ubi_err("node with incompatible UBI version found: " 578 ubi_err("node with incompatible UBI version found: "
@@ -597,6 +598,15 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
597 goto bad; 598 goto bad;
598 } 599 }
599 600
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
600 return 0; 610 return 0;
601 611
602bad: 612bad:
@@ -742,6 +752,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
742 ec_hdr->version = UBI_VERSION; 752 ec_hdr->version = UBI_VERSION;
743 ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset); 753 ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset);
744 ec_hdr->data_offset = cpu_to_be32(ubi->leb_start); 754 ec_hdr->data_offset = cpu_to_be32(ubi->leb_start);
755 ec_hdr->image_seq = cpu_to_be32(ubi->image_seq);
745 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 756 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
746 ec_hdr->hdr_crc = cpu_to_be32(crc); 757 ec_hdr->hdr_crc = cpu_to_be32(crc);
747 758