All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dennis Gilmore <dennis@ausil.us>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Lukas Auer <lukas.auer@aisec.fraunhofer.de>,
	Tom Rini <trini@konsulko.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Michal Simek <michal.simek@xilinx.com>,
	Daniel Schwierzeck <daniel.schwierzeck@gmail.com>,
	Steffen Jaeckel <jaeckel-floss@eyet-services.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v4 17/33] bootstd: Add a bootdev command
Date: Sun,  6 Mar 2022 05:50:00 -0700	[thread overview]
Message-ID: <20220306054946.v4.17.Ic1c0b48869db2404f5d8c89518eb88156b8bc46a@changeid> (raw)
In-Reply-To: <20220306125016.3133737-1-sjg@chromium.org>

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>
---

(no changes since v3)

Changes in v3:
- Use separate Kconfig options for each command

 MAINTAINERS                        |   1 +
 cmd/Kconfig                        |  10 +++
 cmd/Makefile                       |   1 +
 cmd/bootdev.c                      | 120 +++++++++++++++++++++++++++++
 configs/amcore_defconfig           |   1 +
 configs/rcar3_salvator-x_defconfig |   1 +
 configs/tbs2910_defconfig          |   1 +
 7 files changed, 135 insertions(+)
 create mode 100644 cmd/bootdev.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c47a8143b2..873e8f6352 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -689,6 +689,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
diff --git a/cmd/Kconfig b/cmd/Kconfig
index d10deed244..2a54d45be3 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -194,6 +194,16 @@ config CMD_BOOTM
 	help
 	  Boot an application image from the memory.
 
+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
diff --git a/cmd/Makefile b/cmd/Makefile
index 166c652d98..18be0a3ae8 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -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
index 0000000000..ecd797c050
--- /dev/null
+++ b/cmd/bootdev.c
@@ -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));
diff --git a/configs/amcore_defconfig b/configs/amcore_defconfig
index afb3a7707f..9906d736bd 100644
--- a/configs/amcore_defconfig
+++ b/configs/amcore_defconfig
@@ -7,6 +7,7 @@ CONFIG_ENV_SECT_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="amcore"
 CONFIG_TARGET_AMCORE=y
 CONFIG_SYS_LOAD_ADDR=0x20000
+# CONFIG_BOOTSTD is not set
 CONFIG_BOOTDELAY=1
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="bootm ffc20000"
diff --git a/configs/rcar3_salvator-x_defconfig b/configs/rcar3_salvator-x_defconfig
index 5fb27d257a..2db915f887 100644
--- a/configs/rcar3_salvator-x_defconfig
+++ b/configs/rcar3_salvator-x_defconfig
@@ -12,6 +12,7 @@ CONFIG_TARGET_SALVATOR_X=y
 CONFIG_REMAKE_ELF=y
 CONFIG_SYS_LOAD_ADDR=0x58000000
 CONFIG_FIT=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_USE_BOOTCOMMAND=y
diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig
index e1278f2e70..353c61fe7b 100644
--- a/configs/tbs2910_defconfig
+++ b/configs/tbs2910_defconfig
@@ -14,6 +14,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx6q-tbs2910"
 CONFIG_PRE_CON_BUF_ADDR=0x7c000000
 CONFIG_CMD_HDMIDETECT=y
 CONFIG_AHCI=y
+# CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTCOMMAND=y
-- 
2.35.1.616.g0bdcbb4464-goog


  parent reply	other threads:[~2022-03-06 12:53 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 12:49 [PATCH v4 00/33] Initial implementation of standard boot Simon Glass
2022-03-06 12:49 ` [PATCH v4 01/33] lib: Move string tests to the string module Simon Glass
2022-03-06 12:49 ` [PATCH v4 02/33] test: Add tests for trailing_strtol() Simon Glass
2022-03-06 12:49 ` [PATCH v4 03/33] lib: Correct comment formatting to avoid sphinx problems Simon Glass
2022-03-06 12:49 ` [PATCH v4 04/33] lib: Fix a few bugs in trailing_strtoln() Simon Glass
2022-03-06 12:49 ` [PATCH v4 05/33] lib: Add a way to find the postiion of a trailing number Simon Glass
2022-03-06 12:49 ` [PATCH v4 06/33] dm: core: Rename and fix uclass_get_by_name_len() Simon Glass
2022-03-06 12:49 ` [PATCH v4 07/33] dm: core: Allow finding a uclass device by partial name Simon Glass
2022-03-06 12:49 ` [PATCH v4 08/33] test: fastboot: Avoid using mmc1 Simon Glass
2022-03-06 12:49 ` [PATCH v4 09/33] test: dm: Restart USB before assuming it is stopped Simon Glass
2022-03-06 12:49 ` [PATCH v4 10/33] dm: blk: Add a function to return the device type Simon Glass
2022-03-06 12:49 ` [PATCH v4 11/33] fs: Add a function to set the filesystem type Simon Glass
2022-03-06 12:49 ` [PATCH v4 12/33] bootstd: Add the concept of a bootflow Simon Glass
2022-03-06 12:49 ` [PATCH v4 13/33] bootstd: Add the bootstd uclass and core implementation Simon Glass
2022-03-12 14:35   ` Ilias Apalodimas
2022-03-12 17:58     ` Simon Glass
2022-03-06 12:49 ` [PATCH v4 14/33] bootstd: Add the bootdev uclass Simon Glass
2022-03-06 12:49 ` [PATCH v4 15/33] bootstd: Add the bootmeth uclass and helpers Simon Glass
2022-03-06 12:49 ` [PATCH v4 16/33] bootstd: Add support for bootflows Simon Glass
2022-03-06 12:50 ` Simon Glass [this message]
2022-03-06 12:50 ` [PATCH v4 19/33] bootstd: Add a bootmeth command Simon Glass
2022-03-06 12:50 ` [PATCH v4 21/33] bootstd: mmc: Add a bootdev driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 22/33] bootstd: ethernet: " Simon Glass
2022-03-06 12:50 ` [PATCH v4 23/33] bootstd: Add an implementation of distro PXE boot Simon Glass
2022-03-06 12:50 ` [PATCH v4 24/33] bootstd: Add an implementation of EFI boot Simon Glass
2022-03-06 12:50 ` [PATCH v4 25/33] bootstd: Add a system bootdev for strange boot methods Simon Glass
2022-03-06 12:50 ` [PATCH v4 27/33] bootstd: Add a sandbox bootmeth driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 28/33] bootstd: sandbox: Add a hostfs bootdev Simon Glass
2022-03-06 12:50 ` [PATCH v4 30/33] bootstd: usb: Add a bootdev driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 31/33] bootstd: Add tests for bootstd including all uclasses Simon Glass
2022-03-06 12:50 ` [PATCH v4 32/33] bootstd: Add setup for the bootflow tests Simon Glass
2022-03-06 12:50 ` [PATCH v4 33/33] bootstd: doc: Add documentation Simon Glass
2022-03-13 15:47 ` [PATCH v4 00/33] Initial implementation of standard boot Mark Kettenis
2022-03-13 22:23   ` Simon Glass
2022-03-23 14:05 ` Tom Rini
2022-03-23 18:45   ` Simon Glass
2022-03-23 19:21     ` Michael Nazzareno Trimarchi
2022-03-23 19:30       ` Tom Rini
2022-03-23 19:57         ` Michael Nazzareno Trimarchi
2022-03-23 20:07           ` Tom Rini
2022-03-25 14:36             ` Michael Nazzareno Trimarchi
2022-03-25 14:50               ` Tom Rini
2022-03-26 19:56                 ` Simon Glass
2022-03-26 19:58                   ` Tom Rini
2022-03-26 20:51                     ` Simon Glass
2022-03-27 11:00                       ` Michael Nazzareno Trimarchi
2022-03-29  1:36                       ` Tom Rini
2022-03-23 23:15       ` Mark Kettenis
2022-03-24  2:18         ` Simon Glass
2022-03-23 20:09     ` Tom Rini
2022-03-24  2:13       ` Simon Glass
2022-03-24 14:46         ` Tom Rini
2022-03-24 18:33           ` Simon Glass
2022-03-24 19:27             ` Tom Rini
2022-03-24 20:04               ` Simon Glass
2022-03-24 21:16                 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220306054946.v4.17.Ic1c0b48869db2404f5d8c89518eb88156b8bc46a@changeid \
    --to=sjg@chromium.org \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=dennis@ausil.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=lukas.auer@aisec.fraunhofer.de \
    --cc=michal.simek@xilinx.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.