1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2021 Google LLC
14 #include <dm/device-internal.h>
15 #include <dm/uclass-internal.h>
17 static int bootdev_check_state(struct bootstd_priv **stdp)
19 struct bootstd_priv *std;
22 ret = bootstd_get_priv(&std);
25 if (!std->cur_bootdev) {
26 printf("Please use 'bootdev select' first\n");
34 static int do_bootdev_list(struct cmd_tbl *cmdtp, int flag, int argc,
39 probe = argc >= 2 && !strcmp(argv[1], "-p");
45 static int do_bootdev_select(struct cmd_tbl *cmdtp, int flag, int argc,
48 struct bootstd_priv *std;
52 ret = bootstd_get_priv(&std);
54 return CMD_RET_FAILURE;
56 std->cur_bootdev = NULL;
59 if (bootdev_find_by_any(argv[1], &dev, NULL))
60 return CMD_RET_FAILURE;
62 std->cur_bootdev = dev;
67 static int do_bootdev_info(struct cmd_tbl *cmdtp, int flag, int argc,
70 struct bootstd_priv *priv;
71 struct bootflow *bflow;
72 int ret, i, num_valid;
76 probe = argc >= 2 && !strcmp(argv[1], "-p");
78 ret = bootdev_check_state(&priv);
80 return CMD_RET_FAILURE;
82 dev = priv->cur_bootdev;
84 /* Count the number of bootflows, including how many are valid*/
86 for (ret = bootdev_first_bootflow(dev, &bflow), i = 0;
88 ret = bootdev_next_bootflow(&bflow), i++)
89 num_valid += bflow->state == BOOTFLOWST_READY;
92 * Prove the device, if requested, otherwise assume that there is no
97 ret = device_probe(dev);
99 printf("Name: %s\n", dev->name);
100 printf("Sequence: %d\n", dev_seq(dev));
101 printf("Status: %s\n", ret ? simple_itoa(-ret) : device_active(dev) ?
103 printf("Uclass: %s\n", dev_get_uclass_name(dev_get_parent(dev)));
104 printf("Bootflows: %d (%d valid)\n", i, num_valid);
109 static int do_bootdev_hunt(struct cmd_tbl *cmdtp, int flag, int argc,
112 struct bootstd_priv *priv;
113 const char *spec = NULL;
118 if (!strcmp(argv[1], "-l"))
124 ret = bootstd_get_priv(&priv);
128 bootdev_list_hunters(priv);
130 ret = bootdev_hunt(spec, true);
132 printf("Failed (err=%dE)\n", ret);
134 return CMD_RET_FAILURE;
141 U_BOOT_LONGHELP(bootdev,
142 "list [-p] - list all available bootdevs (-p to probe)\n"
143 "bootdev hunt [-l|<spec>] - use hunt drivers to find bootdevs\n"
144 "bootdev select <bd> - select a bootdev by name | label | seq\n"
145 "bootdev info [-p] - show information about a bootdev (-p to probe)");
147 U_BOOT_CMD_WITH_SUBCMDS(bootdev, "Boot devices", bootdev_help_text,
148 U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootdev_list),
149 U_BOOT_SUBCMD_MKENT(hunt, 2, 1, do_bootdev_hunt),
150 U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootdev_select),
151 U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootdev_info));