Skip to contentSkip to conversation

blspec: derive root prefix from blspec config path instead of mountpoint

PATCH Applied [email protected] 4 participants 5 messages Nov 14, 2025 – Dec 8, 2025 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blspec: derive root prefix from blspec config path instead of mountpoint

From: Chali Anis <[email protected]>

Add get_prefix_path() to compute the filesystem prefix of a BLSpec entry by locating the deepest /loader/entries/ component in the configuration path. This ensures correct rootpath extraction for nested loader directories, mixed path layouts, duplicate segments, and paths without valid loader entries. If no prefix is found, fall back to get_mounted_path().

---
 common/blspec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
common/blspec.c +24 -1
index 80ebe256ceaf..ad94d4d6be64 100644
@@ -391,6 +391,29 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
 	return ret;
 }
 
+/*
+ * Return the path prefix before the deepest "/loader/entries/" component
+ * in @configname. Falls back to the mounted path if none is found.
+ */
+static char *get_blspec_prefix_path(char *configname)
+{
+	char *p;
+	char *scfg = configname;
+	char *save = NULL;
+
+	while ((p = strstr(scfg, "/loader/entries/")) != NULL) {
+		if (p - configname > 0)
+			save = p;
+
+		scfg = p + 1;
+	}
+
+	if (save && save - configname > 0)
+		return xstrndup(configname, save - configname);
+
+	return get_mounted_path(configname);
+}
+
 static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 			      const char *configname)
 {
@@ -404,7 +427,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 	if (IS_ERR(entry))
 		return PTR_ERR(entry);
 
-	root = root ?: get_mounted_path(configname);
+	root = root ?: get_blspec_prefix_path(configname);
 	entry->rootpath = xstrdup_const(root);
 	entry->configpath = xstrdup_const(configname);
 	entry->cdev = get_cdev_by_mountpath(root);
Signature · 1 line
2.49.0
#1 lore raw

Hi,

thanks for your patch.

Quoted 4 lines · On 25-11-14, [email protected] wrote:

From: Chali Anis <[email protected]>

Add get_prefix_path() to compute the filesystem prefix of a BLSpec entry by locating the deepest /loader/entries/ component in the

What exactly do you mean by "deepest"? The specification says that the entries should be under /loader/entries of $BOOT or $EFI partition [1].

There is also a note:
"""""""""
In all cases the /loader/entries/ directory should be located directly in the root of the ESP or XBOOTLDR filesystem. Specifically, the /loader/entries/ directory should not be located under the /EFI/ subdirectory on the ESP.
"""""""""

So searching in subdirs seems not to be spec compatible. May I ask why your loader entries are within some subdir in the first place?

Regards,
Marco

[1] https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-specification-entries

Quoted 58 lines

configuration path. This ensures correct rootpath extraction for nested loader directories, mixed path layouts, duplicate segments, and paths without valid loader entries. If no prefix is found, fall back to get_mounted_path().

---
 common/blspec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
common/blspec.c +24 -1
index 80ebe256ceaf..ad94d4d6be64 100644
@@ -391,6 +391,29 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
 	return ret;
 }
 
