From: Stephano Cetola <stephano@cetola.net>
To: Sascha Hauer <s.hauer@pengutronix.de>,
"open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH] extlinux: resolve absolute paths against the partition root
Date: Tue, 25 Aug 2026 17:38:43 -0700 [thread overview]
Message-ID: <20260825-send-extlinux-abs-path-v1-1-910bf0a3dad1@cetola.net> (raw)
extlinux_boot() always joined a path with '/' against rootpath, which
holds the config file's own directory, not the partition root. A
KERNEL/INITRD/FDT value starting with '/', the normal syslinux way to
name a path from the partition root, got treated as relative instead.
The extlinux.conf file itself can live in a different directory than
the partition root (extlinux_scan_directory() looks in both
boot/extlinux/ and extlinux/), so this produced a wrong, nonexistent
path whenever a config used an absolute KERNEL/INITRD/FDT entry.
Track the partition root and the config file's own directory as two
separate fields, cfgdir and rootpath, and resolve a path against
rootpath if it starts with '/', or cfgdir otherwise.
Fixes: b912fa9fc3ca ("Add support for extlinux.conf")
Signed-off-by: Stephano Cetola <stephano@cetola.net>
---
common/extlinux.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/common/extlinux.c b/common/extlinux.c
index caa62923da..7a92c15e4d 100644
--- a/common/extlinux.c
+++ b/common/extlinux.c
@@ -17,6 +17,7 @@
struct extlinux_entry {
struct bootentry entry;
char *rootpath;
+ char *cfgdir;
char *label;
char *kernel;
char *initrd;
@@ -25,6 +26,19 @@ struct extlinux_entry {
char *append;
};
+/*
+ * A path starting with '/' is absolute and resolves against the
+ * partition root. Anything else is relative to the extlinux.conf
+ * file's own directory, per syslinux convention.
+ */
+static char *extlinux_make_abs(const char *rootpath, const char *cfgdir,
+ const char *relpath)
+{
+ if (relpath[0] == '/')
+ return basprintf("%s%s", rootpath, relpath);
+ return basprintf("%s/%s", cfgdir, relpath);
+}
+
static int extlinux_boot(struct bootentry *entry, int verbose, int dryrun)
{
struct extlinux_entry *e =
@@ -38,18 +52,18 @@ static int extlinux_boot(struct bootentry *entry, int verbose, int dryrun)
data.dryrun = max_t(int, dryrun, data.dryrun);
data.verbose = max(verbose, data.verbose);
- kernel_abs = basprintf("%s/%s", e->rootpath, e->kernel);
+ kernel_abs = extlinux_make_abs(e->rootpath, e->cfgdir, e->kernel);
data.os_file = kernel_abs;
if (e->initrd) {
- initrd_abs = basprintf("%s/%s", e->rootpath, e->initrd);
+ initrd_abs = extlinux_make_abs(e->rootpath, e->cfgdir, e->initrd);
data.initrd_file = initrd_abs;
}
if (e->fdt) {
- char *fdtdir = e->fdtdir ? : e->rootpath;
+ char *fdtdir = e->fdtdir ? : e->cfgdir;
- fdt_abs = basprintf("%s/%s", fdtdir, e->fdt);
+ fdt_abs = extlinux_make_abs(e->rootpath, fdtdir, e->fdt);
data.oftree_file = fdt_abs;
}
@@ -76,6 +90,7 @@ static void extlinux_entry_free(struct bootentry *entry)
container_of(entry, struct extlinux_entry, entry);
free(e->rootpath);
+ free(e->cfgdir);
free(e->label);
free(e->kernel);
free(e->initrd);
@@ -124,7 +139,8 @@ static struct extlinux_entry *parse_extlinux_conf(const char *abspath,
if (!strcmp(val, default_label)) {
entry = xzalloc(sizeof(*entry));
entry->label = xstrdup(val);
- entry->rootpath = dirname(xstrdup(abspath));
+ entry->rootpath = xstrdup(rootpath);
+ entry->cfgdir = dirname(xstrdup(abspath));
} else if (entry) {
break;
}
---
base-commit: 9bc1a26592a59919d2ee8c60c273d87d3d9f2e81
change-id: 20260822-send-extlinux-abs-path-bd9809e3dda8
next reply other threads:[~2026-08-26 0:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 0:38 Stephano Cetola [this message]
2026-08-28 10:44 ` Sascha Hauer
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=20260825-send-extlinux-abs-path-v1-1-910bf0a3dad1@cetola.net \
--to=stephano@cetola.net \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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