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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. From 3e7056c3a369e9ef9ca804bc626b60ef6b62ee27 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 2/3] 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 | 46 +-------------------------
  13. drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
  14. 3 files changed, 62 insertions(+), 45 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. @@ -112,47 +112,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. - if (!res)
  63. - return NULL;
  64. - count = 0;
  65. - while (cplen > 0) {
  66. - res[count] = cp;
  67. - l = strlen(cp) + 1;
  68. - cp += l;
  69. - cplen -= l;
  70. - count++;
  71. - }
  72. - return res;
  73. -}
  74. -
  75. -static void of_free_probes(const char * const *probes)
  76. -{
  77. - if (probes != part_probe_types_def)
  78. - kfree(probes);
  79. -}
  80. -
  81. static const struct of_device_id of_flash_match[];
  82. static int of_flash_probe(struct platform_device *dev)
  83. {
  84. - const char * const *part_probe_types;
  85. const struct of_device_id *match;
  86. struct device_node *dp = dev->dev.of_node;
  87. struct resource res;
  88. @@ -311,14 +273,8 @@ static int of_flash_probe(struct platfor
  89. goto err_out;
  90. ppdata.of_node = dp;
  91. - part_probe_types = of_get_probes(dp);
  92. - if (!part_probe_types) {
  93. - err = -ENOMEM;
  94. - goto err_out;
  95. - }
  96. - mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
  97. + mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
  98. NULL, 0);
  99. - of_free_probes(part_probe_types);
  100. kfree(mtd_list);
  101. --- a/drivers/mtd/mtdpart.c
  102. +++ b/drivers/mtd/mtdpart.c
  103. @@ -29,6 +29,7 @@
  104. #include <linux/kmod.h>
  105. #include <linux/mtd/mtd.h>
  106. #include <linux/mtd/partitions.h>
  107. +#include <linux/of.h>
  108. #include <linux/err.h>
  109. #include <linux/kconfig.h>
  110. @@ -721,6 +722,42 @@ void deregister_mtd_parser(struct mtd_pa
  111. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  112. /*
  113. + * Parses the linux,part-probe device tree property.
  114. + * When a non null value is returned it has to be freed with kfree() by
  115. + * the caller.
  116. + */
  117. +static const char * const *of_get_probes(struct device_node *dp)
  118. +{
  119. + const char *cp;
  120. + int cplen;
  121. + unsigned int l;
  122. + unsigned int count;
  123. + const char **res;
  124. +
  125. + cp = of_get_property(dp, "linux,part-probe", &cplen);
  126. + if (cp == NULL)
  127. + return NULL;
  128. +
  129. + count = 0;
  130. + for (l = 0; l != cplen; l++)
  131. + if (cp[l] == 0)
  132. + count++;
  133. +
  134. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  135. + if (!res)
  136. + return NULL;
  137. + count = 0;
  138. + while (cplen > 0) {
  139. + res[count] = cp;
  140. + l = strlen(cp) + 1;
  141. + cp += l;
  142. + cplen -= l;
  143. + count++;
  144. + }
  145. + return res;
  146. +}
  147. +
  148. +/*
  149. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  150. * are changing this array!
  151. */
  152. @@ -756,6 +793,13 @@ int parse_mtd_partitions(struct mtd_info
  153. {
  154. struct mtd_part_parser *parser;
  155. int ret, err = 0;
  156. + const char *const *types_of = NULL;
  157. +
  158. + if (data && data->of_node) {
  159. + types_of = of_get_probes(data->of_node);
  160. + if (types_of != NULL)
  161. + types = types_of;
  162. + }
  163. if (!types)
  164. types = default_mtd_part_types;
  165. @@ -785,6 +829,7 @@ int parse_mtd_partitions(struct mtd_info
  166. if (ret < 0 && !err)
  167. err = ret;
  168. }
  169. + kfree(types_of);
  170. return err;
  171. }