0101-find_active_root.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --- a/drivers/mtd/ofpart.c
  2. +++ b/drivers/mtd/ofpart.c
  3. @@ -25,6 +25,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_ofpart_partitions(struct mtd_info *master,
  39. struct mtd_partition **pparts,
  40. struct mtd_part_parser_data *data)
  41. @@ -35,7 +67,8 @@ static int parse_ofpart_partitions(struc
  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. if (!data)
  49. return 0;
  50. @@ -73,7 +106,9 @@ static int parse_ofpart_partitions(struc
  51. return 0;
  52. *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL);
  53. - if (!*pparts)
  54. + part_nodes = kzalloc(nr_parts * sizeof(*part_nodes), GFP_KERNEL);
  55. +
  56. + if (!*pparts || !part_nodes)
  57. return -ENOMEM;
  58. i = 0;
  59. @@ -121,12 +156,22 @@ static int parse_ofpart_partitions(struc
  60. if (of_get_property(pp, "lock", &len))
  61. (*pparts)[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, (*pparts)[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(*pparts, part_nodes, nr_parts, proot_id);
  73. +
  74. + kfree(part_nodes);
  75. +
  76. return nr_parts;
  77. ofpart_fail:
  78. @@ -136,6 +181,7 @@ ofpart_fail:
  79. ofpart_none:
  80. of_node_put(pp);
  81. kfree(*pparts);
  82. + kfree(part_nodes);
  83. *pparts = NULL;
  84. return ret;
  85. }