diff options
Diffstat (limited to 'drivers/mtd/ubi/scan.c')
| -rw-r--r-- | drivers/mtd/ubi/scan.c | 25 | 
1 files changed, 25 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index c3d653ba5ca..b847745394b 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,  	si->is_empty = 0;  	if (!ec_corr) { +		int image_seq; +  		/* Make sure UBI version is OK */  		if (ech->version != UBI_VERSION) {  			ubi_err("this UBI version is %d, image version is %d", @@ -778,6 +780,29 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,  			ubi_dbg_dump_ec_hdr(ech);  			return -EINVAL;  		} + +		/* +		 * Make sure that all PEBs have the same image sequence number. +		 * This allows us to detect situations when users flash UBI +		 * images incorrectly, so that the flash has the new UBI image +		 * and leftovers from the old one. This feature was added +		 * relatively recently, and the sequence number was always +		 * zero, because old UBI implementations always set it to zero. +		 * For this reasons, we do not panic if some PEBs have zero +		 * sequence number, while other PEBs have non-zero sequence +		 * number. +		 */ +		image_seq = be32_to_cpu(ech->image_seq); +		if (!si->image_seq_set) { +			ubi->image_seq = image_seq; +			si->image_seq_set = 1; +		} else if (ubi->image_seq && ubi->image_seq != image_seq) { +			ubi_err("bad image sequence number %d in PEB %d, " +				"expected %d", image_seq, pnum, ubi->image_seq); +			ubi_dbg_dump_ec_hdr(ech); +			return -EINVAL; +		} +  	}  	/* OK, we've done with the EC header, let's look at the VID header */  |