2
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From: Gabor Juhos <juhosg@openwrt.org>
  2. Subject: mtd: add EOF marker support to the UBI layer
  3. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  4. ---
  5. drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
  6. drivers/mtd/ubi/ubi.h | 1 +
  7. 2 files changed, 23 insertions(+), 3 deletions(-)
  8. --- a/drivers/mtd/ubi/attach.c
  9. +++ b/drivers/mtd/ubi/attach.c
  10. @@ -939,6 +939,13 @@ static bool vol_ignored(int vol_id)
  11. #endif
  12. }
  13. +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
  14. +{
  15. + return ech->padding1[0] == 'E' &&
  16. + ech->padding1[1] == 'O' &&
  17. + ech->padding1[2] == 'F';
  18. +}
  19. +
  20. /**
  21. * scan_peb - scan and process UBI headers of a PEB.
  22. * @ubi: UBI device description object
  23. @@ -971,9 +978,21 @@ static int scan_peb(struct ubi_device *u
  24. return 0;
  25. }
  26. - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  27. - if (err < 0)
  28. - return err;
  29. + if (!ai->eof_found) {
  30. + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  31. + if (err < 0)
  32. + return err;
  33. +
  34. + if (ec_hdr_has_eof(ech)) {
  35. + pr_notice("UBI: EOF marker found, PEBs from %d will be erased\n",
  36. + pnum);
  37. + ai->eof_found = true;
  38. + }
  39. + }
  40. +
  41. + if (ai->eof_found)
  42. + err = UBI_IO_FF_BITFLIPS;
  43. +
  44. switch (err) {
  45. case 0:
  46. break;
  47. --- a/drivers/mtd/ubi/ubi.h
  48. +++ b/drivers/mtd/ubi/ubi.h
  49. @@ -785,6 +785,7 @@ struct ubi_attach_info {
  50. int mean_ec;
  51. uint64_t ec_sum;
  52. int ec_count;
  53. + bool eof_found;
  54. struct kmem_cache *aeb_slab_cache;
  55. struct ubi_ec_hdr *ech;
  56. struct ubi_vid_io_buf *vidb;