aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
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
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')
-rw-r--r--drivers/mtd/ubi/debug.c2
-rw-r--r--drivers/mtd/ubi/scan.c87
-rw-r--r--drivers/mtd/ubi/scan.h2
-rw-r--r--drivers/mtd/ubi/ubi-media.h17
-rw-r--r--drivers/mtd/ubi/vtbl.c1
5 files changed, 30 insertions, 79 deletions
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 21e0d7d76a44..c0ed60e8ade9 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -65,7 +65,6 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
65 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); 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)); 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)); 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)); 68 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)); 69 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)); 70 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
@@ -172,7 +171,6 @@ void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
172 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum); 171 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum);
173 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub); 172 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub);
174 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum); 173 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum);
175 printk(KERN_DEBUG "\tleb_ver %u\n", seb->leb_ver);
176 } 174 }
177} 175}
178 176
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)
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index 4e2e3cc0becd..61df208e2f20 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -34,7 +34,6 @@
34 * @u: unions RB-tree or @list links 34 * @u: unions RB-tree or @list links
35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 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 36 * @u.list: link in one of the eraseblock lists
37 * @leb_ver: logical eraseblock version (obsolete)
38 * 37 *
39 * One object of this type is allocated for each physical eraseblock during 38 * One object of this type is allocated for each physical eraseblock during
40 * scanning. 39 * scanning.
@@ -49,7 +48,6 @@ struct ubi_scan_leb {
49 struct rb_node rb; 48 struct rb_node rb;
50 struct list_head list; 49 struct list_head list;
51 } u; 50 } u;
52 uint32_t leb_ver;
53}; 51};
54 52
55/** 53/**
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index 26bb7af9787a..2ad940409053 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -168,16 +168,15 @@ struct ubi_ec_hdr {
168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
169 * @vol_id: ID of this volume 169 * @vol_id: ID of this volume
170 * @lnum: logical eraseblock number 170 * @lnum: logical eraseblock number
171 * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be 171 * @padding1: reserved for future, zeroes
172 * removed, kept only for not breaking older UBI users)
173 * @data_size: how many bytes of data this logical eraseblock contains 172 * @data_size: how many bytes of data this logical eraseblock contains
174 * @used_ebs: total number of used logical eraseblocks in this volume 173 * @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 174 * @data_pad: how many bytes at the end of this physical eraseblock are not
176 * used 175 * used
177 * @data_crc: CRC checksum of the data stored in this logical eraseblock 176 * @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 177 * @padding2: reserved for future, zeroes
178 * @sqnum: sequence number
179 * @padding3: reserved for future, zeroes
181 * @hdr_crc: volume identifier header CRC checksum 180 * @hdr_crc: volume identifier header CRC checksum
182 * 181 *
183 * The @sqnum is the value of the global sequence counter at the time when this 182 * The @sqnum is the value of the global sequence counter at the time when this
@@ -225,10 +224,6 @@ struct ubi_ec_hdr {
225 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise
226 * the older one (P) is selected. 225 * the older one (P) is selected.
227 * 226 *
228 * Note, there is an obsolete @leb_ver field which was used instead of @sqnum
229 * in the past. But it is not used anymore and we keep it in order to be able
230 * to deal with old UBI images. It will be removed at some point.
231 *
232 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 227 * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
233 * Internal volumes are not seen from outside and are used for various internal 228 * Internal volumes are not seen from outside and are used for various internal
234 * UBI purposes. In this implementation there is only one internal volume - the 229 * UBI purposes. In this implementation there is only one internal volume - the
@@ -278,14 +273,14 @@ struct ubi_vid_hdr {
278 __u8 compat; 273 __u8 compat;
279 __be32 vol_id; 274 __be32 vol_id;
280 __be32 lnum; 275 __be32 lnum;
281 __be32 leb_ver; /* obsolete, to be removed, don't use */ 276 __u8 padding1[4];
282 __be32 data_size; 277 __be32 data_size;
283 __be32 used_ebs; 278 __be32 used_ebs;
284 __be32 data_pad; 279 __be32 data_pad;
285 __be32 data_crc; 280 __be32 data_crc;
286 __u8 padding1[4]; 281 __u8 padding2[4];
287 __be64 sqnum; 282 __be64 sqnum;
288 __u8 padding2[12]; 283 __u8 padding3[12];
289 __be32 hdr_crc; 284 __be32 hdr_crc;
290} __attribute__ ((packed)); 285} __attribute__ ((packed));
291 286
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 4e1c489a3bae..217d0e111b2a 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -338,7 +338,6 @@ retry:
338 vid_hdr->data_pad = cpu_to_be32(0); 338 vid_hdr->data_pad = cpu_to_be32(0);
339 vid_hdr->lnum = cpu_to_be32(copy); 339 vid_hdr->lnum = cpu_to_be32(copy);
340 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 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 /* The EC header is already there, write the VID header */ 342 /* The EC header is already there, write the VID header */
344 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); 343 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);