2
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. THIS METHOD HAS BEEN DEPRECATED
  8. Linux supports "compatible" property in the "partitions" subnode now. It
  9. should be used to specify partitions format (and trigger proper parser
  10. usage) if needed.
  11. Signed-off-by: Hauke Mehrtens <[email protected]>
  12. ---
  13. Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
  14. drivers/mtd/maps/physmap_of.c | 46 +-------------------------
  15. drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
  16. 3 files changed, 62 insertions(+), 45 deletions(-)
  17. --- a/Documentation/devicetree/bindings/mtd/nand.txt
  18. +++ b/Documentation/devicetree/bindings/mtd/nand.txt
  19. @@ -49,6 +49,22 @@ Optional NAND chip properties:
  20. - nand-rb: shall contain the native Ready/Busy ids.
  21. +- linux,part-probe: list of name as strings of the partition parser
  22. + which should be used to parse the partition table.
  23. + They will be tried in the specified ordering and
  24. + the next one will be used if the previous one
  25. + failed.
  26. +
  27. + Example: linux,part-probe = "cmdlinepart", "ofpart";
  28. +
  29. + This is also the default value, which will be used
  30. + if this attribute is not specified. It could be
  31. + that the flash driver in use overwrote the default
  32. + value and uses some other default.
  33. +
  34. + Possible values are: bcm47xxpart, afs, ar7part,
  35. + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
  36. +
  37. The ECC strength and ECC step size properties define the correction capability
  38. of a controller. Together, they say a controller can correct "{strength} bit
  39. errors per {size} bytes".
  40. --- a/drivers/mtd/maps/physmap_of_core.c
  41. +++ b/drivers/mtd/maps/physmap_of_core.c
  42. @@ -115,37 +115,9 @@ static struct mtd_info *obsolete_probe(s
  43. static const char * const part_probe_types_def[] = {
  44. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  45. -static const char * const *of_get_probes(struct device_node *dp)
  46. -{
  47. - const char **res;
  48. - int count;
  49. -
  50. - count = of_property_count_strings(dp, "linux,part-probe");
  51. - if (count < 0)
  52. - return part_probe_types_def;
  53. -
  54. - res = kcalloc(count + 1, sizeof(*res), GFP_KERNEL);
  55. - if (!res)
  56. - return NULL;
  57. -
  58. - count = of_property_read_string_array(dp, "linux,part-probe", res,
  59. - count);
  60. - if (count < 0)
  61. - return NULL;
  62. -
  63. - return res;
  64. -}
  65. -
  66. -static void of_free_probes(const char * const *probes)
  67. -{
  68. - if (probes != part_probe_types_def)
  69. - kfree(probes);
  70. -}
  71. -
  72. static const struct of_device_id of_flash_match[];
  73. static int of_flash_probe(struct platform_device *dev)
  74. {
  75. - const char * const *part_probe_types;
  76. const struct of_device_id *match;
  77. struct device_node *dp = dev->dev.of_node;
  78. struct resource res;
  79. @@ -316,14 +288,8 @@ static int of_flash_probe(struct platfor
  80. info->cmtd->dev.parent = &dev->dev;
  81. mtd_set_of_node(info->cmtd, dp);
  82. - part_probe_types = of_get_probes(dp);
  83. - if (!part_probe_types) {
  84. - err = -ENOMEM;
  85. - goto err_out;
  86. - }
  87. - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
  88. + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
  89. NULL, 0);
  90. - of_free_probes(part_probe_types);
  91. kfree(mtd_list);
  92. --- a/drivers/mtd/mtdpart.c
  93. +++ b/drivers/mtd/mtdpart.c
  94. @@ -29,6 +29,7 @@
  95. #include <linux/kmod.h>
  96. #include <linux/mtd/mtd.h>
  97. #include <linux/mtd/partitions.h>
  98. +#include <linux/of.h>
  99. #include <linux/err.h>
  100. #include <linux/of.h>
  101. @@ -796,6 +797,37 @@ void deregister_mtd_parser(struct mtd_pa
  102. }
  103. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  104. +#include <linux/version.h>
  105. +
  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 **res;
  114. + int count;
  115. +
  116. + count = of_property_count_strings(dp, "linux,part-probe");
  117. + if (count < 0)
  118. + return NULL;
  119. +
  120. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  121. + if (!res)
  122. + return NULL;
  123. +
  124. + count = of_property_read_string_array(dp, "linux,part-probe", res,
  125. + count);
  126. + if (count < 0)
  127. + return NULL;
  128. +
  129. + pr_warn("Support for the generic \"linux,part-probe\" has been deprecated and will be removed soon");
  130. + BUILD_BUG_ON(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0));
  131. +
  132. + return res;
  133. +}
  134. +
  135. /*
  136. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  137. * are changing this array!
  138. @@ -948,6 +980,13 @@ int parse_mtd_partitions(struct mtd_info
  139. struct mtd_partitions pparts = { };
  140. struct mtd_part_parser *parser;
  141. int ret, err = 0;
  142. + const char *const *types_of = NULL;
  143. +
  144. + if (mtd_get_of_node(master)) {
  145. + types_of = of_get_probes(mtd_get_of_node(master));
  146. + if (types_of != NULL)
  147. + types = types_of;
  148. + }
  149. if (!types)
  150. types = mtd_is_partition(master) ? default_subpartition_types :
  151. @@ -989,6 +1028,7 @@ int parse_mtd_partitions(struct mtd_info
  152. if (ret < 0 && !err)
  153. err = ret;
  154. }
  155. + kfree(types_of);
  156. return err;
  157. }