120-mtd-add-of_match_table-parsing-for-partition-parsers.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 53980645bb12bd8723ac226805ee171780b24196 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <[email protected]>
  3. Date: Mon, 26 Jun 2017 13:37:11 +0200
  4. Subject: [PATCH 1/4] mtd: add of_match_table parsing for partition parsers
  5. Allow partition parsers to be matched by attaching compatible strings to
  6. partitions.
  7. This allows specifying the expected format of flash partitions for
  8. matching partition parsers.
  9. Example:
  10. flash@foo {
  11. ...
  12. partitions {
  13. compatible = "fixed-partitions";
  14. cfe@0 {
  15. reg = <0x0 0x10000>;
  16. label = "cfe";
  17. read-only;
  18. };
  19. firmware@10000 {
  20. reg = <0x10000 0x3e0000>;
  21. label = "firmware";
  22. compatible = "brcm,bcm63xx-imagetag";
  23. };
  24. nvram@3f0000 {
  25. reg = <0x3e0000 0x10000>;
  26. label = "nvram";
  27. };
  28. };
  29. };
  30. Signed-off-by: Jonas Gorski <[email protected]>
  31. ---
  32. drivers/mtd/mtdpart.c | 12 ++++++++----
  33. 1 file changed, 8 insertions(+), 4 deletions(-)
  34. --- a/drivers/mtd/mtdpart.c
  35. +++ b/drivers/mtd/mtdpart.c
  36. @@ -953,8 +953,7 @@ int add_mtd_partitions(struct mtd_info *
  37. add_mtd_device(&slave->mtd);
  38. mtd_partition_split(master, slave);
  39. mtd_add_partition_attrs(slave);
  40. - if (parts[i].types)
  41. - mtd_parse_part(slave, parts[i].types);
  42. + mtd_parse_part(slave, parts[i].types);
  43. cur_offset = slave->offset + slave->mtd.size;
  44. }
  45. @@ -1164,7 +1163,9 @@ int parse_mtd_partitions(struct mtd_info
  46. types = types_of;
  47. }
  48. - np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
  49. + np = mtd_get_of_node(master);
  50. + if (!mtd_is_partition(master))
  51. + np = of_get_child_by_name(np, "partitions");
  52. of_property_for_each_string(np, "compatible", prop, compat) {
  53. parser = mtd_part_get_compatible_parser(compat);
  54. if (!parser)
  55. @@ -1180,8 +1181,12 @@ int parse_mtd_partitions(struct mtd_info
  56. }
  57. of_node_put(np);
  58. - if (!types)
  59. + if (!types) {
  60. + if (mtd_is_partition(master))
  61. + return -ENOENT;
  62. +
  63. types = default_mtd_part_types;
  64. + }
  65. for ( ; *types; types++) {
  66. pr_debug("%s: parsing partitions %s\n", master->name, *types);