bcm53xx: fix UBI EOF patch to allow sysupgrade after first installation
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-3.18 / 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 diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
17 index 380268b..8f525c2 100644
18 --- a/drivers/mtd/ubi/attach.c
19 +++ b/drivers/mtd/ubi/attach.c
20 @@ -95,6 +95,9 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
21 static struct ubi_ec_hdr *ech;
22 static struct ubi_vid_hdr *vidh;
23
24 +/* Set on finding block with 0xdeadc0de, indicates erasing all blocks behind */
25 +bool erase_all_next;
26 +
27 /**
28 * add_to_list - add physical eraseblock to a list.
29 * @ai: attaching information
30 @@ -1418,6 +1421,8 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
31 if (!ai)
32 return -ENOMEM;
33
34 + erase_all_next = false;
35 +
36 #ifdef CONFIG_MTD_UBI_FASTMAP
37 /* On small flash devices we disable fastmap in any case. */
38 if ((int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) <= UBI_FM_MAX_START) {
39 diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
40 index d361349..f3d29ce 100644
41 --- a/drivers/mtd/ubi/io.c
42 +++ b/drivers/mtd/ubi/io.c
43 @@ -753,6 +753,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
44 }
45
46 magic = be32_to_cpu(ec_hdr->magic);
47 + if (magic == 0xdeadc0de)
48 + erase_all_next = true;
49 + if (erase_all_next)
50 + return read_err ? UBI_IO_FF_BITFLIPS : UBI_IO_FF;
51 if (magic != UBI_EC_HDR_MAGIC) {
52 if (mtd_is_eccerr(read_err))
53 return UBI_IO_BAD_HDR_EBADMSG;
54 diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
55 index 1259e72..142ee3d 100644
56 --- a/drivers/mtd/ubi/ubi.h
57 +++ b/drivers/mtd/ubi/ubi.h
58 @@ -743,6 +743,7 @@ extern struct mutex ubi_devices_mutex;
59 extern struct blocking_notifier_head ubi_notifiers;
60
61 /* attach.c */
62 +extern bool erase_all_next;
63 int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
64 int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips);
65 struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,
66 --
67 1.8.4.5
68