1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
15 #include <dm/device-internal.h>
16 #include <dm/uclass-internal.h>
18 static int bootdev_check_state(struct bootstd_priv **stdp)
20 struct bootstd_priv *std;
23 ret = bootstd_get_priv(&std);
26 if (!std->cur_bootdev) {
27 printf("Please use 'bootdev select' first\n");
35 static int do_bootdev_list(struct cmd_tbl *cmdtp, int flag, int argc,
40 probe = argc >= 2 && !strcmp(argv[1], "-p");
46 static int do_bootdev_select(struct cmd_tbl *cmdtp, int flag, int argc,
49 struct bootstd_priv *std;
53 ret = bootstd_get_priv(&std);
55 return CMD_RET_FAILURE;
57 std->cur_bootdev = NULL;
60 if (bootdev_find_by_any(argv[1], &dev))
61 return CMD_RET_FAILURE;
63 std->cur_bootdev = dev;
68 static int do_bootdev_info(struct cmd_tbl *cmdtp, int flag, int argc,
71 struct bootstd_priv *priv;
72 struct bootflow *bflow;
73 int ret, i, num_valid;
77 probe = argc >= 2 && !strcmp(argv[1], "-p");
79 ret = bootdev_check_state(&priv);
81 return CMD_RET_FAILURE;
83 dev = priv->cur_bootdev;
85 /* Count the number of bootflows, including how many are valid*/
87 for (ret = bootdev_first_bootflow(dev, &bflow), i = 0;
89 ret = bootdev_next_bootflow(&bflow), i++)
90 num_valid += bflow->state == BOOTFLOWST_READY;
93 * Prove the device, if requested, otherwise assume that there is no
98 ret = device_probe(dev);
100 printf("Name: %s\n", dev->name);
101 printf("Sequence: %d\n", dev_seq(dev));
102 printf("Status: %s\n", ret ? simple_itoa(ret) : device_active(dev) ?
104 printf("Uclass: %s\n", dev_get_uclass_name(dev_get_parent(dev)));
105 printf("Bootflows: %d (%d valid)\n", i, num_valid);
110 #ifdef CONFIG_SYS_LONGHELP
111 static char bootdev_help_text[] =
112 "list [-p] - list all available bootdevs (-p to probe)\n"
113 "bootdev select <bd> - select a bootdev by name | label | seq\n"
114 "bootdev info [-p] - show information about a bootdev (-p to probe)";
117 U_BOOT_CMD_WITH_SUBCMDS(bootdev, "Boot devices", bootdev_help_text,
118 U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootdev_list),
119 U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootdev_select),
120 U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootdev_info));