6d7a45f7baaa1e788cc2ab502bbc5cad4f112224
[oweals/openwrt.git] / target / linux / bcm53xx / patches-5.4 / 500-UBI-Detect-EOF-mark-and-erase-all-remaining-blocks.patch
1 From 2a2af518266a29323cf30c3f9ba9ef2ceb1dd84b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Thu, 16 Oct 2014 20:52:16 +0200
4 Subject: [PATCH] UBI: Detect EOF mark and erase all remaining blocks
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
10 ---
11  drivers/mtd/ubi/attach.c | 5 +++++
12  drivers/mtd/ubi/io.c     | 4 ++++
13  drivers/mtd/ubi/ubi.h    | 1 +
14  3 files changed, 10 insertions(+)
15
16 --- a/drivers/mtd/ubi/attach.c
17 +++ b/drivers/mtd/ubi/attach.c
18 @@ -95,6 +95,9 @@ static int self_check_ai(struct ubi_devi
19  #define AV_ADD         BIT(1)
20  #define AV_FIND_OR_ADD (AV_FIND | AV_ADD)
21  
22 +/* Set on finding block with 0xdeadc0de, indicates erasing all blocks behind */
23 +bool erase_all_next;
24 +
25  /**
26   * find_or_add_av - internal function to find a volume, add a volume or do
27   *                 both (find and add if missing).
28 @@ -1592,6 +1595,8 @@ int ubi_attach(struct ubi_device *ubi, i
29         if (!ai)
30                 return -ENOMEM;
31  
32 +       erase_all_next = false;
33 +
34  #ifdef CONFIG_MTD_UBI_FASTMAP
35         /* On small flash devices we disable fastmap in any case. */
36         if ((int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) <= UBI_FM_MAX_START) {
37 --- a/drivers/mtd/ubi/io.c
38 +++ b/drivers/mtd/ubi/io.c
39 @@ -723,6 +723,10 @@ int ubi_io_read_ec_hdr(struct ubi_device
40         }
41  
42         magic = be32_to_cpu(ec_hdr->magic);
43 +       if (magic == 0xdeadc0de)
44 +               erase_all_next = true;
45 +       if (erase_all_next)
46 +               return read_err ? UBI_IO_FF_BITFLIPS : UBI_IO_FF;
47         if (magic != UBI_EC_HDR_MAGIC) {
48                 if (mtd_is_eccerr(read_err))
49                         return UBI_IO_BAD_HDR_EBADMSG;
50 --- a/drivers/mtd/ubi/ubi.h
51 +++ b/drivers/mtd/ubi/ubi.h
52 @@ -833,6 +833,7 @@ extern struct mutex ubi_devices_mutex;
53  extern struct blocking_notifier_head ubi_notifiers;
54  
55  /* attach.c */
56 +extern bool erase_all_next;
57  struct ubi_ainf_peb *ubi_alloc_aeb(struct ubi_attach_info *ai, int pnum,
58                                    int ec);
59  void ubi_free_aeb(struct ubi_attach_info *ai, struct ubi_ainf_peb *aeb);