161-mtd-part-add-generic-parsing-of-linux-part-probe.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From: Hauke Mehrtens <[email protected]>
  2. Subject: mtd: part: add generic parsing of linux,part-probe
  3. This moves the linux,part-probe device tree parsing code from
  4. physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
  5. providing a reference to their device tree node in struct
  6. mtd_part_parser_data.
  7. Signed-off-by: Hauke Mehrtens <[email protected]>
  8. ---
  9. Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
  10. drivers/mtd/maps/physmap_of.c | 46 +-------------------------
  11. drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
  12. 3 files changed, 62 insertions(+), 45 deletions(-)
  13. --- a/Documentation/devicetree/bindings/mtd/nand.txt
  14. +++ b/Documentation/devicetree/bindings/mtd/nand.txt
  15. @@ -44,6 +44,22 @@ Optional NAND chip properties:
  16. used by the upper layers, and you want to make your NAND
  17. as reliable as possible.
  18. +- linux,part-probe: list of name as strings of the partition parser
  19. + which should be used to parse the partition table.
  20. + They will be tried in the specified ordering and
  21. + the next one will be used if the previous one
  22. + failed.
  23. +
  24. + Example: linux,part-probe = "cmdlinepart", "ofpart";
  25. +
  26. + This is also the default value, which will be used
  27. + if this attribute is not specified. It could be
  28. + that the flash driver in use overwrote the default
  29. + value and uses some other default.
  30. +
  31. + Possible values are: bcm47xxpart, afs, ar7part,
  32. + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
  33. +
  34. The ECC strength and ECC step size properties define the correction capability
  35. of a controller. Together, they say a controller can correct "{strength} bit
  36. errors per {size} bytes".
  37. --- a/drivers/mtd/maps/physmap_of.c
  38. +++ b/drivers/mtd/maps/physmap_of.c
  39. @@ -113,47 +113,9 @@ static struct mtd_info *obsolete_probe(s
  40. static const char * const part_probe_types_def[] = {
  41. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  42. -static const char * const *of_get_probes(struct device_node *dp)
  43. -{
  44. - const char *cp;
  45. - int cplen;
  46. - unsigned int l;
  47. - unsigned int count;
  48. - const char **res;
  49. -
  50. - cp = of_get_property(dp, "linux,part-probe", &cplen);
  51. - if (cp == NULL)
  52. - return part_probe_types_def;
  53. -
  54. - count = 0;
  55. - for (l = 0; l != cplen; l++)
  56. - if (cp[l] == 0)
  57. - count++;
  58. -
  59. - res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
  60. - if (!res)
  61. - return NULL;
  62. - count = 0;
  63. - while (cplen > 0) {
  64. - res[count] = cp;
  65. - l = strlen(cp) + 1;
  66. - cp += l;
  67. - cplen -= l;
  68. - count++;
  69. - }
  70. - return res;
  71. -}
  72. -
  73. -static void of_free_probes(const char * const *probes)
  74. -{
  75. - if (probes != part_probe_types_def)
  76. - kfree(probes);
  77. -}
  78. -
  79. static const struct of_device_id of_flash_match[];
  80. static int of_flash_probe(struct platform_device *dev)
  81. {
  82. - const char * const *part_probe_types;
  83. const struct of_device_id *match;
  84. struct device_node *dp = dev->dev.of_node;
  85. struct resource res;
  86. @@ -317,14 +279,8 @@ static int of_flash_probe(struct platfor
  87. info->cmtd->dev.parent = &dev->dev;
  88. mtd_set_of_node(info->cmtd, dp);
  89. - part_probe_types = of_get_probes(dp);
  90. - if (!part_probe_types) {
  91. - err = -ENOMEM;
  92. - goto err_out;
  93. - }
  94. - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
  95. + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
  96. NULL, 0);
  97. - of_free_probes(part_probe_types);
  98. kfree(mtd_list);
  99. --- a/drivers/mtd/mtdpart.c
  100. +++ b/drivers/mtd/mtdpart.c
  101. @@ -29,6 +29,7 @@
  102. #include <linux/kmod.h>
  103. #include <linux/mtd/mtd.h>
  104. #include <linux/mtd/partitions.h>
  105. +#include <linux/of.h>
  106. #include <linux/err.h>
  107. #include <linux/of.h>
  108. @@ -827,6 +828,42 @@ void deregister_mtd_parser(struct mtd_pa
  109. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  110. /*
  111. + * Parses the linux,part-probe device tree property.
  112. + * When a non null value is returned it has to be freed with kfree() by
  113. + * the caller.
  114. + */
  115. +static const char * const *of_get_probes(struct device_node *dp)
  116. +{
  117. + const char *cp;
  118. + int cplen;
  119. + unsigned int l;
  120. + unsigned int count;
  121. + const char **res;
  122. +
  123. + cp = of_get_property(dp, "linux,part-probe", &cplen);
  124. + if (cp == NULL)
  125. + return NULL;
  126. +
  127. + count = 0;
  128. + for (l = 0; l != cplen; l++)
  129. + if (cp[l] == 0)
  130. + count++;
  131. +
  132. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  133. + if (!res)
  134. + return NULL;
  135. + count = 0;
  136. + while (cplen > 0) {
  137. + res[count] = cp;
  138. + l = strlen(cp) + 1;
  139. + cp += l;
  140. + cplen -= l;
  141. + count++;
  142. + }
  143. + return res;
  144. +}
  145. +
  146. +/*
  147. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  148. * are changing this array!
  149. */
  150. @@ -975,6 +1012,13 @@ int parse_mtd_partitions(struct mtd_info
  151. struct mtd_partitions pparts = { };
  152. struct mtd_part_parser *parser;
  153. int ret, err = 0;
  154. + const char *const *types_of = NULL;
  155. +
  156. + if (mtd_get_of_node(master)) {
  157. + types_of = of_get_probes(mtd_get_of_node(master));
  158. + if (types_of != NULL)
  159. + types = types_of;
  160. + }
  161. if (!types)
  162. types = mtd_is_partition(master) ? default_subpartition_types :
  163. @@ -1016,6 +1060,7 @@ int parse_mtd_partitions(struct mtd_info
  164. if (ret < 0 && !err)
  165. err = ret;
  166. }
  167. + kfree(types_of);
  168. return err;
  169. }