431-mtd-bcm47xxpart-check-for-bad-blocks-when-calculatin.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  2. Date: Sat, 2 Jan 2016 01:04:52 +0100
  3. Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating
  4. offsets
  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 <[email protected]>
  9. ---
  10. drivers/mtd/bcm47xxpart.c | 50 +++++++++++++++++++++++++++++++++++++----------
  11. 1 file changed, 40 insertions(+), 10 deletions(-)
  12. --- a/drivers/mtd/bcm47xxpart.c
  13. +++ b/drivers/mtd/bcm47xxpart.c
  14. @@ -62,6 +62,34 @@ static void bcm47xxpart_add_part(struct
  15. part->mask_flags = mask_flags;
  16. }
  17. +/*
  18. + * Calculate real end offset (address) for a given amount of data. It checks
  19. + * all blocks skipping bad ones.
  20. + */
  21. +static size_t bcm47xxpart_real_offset(struct mtd_info *master, size_t offset,
  22. + size_t bytes)
  23. +{
  24. + size_t real_offset = offset;
  25. +
  26. + if (mtd_block_isbad(master, real_offset))
  27. + pr_warn("Base offset shouldn't be at bad block");
  28. +
  29. + while (bytes >= master->erasesize) {
  30. + bytes -= master->erasesize;
  31. + real_offset += master->erasesize;
  32. + while (mtd_block_isbad(master, real_offset)) {
  33. + real_offset += master->erasesize;
  34. +
  35. + if (real_offset >= master->size)
  36. + return real_offset - master->erasesize;
  37. + }
  38. + }
  39. +
  40. + real_offset += bytes;
  41. +
  42. + return real_offset;
  43. +}
  44. +
  45. static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
  46. size_t offset)
  47. {
  48. @@ -113,19 +141,22 @@ static int bcm47xxpart_parse_trx(struct
  49. if (header.offset[2]) {
  50. part = &parts[curr_part++];
  51. part->name = "loader";
  52. - part->offset = trx->offset + header.offset[i];
  53. + part->offset = bcm47xxpart_real_offset(master, trx->offset,
  54. + header.offset[i]);
  55. i++;
  56. }
  57. if (header.offset[i]) {
  58. part = &parts[curr_part++];
  59. part->name = "linux";
  60. - part->offset = trx->offset + header.offset[i];
  61. + part->offset = bcm47xxpart_real_offset(master, trx->offset,
  62. + header.offset[i]);
  63. i++;
  64. }
  65. if (header.offset[i]) {
  66. - size_t offset = trx->offset + header.offset[i];
  67. + size_t offset = bcm47xxpart_real_offset(master, trx->offset,
  68. + header.offset[i]);
  69. part = &parts[curr_part++];
  70. part->name = bcm47xxpart_trx_data_part_name(master, offset);