0101-find_active_root.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --- a/drivers/mtd/parsers/ofpart.c
  2. +++ b/drivers/mtd/parsers/ofpart.c
  3. @@ -21,6 +21,38 @@ static bool node_has_compatible(struct d
  4. return of_get_property(pp, "compatible", NULL);
  5. }
  6. +static uint8_t * brnboot_get_selected_root_part(struct mtd_info *master,
  7. + loff_t offset)
  8. +{
  9. + static uint8_t root_id;
  10. + int err, len;
  11. +
  12. + err = mtd_read(master, offset, 0x01, &len, &root_id);
  13. +
  14. + if (mtd_is_bitflip(err) || !err)
  15. + return &root_id;
  16. +
  17. + return NULL;
  18. +}
  19. +
  20. +static void brnboot_set_active_root_part(struct mtd_partition *pparts,
  21. + struct device_node **part_nodes,
  22. + int nr_parts,
  23. + uint8_t *root_id)
  24. +{
  25. + int i;
  26. +
  27. + for (i = 0; i < nr_parts; i++) {
  28. + int part_root_id;
  29. +
  30. + if (!of_property_read_u32(part_nodes[i], "brnboot,root-id", &part_root_id)
  31. + && part_root_id == *root_id) {
  32. + pparts[i].name = "firmware";
  33. + break;
  34. + }
  35. + }
  36. +}
  37. +
  38. static int parse_fixed_partitions(struct mtd_info *master,
  39. const struct mtd_partition **pparts,
  40. struct mtd_part_parser_data *data)
  41. @@ -32,7 +64,8 @@ static int parse_fixed_partitions(struct
  42. struct device_node *pp;
  43. int nr_parts, i, ret = 0;
  44. bool dedicated = true;
  45. -
  46. + uint8_t *proot_id = NULL;
  47. + struct device_node **part_nodes;
  48. /* Pull of_node from the master device node */
  49. mtd_node = mtd_get_of_node(master);
  50. @@ -68,7 +101,9 @@ static int parse_fixed_partitions(struct
  51. return 0;
  52. parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
  53. - if (!parts)
  54. + part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL);
  55. +
  56. + if (!parts || !part_nodes)
  57. return -ENOMEM;
  58. i = 0;
  59. @@ -117,12 +152,22 @@ static int parse_fixed_partitions(struct
  60. if (of_get_property(pp, "lock", &len))
  61. parts[i].mask_flags |= MTD_POWERUP_LOCK;
  62. + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
  63. + proot_id = brnboot_get_selected_root_part(master, parts[i].offset);
  64. +
  65. + part_nodes[i] = pp;
  66. +
  67. i++;
  68. }
  69. if (!nr_parts)
  70. goto ofpart_none;
  71. + if (proot_id)
  72. + brnboot_set_active_root_part(parts, part_nodes, nr_parts, proot_id);
  73. +
  74. + kfree(part_nodes);
  75. +
  76. *pparts = parts;
  77. return nr_parts;
  78. @@ -133,6 +178,7 @@ ofpart_fail:
  79. ofpart_none:
  80. of_node_put(pp);
  81. kfree(parts);
  82. + kfree(part_nodes);
  83. return ret;
  84. }