417-MTD-bcm63xxpart-allow-passing-a-caldata-offset.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. Allow bcm63xxpart to receive a caldata offset if calibration data is
  2. contained in flash.
  3. ---
  4. drivers/mtd/bcm63xxpart.c | 51 ++++++++++++++++++++++++++++++++++++---
  5. include/linux/mtd/partitions.h | 2 +
  6. 2 files changed, 49 insertions(+), 4 deletions(-)
  7. --- a/drivers/mtd/bcm63xxpart.c
  8. +++ b/drivers/mtd/bcm63xxpart.c
  9. @@ -53,10 +53,12 @@ static int bcm63xx_parse_cfe_partitions(
  10. struct mtd_partition *parts;
  11. int ret;
  12. size_t retlen;
  13. - unsigned int rootfsaddr, kerneladdr, spareaddr;
  14. + unsigned int rootfsaddr, kerneladdr, spareaddr, nvramaddr;
  15. unsigned int rootfslen, kernellen, sparelen, totallen;
  16. unsigned int cfelen, nvramlen;
  17. unsigned int cfe_erasesize;
  18. + unsigned int caldatalen1 = 0, caldataaddr1 = 0;
  19. + unsigned int caldatalen2 = 0, caldataaddr2 = 0;
  20. int i;
  21. u32 computed_crc;
  22. bool rootfs_first = false;
  23. @@ -70,6 +72,24 @@ static int bcm63xx_parse_cfe_partitions(
  24. cfelen = cfe_erasesize;
  25. nvramlen = bcm63xx_nvram_get_psi_size() * SZ_1K;
  26. nvramlen = roundup(nvramlen, cfe_erasesize);
  27. + nvramaddr = master->size - nvramlen;
  28. +
  29. + if (data) {
  30. + if (data->caldata[0]) {
  31. + caldatalen1 = cfe_erasesize;
  32. + caldataaddr1 = rounddown(data->caldata[0],
  33. + cfe_erasesize);
  34. + }
  35. + if (data->caldata[1]) {
  36. + caldatalen2 = cfe_erasesize;
  37. + caldataaddr2 = rounddown(data->caldata[1],
  38. + cfe_erasesize);
  39. + }
  40. + if (caldataaddr1 == caldataaddr2) {
  41. + caldataaddr2 = 0;
  42. + caldatalen2 = 0;
  43. + }
  44. + }
  45. /* Allocate memory for buffer */
  46. buf = vmalloc(sizeof(struct bcm_tag));
  47. @@ -121,7 +141,7 @@ static int bcm63xx_parse_cfe_partitions(
  48. rootfsaddr = 0;
  49. spareaddr = cfelen;
  50. }
  51. - sparelen = master->size - spareaddr - nvramlen;
  52. + sparelen = min_not_zero(nvramaddr, caldataaddr1) - spareaddr;
  53. /* Determine number of partitions */
  54. if (rootfslen > 0)
  55. @@ -130,6 +150,12 @@ static int bcm63xx_parse_cfe_partitions(
  56. if (kernellen > 0)
  57. nrparts++;
  58. + if (caldatalen1 > 0)
  59. + nrparts++;
  60. +
  61. + if (caldatalen2 > 0)
  62. + nrparts++;
  63. +
  64. /* Ask kernel for more memory */
  65. parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL);
  66. if (!parts) {
  67. @@ -167,15 +193,32 @@ static int bcm63xx_parse_cfe_partitions(
  68. curpart++;
  69. }
  70. + if (caldatalen1 > 0) {
  71. + if (caldatalen2 > 0)
  72. + parts[curpart].name = "cal_data1";
  73. + else
  74. + parts[curpart].name = "cal_data";
  75. + parts[curpart].offset = caldataaddr1;
  76. + parts[curpart].size = caldatalen1;
  77. + curpart++;
  78. + }
  79. +
  80. + if (caldatalen2 > 0) {
  81. + parts[curpart].name = "cal_data2";
  82. + parts[curpart].offset = caldataaddr2;
  83. + parts[curpart].size = caldatalen2;
  84. + curpart++;
  85. + }
  86. +
  87. parts[curpart].name = "nvram";
  88. - parts[curpart].offset = master->size - nvramlen;
  89. + parts[curpart].offset = nvramaddr;
  90. parts[curpart].size = nvramlen;
  91. curpart++;
  92. /* Global partition "linux" to make easy firmware upgrade */
  93. parts[curpart].name = "linux";
  94. parts[curpart].offset = cfelen;
  95. - parts[curpart].size = master->size - cfelen - nvramlen;
  96. + parts[curpart].size = min_not_zero(nvramaddr, caldataaddr1) - cfelen;
  97. for (i = 0; i < nrparts; i++)
  98. pr_info("Partition %d is %s offset %llx and length %llx\n", i,
  99. --- a/include/linux/mtd/partitions.h
  100. +++ b/include/linux/mtd/partitions.h
  101. @@ -56,10 +56,12 @@ struct device_node;
  102. /**
  103. * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
  104. * @origin: for RedBoot, start address of MTD device
  105. + * @caldata: for CFE, start address of wifi calibration data
  106. * @of_node: for OF parsers, device node containing partitioning information
  107. */
  108. struct mtd_part_parser_data {
  109. unsigned long origin;
  110. + unsigned long caldata[2];
  111. struct device_node *of_node;
  112. };