2
0

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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  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 <zajec5@gmail.com>
  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. @@ -91,6 +119,7 @@ static int bcm47xxpart_parse_trx(struct
  49. {
  50. struct trx_header header;
  51. size_t bytes_read;
  52. + size_t offset;
  53. int curr_part = 0;
  54. int i, err;
  55. @@ -110,21 +139,25 @@ static int bcm47xxpart_parse_trx(struct
  56. /* We have LZMA loader if offset[2] points to sth */
  57. if (header.offset[2]) {
  58. - bcm47xxpart_add_part(&parts[curr_part++], "loader",
  59. - trx->offset + header.offset[i], 0);
  60. + offset = bcm47xxpart_real_offset(master, trx->offset,
  61. + header.offset[i]);
  62. + bcm47xxpart_add_part(&parts[curr_part++], "loader", offset, 0);
  63. i++;
  64. }
  65. if (header.offset[i]) {
  66. - bcm47xxpart_add_part(&parts[curr_part++], "linux",
  67. - trx->offset + header.offset[i], 0);
  68. + offset = bcm47xxpart_real_offset(master, trx->offset,
  69. + header.offset[i]);
  70. + bcm47xxpart_add_part(&parts[curr_part++], "linux", offset, 0);
  71. i++;
  72. }
  73. if (header.offset[i]) {
  74. - size_t offset = trx->offset + header.offset[i];
  75. - const char *name = bcm47xxpart_trx_data_part_name(master,
  76. - offset);
  77. + const char *name;
  78. +
  79. + offset = bcm47xxpart_real_offset(master, trx->offset,
  80. + header.offset[i]);
  81. + name = bcm47xxpart_trx_data_part_name(master, offset);
  82. bcm47xxpart_add_part(&parts[curr_part++], name, offset, 0);
  83. i++;