[Concept,v2,12/15] boot: Don't change the method count after global bootmeths

Message ID 20250930232611.1564850-13-sjg@u-boot.org
State New
Headers
Series boot: Support priority for global bootmeths |

Commit Message

Simon Glass Sept. 30, 2025, 11:25 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

At present before scanning global bootmeths, the iterator sets the
method count to the index of the first global bootmeth. Now that we
support scanning the global bootmeths multiple times, we must leave this
count alone.

Check against have_global and first_glob_method instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 boot/bootflow.c      | 18 ++++++++++++++----
 test/boot/bootflow.c |  6 +++---
 2 files changed, 17 insertions(+), 7 deletions(-)
  

Patch

diff --git a/boot/bootflow.c b/boot/bootflow.c
index bdae861a96c..98d57ef017e 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -366,9 +366,20 @@  static int iter_incr(struct bootflow_iter *iter)
 	for (iter->cur_method++; iter->cur_method < iter->num_methods;
 	     iter->cur_method++) {
 		/* loop until we find a global bootmeth we haven't used */
-		if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && iter->doing_global &&
-		    !bootmeth_glob_allowed(iter, iter->cur_method))
-			continue;
+		if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && iter->doing_global) {
+			if (!bootmeth_glob_allowed(iter, iter->cur_method))
+				continue;
+
+			iter->method = iter->method_order[iter->cur_method];
+			log_debug("-> next global method '%s'\n",
+				  iter->method->name);
+			return 0;
+		}
+
+		/* at this point we are only considering non-global bootmeths */
+		if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && iter->have_global &&
+		    iter->cur_method >= iter->first_glob_method)
+			break;
 
 		iter->method = iter->method_order[iter->cur_method];
 		log_debug("-> next method '%s'\n", iter->method->name);
@@ -382,7 +393,6 @@  static int iter_incr(struct bootflow_iter *iter)
 	 * normal bootdev scan
 	 */
 	if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && global) {
-		iter->num_methods = iter->first_glob_method;
 		iter->doing_global = false;
 
 		/*
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index af7f7391160..ceab3c453c4 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -467,7 +467,7 @@  static int bootflow_iter_glob(struct unit_test_state *uts)
 	ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow));
 
 	/* at this point the global bootmeths are stranded above num_methods */
-	ut_asserteq(3, iter.num_methods);
+	ut_asserteq(4, iter.num_methods);
 	ut_asserteq(3, iter.first_glob_method);
 	ut_assert(!iter.doing_global);
 	ut_assert(iter.have_global);
@@ -534,7 +534,7 @@  static int bootflow_iter_disable(struct unit_test_state *uts)
 	ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
 
 	/* at this point the global bootmeths are stranded above num_methods */
-	ut_asserteq(4, iter.num_methods);
+	ut_asserteq(5, iter.num_methods);
 	ut_assert(!iter.doing_global);
 	ut_assert(iter.have_global);
 	ut_asserteq(4, iter.first_glob_method);
@@ -546,7 +546,7 @@  static int bootflow_iter_disable(struct unit_test_state *uts)
 	ut_assert_console_end();
 
 	/* Check that the sandbox bootmeth has been removed */
-	ut_asserteq(3, iter.num_methods);
+	ut_asserteq(4, iter.num_methods);
 
 	for (i = 0; i < iter.num_methods; i++)
 		ut_assert(strcmp("sandbox", iter.method_order[i]->name));