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(-)
@@ -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))
@@ -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;
}
/**
@@ -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);
@@ -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 */
@@ -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
@@ -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;
@@ -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)");