[PATCH 3/3] FIT: match best configuration when multiple are compatible

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Dec 5 03:36:18 PST 2023


Currently, we match the first compatible configuration. There may be
multiple matching configurations however and we should continue looking
for a better match if a match didn't achieve maximal score.

Do that by checking score against OF_DEVICE_COMPATIBLE_MAX_SCORE and
continuing the search if unequal.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/image-fit.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 5ef5013bd41d..b16752de05bc 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -720,6 +720,7 @@ static int fit_find_compatible_unit(struct device_node *conf_node,
 {
 	struct device_node *child = NULL;
 	struct device_node *barebox_root;
+	int best_score = 0;
 	const char *machine;
 	int ret;
 
@@ -732,13 +733,21 @@ static int fit_find_compatible_unit(struct device_node *conf_node,
 		return -ENOENT;
 
 	for_each_child_of_node(conf_node, child) {
-		if (of_device_is_compatible(child, machine)) {
+		int score = of_device_is_compatible(child, machine);
+		if (score > best_score) {
+			best_score = score;
 			*unit = child->name;
-			pr_info("matching unit '%s' found\n", *unit);
-			return 0;
+
+			if (score == OF_DEVICE_COMPATIBLE_MAX_SCORE)
+				break;
 		}
 	}
 
+	if (best_score) {
+		pr_info("matching unit '%s' found\n", *unit);
+		return 0;
+	}
+
 default_unit:
 	pr_info("No match found. Trying default.\n");
 	if (of_property_read_string(conf_node, "default", unit) == 0)
-- 
2.39.2




More information about the barebox mailing list