[Concept,09/12] bootstd: Show entry name in bootflow info

Message ID 20260324221911.3678307-10-sjg@u-boot.org
State New
Headers
Series bootstd: Support multiple bootflows per partition |

Commit Message

Simon Glass March 24, 2026, 10:19 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add an entry_name field to struct bootflow to store a short identifier
for the entry. For extlinux, this is the label name (e.g. "l0"). For
BLS, this is the title field (e.g. "Test Boot").

Display it after the entry number in 'bootflow info', e.g.
"Entry:     0: l0", so the user can identify which entry a bootflow
represents without relying solely on the OS name.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/bootflow.c            |  1 +
 boot/bootmeth_bls.c        | 11 ++++++++++-
 boot/bootmeth_extlinux.c   |  7 +++++++
 cmd/bootflow.c             |  3 ++-
 doc/usage/cmd/bootflow.rst |  4 ++--
 include/bootflow.h         |  3 +++
 test/boot/bootflow.c       |  6 +++---
 7 files changed, 28 insertions(+), 7 deletions(-)
  

Patch

diff --git a/boot/bootflow.c b/boot/bootflow.c
index d44ba65c1a9..4247093548b 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -738,6 +738,7 @@  void bootflow_free(struct bootflow *bflow)
 	struct bootflow_img *img;
 
 	free(bflow->name);
+	free(bflow->entry_name);
 	free(bflow->subdir);
 	free(bflow->fname);
 	if (!(bflow->flags & BOOTFLOWF_STATIC_BUF))
diff --git a/boot/bootmeth_bls.c b/boot/bootmeth_bls.c
index fc9c1bb70a2..85d8dfa91df 100644
--- a/boot/bootmeth_bls.c
+++ b/boot/bootmeth_bls.c
@@ -364,8 +364,17 @@  static int bls_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 
 	ret = bls_entry_init(&entry, bflow, size);
 	bls_entry_uninit(&entry);
+	if (ret)
+		return ret;
 
-	return ret;
+	/* Use the title as the entry identifier */
+	if (bflow->os_name) {
+		bflow->entry_name = strdup(bflow->os_name);
+		if (!bflow->entry_name)
+			return log_msg_ret("ent", -ENOMEM);
+	}
+
+	return 0;
 }
 
 /**
diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c
index bfc816f3628..542daf9ab41 100644
--- a/boot/bootmeth_extlinux.c
+++ b/boot/bootmeth_extlinux.c
@@ -160,6 +160,13 @@  found:
 			return log_msg_ret("os", -ENOMEM);
 		}
 	}
+	if (label->name) {
+		bflow->entry_name = strdup(label->name);
+		if (!bflow->entry_name) {
+			pxe_cleanup(ctx);
+			return log_msg_ret("xnt", -ENOMEM);
+		}
+	}
 
 	pxe_cleanup(ctx);
 
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 1c40037e6a6..a701b960efe 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -377,7 +377,8 @@  static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
 
 		ucp = dev_get_uclass_plat(bflow->method);
 		if (ucp->flags & BOOTMETHF_MULTI)
-			printf("Entry:     %d\n", bflow->entry);
+			printf("Entry:     %d: %s\n", bflow->entry,
+			       bflow->entry_name);
 	}
 
 	/* Show encryption status with LUKS version if applicable */
diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst
index 3a21e00a47b..6a1676a6098 100644
--- a/doc/usage/cmd/bootflow.rst
+++ b/doc/usage/cmd/bootflow.rst
@@ -167,7 +167,7 @@  Type       distro
 Method:    extlinux
 State      ready
 Partition  2
-Entry      0
+Entry      0: l0
 Encrypted  no
 Subdir     (none)
 Filename   /extlinux/extlinux.conf
@@ -351,7 +351,7 @@  displayed and booted::
     Method:    distro
     State:     ready
     Partition: 2
-    Entry:     0
+    Entry:     0: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
     Encrypted: no
     Subdir:    (none)
     Filename:  extlinux/extlinux.conf
diff --git a/include/bootflow.h b/include/bootflow.h
index 2a4a96c1031..750abafaf6e 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -78,6 +78,8 @@  enum bootflow_flags_t {
  * @entry: Entry index within this (dev, part, method) combination. Used by
  *	bootmeths with BOOTMETHF_MULTI to select which entry to return (e.g.
  *	which label in an extlinux config). Always 0 for non-multi bootmeths.
+ * @entry_name: Short identifier for this entry (allocated), e.g. the extlinux
+ *	label name or BLS conf filename. NULL if not set.
  * @fs_type: Filesystem type (FS_TYPE...) if this is fixed by the media, else 0.
  *	For example, the sandbox host-filesystem bootdev sets this to
  *	FS_TYPE_SANDBOX
@@ -114,6 +116,7 @@  struct bootflow {
 	struct udevice *blk;
 	int part;
 	int entry;
+	char *entry_name;
 	int fs_type;
 	struct udevice *method;
 	char *name;
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 84d80d9fd10..317d7e4c47d 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -258,7 +258,7 @@  static int bootflow_cmd_info(struct unit_test_state *uts)
 	ut_assert_nextline("Method:    extlinux");
 	ut_assert_nextline("State:     ready");
 	ut_assert_nextline("Partition: 1");
-	ut_assert_nextline("Entry:     0");
+	ut_assert_nextline("Entry:     0: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
 	if (IS_ENABLED(CONFIG_BLK_LUKS))
 		ut_assert_nextline("Encrypted: no");
 	ut_assert_nextline("Subdir:    (none)");
@@ -1846,7 +1846,7 @@  static int bootflow_cmd_info_encrypted(struct unit_test_state *uts)
 	ut_assert_nextline("Method:    extlinux");
 	ut_assert_nextline("State:     ready");
 	ut_assert_nextline("Partition: 1");
-	ut_assert_nextline("Entry:     0");
+	ut_assert_nextline("Entry:     0: l0");
 	if (IS_ENABLED(CONFIG_BLK_LUKS))
 		ut_assert_nextline("Encrypted: LUKSv2");
 	ut_assert_skip_to_line("Error:     0");
@@ -1892,7 +1892,7 @@  static int bootflow_cmd_bls(struct unit_test_state *uts)
 	ut_assert_nextline("Method:    bls");
 	ut_assert_nextline("State:     ready");
 	ut_assert_nextline("Partition: 1");
-	ut_assert_nextline("Entry:     0");
+	ut_assert_nextline("Entry:     0: Test Boot");
 	if (IS_ENABLED(CONFIG_BLK_LUKS))
 		ut_assert_nextline("Encrypted: no");
 	ut_assert_nextline("Subdir:    (none)");