1
0

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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  2. Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating offsets
  3. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  4. ---
  5. --- a/drivers/mtd/parsers/parser_trx.c
  6. +++ b/drivers/mtd/parsers/parser_trx.c
  7. @@ -30,6 +30,33 @@ struct trx_header {
  8. uint32_t offset[3];
  9. } __packed;
  10. +/*
  11. + * Calculate real end offset (address) for a given amount of data. It checks
  12. + * all blocks skipping bad ones.
  13. + */
  14. +static size_t parser_trx_real_offset(struct mtd_info *mtd, size_t bytes)
  15. +{
  16. + size_t real_offset = 0;
  17. +
  18. + if (mtd_block_isbad(mtd, real_offset))
  19. + pr_warn("Base offset shouldn't be at bad block");
  20. +
  21. + while (bytes >= mtd->erasesize) {
  22. + bytes -= mtd->erasesize;
  23. + real_offset += mtd->erasesize;
  24. + while (mtd_block_isbad(mtd, real_offset)) {
  25. + real_offset += mtd->erasesize;
  26. +
  27. + if (real_offset >= mtd->size)
  28. + return real_offset - mtd->erasesize;
  29. + }
  30. + }
  31. +
  32. + real_offset += bytes;
  33. +
  34. + return real_offset;
  35. +}
  36. +
  37. static const char *parser_trx_data_part_name(struct mtd_info *master,
  38. size_t offset)
  39. {
  40. @@ -84,21 +111,21 @@ static int parser_trx_parse(struct mtd_i
  41. if (trx.offset[2]) {
  42. part = &parts[curr_part++];
  43. part->name = "loader";
  44. - part->offset = trx.offset[i];
  45. + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
  46. i++;
  47. }
  48. if (trx.offset[i]) {
  49. part = &parts[curr_part++];
  50. part->name = "linux";
  51. - part->offset = trx.offset[i];
  52. + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
  53. i++;
  54. }
  55. if (trx.offset[i]) {
  56. part = &parts[curr_part++];
  57. - part->name = parser_trx_data_part_name(mtd, trx.offset[i]);
  58. - part->offset = trx.offset[i];
  59. + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
  60. + part->name = parser_trx_data_part_name(mtd, part->offset);
  61. i++;
  62. }