Skip to content

Commit c22301a

Browse files
rgenouddedekind
authored andcommitted
UBI: fastmap: fix backward compatibility with image_seq
Some old UBI implementations (e.g. U-Boot) have not implemented the image sequence feature. So, when erase blocks are written, the image sequence in the ec header is lost (set to zero). UBI scan_all() takes this case into account (commits 32bc482 and 2eadaad) But fastmap scan functions (ubi_scan_fastmap() and scan_pool()) didn't. This patch fixes the issue. Signed-off-by: Richard Genoud <richard.genoud@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent 4b3e0a2 commit c22301a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎drivers/mtd/ubi/fastmap.c‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
407407
*/
408408
for (i = 0; i < pool_size; i++) {
409409
int scrub = 0;
410+
int image_seq;
410411

411412
pnum = be32_to_cpu(pebs[i]);
412413

@@ -425,7 +426,13 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
425426
} else if (ret == UBI_IO_BITFLIPS)
426427
scrub = 1;
427428

428-
if (be32_to_cpu(ech->image_seq) != ubi->image_seq) {
429+
/*
430+
* Older UBI implementations have image_seq set to zero, so
431+
* we shouldn't fail if image_seq == 0.
432+
*/
433+
image_seq = be32_to_cpu(ech->image_seq);
434+
435+
if (image_seq && (image_seq != ubi->image_seq)) {
429436
ubi_err("bad image seq: 0x%x, expected: 0x%x",
430437
be32_to_cpu(ech->image_seq), ubi->image_seq);
431438
ret = UBI_BAD_FASTMAP;
@@ -923,6 +930,8 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
923930
}
924931

925932
for (i = 0; i < used_blocks; i++) {
933+
int image_seq;
934+
926935
pnum = be32_to_cpu(fmsb->block_loc[i]);
927936

928937
if (ubi_io_is_bad(ubi, pnum)) {
@@ -940,10 +949,17 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
940949
} else if (ret == UBI_IO_BITFLIPS)
941950
fm->to_be_tortured[i] = 1;
942951

952+
image_seq = be32_to_cpu(ech->image_seq);
943953
if (!ubi->image_seq)
944-
ubi->image_seq = be32_to_cpu(ech->image_seq);
954+
ubi->image_seq = image_seq;
945955

946-
if (be32_to_cpu(ech->image_seq) != ubi->image_seq) {
956+
/*
957+
* Older UBI implementations have image_seq set to zero, so
958+
* we shouldn't fail if image_seq == 0.
959+
*/
960+
if (image_seq && (image_seq != ubi->image_seq)) {
961+
ubi_err("wrong image seq:%d instead of %d",
962+
be32_to_cpu(ech->image_seq), ubi->image_seq);
947963
ret = UBI_BAD_FASTMAP;
948964
goto free_hdr;
949965
}

0 commit comments

Comments
 (0)