boot: Implement a priority for global bootmeths
authorSimon Glass <sjg@chromium.org>
Wed, 15 Oct 2025 15:44:11 +0000 (16:44 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 22 Oct 2025 20:16:56 +0000 (14:16 -0600)
Allow bootmeths to select when they want to run, using the bootdev
priority. Provide a new bootmeth_glob_allowed() function which checks if
a bootmeth is ready to use.

Fix a comment in bootflow_system() which is a test for global bootmeths.

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

index ca1fe74..1a4cd0e 100644 (file)
@@ -191,17 +191,24 @@ static void scan_next_in_uclass(struct udevice **devp)
  * bootmeth_glob_allowed() - Check if a global bootmeth is usable at this point
  *
  * @iter: Bootflow iterator being used
- * Return: true if the global bootmeth has not already been used
+ * Return: true if the global bootmeth has a suitable priority and has not
+ * already been used
  */
 static bool bootmeth_glob_allowed(struct bootflow_iter *iter, int meth_seq)
 {
        struct udevice *meth = iter->method_order[meth_seq];
        bool done = iter->methods_done & BIT(meth_seq);
+       struct bootmeth_uc_plat *ucp;
 
-       log_debug("considering glob '%s': done %d\n", meth->name, done);
+       ucp = dev_get_uclass_plat(meth);
+       log_debug("considering glob '%s': done %d glob_prio %d\n", meth->name,
+                 done, ucp->glob_prio);
 
-       /* if this one has already been used, try the next */
-       if (done)
+       /*
+        * if this one has already been used, or its priority is too low, try
+        * the next
+        */
+       if (done || ucp->glob_prio > iter->cur_prio)
                return false;
 
        return true;
index 059d382..1cfdda4 100644 (file)
@@ -262,7 +262,7 @@ enum {
  *     appear first, then the global ones, if any
  * @have_global: true if we have global bootmeths in @method_order[]
  * @doing_global: true if we are iterating through the global bootmeths (which
- *     happens before the normal ones)
+ *     generally happens before the normal ones)
  * @method_flags: flags controlling which methods should be used for this @dev
  * (enum bootflow_meth_flags_t)
  * @methods_done: indicates which methods have been processed, one bit for
index 26de593..2a492df 100644 (file)
@@ -30,10 +30,14 @@ enum bootmeth_flags {
  *
  * @desc: A long description of the bootmeth
  * @flags: Flags for this bootmeth (enum bootmeth_flags)
+ * @glob_prio: Priority for this bootmeth. If unset (0) the bootmeth is started
+ * before all other bootmeths. Otherwise it is started before the iteration
+ * reaches the given priority.
  */
 struct bootmeth_uc_plat {
        const char *desc;
        int flags;
+       enum bootdev_prio_t glob_prio;
 };
 
 /** struct bootmeth_ops - Operations for boot methods */