mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 3/5] boot: give struct bootentry a path member
Date: Mon,  9 Feb 2026 10:08:53 +0100	[thread overview]
Message-ID: <20260209090911.3561875-4-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260209090911.3561875-1-a.fatoum@barebox.org>

Both bootloader spec entries and boot spec maintain a path to the file
the struct bootentry was generated from. Add this member to the struct
bootentry directly to allow referencing it from the boot command in a
follow-up commit.

No functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/blspec.c | 12 ++++--------
 common/boot.c   | 17 +++++++----------
 include/boot.h  |  1 +
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index f13e44f1de71..c07e3a2d672d 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -27,7 +27,7 @@ struct blspec_entry {
 	struct device_node *node;
 	struct cdev *cdev;
 	const char *rootpath;
-	const char *configpath;
+	/* configpath is entry.path */
 	char *sortkey;
 };
 
@@ -180,7 +180,6 @@ static void blspec_entry_free(struct bootentry *be)
 	struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
 
 	of_delete_node(entry->node);
-	free_const(entry->configpath);
 	free_const(entry->rootpath);
 	free(entry->sortkey);
 	free(entry);
@@ -305,7 +304,7 @@ static int blspec_have_entry(struct bootentries *bootentries, const char *path)
 		if (!is_blspec_entry(be))
 			continue;
 		e = container_of(be, struct blspec_entry, entry);
-		if (e->configpath && !strcmp(e->configpath, path))
+		if (e->entry.path && !strcmp(e->entry.path, path))
 			return 1;
 	}
 
@@ -426,8 +425,8 @@ static int blspec_compare(struct list_head *list_a, struct list_head *list_b)
 {
 	struct bootentry *be_a = container_of(list_a, struct bootentry, list);
 	struct bootentry *be_b = container_of(list_b, struct bootentry, list);
+	const char *a_version = be_a->path, *b_version = be_b->path;
 	struct blspec_entry *a, *b;
-	const char *a_version, *b_version;
 	int r;
 
 	/* The boot entry providers are called one by one and passed an empty
@@ -439,9 +438,6 @@ static int blspec_compare(struct list_head *list_a, struct list_head *list_b)
 	a = container_of(be_a, struct blspec_entry, entry);
 	b = container_of(be_b, struct blspec_entry, entry);
 
-	a_version = a->configpath;
-	b_version = b->configpath;
-
 	if (a->sortkey && b->sortkey) {
 		const char *a_machine_id, *b_machine_id;
 
@@ -489,7 +485,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 
 	root = root ?: get_blspec_prefix_path(configname);
 	entry->rootpath = xstrdup_const(root);
-	entry->configpath = xstrdup_const(configname);
+	entry->entry.path = xstrdup_const(configname);
 	entry->cdev = get_cdev_by_mountpath(root);
 
 	if (!entry_is_of_compatible(entry)) {
diff --git a/common/boot.c b/common/boot.c
index 2e5294ffa2f0..a325f350a80c 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -64,6 +64,7 @@ void bootentries_free(struct bootentries *bootentries)
 		list_del(&be->list);
 		free_const(be->title);
 		free(be->description);
+		free_const(be->path);
 		free_const(be->me.display);
 		be->release(be);
 	}
@@ -81,7 +82,6 @@ void bootentries_free(struct bootentries *bootentries)
 
 struct bootentry_script {
 	struct bootentry entry;
-	const char *scriptpath;
 };
 
 /*
@@ -96,7 +96,7 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 	struct bootm_data backup = {}, data = {};
 
 	if (dryrun == 1) {
-		printf("Would run %s\n", bs->scriptpath);
+		printf("Would run %s\n", bs->entry.path);
 		return 0;
 	}
 
@@ -107,9 +107,9 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 
 	bootm_nattempts = bootm_command_attempts();
 
-	ret = run_command(bs->scriptpath);
+	ret = run_command(bs->entry.path);
 	if (ret) {
-		pr_err("Running script '%s' failed: %pe\n", bs->scriptpath, ERR_PTR(ret));
+		pr_err("Running script '%s' failed: %s\n", bs->entry.path, strerror(-ret));
 		goto out;
 	}
 
@@ -222,10 +222,7 @@ static void bootsource_action(struct menu *m, struct menu_entry *me)
 
 static void bootscript_entry_release(struct bootentry *entry)
 {
-	struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
-
-	free_const(bs->scriptpath);
-	free(bs);
+	free(entry);
 }
 
 /*
@@ -248,8 +245,8 @@ static int bootscript_create_entry(struct bootentries *bootentries, const char *
 	bs->entry.me.type = MENU_ENTRY_NORMAL;
 	bs->entry.release = bootscript_entry_release;
 	bs->entry.boot = bootscript_boot;
-	bs->scriptpath = xstrdup_const(name);
-	bs->entry.title = xstrdup_const(kbasename(bs->scriptpath));
+	bs->entry.path = xstrdup_const(name);
+	bs->entry.title = xstrdup_const(kbasename(bs->entry.path));
 	bs->entry.description = basprintf("script: %s", name);
 	bootentries_add_entry(bootentries, &bs->entry);
 
diff --git a/include/boot.h b/include/boot.h
index fdc108b7a21d..836a180a0c7b 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -18,6 +18,7 @@ struct bootentry {
 	struct menu_entry me;
 	const char *title;
 	char *description;
+	const char *path;
 	int (*boot)(struct bootentry *entry, int verbose, int dryrun);
 	void (*release)(struct bootentry *entry);
 	struct bootm_overrides overrides;
-- 
2.47.3




  parent reply	other threads:[~2026-02-09  9:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09  9:08 [PATCH 0/5] blspec: sort entries according to specification Ahmad Fatoum
2026-02-09  9:08 ` [PATCH 1/5] boot: aggregate bootentry provider entries one by one Ahmad Fatoum
2026-02-09  9:08 ` [PATCH 2/5] blspec: sort entries according to specification Ahmad Fatoum
2026-02-09  9:08 ` Ahmad Fatoum [this message]
2026-02-09  9:08 ` [PATCH 4/5] commands: boot: support file path in boot -M for default entry Ahmad Fatoum
2026-02-09  9:08 ` [PATCH 5/5] test: self: add bootloader spec files test Ahmad Fatoum

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=20260209090911.3561875-4-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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