aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/scan.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-07-18 06:53:39 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-07-24 06:36:09 -0400
commit9869cd801c107bbae91663c3f4edbb6b5715919f (patch)
tree1e3b8bb14e4895a425de05a0547d733c8fbf2007 /drivers/mtd/ubi/scan.c
parentebaaf1af3e9ef05c4fb7c61e4530c15e1ad10e3b (diff)
UBI: remove pre-sqnum images support
Before UBI got into mainline, there was a slight flash format change - we did not have sequence number support, then added it. We have carried full support of those ancient images till this moment. Now the support is removed, well, not fully removed. Now UBI will support only _clean_ old images, which were cleanly detached last time (just before kernel upgrade). This is most likely the case. But we will not support unclean ancient images. Surprisingly, this allows us to remove a big chunk of legacy code. And the same should be true for downgrading: clean images should downgrade fine, but unclean ones will not. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi/scan.c')
-rw-r--r--drivers/mtd/ubi/scan.c87
1 files changed, 24 insertions, 63 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 4dfbf27b0656..967bb4406df9 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -246,46 +246,21 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
246 struct ubi_vid_hdr *vh = NULL; 246 struct ubi_vid_hdr *vh = NULL;
247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);
248 248
249 if (seb->sqnum == 0 && sqnum2 == 0) { 249 if (sqnum2 == seb->sqnum) {
250 long long abs;
251 long long v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);
252
253 /* 250 /*
254 * UBI constantly increases the logical eraseblock version 251 * This must be a really ancient UBI image which has been
255 * number and it can overflow. Thus, we have to bear in mind 252 * created before sequence numbers support has been added. At
256 * that versions that are close to %0xFFFFFFFF are less then 253 * that times we used 32-bit LEB versions stored in logical
257 * versions that are close to %0. 254 * eraseblocks. That was before UBI got into mainline. We do not
258 * 255 * support these images anymore. Well, those images will work
259 * The UBI WL sub-system guarantees that the number of pending 256 * still work, but only if no unclean reboots happened.
260 * tasks is not greater then %0x7FFFFFFF. So, if the difference
261 * between any two versions is greater or equivalent to
262 * %0x7FFFFFFF, there was an overflow and the logical
263 * eraseblock with lower version is actually newer then the one
264 * with higher version.
265 *
266 * FIXME: but this is anyway obsolete and will be removed at
267 * some point.
268 */ 257 */
269 dbg_bld("using old crappy leb_ver stuff"); 258 ubi_err("unsupported on-flash UBI format\n");
270 259 return -EINVAL;
271 if (v1 == v2) { 260 }
272 ubi_err("PEB %d and PEB %d have the same version %lld",
273 seb->pnum, pnum, v1);
274 return -EINVAL;
275 }
276 261
277 abs = v1 - v2; 262 /* Obviously the LEB with lower sequence counter is older */
278 if (abs < 0) 263 second_is_newer = !!(sqnum2 > seb->sqnum);
279 abs = -abs;
280
281 if (abs < 0x7FFFFFFF)
282 /* Non-overflow situation */
283 second_is_newer = (v2 > v1);
284 else
285 second_is_newer = (v2 < v1);
286 } else
287 /* Obviously the LEB with lower sequence counter is older */
288 second_is_newer = sqnum2 > seb->sqnum;
289 264
290 /* 265 /*
291 * Now we know which copy is newer. If the copy flag of the PEB with 266 * Now we know which copy is newer. If the copy flag of the PEB with
@@ -293,7 +268,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
293 * check data CRC. For the second PEB we already have the VID header, 268 * check data CRC. For the second PEB we already have the VID header,
294 * for the first one - we'll need to re-read it from flash. 269 * for the first one - we'll need to re-read it from flash.
295 * 270 *
296 * FIXME: this may be optimized so that we wouldn't read twice. 271 * Note: this may be optimized so that we wouldn't read twice.
297 */ 272 */
298 273
299 if (second_is_newer) { 274 if (second_is_newer) {
@@ -399,7 +374,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
399 int bitflips) 374 int bitflips)
400{ 375{
401 int err, vol_id, lnum; 376 int err, vol_id, lnum;
402 uint32_t leb_ver;
403 unsigned long long sqnum; 377 unsigned long long sqnum;
404 struct ubi_scan_volume *sv; 378 struct ubi_scan_volume *sv;
405 struct ubi_scan_leb *seb; 379 struct ubi_scan_leb *seb;
@@ -408,10 +382,9 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
408 vol_id = be32_to_cpu(vid_hdr->vol_id); 382 vol_id = be32_to_cpu(vid_hdr->vol_id);
409 lnum = be32_to_cpu(vid_hdr->lnum); 383 lnum = be32_to_cpu(vid_hdr->lnum);
410 sqnum = be64_to_cpu(vid_hdr->sqnum); 384 sqnum = be64_to_cpu(vid_hdr->sqnum);
411 leb_ver = be32_to_cpu(vid_hdr->leb_ver);
412 385
413 dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", 386 dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d",
414 pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); 387 pnum, vol_id, lnum, ec, sqnum, bitflips);
415 388
416 sv = add_volume(si, vol_id, pnum, vid_hdr); 389 sv = add_volume(si, vol_id, pnum, vid_hdr);
417 if (IS_ERR(sv) < 0) 390 if (IS_ERR(sv) < 0)
@@ -444,25 +417,20 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
444 */ 417 */
445 418
446 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " 419 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, "
447 "LEB ver %u, EC %d", seb->pnum, seb->sqnum, 420 "EC %d", seb->pnum, seb->sqnum, seb->ec);
448 seb->leb_ver, seb->ec);
449
450 /*
451 * Make sure that the logical eraseblocks have different
452 * versions. Otherwise the image is bad.
453 */
454 if (seb->leb_ver == leb_ver && leb_ver != 0) {
455 ubi_err("two LEBs with same version %u", leb_ver);
456 ubi_dbg_dump_seb(seb, 0);
457 ubi_dbg_dump_vid_hdr(vid_hdr);
458 return -EINVAL;
459 }
460 421
461 /* 422 /*
462 * Make sure that the logical eraseblocks have different 423 * Make sure that the logical eraseblocks have different
463 * sequence numbers. Otherwise the image is bad. 424 * sequence numbers. Otherwise the image is bad.
464 * 425 *
465 * FIXME: remove 'sqnum != 0' check when leb_ver is removed. 426 * However, if the sequence number is zero, we assume it must
427 * be an ancient UBI image from the era when UBI did not have
428 * sequence numbers. We still can attach these images, unless
429 * there is a need to distinguish between old and new
430 * eraseblocks, in which case we'll refuse the image in
431 * 'compare_lebs()'. In other words, we attach old clean
432 * images, but refuse attaching old images with duplicated
433 * logical eraseblocks because there was an unclean reboot.
466 */ 434 */
467 if (seb->sqnum == sqnum && sqnum != 0) { 435 if (seb->sqnum == sqnum && sqnum != 0) {
468 ubi_err("two LEBs with same sequence number %llu", 436 ubi_err("two LEBs with same sequence number %llu",
@@ -502,7 +470,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
502 seb->pnum = pnum; 470 seb->pnum = pnum;
503 seb->scrub = ((cmp_res & 2) || bitflips); 471 seb->scrub = ((cmp_res & 2) || bitflips);
504 seb->sqnum = sqnum; 472 seb->sqnum = sqnum;
505 seb->leb_ver = leb_ver;
506 473
507 if (sv->highest_lnum == lnum) 474 if (sv->highest_lnum == lnum)
508 sv->last_data_size = 475 sv->last_data_size =
@@ -539,7 +506,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
539 seb->lnum = lnum; 506 seb->lnum = lnum;
540 seb->sqnum = sqnum; 507 seb->sqnum = sqnum;
541 seb->scrub = bitflips; 508 seb->scrub = bitflips;
542 seb->leb_ver = leb_ver;
543 509
544 if (sv->highest_lnum <= lnum) { 510 if (sv->highest_lnum <= lnum) {
545 sv->highest_lnum = lnum; 511 sv->highest_lnum = lnum;
@@ -1263,11 +1229,6 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1263 ubi_err("bad data_pad %d", sv->data_pad); 1229 ubi_err("bad data_pad %d", sv->data_pad);
1264 goto bad_vid_hdr; 1230 goto bad_vid_hdr;
1265 } 1231 }
1266
1267 if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) {
1268 ubi_err("bad leb_ver %u", seb->leb_ver);
1269 goto bad_vid_hdr;
1270 }
1271 } 1232 }
1272 1233
1273 if (!last_seb) 1234 if (!last_seb)