]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
boot: Update first_glob_method when dropping a bootmeth
authorSimon Glass <sjg@chromium.org>
Wed, 15 Oct 2025 15:44:06 +0000 (16:44 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 22 Oct 2025 20:16:56 +0000 (14:16 -0600)
For now we only support dropping non-global bootmeths from the
iteration. Update first_glob_method in that case and add a few checks
that things are correct.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootflow.c
test/boot/bootflow.c

index deb5f42ba656f635892f1e2793c3be4d337e2702..62634a59a94a0b39500de0815c1d6f40111e2e5c 100644 (file)
@@ -109,11 +109,17 @@ int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter,
            iter->method_order[iter->cur_method] != bmeth)
                return -EINVAL;
 
+       log_debug("Dropping bootmeth '%s'\n", bmeth->name);
+
        memmove(&iter->method_order[iter->cur_method],
                &iter->method_order[iter->cur_method + 1],
                (iter->num_methods - iter->cur_method - 1) * sizeof(void *));
 
        iter->num_methods--;
+       if (iter->first_glob_method > 0) {
+               iter->first_glob_method--;
+               log_debug("first_glob_method %d\n", iter->first_glob_method);
+       }
 
        return 0;
 }
index f3386a1eb3120a41c07e4e535fcf957c9a7371fc..07bf239485ce613c128b9f2bbb05d00a1bf0a789 100644 (file)
@@ -482,7 +482,11 @@ static int bootflow_iter_disable(struct unit_test_state *uts)
        /* Try to boot the bootmgr flow, which will fail */
        console_record_reset_enable();
        ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
+
+       /* at this point the global bootmeths are stranded above num_methods */
        ut_asserteq(3, iter.num_methods);
+       ut_assert(!iter.doing_global);
+       ut_asserteq(3, iter.first_glob_method);
        ut_asserteq_str("sandbox", iter.method->name);
        ut_assertok(inject_response(uts));
        ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow));
@@ -492,9 +496,13 @@ static int bootflow_iter_disable(struct unit_test_state *uts)
 
        /* Check that the sandbox bootmeth has been removed */
        ut_asserteq(2, iter.num_methods);
+
        for (i = 0; i < iter.num_methods; i++)
                ut_assert(strcmp("sandbox", iter.method_order[i]->name));
 
+       /* the first global bootmeth is now down one place in the list */
+       ut_asserteq(2, iter.first_glob_method);
+
        return 0;
 }
 BOOTSTD_TEST(bootflow_iter_disable, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);