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, NULL))
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 static int do_bootdev_hunt(struct cmd_tbl *cmdtp, int flag, int argc,
113 struct bootstd_priv *priv;
114 const char *spec = NULL;
119 if (!strcmp(argv[1], "-l"))
125 ret = bootstd_get_priv(&priv);
129 bootdev_list_hunters(priv);
131 ret = bootdev_hunt(spec, true);
133 printf("Failed (err=%dE)\n", ret);
135 return CMD_RET_FAILURE;
142 #ifdef CONFIG_SYS_LONGHELP
143 static char bootdev_help_text[] =
144 "list [-p] - list all available bootdevs (-p to probe)\n"
145 "bootdev hunt [-l|<spec>] - use hunt drivers to find bootdevs\n"
146 "bootdev select <bd> - select a bootdev by name | label | seq\n"
147 "bootdev info [-p] - show information about a bootdev (-p to probe)";
150 U_BOOT_CMD_WITH_SUBCMDS(bootdev, "Boot devices", bootdev_help_text,
151 U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootdev_list),
152 U_BOOT_SUBCMD_MKENT(hunt, 2, 1, do_bootdev_hunt),
153 U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootdev_select),
154 U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootdev_info));