100-27-mtd-ubi-add-support-for-UBI-end-of-filesystem-marker.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From 189a2fe96931ef3ea0e187c8e9bfa589c2a0ae10 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Mon, 25 Jul 2022 17:24:56 +0800
  4. Subject: [PATCH 62/71] mtd: ubi: add support for UBI end-of-filesystem marker
  5. used by OpenWrt
  6. Add support for UBI end-of-filesystem marker used by OpenWrt to allow
  7. attaching a new UBI mtd partition just upgraded.
  8. Signed-off-by: Weijie Gao <[email protected]>
  9. ---
  10. drivers/mtd/ubi/attach.c | 25 ++++++++++++++++++++++---
  11. drivers/mtd/ubi/ubi.h | 1 +
  12. 2 files changed, 23 insertions(+), 3 deletions(-)
  13. --- a/drivers/mtd/ubi/attach.c
  14. +++ b/drivers/mtd/ubi/attach.c
  15. @@ -803,6 +803,13 @@ out_unlock:
  16. return err;
  17. }
  18. +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
  19. +{
  20. + return ech->padding1[0] == 'E' &&
  21. + ech->padding1[1] == 'O' &&
  22. + ech->padding1[2] == 'F';
  23. +}
  24. +
  25. /**
  26. * scan_peb - scan and process UBI headers of a PEB.
  27. * @ubi: UBI device description object
  28. @@ -833,9 +840,21 @@ static int scan_peb(struct ubi_device *u
  29. return 0;
  30. }
  31. - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  32. - if (err < 0)
  33. - return err;
  34. + if (!ai->eof_found) {
  35. + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
  36. + if (err < 0)
  37. + return err;
  38. +
  39. + if (ec_hdr_has_eof(ech)) {
  40. + pr_notice("UBI: EOF marker found, PEBs from %d will be erased\n",
  41. + pnum);
  42. + ai->eof_found = true;
  43. + }
  44. + }
  45. +
  46. + if (ai->eof_found)
  47. + err = UBI_IO_FF_BITFLIPS;
  48. +
  49. switch (err) {
  50. case 0:
  51. break;
  52. --- a/drivers/mtd/ubi/ubi.h
  53. +++ b/drivers/mtd/ubi/ubi.h
  54. @@ -746,6 +746,7 @@ struct ubi_attach_info {
  55. int mean_ec;
  56. uint64_t ec_sum;
  57. int ec_count;
  58. + bool eof_found;
  59. struct kmem_cache *aeb_slab_cache;
  60. };