1
0

041-mtd-bcm47xxpart-backports-from-3.20.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --- a/drivers/mtd/bcm47xxpart.c
  2. +++ b/drivers/mtd/bcm47xxpart.c
  3. @@ -15,6 +15,8 @@
  4. #include <linux/mtd/mtd.h>
  5. #include <linux/mtd/partitions.h>
  6. +#include <uapi/linux/magic.h>
  7. +
  8. /*
  9. * NAND flash on Netgear R6250 was verified to contain 15 partitions.
  10. * This will result in allocating too big array for some old devices, but the
  11. @@ -39,7 +41,8 @@
  12. #define ML_MAGIC1 0x39685a42
  13. #define ML_MAGIC2 0x26594131
  14. #define TRX_MAGIC 0x30524448
  15. -#define SQSH_MAGIC 0x71736873 /* shsq */
  16. +#define SHSQ_MAGIC 0x71736873 /* shsq (weird ZTE H218N endianness) */
  17. +#define UBI_EC_MAGIC 0x23494255 /* UBI# */
  18. struct trx_header {
  19. uint32_t magic;
  20. @@ -50,7 +53,7 @@ struct trx_header {
  21. uint32_t offset[3];
  22. } __packed;
  23. -static void bcm47xxpart_add_part(struct mtd_partition *part, char *name,
  24. +static void bcm47xxpart_add_part(struct mtd_partition *part, const char *name,
  25. u64 offset, uint32_t mask_flags)
  26. {
  27. part->name = name;
  28. @@ -58,6 +61,26 @@ static void bcm47xxpart_add_part(struct
  29. part->mask_flags = mask_flags;
  30. }
  31. +static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
  32. + size_t offset)
  33. +{
  34. + uint32_t buf;
  35. + size_t bytes_read;
  36. +
  37. + if (mtd_read(master, offset, sizeof(buf), &bytes_read,
  38. + (uint8_t *)&buf) < 0) {
  39. + pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
  40. + offset);
  41. + goto out_default;
  42. + }
  43. +
  44. + if (buf == UBI_EC_MAGIC)
  45. + return "ubi";
  46. +
  47. +out_default:
  48. + return "rootfs";
  49. +}
  50. +
  51. static int bcm47xxpart_parse(struct mtd_info *master,
  52. struct mtd_partition **pparts,
  53. struct mtd_part_parser_data *data)
  54. @@ -73,8 +96,12 @@ static int bcm47xxpart_parse(struct mtd_
  55. int last_trx_part = -1;
  56. int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
  57. - if (blocksize <= 0x10000)
  58. - blocksize = 0x10000;
  59. + /*
  60. + * Some really old flashes (like AT45DB*) had smaller erasesize-s, but
  61. + * partitions were aligned to at least 0x1000 anyway.
  62. + */
  63. + if (blocksize < 0x1000)
  64. + blocksize = 0x1000;
  65. /* Alloc */
  66. parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
  67. @@ -186,8 +213,11 @@ static int bcm47xxpart_parse(struct mtd_
  68. * we want to have jffs2 (overlay) in the same mtd.
  69. */
  70. if (trx->offset[i]) {
  71. + const char *name;
  72. +
  73. + name = bcm47xxpart_trx_data_part_name(master, offset + trx->offset[i]);
  74. bcm47xxpart_add_part(&parts[curr_part++],
  75. - "rootfs",
  76. + name,
  77. offset + trx->offset[i],
  78. 0);
  79. i++;
  80. @@ -205,7 +235,8 @@ static int bcm47xxpart_parse(struct mtd_
  81. }
  82. /* Squashfs on devices not using TRX */
  83. - if (buf[0x000 / 4] == SQSH_MAGIC) {
  84. + if (le32_to_cpu(buf[0x000 / 4]) == SQUASHFS_MAGIC ||
  85. + buf[0x000 / 4] == SHSQ_MAGIC) {
  86. bcm47xxpart_add_part(&parts[curr_part++], "rootfs",
  87. offset, 0);
  88. continue;