+/*
+ * Return the path prefix before the deepest "/loader/entries/" component
+ * in @configname. Falls back to the mounted path if none is found.
+ */
+static char *get_blspec_prefix_path(char *configname)
+{
+	char *p;
+	char *scfg = configname;
+	char *save = NULL;
+
+	while ((p = strstr(scfg, "/loader/entries/")) != NULL) {
+		if (p - configname > 0)
+			save = p;
+
+		scfg = p + 1;
+	}
+
+	if (save && save - configname > 0)
+		return xstrndup(configname, save - configname);
+
+	return get_mounted_path(configname);
+}
+
 static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 			      const char *configname)
 {
@@ -404,7 +427,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 	if (IS_ERR(entry))
 		return PTR_ERR(entry);
 
-	root = root ?: get_mounted_path(configname);
+	root = root ?: get_blspec_prefix_path(configname);
 	entry->rootpath = xstrdup_const(root);
 	entry->configpath = xstrdup_const(configname);
 	entry->cdev = get_cdev_by_mountpath(root);
Signature · 1 line
2.49.0
Signature · 7 lines
#gernperDu 
#CallMeByMyFirstName

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-9    |
#2 lore raw

Hello Marco,

Quoted 21 lines · Marco Felsch

Hi,

thanks for your patch.

Quoted 4 lines · On 25-11-14, [email protected] wrote:

From: Chali Anis <[email protected]>

Add get_prefix_path() to compute the filesystem prefix of a BLSpec entry by locating the deepest /loader/entries/ component in the

What exactly do you mean by "deepest"? The specification says that the entries should be under /loader/entries of $BOOT or $EFI partition [1].

There is also a note:
"""""""""
In all cases the /loader/entries/ directory should be located directly in the root of the ESP or XBOOTLDR filesystem. Specifically, the /loader/entries/ directory should not be located under the /EFI/ subdirectory on the ESP.
"""""""""

Quoted 2 lines

So searching in subdirs seems not to be spec compatible. May I ask why your loader entries are within some subdir in the first place?

I was also confused when Anis first mentioned this on IRC, but the missing piece of information was that get_mounted_path() (and now get_blspec_prefix_path()) is only used when booting a specific bootloader spec config by name, e.g.,

bootm /mnt/.../loader/entries/my.conf

as opposed to:

bootm /mnt/.../

In that case, it makes sense to not go up to the first mount, but just take the loader/entries the file is inside.

I believe this can also be useful for testing: include a loader/ directory in the barebox environment and then run tests over it directly without having to copy /env/loader to /loader first, because that's the file system root.

Cheers,
Ahmad

Quoted 65 lines

Regards,
Marco

[1] https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-specification-entries

Quoted 58 lines

configuration path. This ensures correct rootpath extraction for nested loader directories, mixed path layouts, duplicate segments, and paths without valid loader entries. If no prefix is found, fall back to get_mounted_path().

---
 common/blspec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
common/blspec.c +24 -1
index 80ebe256ceaf..ad94d4d6be64 100644
@@ -391,6 +391,29 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
 	return ret;
 }
 
