1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: mtd: add EOF marker support to the UBI layer
4 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
6 drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
7 drivers/mtd/ubi/ubi.h | 1 +
8 2 files changed, 23 insertions(+), 3 deletions(-)
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)
18 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
20 + return ech->padding1[0] == 'E' &&
21 + ech->padding1[1] == 'O' &&
22 + ech->padding1[2] == 'F';
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,
32 - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
35 + if (!ai->eof_found) {
36 + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
40 + if (ec_hdr_has_eof(ech)) {
41 + pr_notice("UBI: EOF marker found, PEBs from %d will be erased",
43 + ai->eof_found = true;
48 + err = UBI_IO_FF_BITFLIPS;
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 {
62 struct kmem_cache *aeb_slab_cache;
63 struct ubi_ec_hdr *ech;
64 struct ubi_vid_io_buf *vidb;