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 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); 66 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); 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 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); 70 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); 71 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); ··· 171 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); 172 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); 173 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); 174 - printk(KERN_DEBUG "\tleb_ver %u\n", seb->leb_ver); 175 } 176 } 177
··· 65 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); 66 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); 67 printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); 68 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); 69 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); 70 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); ··· 172 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); 173 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); 174 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); 175 } 176 } 177
+24 -63
drivers/mtd/ubi/scan.c
··· 246 struct ubi_vid_hdr *vh = NULL; 247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 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 - 253 /* 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. 268 */ 269 - dbg_bld("using old crappy leb_ver stuff"); 270 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; 289 290 /* 291 * Now we know which copy is newer. If the copy flag of the PEB with ··· 268 * check data CRC. For the second PEB we already have the VID header, 269 * for the first one - we'll need to re-read it from flash. 270 * 271 - * FIXME: this may be optimized so that we wouldn't read twice. 272 */ 273 274 if (second_is_newer) { ··· 374 int bitflips) 375 { 376 int err, vol_id, lnum; 377 - uint32_t leb_ver; 378 unsigned long long sqnum; 379 struct ubi_scan_volume *sv; 380 struct ubi_scan_leb *seb; ··· 382 vol_id = be32_to_cpu(vid_hdr->vol_id); 383 lnum = be32_to_cpu(vid_hdr->lnum); 384 sqnum = be64_to_cpu(vid_hdr->sqnum); 385 - leb_ver = be32_to_cpu(vid_hdr->leb_ver); 386 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); 389 390 sv = add_volume(si, vol_id, pnum, vid_hdr); 391 if (IS_ERR(sv) < 0) ··· 417 */ 418 419 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 - } 433 434 /* 435 * Make sure that the logical eraseblocks have different 436 * sequence numbers. Otherwise the image is bad. 437 * 438 - * FIXME: remove 'sqnum != 0' check when leb_ver is removed. 439 */ 440 if (seb->sqnum == sqnum && sqnum != 0) { 441 ubi_err("two LEBs with same sequence number %llu", ··· 470 seb->pnum = pnum; 471 seb->scrub = ((cmp_res & 2) || bitflips); 472 seb->sqnum = sqnum; 473 - seb->leb_ver = leb_ver; 474 475 if (sv->highest_lnum == lnum) 476 sv->last_data_size = ··· 506 seb->lnum = lnum; 507 seb->sqnum = sqnum; 508 seb->scrub = bitflips; 509 - seb->leb_ver = leb_ver; 510 511 if (sv->highest_lnum <= lnum) { 512 sv->highest_lnum = lnum; ··· 1227 1228 if (sv->data_pad != be32_to_cpu(vidh->data_pad)) { 1229 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 goto bad_vid_hdr; 1236 } 1237 }
··· 246 struct ubi_vid_hdr *vh = NULL; 247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 248 249 + if (sqnum2 == seb->sqnum) { 250 /* 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. 257 */ 258 + ubi_err("unsupported on-flash UBI format\n"); 259 + return -EINVAL; 260 + } 261 262 + /* Obviously the LEB with lower sequence counter is older */ 263 + second_is_newer = !!(sqnum2 > seb->sqnum); 264 265 /* 266 * Now we know which copy is newer. If the copy flag of the PEB with ··· 293 * 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. 295 * 296 + * Note: this may be optimized so that we wouldn't read twice. 297 */ 298 299 if (second_is_newer) { ··· 399 int bitflips) 400 { 401 int err, vol_id, lnum; 402 unsigned long long sqnum; 403 struct ubi_scan_volume *sv; 404 struct ubi_scan_leb *seb; ··· 408 vol_id = be32_to_cpu(vid_hdr->vol_id); 409 lnum = be32_to_cpu(vid_hdr->lnum); 410 sqnum = be64_to_cpu(vid_hdr->sqnum); 411 412 + dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d", 413 + pnum, vol_id, lnum, ec, sqnum, bitflips); 414 415 sv = add_volume(si, vol_id, pnum, vid_hdr); 416 if (IS_ERR(sv) < 0) ··· 444 */ 445 446 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " 447 + "EC %d", seb->pnum, seb->sqnum, seb->ec); 448 449 /* 450 * Make sure that the logical eraseblocks have different 451 * sequence numbers. Otherwise the image is bad. 452 * 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. 461 */ 462 if (seb->sqnum == sqnum && sqnum != 0) { 463 ubi_err("two LEBs with same sequence number %llu", ··· 502 seb->pnum = pnum; 503 seb->scrub = ((cmp_res & 2) || bitflips); 504 seb->sqnum = sqnum; 505 506 if (sv->highest_lnum == lnum) 507 sv->last_data_size = ··· 539 seb->lnum = lnum; 540 seb->sqnum = sqnum; 541 seb->scrub = bitflips; 542 543 if (sv->highest_lnum <= lnum) { 544 sv->highest_lnum = lnum; ··· 1261 1262 if (sv->data_pad != be32_to_cpu(vidh->data_pad)) { 1263 ubi_err("bad data_pad %d", sv->data_pad); 1264 goto bad_vid_hdr; 1265 } 1266 }
-2
drivers/mtd/ubi/scan.h
··· 34 * @u: unions RB-tree or @list links 35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 36 * @u.list: link in one of the eraseblock lists 37 - * @leb_ver: logical eraseblock version (obsolete) 38 * 39 * One object of this type is allocated for each physical eraseblock during 40 * scanning. ··· 48 struct rb_node rb; 49 struct list_head list; 50 } u; 51 - uint32_t leb_ver; 52 }; 53 54 /**
··· 34 * @u: unions RB-tree or @list links 35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 36 * @u.list: link in one of the eraseblock lists 37 * 38 * One object of this type is allocated for each physical eraseblock during 39 * scanning. ··· 49 struct rb_node rb; 50 struct list_head list; 51 } u; 52 }; 53 54 /**
+6 -11
drivers/mtd/ubi/ubi-media.h
··· 168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 169 * @vol_id: ID of this volume 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) 173 * @data_size: how many bytes of data this logical eraseblock contains 174 * @used_ebs: total number of used logical eraseblocks in this volume 175 * @data_pad: how many bytes at the end of this physical eraseblock are not 176 * used 177 * @data_crc: CRC checksum of the data stored in this logical eraseblock 178 - * @padding1: reserved for future, zeroes 179 - * @sqnum: sequence number 180 * @padding2: reserved for future, zeroes 181 * @hdr_crc: volume identifier header CRC checksum 182 * 183 * The @sqnum is the value of the global sequence counter at the time when this ··· 223 * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC 224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 225 * 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 * 231 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 232 * Internal volumes are not seen from outside and are used for various internal ··· 273 __u8 compat; 274 __be32 vol_id; 275 __be32 lnum; 276 - __be32 leb_ver; /* obsolete, to be removed, don't use */ 277 __be32 data_size; 278 __be32 used_ebs; 279 __be32 data_pad; 280 __be32 data_crc; 281 - __u8 padding1[4]; 282 __be64 sqnum; 283 - __u8 padding2[12]; 284 __be32 hdr_crc; 285 } __attribute__ ((packed)); 286
··· 168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 169 * @vol_id: ID of this volume 170 * @lnum: logical eraseblock number 171 + * @padding1: reserved for future, zeroes 172 * @data_size: how many bytes of data this logical eraseblock contains 173 * @used_ebs: total number of used logical eraseblocks in this volume 174 * @data_pad: how many bytes at the end of this physical eraseblock are not 175 * used 176 * @data_crc: CRC checksum of the data stored in this logical eraseblock 177 * @padding2: reserved for future, zeroes 178 + * @sqnum: sequence number 179 + * @padding3: reserved for future, zeroes 180 * @hdr_crc: volume identifier header CRC checksum 181 * 182 * The @sqnum is the value of the global sequence counter at the time when this ··· 224 * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC 225 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 226 * the older one (P) is selected. 227 * 228 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 229 * Internal volumes are not seen from outside and are used for various internal ··· 278 __u8 compat; 279 __be32 vol_id; 280 __be32 lnum; 281 + __u8 padding1[4]; 282 __be32 data_size; 283 __be32 used_ebs; 284 __be32 data_pad; 285 __be32 data_crc; 286 + __u8 padding2[4]; 287 __be64 sqnum; 288 + __u8 padding3[12]; 289 __be32 hdr_crc; 290 } __attribute__ ((packed)); 291
-1
drivers/mtd/ubi/vtbl.c
··· 338 vid_hdr->data_pad = cpu_to_be32(0); 339 vid_hdr->lnum = cpu_to_be32(copy); 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 343 /* The EC header is already there, write the VID header */ 344 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);
··· 338 vid_hdr->data_pad = cpu_to_be32(0); 339 vid_hdr->lnum = cpu_to_be32(copy); 340 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 341 342 /* The EC header is already there, write the VID header */ 343 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);