+/*
+ * Return the path prefix before the deepest "/loader/entries/" component
+ * in @configname. Falls back to the mounted path if none is found.
+ */
+static char *get_blspec_prefix_path(char *configname)
+{
+	char *p;
+	char *scfg = configname;
+	char *save = NULL;
+
+	while ((p = strstr(scfg, "/loader/entries/")) != NULL) {
+		if (p - configname > 0)
+			save = p;
+
+		scfg = p + 1;
+	}
+
+	if (save && save - configname > 0)
+		return xstrndup(configname, save - configname);
+
+	return get_mounted_path(configname);
+}
+
 static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 			      const char *configname)
 {
@@ -404,7 +427,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 	if (IS_ERR(entry))
 		return PTR_ERR(entry);
 
-	root = root ?: get_mounted_path(configname);
+	root = root ?: get_blspec_prefix_path(configname);
 	entry->rootpath = xstrdup_const(root);
 	entry->configpath = xstrdup_const(configname);
 	entry->cdev = get_cdev_by_mountpath(root);
Signature · 1 line
2.49.0
Signature · 4 lines
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

A message that is not in the archive (sent off-list or not yet received): CAL+1fyCeZdxMhpDNYjpvbteGre+mgDi0pRyUn_24wUkKJa_+4w@mail.gmail.com

author
#4 lore raw

Hi Marco,

As Ahmad mentioned this will serve to boot blspec files directly, a practical use case is when using ostree without separating the /boot from the rest of rootfs in one partition, in that case the loader is under /boot. And inside the same entry directory they put two configs. This force the user to use the full config path to boot specific system. Without this patch the boot fails because the path to the kernel is broken because it puts only the prefix with the mount point and not mount point/boot/....

Thanks.

Anis C.

Quoted 134 lines · anis chali

Hi Marco,

As Ahmad mentioned this will serve to boot blspec files directly, a practical use case is when using ostree without separating the /boot from the rest of rootfs in one partition, in that case the loader is under /boot. And inside the same entry directory they put two configs. This force the user to use the full config path to boot specific system. Without this patch the boot fails because the path to the kernel is broken because it puts only the prefix with the mount point and not mount point/boot/....

Thanks.

Anis C.

Quoted 123 lines · Ahmad Fatoum

Hello Marco,

Quoted 21 lines · Marco Felsch

Hi,

thanks for your patch.

Quoted 4 lines · On 25-11-14, [email protected] wrote:

From: Chali Anis <[email protected]>

Add get_prefix_path() to compute the filesystem prefix of a BLSpec entry by locating the deepest /loader/entries/ component in the

What exactly do you mean by "deepest"? The specification says that the entries should be under /loader/entries of $BOOT or $EFI partition [1].

There is also a note:
"""""""""
In all cases the /loader/entries/ directory should be located directly in the root of the ESP or XBOOTLDR filesystem. Specifically, the /loader/entries/ directory should not be located under the /EFI/ subdirectory on the ESP.
"""""""""

Quoted 2 lines

So searching in subdirs seems not to be spec compatible. May I ask why your loader entries are within some subdir in the first place?

I was also confused when Anis first mentioned this on IRC, but the missing piece of information was that get_mounted_path() (and now get_blspec_prefix_path()) is only used when booting a specific bootloader spec config by name, e.g.,

bootm /mnt/.../loader/entries/my.conf

as opposed to:

bootm /mnt/.../

In that case, it makes sense to not go up to the first mount, but just take the loader/entries the file is inside.

I believe this can also be useful for testing: include a loader/ directory in the barebox environment and then run tests over it directly without having to copy /env/loader to /loader first, because that's the file system root.

Cheers,
Ahmad

Quoted 54 lines

Regards,
Marco

[1] https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-specification-entries

Quoted 48 lines

configuration path. This ensures correct rootpath extraction for nested loader directories, mixed path layouts, duplicate segments, and paths without valid loader entries. If no prefix is found, fall back to get_mounted_path().

---
 common/blspec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
common/blspec.c +23 -0
index 80ebe256ceaf..ad94d4d6be64 100644
@@ -391,6 +391,29 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
     return ret;
 }
 
+/*
+ * Return the path prefix before the deepest "/loader/entries/" component
+ * in @configname. Falls back to the mounted path if none is found.
+ */
+static char *get_blspec_prefix_path(char *configname)
+{
+    char *p;
+    char *scfg = configname;
+    char *save = NULL;
+
+    while ((p = strstr(scfg, "/loader/entries/")) != NULL) {
+            if (p - configname > 0)
+                    save = p;
+
+            scfg = p + 1;
+    }
+
+    if (save && save - configname > 0)
+            return xstrndup(configname, save - configname);
+
+    return get_mounted_path(configname);
+}
+
 static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
                           const char *configname)
 {
@@ -404,7 +427,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
     if (IS_ERR(entry))
             return PTR_ERR(entry);
 
Quoted 11 lines
Quoted 10 lines
common/blspec.c +1 -2
-    root = root ?: get_mounted_path(configname);
+    root = root ?: get_blspec_prefix_path(configname);
     entry->rootpath = xstrdup_const(root);
     entry->configpath = xstrdup_const(configname);
     entry->cdev = get_cdev_by_mountpath(root);
--

2.49.0

--

Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
Applied
#5 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, 14 Nov 2025 00:00:34 -0500, [email protected] wrote:

Add get_prefix_path() to compute the filesystem prefix of a BLSpec entry by locating the deepest /loader/entries/ component in the configuration path. This ensures correct rootpath extraction for nested loader directories, mixed path layouts, duplicate segments, and paths without valid loader entries. If no prefix is found, fall back to get_mounted_path().

[...]

Applied, thanks!

[1/1] blspec: derive root prefix from blspec config path instead of mountpoint
https://git.pengutronix.de/cgit/barebox/commit/?id=7234dd9aecce (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>