kernel: split patches folder up into backport, pending and hack folders
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 494-mtd-ubi-add-EOF-marker-support.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: mtd: add EOF marker support to the UBI layer
3
4 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
5 ---
6  drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
7  drivers/mtd/ubi/ubi.h    |  1 +
8  2 files changed, 23 insertions(+), 3 deletions(-)
9
10 diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
11 index 93ceea4f27d5..a4f849d69104 100644
12 --- a/drivers/mtd/ubi/attach.c
13 +++ b/drivers/mtd/ubi/attach.c
14 @@ -939,6 +939,13 @@ static bool vol_ignored(int vol_id)
15  #endif
16  }
17  
18 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
19 +{
20 +       return ech->padding1[0] == 'E' &&
21 +              ech->padding1[1] == 'O' &&
22 +              ech->padding1[2] == 'F';
23 +}
24 +
25  /**
26   * scan_peb - scan and process UBI headers of a PEB.
27   * @ubi: UBI device description object
28 @@ -971,9 +978,21 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
29                 return 0;
30         }
31  
32 -       err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
33 -       if (err < 0)
34 -               return err;
35 +       if (!ai->eof_found) {
36 +               err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
37 +               if (err < 0)
38 +                       return err;
39 +
40 +               if (ec_hdr_has_eof(ech)) {
41 +                       pr_notice("UBI: EOF marker found, PEBs from %d will be erased",
42 +                               pnum);
43 +                       ai->eof_found = true;
44 +               }
45 +       }
46 +
47 +       if (ai->eof_found)
48 +               err = UBI_IO_FF_BITFLIPS;
49 +
50         switch (err) {
51         case 0:
52                 break;
53 diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
54 index 697dbcba7371..92d207ff2458 100644
55 --- a/drivers/mtd/ubi/ubi.h
56 +++ b/drivers/mtd/ubi/ubi.h
57 @@ -779,6 +779,7 @@ struct ubi_attach_info {
58         int mean_ec;
59         uint64_t ec_sum;
60         int ec_count;
61 +       bool eof_found;
62         struct kmem_cache *aeb_slab_cache;
63         struct ubi_ec_hdr *ech;
64         struct ubi_vid_io_buf *vidb;
65 -- 
66 2.11.0
67