
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. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootflow.c | 27 +++++++++++++++++++++++++++ cmd/bootflow.c | 16 +--------------- include/bootflow.h | 8 ++++++++ 3 files changed, 36 insertions(+), 15 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 -- 2.43.0