cd1794f0d119e69be1412043fc3afe135264dbea
[openwrt/staging/jow.git] /
1 From 189a2fe96931ef3ea0e187c8e9bfa589c2a0ae10 Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Mon, 25 Jul 2022 17:24:56 +0800
4 Subject: [PATCH 62/71] mtd: ubi: add support for UBI end-of-filesystem marker
5 used by OpenWrt
6
7 Add support for UBI end-of-filesystem marker used by OpenWrt to allow
8 attaching a new UBI mtd partition just upgraded.
9
10 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
11 ---
12 drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
13 drivers/mtd/ubi/ubi.h | 1 +
14 2 files changed, 23 insertions(+), 3 deletions(-)
15
16 --- a/drivers/mtd/ubi/attach.c
17 +++ b/drivers/mtd/ubi/attach.c
18 @@ -802,6 +802,13 @@ out_unlock:
19 return err;
20 }
21
22 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
23 +{
24 + return ech->padding1[0] == 'E' &&
25 + ech->padding1[1] == 'O' &&
26 + ech->padding1[2] == 'F';
27 +}
28 +
29 /**
30 * scan_peb - scan and process UBI headers of a PEB.
31 * @ubi: UBI device description object
32 @@ -832,9 +839,21 @@ static int scan_peb(struct ubi_device *u
33 return 0;
34 }
35
36 - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
37 - if (err < 0)
38 - return err;
39 + if (!ai->eof_found) {
40 + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
41 + if (err < 0)
42 + return err;
43 +
44 + if (ec_hdr_has_eof(ech)) {
45 + pr_notice("UBI: EOF marker found, PEBs from %d will be erased\n",
46 + pnum);
47 + ai->eof_found = true;
48 + }
49 + }
50 +
51 + if (ai->eof_found)
52 + err = UBI_IO_FF_BITFLIPS;
53 +
54 switch (err) {
55 case 0:
56 break;
57 --- a/drivers/mtd/ubi/ubi.h
58 +++ b/drivers/mtd/ubi/ubi.h
59 @@ -745,6 +745,7 @@ struct ubi_attach_info {
60 int mean_ec;
61 uint64_t ec_sum;
62 int ec_count;
63 + bool eof_found;
64 struct kmem_cache *aeb_slab_cache;
65 };
66