
From: Simon Glass <sjg@chromium.org> The 'bootflow list' command supports looking at the EFI device-path when available. Move this piece into a common function so it can be used elsewhere. This updates the output from 'bootflow list'. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootflow.c | 27 +++++++++++++++++++++++++++ cmd/bootflow.c | 16 +--------------- include/bootflow.h | 8 ++++++++ test/boot/bootflow.c | 4 ++-- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index c088300ea96..c8391641001 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -11,6 +11,7 @@ #include <bootmeth.h> #include <bootstd.h> #include <dm.h> +#include <efi_device_path.h> #include <env_internal.h> #include <malloc.h> #include <serial.h> @@ -1024,3 +1025,29 @@ int bootflow_get_seq(const struct bootflow *bflow) return alist_calc_index(&std->bootflows, bflow); } + +const char *bootflow_guess_label(const struct bootflow *bflow) +{ + const char *name = NULL; + + if (IS_ENABLED(CONFIG_EFI_APP)) { + struct efi_device_path *dp; + enum uclass_id id; + int ret; + + ret = efi_dp_from_bootflow(bflow, &dp, NULL); + if (!ret) + name = efi_dp_guess_uclass(dp, &id); + } else if (bflow->dev) { + struct udevice *media = dev_get_parent(bflow->dev); + + if (device_get_uclass_id(media) == UCLASS_MASS_STORAGE) + name = "usb"; + else + name = dev_get_uclass_name(media); + } + if (!name) + name = "(none)"; + + return name; +} diff --git a/cmd/bootflow.c b/cmd/bootflow.c index 20fc04bdda3..43335fecb34 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -70,21 +70,7 @@ static void report_bootflow_err(struct bootflow *bflow, int err) */ static void show_bootflow(int index, struct bootflow *bflow, bool errors) { - const char *name = NULL; - - if (IS_ENABLED(CONFIG_EFI_APP)) { - struct efi_device_path *dp; - enum uclass_id id; - int ret; - - ret = efi_dp_from_bootflow(bflow, &dp, NULL); - if (!ret) - name = efi_dp_guess_uclass(dp, &id); - } else if (bflow->dev) { - name = dev_get_uclass_name(dev_get_parent(bflow->dev)); - } - if (!name) - name = "(none)"; + const char *name = bootflow_guess_label(bflow); printf("%3x %-11s %-6s %-9.9s %4x %-25.25s %s\n", index, bflow->method ? bflow->method->name : "(none)", diff --git a/include/bootflow.h b/include/bootflow.h index ec5baff7e01..422fd32a3ca 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -725,4 +725,12 @@ int bootflow_menu_start(struct bootstd_priv *std, bool text_mode, */ int bootflow_menu_poll(struct expo *exp, int *seqp); +/** + * bootflow_guess_label() - Produce a plausible label for a bootflow + * + * This uses the uclass name or EFI device-path to come up with a useful label + * for display to the user. Ideally it will say "mmc", "usb", nvme", etc. + */ +const char *bootflow_guess_label(const struct bootflow *bflow); + #endif diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 620af312700..14e3326a08f 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1349,9 +1349,9 @@ static int bootflow_efi(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextlinen(" 0 extlinux"); ut_assert_nextlinen( - " 1 efi ready usb_mass_ 1 hub1.p2.usb_mass_storage. /EFI/BOOT/BOOTSBOX.EFI"); + " 1 efi ready usb 1 hub1.p2.usb_mass_storage. /EFI/BOOT/BOOTSBOX.EFI"); ut_assert_nextlinen( - " 2 extlinux ready usb_mass_ 1 hub1.p4.usb_mass_storage. /extlinux/extlinux.conf"); + " 2 extlinux ready usb 1 hub1.p4.usb_mass_storage. /extlinux/extlinux.conf"); ut_assert_nextlinen("---"); ut_assert_skip_to_line("(3 bootflows, 3 valid)"); ut_assert_console_end(); -- 2.43.0