1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
15 #include <dm/uclass-internal.h>
17 static int do_bootmeth_list(struct cmd_tbl *cmdtp, int flag, int argc,
20 struct bootstd_priv *std;
27 if (argc > 1 && *argv[1] == '-') {
28 all = strchr(argv[1], 'a');
33 ret = bootstd_get_priv(&std);
35 printf("Cannot get bootstd (err=%d)\n", ret);
36 return CMD_RET_FAILURE;
39 printf("Order Seq Name Description\n");
40 printf("----- --- ------------------ ------------------\n");
43 * Use the ordering if we have one, so long as we are not trying to list
46 use_order = std->bootmeth_count && !all;
48 dev = std->bootmeth_order[0];
50 ret = uclass_find_first_device(UCLASS_BOOTMETH, &dev);
53 struct bootmeth_uc_plat *ucp = dev_get_uclass_plat(dev);
57 * With the -a flag we may list bootdevs that are not in the
58 * ordering. Find their place in the order
60 if (all && std->bootmeth_count) {
63 /* Find the position of this bootmeth in the order */
65 for (j = 0; j < std->bootmeth_count; j++) {
66 if (std->bootmeth_order[j] == dev)
71 if (ucp->flags & BOOTMETHF_GLOBAL)
72 printf("%5s", "glob");
77 printf(" %3x %-19.19s %s\n", dev_seq(dev), dev->name,
81 dev = std->bootmeth_order[i];
83 uclass_find_next_device(&dev);
85 printf("----- --- ------------------ ------------------\n");
86 printf("(%d bootmeth%s)\n", i, i != 1 ? "s" : "");
91 static int do_bootmeth_order(struct cmd_tbl *cmdtp, int flag, int argc,
96 ret = bootmeth_set_order(argv[1]);
98 printf("Failed (err=%d)\n", ret);
99 return CMD_RET_FAILURE;
101 env_set("bootmeths", argv[1]);
106 U_BOOT_LONGHELP(bootmeth,
107 "list [-a] - list available bootmeths (-a all)\n"
108 "bootmeth order [<bd> ...] - select bootmeth order / subset to use");
110 U_BOOT_CMD_WITH_SUBCMDS(bootmeth, "Boot methods", bootmeth_help_text,
111 U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootmeth_list),
112 U_BOOT_SUBCMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_bootmeth_order));