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
7 Add support for UBI end-of-filesystem marker used by OpenWrt to allow
8 attaching a new UBI mtd partition just upgraded.
10 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
12 drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
13 drivers/mtd/ubi/ubi.h | 1 +
14 2 files changed, 23 insertions(+), 3 deletions(-)
16 --- a/drivers/mtd/ubi/attach.c
17 +++ b/drivers/mtd/ubi/attach.c
18 @@ -802,6 +802,13 @@ out_unlock:
22 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
24 + return ech->padding1[0] == 'E' &&
25 + ech->padding1[1] == 'O' &&
26 + ech->padding1[2] == 'F';
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
36 - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
39 + if (!ai->eof_found) {
40 + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
44 + if (ec_hdr_has_eof(ech)) {
45 + pr_notice("UBI: EOF marker found, PEBs from %d will be erased\n",
47 + ai->eof_found = true;
52 + err = UBI_IO_FF_BITFLIPS;
57 --- a/drivers/mtd/ubi/ubi.h
58 +++ b/drivers/mtd/ubi/ubi.h
59 @@ -745,6 +745,7 @@ struct ubi_attach_info {
64 struct kmem_cache *aeb_slab_cache;