ar71xx: fix legacy image build error
[openwrt/openwrt.git] / target / linux / generic / patches-4.1 / 494-mtd-ubi-add-EOF-marker-support.patch
1 --- a/drivers/mtd/ubi/attach.c
2 +++ b/drivers/mtd/ubi/attach.c
3 @@ -803,6 +803,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 @@ -833,9 +840,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 + pr_notice("UBI: 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 @@ -741,6 +741,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