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>

+30 -79
-2
drivers/mtd/ubi/debug.c
··· 65 65 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); 66 66 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); 67 67 printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); 68 - printk(KERN_DEBUG "\tleb_ver %u\n", be32_to_cpu(vid_hdr->leb_ver)); 69 68 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); 70 69 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); 71 70 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); ··· 171 172 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); 172 173 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); 173 174 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); 174 - printk(KERN_DEBUG "\tleb_ver %u\n", seb->leb_ver); 175 175 } 176 176 } 177 177
+24 -63
drivers/mtd/ubi/scan.c
··· 246 246 struct ubi_vid_hdr *vh = NULL; 247 247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 248 248 249 - if (seb->sqnum == 0 && sqnum2 == 0) { 250 - long long abs; 251 - long long v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver); 252 - 249 + if (sqnum2 == seb->sqnum) { 253 250 /* 254 - * UBI constantly increases the logical eraseblock version 255 - * number and it can overflow. Thus, we have to bear in mind 256 - * that versions that are close to %0xFFFFFFFF are less then 257 - * versions that are close to %0. 258 - * 259 - * The UBI WL sub-system guarantees that the number of pending 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. 251 + * This must be a really ancient UBI image which has been 252 + * created before sequence numbers support has been added. At 253 + * that times we used 32-bit LEB versions stored in logical 254 + * eraseblocks. That was before UBI got into mainline. We do not 255 + * support these images anymore. Well, those images will work 256 + * still work, but only if no unclean reboots happened. 268 257 */ 269 - dbg_bld("using old crappy leb_ver stuff"); 258 + ubi_err("unsupported on-flash UBI format\n"); 259 + return -EINVAL; 260 + } 270 261 271 - if (v1 == v2) { 272 - ubi_err("PEB %d and PEB %d have the same version %lld", 273 - seb->pnum, pnum, v1); 274 - return -EINVAL; 275 - } 276 - 277 - abs = v1 - v2; 278 - if (abs < 0) 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; 262 + /* Obviously the LEB with lower sequence counter is older */ 263 + second_is_newer = !!(sqnum2 > seb->sqnum); 289 264 290 265 /* 291 266 * Now we know which copy is newer. If the copy flag of the PEB with ··· 268 293 * check data CRC. For the second PEB we already have the VID header, 269 294 * for the first one - we'll need to re-read it from flash. 270 295 * 271 - * FIXME: this may be optimized so that we wouldn't read twice. 296 + * Note: this may be optimized so that we wouldn't read twice. 272 297 */ 273 298 274 299 if (second_is_newer) { ··· 374 399 int bitflips) 375 400 { 376 401 int err, vol_id, lnum; 377 - uint32_t leb_ver; 378 402 unsigned long long sqnum; 379 403 struct ubi_scan_volume *sv; 380 404 struct ubi_scan_leb *seb; ··· 382 408 vol_id = be32_to_cpu(vid_hdr->vol_id); 383 409 lnum = be32_to_cpu(vid_hdr->lnum); 384 410 sqnum = be64_to_cpu(vid_hdr->sqnum); 385 - leb_ver = be32_to_cpu(vid_hdr->leb_ver); 386 411 387 - dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", 388 - pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); 412 + dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d", 413 + pnum, vol_id, lnum, ec, sqnum, bitflips); 389 414 390 415 sv = add_volume(si, vol_id, pnum, vid_hdr); 391 416 if (IS_ERR(sv) < 0) ··· 417 444 */ 418 445 419 446 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " 420 - "LEB ver %u, EC %d", seb->pnum, seb->sqnum, 421 - seb->leb_ver, seb->ec); 422 - 423 - /* 424 - * Make sure that the logical eraseblocks have different 425 - * versions. Otherwise the image is bad. 426 - */ 427 - if (seb->leb_ver == leb_ver && leb_ver != 0) { 428 - ubi_err("two LEBs with same version %u", leb_ver); 429 - ubi_dbg_dump_seb(seb, 0); 430 - ubi_dbg_dump_vid_hdr(vid_hdr); 431 - return -EINVAL; 432 - } 447 + "EC %d", seb->pnum, seb->sqnum, seb->ec); 433 448 434 449 /* 435 450 * Make sure that the logical eraseblocks have different 436 451 * sequence numbers. Otherwise the image is bad. 437 452 * 438 - * FIXME: remove 'sqnum != 0' check when leb_ver is removed. 453 + * However, if the sequence number is zero, we assume it must 454 + * be an ancient UBI image from the era when UBI did not have 455 + * sequence numbers. We still can attach these images, unless 456 + * there is a need to distinguish between old and new 457 + * eraseblocks, in which case we'll refuse the image in 458 + * 'compare_lebs()'. In other words, we attach old clean 459 + * images, but refuse attaching old images with duplicated 460 + * logical eraseblocks because there was an unclean reboot. 439 461 */ 440 462 if (seb->sqnum == sqnum && sqnum != 0) { 441 463 ubi_err("two LEBs with same sequence number %llu", ··· 470 502 seb->pnum = pnum; 471 503 seb->scrub = ((cmp_res & 2) || bitflips); 472 504 seb->sqnum = sqnum; 473 - seb->leb_ver = leb_ver; 474 505 475 506 if (sv->highest_lnum == lnum) 476 507 sv->last_data_size = ··· 506 539 seb->lnum = lnum; 507 540 seb->sqnum = sqnum; 508 541 seb->scrub = bitflips; 509 - seb->leb_ver = leb_ver; 510 542 511 543 if (sv->highest_lnum <= lnum) { 512 544 sv->highest_lnum = lnum; ··· 1227 1261 1228 1262 if (sv->data_pad != be32_to_cpu(vidh->data_pad)) { 1229 1263 ubi_err("bad data_pad %d", sv->data_pad); 1230 - goto bad_vid_hdr; 1231 - } 1232 - 1233 - if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) { 1234 - ubi_err("bad leb_ver %u", seb->leb_ver); 1235 1264 goto bad_vid_hdr; 1236 1265 } 1237 1266 }
-2
drivers/mtd/ubi/scan.h
··· 34 34 * @u: unions RB-tree or @list links 35 35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 36 36 * @u.list: link in one of the eraseblock lists 37 - * @leb_ver: logical eraseblock version (obsolete) 38 37 * 39 38 * One object of this type is allocated for each physical eraseblock during 40 39 * scanning. ··· 48 49 struct rb_node rb; 49 50 struct list_head list; 50 51 } u; 51 - uint32_t leb_ver; 52 52 }; 53 53 54 54 /**
+6 -11
drivers/mtd/ubi/ubi-media.h
··· 168 168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 169 169 * @vol_id: ID of this volume 170 170 * @lnum: logical eraseblock number 171 - * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be 172 - * removed, kept only for not breaking older UBI users) 171 + * @padding1: reserved for future, zeroes 173 172 * @data_size: how many bytes of data this logical eraseblock contains 174 173 * @used_ebs: total number of used logical eraseblocks in this volume 175 174 * @data_pad: how many bytes at the end of this physical eraseblock are not 176 175 * used 177 176 * @data_crc: CRC checksum of the data stored in this logical eraseblock 178 - * @padding1: reserved for future, zeroes 179 - * @sqnum: sequence number 180 177 * @padding2: reserved for future, zeroes 178 + * @sqnum: sequence number 179 + * @padding3: reserved for future, zeroes 181 180 * @hdr_crc: volume identifier header CRC checksum 182 181 * 183 182 * The @sqnum is the value of the global sequence counter at the time when this ··· 223 224 * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC 224 225 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 225 226 * the older one (P) is selected. 226 - * 227 - * Note, there is an obsolete @leb_ver field which was used instead of @sqnum 228 - * in the past. But it is not used anymore and we keep it in order to be able 229 - * to deal with old UBI images. It will be removed at some point. 230 227 * 231 228 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 232 229 * Internal volumes are not seen from outside and are used for various internal ··· 273 278 __u8 compat; 274 279 __be32 vol_id; 275 280 __be32 lnum; 276 - __be32 leb_ver; /* obsolete, to be removed, don't use */ 281 + __u8 padding1[4]; 277 282 __be32 data_size; 278 283 __be32 used_ebs; 279 284 __be32 data_pad; 280 285 __be32 data_crc; 281 - __u8 padding1[4]; 286 + __u8 padding2[4]; 282 287 __be64 sqnum; 283 - __u8 padding2[12]; 288 + __u8 padding3[12]; 284 289 __be32 hdr_crc; 285 290 } __attribute__ ((packed)); 286 291
-1
drivers/mtd/ubi/vtbl.c
··· 338 338 vid_hdr->data_pad = cpu_to_be32(0); 339 339 vid_hdr->lnum = cpu_to_be32(copy); 340 340 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 341 - vid_hdr->leb_ver = cpu_to_be32(old_seb ? old_seb->leb_ver + 1: 0); 342 341 343 342 /* The EC header is already there, write the VID header */ 344 343 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);