Fix 3.18.8 breakage of UBI devices with EOF marker (e.g. WNDR4300)
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.18 / 490-mtd-ubi-add-EOF-marker-support.patch
1 --- a/drivers/mtd/ubi/attach.c
2 +++ b/drivers/mtd/ubi/attach.c
3 @@ -800,6 +800,13 @@ out_unlock:
4 return err;
5 }
6
7 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
8 +{
9 + return ech->padding1[0] == 'E' &&
10 + ech->padding1[1] == 'O' &&
11 + ech->padding1[2] == 'F';
12 +}
13 +
14 /**
15 * scan_peb - scan and process UBI headers of a PEB.
16 * @ubi: UBI device description object
17 @@ -830,9 +837,21 @@ static int scan_peb(struct ubi_device *u
18 return 0;
19 }
20
21 - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
22 - if (err < 0)
23 - return err;
24 + if (!ai->eof_found) {
25 + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
26 + if (err < 0)
27 + return err;
28 +
29 + if (ec_hdr_has_eof(ech)) {
30 + ubi_msg("EOF marker found, PEBs from %d will be erased",
31 + pnum);
32 + ai->eof_found = true;
33 + }
34 + }
35 +
36 + if (ai->eof_found)
37 + err = UBI_IO_FF_BITFLIPS;
38 +
39 switch (err) {
40 case 0:
41 break;
42 --- a/drivers/mtd/ubi/ubi.h
43 +++ b/drivers/mtd/ubi/ubi.h
44 @@ -701,6 +701,7 @@ struct ubi_attach_info {
45 int mean_ec;
46 uint64_t ec_sum;
47 int ec_count;
48 + bool eof_found;
49 struct kmem_cache *aeb_slab_cache;
50 };
51