[Concept,5/8] boot: Move obtaining the label into a common file
Commit Message
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(-)
@@ -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;
+}
@@ -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)",
@@ -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