140-mtd-part-add-generic-parsing-of-linux-part-probe.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. From 173b0add0cff6558f950c0cb1eacfb729d482711 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Sun, 17 May 2015 18:48:38 +0200
  4. Subject: [PATCH 4/8] mtd: part: add generic parsing of linux,part-probe
  5. This moves the linux,part-probe device tree parsing code from
  6. physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
  7. providing a reference to their device tree node in struct
  8. mtd_part_parser_data.
  9. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  10. ---
  11. Documentation/devicetree/bindings/mtd/nand.txt | 16 ++++++++++
  12. drivers/mtd/maps/physmap_of.c | 40 +-----------------------
  13. drivers/mtd/mtdpart.c | 43 ++++++++++++++++++++++++++
  14. 3 files changed, 60 insertions(+), 39 deletions(-)
  15. --- a/Documentation/devicetree/bindings/mtd/nand.txt
  16. +++ b/Documentation/devicetree/bindings/mtd/nand.txt
  17. @@ -12,6 +12,22 @@
  18. - nand-ecc-step-size: integer representing the number of data bytes
  19. that are covered by a single ECC step.
  20. +- linux,part-probe: list of name as strings of the partition parser
  21. + which should be used to parse the partition table.
  22. + They will be tried in the specified ordering and
  23. + the next one will be used if the previous one
  24. + failed.
  25. +
  26. + Example: linux,part-probe = "cmdlinepart", "ofpart";
  27. +
  28. + This is also the default value, which will be used
  29. + if this attribute is not specified. It could be
  30. + that the flash driver in use overwrote the default
  31. + value and uses some other default.
  32. +
  33. + Possible values are: bcm47xxpart, afs, ar7part,
  34. + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
  35. +
  36. The ECC strength and ECC step size properties define the correction capability
  37. of a controller. Together, they say a controller can correct "{strength} bit
  38. errors per {size} bytes".
  39. --- a/drivers/mtd/maps/physmap_of.c
  40. +++ b/drivers/mtd/maps/physmap_of.c
  41. @@ -114,45 +114,9 @@ static struct mtd_info *obsolete_probe(s
  42. static const char * const part_probe_types_def[] = {
  43. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  44. -static const char * const *of_get_probes(struct device_node *dp)
  45. -{
  46. - const char *cp;
  47. - int cplen;
  48. - unsigned int l;
  49. - unsigned int count;
  50. - const char **res;
  51. -
  52. - cp = of_get_property(dp, "linux,part-probe", &cplen);
  53. - if (cp == NULL)
  54. - return part_probe_types_def;
  55. -
  56. - count = 0;
  57. - for (l = 0; l != cplen; l++)
  58. - if (cp[l] == 0)
  59. - count++;
  60. -
  61. - res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
  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 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. @@ -302,10 +266,8 @@ static int of_flash_probe(struct platfor
  87. goto err_out;
  88. ppdata.of_node = dp;
  89. - part_probe_types = of_get_probes(dp);
  90. - mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
  91. + mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
  92. NULL, 0);
  93. - of_free_probes(part_probe_types);
  94. kfree(mtd_list);
  95. --- a/drivers/mtd/mtdpart.c
  96. +++ b/drivers/mtd/mtdpart.c
  97. @@ -29,6 +29,7 @@
  98. #include <linux/kmod.h>
  99. #include <linux/mtd/mtd.h>
  100. #include <linux/mtd/partitions.h>
  101. +#include <linux/of.h>
  102. #include <linux/err.h>
  103. #include "mtdcore.h"
  104. @@ -702,6 +703,40 @@ void deregister_mtd_parser(struct mtd_pa
  105. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  106. /*
  107. + * Parses the linux,part-probe device tree property.
  108. + * When a non null value is returned it has to be freed with kfree() by
  109. + * the caller.
  110. + */
  111. +static const char * const *of_get_probes(struct device_node *dp)
  112. +{
  113. + const char *cp;
  114. + int cplen;
  115. + unsigned int l;
  116. + unsigned int count;
  117. + const char **res;
  118. +
  119. + cp = of_get_property(dp, "linux,part-probe", &cplen);
  120. + if (cp == NULL)
  121. + return NULL;
  122. +
  123. + count = 0;
  124. + for (l = 0; l != cplen; l++)
  125. + if (cp[l] == 0)
  126. + count++;
  127. +
  128. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  129. + count = 0;
  130. + while (cplen > 0) {
  131. + res[count] = cp;
  132. + l = strlen(cp) + 1;
  133. + cp += l;
  134. + cplen -= l;
  135. + count++;
  136. + }
  137. + return res;
  138. +}
  139. +
  140. +/*
  141. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  142. * are changing this array!
  143. */
  144. @@ -737,6 +772,13 @@ int parse_mtd_partitions(struct mtd_info
  145. {
  146. struct mtd_part_parser *parser;
  147. int ret = 0;
  148. + const char *const *types_of = NULL;
  149. +
  150. + if (data && data->of_node) {
  151. + types_of = of_get_probes(data->of_node);
  152. + if (types_of != NULL)
  153. + types = types_of;
  154. + }
  155. if (!types)
  156. types = default_mtd_part_types;
  157. @@ -755,6 +797,7 @@ int parse_mtd_partitions(struct mtd_info
  158. break;
  159. }
  160. }
  161. + kfree(types_of);
  162. return ret;
  163. }