494-mtd-ubi-add-EOF-marker-support.patch 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --- a/drivers/mtd/ubi/attach.c
  2. +++ b/drivers/mtd/ubi/attach.c
  3. @@ -851,6 +851,13 @@ static bool vol_ignored(int vol_id)
  4. #endif
  5. }
  6. +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
  7. +{
  8. + return ech->padding1[0] == 'E' &&
  9. + ech->padding1[1] == 'O' &&
  10. + ech->padding1[2] == 'F';
  11. +}
  12. +
  13. /**
  14. * scan_peb - scan and process UBI headers of a PEB.
  15. * @ubi: UBI device description object
  16. @@ -880,9 +887,21 @@ static int scan_peb(struct ubi_device *u
  17. return 0;
  18. }
  19. - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  20. - if (err < 0)
  21. - return err;
  22. + if (!ai->eof_found) {
  23. + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  24. + if (err < 0)
  25. + return err;
  26. +
  27. + if (ec_hdr_has_eof(ech)) {
  28. + pr_notice("UBI: EOF marker found, PEBs from %d will be erased",
  29. + pnum);
  30. + ai->eof_found = true;
  31. + }
  32. + }
  33. +
  34. + if (ai->eof_found)
  35. + err = UBI_IO_FF_BITFLIPS;
  36. +
  37. switch (err) {
  38. case 0:
  39. break;
  40. --- a/drivers/mtd/ubi/ubi.h
  41. +++ b/drivers/mtd/ubi/ubi.h
  42. @@ -747,6 +747,7 @@ struct ubi_attach_info {
  43. int mean_ec;
  44. uint64_t ec_sum;
  45. int ec_count;
  46. + bool eof_found;
  47. struct kmem_cache *aeb_slab_cache;
  48. };