--- zzzz-none-000/linux-4.4.60/drivers/mtd/ubi/attach.c 2017-04-08 07:53:53.000000000 +0000 +++ scorpion-1750e-727/linux-4.4.60/drivers/mtd/ubi/attach.c 2021-02-04 17:41:59.000000000 +0000 @@ -803,6 +803,13 @@ return err; } +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech) +{ + return ech->padding1[0] == 'E' && + ech->padding1[1] == 'O' && + ech->padding1[2] == 'F'; +} + /** * scan_peb - scan and process UBI headers of a PEB. * @ubi: UBI device description object @@ -833,9 +840,21 @@ return 0; } - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); - if (err < 0) - return err; + if (!ai->eof_found) { + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); + if (err < 0) + return err; + + if (ec_hdr_has_eof(ech)) { + pr_notice("UBI: EOF marker found, PEBs from %d will be erased", + pnum); + ai->eof_found = true; + } + } + + if (ai->eof_found) + err = UBI_IO_FF_BITFLIPS; + switch (err) { case 0: break;