500-UBI-Detect-EOF-mark-and-erase-all-remaining-blocks.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 2a2af518266a29323cf30c3f9ba9ef2ceb1dd84b Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Thu, 16 Oct 2014 20:52:16 +0200
  4. Subject: [PATCH] UBI: Detect EOF mark and erase all remaining blocks
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  9. ---
  10. drivers/mtd/ubi/attach.c | 5 +++++
  11. drivers/mtd/ubi/io.c | 4 ++++
  12. drivers/mtd/ubi/ubi.h | 1 +
  13. 3 files changed, 10 insertions(+)
  14. --- a/drivers/mtd/ubi/attach.c
  15. +++ b/drivers/mtd/ubi/attach.c
  16. @@ -95,6 +95,9 @@ static int self_check_ai(struct ubi_devi
  17. static struct ubi_ec_hdr *ech;
  18. static struct ubi_vid_hdr *vidh;
  19. +/* Set on finding block with 0xdeadc0de, indicates erasing all blocks behind */
  20. +bool erase_all_next;
  21. +
  22. /**
  23. * add_to_list - add physical eraseblock to a list.
  24. * @ai: attaching information
  25. @@ -1425,6 +1428,8 @@ int ubi_attach(struct ubi_device *ubi, i
  26. if (!ai)
  27. return -ENOMEM;
  28. + erase_all_next = false;
  29. +
  30. #ifdef CONFIG_MTD_UBI_FASTMAP
  31. /* On small flash devices we disable fastmap in any case. */
  32. if ((int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) <= UBI_FM_MAX_START) {
  33. --- a/drivers/mtd/ubi/io.c
  34. +++ b/drivers/mtd/ubi/io.c
  35. @@ -755,6 +755,10 @@ int ubi_io_read_ec_hdr(struct ubi_device
  36. }
  37. magic = be32_to_cpu(ec_hdr->magic);
  38. + if (magic == 0xdeadc0de)
  39. + erase_all_next = true;
  40. + if (erase_all_next)
  41. + return read_err ? UBI_IO_FF_BITFLIPS : UBI_IO_FF;
  42. if (magic != UBI_EC_HDR_MAGIC) {
  43. if (mtd_is_eccerr(read_err))
  44. return UBI_IO_BAD_HDR_EBADMSG;
  45. --- a/drivers/mtd/ubi/ubi.h
  46. +++ b/drivers/mtd/ubi/ubi.h
  47. @@ -783,6 +783,7 @@ extern struct mutex ubi_devices_mutex;
  48. extern struct blocking_notifier_head ubi_notifiers;
  49. /* attach.c */
  50. +extern bool erase_all_next;
  51. int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
  52. int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips);
  53. struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,