]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Add a bootdev command
authorSimon Glass <sjg@chromium.org>
Mon, 25 Apr 2022 05:31:10 +0000 (23:31 -0600)
committerTom Rini <trini@konsulko.com>
Mon, 25 Apr 2022 14:00:04 +0000 (10:00 -0400)
Add a 'bootdev' command to handle listing and selection of bootdevs.

Disable standard boot for a few boards which otherwise run out of space.

Signed-off-by: Simon Glass <sjg@chromium.org>
MAINTAINERS
cmd/Kconfig
cmd/Makefile
cmd/bootdev.c [new file with mode: 0644]
configs/rcar3_salvator-x_defconfig
configs/tbs2910_defconfig

index 24e2ad75f82e5ae2ad3fd8137fe5c36a30aa1db5..5a48b8419909b70f7abb4ab31b6ca6a5fc22d424 100644 (file)
@@ -700,6 +700,7 @@ F:  boot/bootdev*.c
 F:     boot/bootflow.c
 F:     boot/bootmeth*.c
 F:     boot/bootstd.c
+F:     cmd/bootdev.c
 F:     include/bootdev*.h
 F:     include/bootflow.h
 F:     include/bootmeth.h
index f580797d2d3e93c2d2ecf70648f38ada80cfa15a..a5c6918791144016b72db2f1528da30c847f500c 100644 (file)
@@ -211,6 +211,16 @@ config CMD_BOOTM_PRE_LOAD
         This stage allow to check or modify the image provided
         to the bootm command.
 
+config CMD_BOOTDEV
+       bool "bootdev"
+       depends on BOOTSTD
+       default y if BOOTSTD_FULL
+       help
+         Support listing available bootdevs (boot devices) which can provide an
+         OS to boot, as well as showing information about a particular one.
+
+         This command is not necessary for bootstd to work.
+
 config BOOTM_EFI
        bool "Support booting UEFI FIT images"
        depends on CMD_BOOTEFI && CMD_BOOTM && FIT
index ede634d731cdb0076be1daa8a6c935e32875a9c5..474f6d55f84c38f787d34f21754f59bf9f076e6c 100644 (file)
@@ -19,6 +19,7 @@ obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o
 obj-$(CONFIG_CMD_ADC) += adc.o
 obj-$(CONFIG_CMD_ARMFLASH) += armflash.o
 obj-$(CONFIG_HAVE_BLOCK_DEVICE) += blk_common.o
+obj-$(CONFIG_CMD_BOOTDEV) += bootdev.o
 obj-$(CONFIG_CMD_SOURCE) += source.o
 obj-$(CONFIG_CMD_BCB) += bcb.o
 obj-$(CONFIG_CMD_BDI) += bdinfo.o
diff --git a/cmd/bootdev.c b/cmd/bootdev.c
new file mode 100644 (file)
index 0000000..ecd797c
--- /dev/null
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * 'bootdev' command
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <bootdev.h>
+#include <bootflow.h>
+#include <bootstd.h>
+#include <command.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+
+static int bootdev_check_state(struct bootstd_priv **stdp)
+{
+       struct bootstd_priv *std;
+       int ret;
+
+       ret = bootstd_get_priv(&std);
+       if (ret)
+               return ret;
+       if (!std->cur_bootdev) {
+               printf("Please use 'bootdev select' first\n");
+               return -ENOENT;
+       }
+       *stdp = std;
+
+       return 0;
+}
+
+static int do_bootdev_list(struct cmd_tbl *cmdtp, int flag, int argc,
+                          char *const argv[])
+{
+       bool probe;
+
+       probe = argc >= 2 && !strcmp(argv[1], "-p");
+       bootdev_list(probe);
+
+       return 0;
+}
+
+static int do_bootdev_select(struct cmd_tbl *cmdtp, int flag, int argc,
+                            char *const argv[])
+{
+       struct bootstd_priv *std;
+       struct udevice *dev;
+       int ret;
+
+       ret = bootstd_get_priv(&std);
+       if (ret)
+               return CMD_RET_FAILURE;
+       if (argc < 2) {
+               std->cur_bootdev = NULL;
+               return 0;
+       }
+       if (bootdev_find_by_any(argv[1], &dev))
+               return CMD_RET_FAILURE;
+
+       std->cur_bootdev = dev;
+
+       return 0;
+}
+
+static int do_bootdev_info(struct cmd_tbl *cmdtp, int flag, int argc,
+                          char *const argv[])
+{
+       struct bootstd_priv *priv;
+       struct bootflow *bflow;
+       int ret, i, num_valid;
+       struct udevice *dev;
+       bool probe;
+
+       probe = argc >= 2 && !strcmp(argv[1], "-p");
+
+       ret = bootdev_check_state(&priv);
+       if (ret)
+               return CMD_RET_FAILURE;
+
+       dev = priv->cur_bootdev;
+
+       /* Count the number of bootflows, including how many are valid*/
+       num_valid = 0;
+       for (ret = bootdev_first_bootflow(dev, &bflow), i = 0;
+            !ret;
+            ret = bootdev_next_bootflow(&bflow), i++)
+               num_valid += bflow->state == BOOTFLOWST_READY;
+
+       /*
+        * Prove the device, if requested, otherwise assume that there is no
+        * error
+        */
+       ret = 0;
+       if (probe)
+               ret = device_probe(dev);
+
+       printf("Name:      %s\n", dev->name);
+       printf("Sequence:  %d\n", dev_seq(dev));
+       printf("Status:    %s\n", ret ? simple_itoa(ret) : device_active(dev) ?
+               "Probed" : "OK");
+       printf("Uclass:    %s\n", dev_get_uclass_name(dev_get_parent(dev)));
+       printf("Bootflows: %d (%d valid)\n", i, num_valid);
+
+       return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char bootdev_help_text[] =
+       "list [-p]      - list all available bootdevs (-p to probe)\n"
+       "bootdev select <bd>    - select a bootdev by name | label | seq\n"
+       "bootdev info [-p]      - show information about a bootdev (-p to probe)";
+#endif
+
+U_BOOT_CMD_WITH_SUBCMDS(bootdev, "Boot devices", bootdev_help_text,
+       U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootdev_list),
+       U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootdev_select),
+       U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootdev_info));
index f333291aa4b93921a66263aae7e5dd0feb028e44..6ef62ab4cbba2bae912bc976d614b05a38ea4917 100644 (file)
@@ -14,6 +14,7 @@ CONFIG_SYS_LOAD_ADDR=0x58000000
 CONFIG_LTO=y
 CONFIG_REMAKE_ELF=y
 CONFIG_FIT=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_SYS_MONITOR_BASE=0x00000000
 CONFIG_USE_BOOTARGS=y
index 60a816059a68687e635883eb9dfa6fe16012ffaa..9f7642f25ca0d520df9dbaa459c7cfd2f766e8f6 100644 (file)
@@ -17,6 +17,7 @@ CONFIG_SYS_MEMTEST_END=0x2f400000
 CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=392192
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTCOMMAND=y