mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] boot: allow prioritizing boot entry providers
Date: Thu, 11 Dec 2025 21:42:57 +0100	[thread overview]
Message-ID: <20251211204257.2605869-1-a.fatoum@pengutronix.de> (raw)

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@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




                 reply	other threads:[~2025-12-11 20:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211204257.2605869-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox