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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. From: Hauke Mehrtens <hauke@hauke-m.de>
  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 <hauke@hauke-m.de>
  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. @@ -44,6 +44,22 @@ Optional NAND chip properties:
  20. used by the upper layers, and you want to make your NAND
  21. as reliable as possible.
  22. +- linux,part-probe: list of name as strings of the partition parser
  23. + which should be used to parse the partition table.
  24. + They will be tried in the specified ordering and
  25. + the next one will be used if the previous one
  26. + failed.
  27. +
  28. + Example: linux,part-probe = "cmdlinepart", "ofpart";
  29. +
  30. + This is also the default value, which will be used
  31. + if this attribute is not specified. It could be
  32. + that the flash driver in use overwrote the default
  33. + value and uses some other default.
  34. +
  35. + Possible values are: bcm47xxpart, afs, ar7part,
  36. + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
  37. +
  38. The ECC strength and ECC step size properties define the correction capability
  39. of a controller. Together, they say a controller can correct "{strength} bit
  40. errors per {size} bytes".
  41. --- a/drivers/mtd/maps/physmap_of_core.c
  42. +++ b/drivers/mtd/maps/physmap_of_core.c
  43. @@ -114,37 +114,9 @@ static struct mtd_info *obsolete_probe(s
  44. static const char * const part_probe_types_def[] = {
  45. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  46. -static const char * const *of_get_probes(struct device_node *dp)
  47. -{
  48. - const char **res;
  49. - int count;
  50. -
  51. - count = of_property_count_strings(dp, "linux,part-probe");
  52. - if (count < 0)
  53. - return part_probe_types_def;
  54. -
  55. - res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  56. - if (!res)
  57. - return NULL;
  58. -
  59. - count = of_property_read_string_array(dp, "linux,part-probe", res,
  60. - count);
  61. - if (count < 0)
  62. - return NULL;
  63. -
  64. - return res;
  65. -}
  66. -
  67. -static void of_free_probes(const char * const *probes)
  68. -{
  69. - if (probes != part_probe_types_def)
  70. - kfree(probes);
  71. -}
  72. -
  73. static const struct of_device_id of_flash_match[];
  74. static int of_flash_probe(struct platform_device *dev)
  75. {
  76. - const char * const *part_probe_types;
  77. const struct of_device_id *match;
  78. struct device_node *dp = dev->dev.of_node;
  79. struct resource res;
  80. @@ -310,14 +282,8 @@ static int of_flash_probe(struct platfor
  81. info->cmtd->dev.parent = &dev->dev;
  82. mtd_set_of_node(info->cmtd, dp);
  83. - part_probe_types = of_get_probes(dp);
  84. - if (!part_probe_types) {
  85. - err = -ENOMEM;
  86. - goto err_out;
  87. - }
  88. - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
  89. + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
  90. NULL, 0);
  91. - of_free_probes(part_probe_types);
  92. kfree(mtd_list);
  93. --- a/drivers/mtd/mtdpart.c
  94. +++ b/drivers/mtd/mtdpart.c
  95. @@ -29,6 +29,7 @@
  96. #include <linux/kmod.h>
  97. #include <linux/mtd/mtd.h>
  98. #include <linux/mtd/partitions.h>
  99. +#include <linux/of.h>
  100. #include <linux/err.h>
  101. #include <linux/of.h>
  102. @@ -834,6 +835,37 @@ void deregister_mtd_parser(struct mtd_pa
  103. }
  104. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  105. +#include <linux/version.h>
  106. +
  107. +/*
  108. + * Parses the linux,part-probe device tree property.
  109. + * When a non null value is returned it has to be freed with kfree() by
  110. + * the caller.
  111. + */
  112. +static const char * const *of_get_probes(struct device_node *dp)
  113. +{
  114. + const char **res;
  115. + int count;
  116. +
  117. + count = of_property_count_strings(dp, "linux,part-probe");
  118. + if (count < 0)
  119. + return NULL;
  120. +
  121. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  122. + if (!res)
  123. + return NULL;
  124. +
  125. + count = of_property_read_string_array(dp, "linux,part-probe", res,
  126. + count);
  127. + if (count < 0)
  128. + return NULL;
  129. +
  130. + pr_warn("Support for the generic \"linux,part-probe\" has been deprecated and will be removed soon");
  131. + BUILD_BUG_ON(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0));
  132. +
  133. + return res;
  134. +}
  135. +
  136. /*
  137. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  138. * are changing this array!
  139. @@ -983,6 +1015,13 @@ int parse_mtd_partitions(struct mtd_info
  140. struct mtd_partitions pparts = { };
  141. struct mtd_part_parser *parser;
  142. int ret, err = 0;
  143. + const char *const *types_of = NULL;
  144. +
  145. + if (mtd_get_of_node(master)) {
  146. + types_of = of_get_probes(mtd_get_of_node(master));
  147. + if (types_of != NULL)
  148. + types = types_of;
  149. + }
  150. if (!types)
  151. types = mtd_is_partition(master) ? default_subpartition_types :
  152. @@ -1024,6 +1063,7 @@ int parse_mtd_partitions(struct mtd_info
  153. if (ret < 0 && !err)
  154. err = ret;
  155. }
  156. + kfree(types_of);
  157. return err;
  158. }