[PATCH] boot: allow prioritizing boot entry providers

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Dec 11 12:42:57 PST 2025


It's not unusual for an EFI system partition to both have boot loader
spec entries and an EFI application at the default payload path for
removable media.

In that case, we will want to establish a fixed order for boot entries,
so add an optional priority field for this purpose. The default priority
is 0 and providers can sort themself higher or lower.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/boot.c  | 10 +++++++++-
 include/boot.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/common/boot.c b/common/boot.c
index 1059e6d995d3..a8a92057844b 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -282,9 +282,17 @@ static int bootscript_scan_path(struct bootentries *bootentries, const char *pat
 
 static LIST_HEAD(bootentry_providers);
 
+static int bootentry_provider_sort(struct list_head *_a, struct list_head *_b)
+{
+	struct bootentry_provider *a = container_of(_a, struct bootentry_provider, list);
+	struct bootentry_provider *b = container_of(_b, struct bootentry_provider, list);
+
+	return compare3(b->priority, a->priority); /* descending order */
+}
+
 int bootentry_register_provider(struct bootentry_provider *p)
 {
-	list_add(&p->list, &bootentry_providers);
+	list_add_sort(&p->list, &bootentry_providers, bootentry_provider_sort);
 	return 0;
 }
 
diff --git a/include/boot.h b/include/boot.h
index ae32b9ead93f..e6309b65a0c3 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -28,6 +28,7 @@ int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
 struct bootentry_provider {
 	const char *name;
 	int (*generate)(struct bootentries *bootentries, const char *name);
+	int priority;
 	/* internal fields */
 	struct list_head list;
 };
-- 
2.47.3




More information about the barebox mailing list