--- zzzz-none-000/linux-4.9.231/drivers/mtd/ubi/attach.c 2020-07-22 07:10:54.000000000 +0000 +++ falcon-5530-730/linux-4.9.231/drivers/mtd/ubi/attach.c 2022-08-31 08:19:49.000000000 +0000 @@ -939,6 +939,13 @@ #endif } +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 @@ -971,9 +978,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\n", + pnum); + ai->eof_found = true; + } + } + + if (ai->eof_found) + err = UBI_IO_FF_BITFLIPS; + switch (err) { case 0: break;