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: U-Boot Custodians <u-boot-custodians@lists.denx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 24/71] bootstd: Support running bootdev hunters
Date: Sat,  7 Jan 2023 19:50:00 -0700	[thread overview]
Message-ID: <20230108025047.522240-25-sjg@chromium.org> (raw)
In-Reply-To: <20230108025047.522240-1-sjg@chromium.org>

Add a way to run a bootdev hunter to find bootdevs of a certain type. Add
this to the 'bootdev hunt' command. Test for this are added in a later
patch, since a useful test needs some hunters to work with.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 boot/bootdev-uclass.c | 61 +++++++++++++++++++++++++++++++++++++++++++
 cmd/bootdev.c         |  7 ++++-
 include/bootdev.h     | 14 ++++++++++
 test/boot/bootdev.c   |  3 +++
 4 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 62eb0b617cd..081b94ce332 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -636,6 +636,67 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp)
 	return 0;
 }
 
+static int bootdev_hunt_drv(struct bootdev_hunter *info, uint seq, bool show)
+{
+	const char *name = uclass_get_name(info->uclass);
+	struct bootstd_priv *std;
+	int ret;
+
+	ret = bootstd_get_priv(&std);
+	if (ret)
+		return log_msg_ret("std", ret);
+
+	if (!(std->hunters_used & BIT(seq))) {
+		if (show)
+			printf("Hunting with: %s\n",
+			       uclass_get_name(info->uclass));
+		log_debug("Hunting with: %s\n", name);
+		if (info->hunt) {
+			ret = info->hunt(info, show);
+			if (ret)
+				return ret;
+		}
+		std->hunters_used |= BIT(seq);
+	}
+
+	return 0;
+}
+
+int bootdev_hunt(const char *spec, bool show)
+{
+	struct bootdev_hunter *start;
+	const char *end;
+	int n_ent, i;
+	int result;
+	size_t len;
+
+	start = ll_entry_start(struct bootdev_hunter, bootdev_hunter);
+	n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter);
+	result = 0;
+
+	len = SIZE_MAX;
+	if (spec) {
+		trailing_strtoln_end(spec, NULL, &end);
+		len = end - spec;
+	}
+
+	for (i = 0; i < n_ent; i++) {
+		struct bootdev_hunter *info = start + i;
+		const char *name = uclass_get_name(info->uclass);
+		int ret;
+
+		log_debug("looking at %.*s for %s\n",
+			  (int)max(strlen(name), len), spec, name);
+		if (spec && strncmp(spec, name, max(strlen(name), len)))
+			continue;
+		ret = bootdev_hunt_drv(info, i, show);
+		if (ret)
+			result = ret;
+	}
+
+	return result;
+}
+
 void bootdev_list_hunters(struct bootstd_priv *std)
 {
 	struct bootdev_hunter *orig, *start;
diff --git a/cmd/bootdev.c b/cmd/bootdev.c
index 80bfe2812e4..28866faac76 100644
--- a/cmd/bootdev.c
+++ b/cmd/bootdev.c
@@ -128,7 +128,12 @@ static int do_bootdev_hunt(struct cmd_tbl *cmdtp, int flag, int argc,
 	if (list) {
 		bootdev_list_hunters(priv);
 	} else {
-		/* TODO: implement hunting */
+		ret = bootdev_hunt(spec, true);
+		if (ret) {
+			printf("Failed (err=%dE)\n", ret);
+
+			return CMD_RET_FAILURE;
+		}
 	}
 
 	return 0;
diff --git a/include/bootdev.h b/include/bootdev.h
index cafb5285a28..deef7890489 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -263,6 +263,20 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp);
  */
 void bootdev_list_hunters(struct bootstd_priv *std);
 
+/**
+ * bootdev_hunt() - Hunt for bootdevs matching a particular spec
+ *
+ * This runs the selected hunter (or all if @spec is NULL) to try to find new
+ * bootdevs.
+ *
+ * @spec: Spec to match, e.g. "mmc0", or NULL for any. If provided, this must
+ * match a uclass name so that the hunter can be determined. Any trailing number
+ * is ignored
+ * @show: true to show each hunter before using it
+ * Returns: 0 if OK, -ve on error
+ */
+int bootdev_hunt(const char *spec, bool show);
+
 #if CONFIG_IS_ENABLED(BOOTSTD)
 /**
  * bootdev_setup_for_dev() - Bind a new bootdev device (deprecated)
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index a8ca12a3c8f..45a00c34c0c 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -237,6 +237,9 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
 	ut_assert_nextline("(total hunters: 0)");
 	ut_assert_console_end();
 
+	ut_assertok(bootdev_hunt("mmc1", false));
+	ut_assert_console_end();
+
 	return 0;
 }
 BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
-- 
2.39.0.314.g84b9a713c41-goog


  parent reply	other threads:[~2023-01-08  2:58 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08  2:49 [PATCH v2 00/71] bootstd: Allow migration from distro_bootcmd scripts Simon Glass
2023-01-08  2:49 ` [PATCH v2 01/71] dm: core: Correct ordering of uclasses IDs Simon Glass
2023-01-08  2:49 ` [PATCH v2 02/71] dm: core: Support sorting devices with dm tree Simon Glass
2023-01-08  2:49 ` [PATCH v2 03/71] dm: test: Correct assertion in dm_test_part() Simon Glass
2023-01-08  2:49 ` [PATCH v2 04/71] lib: Add a function to split a string into substrings Simon Glass
2023-01-08  2:49 ` [PATCH v2 05/71] bootstd: Remove special-case code for boot_targets Simon Glass
2023-01-08  2:49 ` [PATCH v2 06/71] bootstd: Simplify locating existing bootdevs Simon Glass
2023-01-08  2:49 ` [PATCH v2 07/71] test: Fix the help for the ut command Simon Glass
2023-01-08  2:49 ` [PATCH v2 08/71] test: Drop duplicate restore of DM state Simon Glass
2023-01-08  2:49 ` [PATCH v2 09/71] sandbox: mmc: Start off with a zeroed file Simon Glass
2023-01-08  2:49 ` [PATCH v2 10/71] vbe: Avoid a build failure when bloblist is not enabled Simon Glass
2023-01-08  2:49 ` [PATCH v2 11/71] vbe: sandbox: Drop VBE node in chosen Simon Glass
2023-01-08  2:49 ` [PATCH v2 12/71] dm: part: Update test to use mmc2 Simon Glass
2023-01-08  2:49 ` [PATCH v2 13/71] dm: test: Correct ordering of DM setup Simon Glass
2023-01-08  2:49 ` [PATCH v2 14/71] ide: Drop non-DM code for BLK Simon Glass
2023-01-08  2:49 ` [PATCH v2 15/71] dm: mmc: Use bootdev_setup_sibling_blk() Simon Glass
2023-01-08  2:49 ` [PATCH v2 16/71] bootstd: Add a default method to get bootflows Simon Glass
2023-01-08  2:49 ` [PATCH v2 17/71] sandbox: Allow ethernet to be disabled at runtime Simon Glass
2023-01-08  2:49 ` [PATCH v2 18/71] sandbox: Allow ethernet bootdevs to be disabled for tests Simon Glass
2023-01-08  2:49 ` [PATCH v2 19/71] sandbox: Enable the Ethernet bootdev Simon Glass
2023-01-08  2:49 ` [PATCH v2 20/71] lib: Support printing an error string Simon Glass
2023-01-08  2:49 ` [PATCH v2 21/71] event: Correct duplicate log message in event_notify() Simon Glass
2023-01-08  2:49 ` [PATCH v2 22/71] efi: Improve logging in efi_disk Simon Glass
2023-01-13 20:35   ` Heinrich Schuchardt
2023-01-13 20:40     ` Tom Rini
2023-01-13 20:49       ` Heinrich Schuchardt
2023-01-13 22:40       ` Simon Glass
2023-01-13 22:52         ` Heinrich Schuchardt
2023-01-08  2:49 ` [PATCH v2 23/71] bootstd: Add the concept of a bootdev hunter Simon Glass
2023-01-08  2:50 ` Simon Glass [this message]
2023-01-08  2:50 ` [PATCH v2 25/71] dm: usb: Drop some dead code Simon Glass
2023-01-08  2:50 ` [PATCH v2 26/71] dm: usb: Mark the device name as alloced when binding Simon Glass
2023-01-08  2:50 ` [PATCH v2 27/71] test: Add a generic function to skip delays Simon Glass
2023-01-08  2:50 ` [PATCH v2 28/71] bootstd: Add a USB hunter Simon Glass
2023-01-08  2:50 ` [PATCH v2 29/71] bootstd: Add an MMC hunter Simon Glass
2023-01-08  2:50 ` [PATCH v2 30/71] net: Add a function to run dhcp Simon Glass
2023-01-10 17:03   ` Ramon Fried
2023-01-08  2:50 ` [PATCH v2 31/71] bootstd: Add a hunter for ethernet Simon Glass
2023-01-08  2:50 ` [PATCH v2 32/71] part: Add a function to find the first bootable partition Simon Glass
2023-01-08  2:50 ` [PATCH v2 33/71] bootstd: Only scan bootable partitions Simon Glass
2023-01-08  2:50 ` [PATCH v2 34/71] scsi: Correct allocation of block-device name Simon Glass
2023-01-08  2:50 ` [PATCH v2 35/71] scsi: Remove all children of SCSI devices before rescanning Simon Glass
2023-01-08  2:50 ` [PATCH v2 36/71] bootstd: Add a SCSI bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 37/71] bootstd: Add an IDE bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 38/71] bootstd: Add an NVMe bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 39/71] virtio: Avoid repeating a long expression Simon Glass
2023-01-08  2:50 ` [PATCH v2 40/71] virtio: Fix returning -ENODEV Simon Glass
2023-01-08  2:50 ` [PATCH v2 41/71] virtio: Avoid strange behaviour on removal Simon Glass
2023-01-08  2:50 ` [PATCH v2 42/71] virtio: Add a block device Simon Glass
2023-01-08  2:50 ` [PATCH v2 43/71] bootstd: Add a virtio bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 44/71] ata: Don't try to use non-existent ports Simon Glass
2023-01-08  2:50 ` [PATCH v2 45/71] bootstd: Rename bootdev checkers Simon Glass
2023-01-08  2:50 ` [PATCH v2 46/71] bootstd: Allow reading an EFI file from the network Simon Glass
2023-01-08  2:50 ` [PATCH v2 47/71] bootstd: Include the device tree in the bootflow Simon Glass
2023-01-08  2:50 ` [PATCH v2 48/71] bootstd: Support reading the device tree with EFI Simon Glass
2023-01-08 10:25   ` Mark Kettenis
2023-01-13 18:00     ` Simon Glass
2023-01-08  2:50 ` [PATCH v2 49/71] bootstd: Set the distro_bootpart env var with scripts Simon Glass
2023-01-08  2:50 ` [PATCH v2 50/71] bootstd: Update docs on bootmeth_try_file() for sandbox Simon Glass
2023-01-08  2:50 ` [PATCH v2 51/71] bootstd: Move label parsing into its own function Simon Glass
2023-01-08  2:50 ` [PATCH v2 52/71] bootstd: Add a new bootmeth method to set the bootflow Simon Glass
2023-01-08  2:50 ` [PATCH v2 53/71] sandbox: Allow SPI flash bootdevs to be disabled for tests Simon Glass
2023-01-08  2:50 ` [PATCH v2 54/71] bootstd: Add a SPI flash bootdev Simon Glass
2023-01-08  2:50 ` [PATCH v2 55/71] bootstd: Support reading a script from network or SPI flash Simon Glass
2023-01-08  2:50 ` [PATCH v2 56/71] bootstd: Treat DHCP and PXE as bootdev labels Simon Glass
2023-01-08  2:50 ` [PATCH v2 57/71] bootstd: Use hunters when scanning for bootflows Simon Glass
2023-01-08  2:50 ` [PATCH v2 58/71] bootstd: Allow hunting for bootdevs of a given priority Simon Glass
2023-01-08  2:50 ` [PATCH v2 59/71] bootstd: Add a new pre-scan priority for bootdevs Simon Glass
2023-01-08  2:50 ` [PATCH v2 60/71] bootstd: Allow hunting for a bootdev by label Simon Glass
2023-01-08  2:50 ` [PATCH v2 61/71] bootstd: Allow iterating to the next label in a list Simon Glass
2023-01-08  2:50 ` [PATCH v2 63/71] extension: Refactor to allow non-command usage Simon Glass
2023-01-08  2:50 ` [PATCH v2 64/71] bootstd: Add a hunter for the extension feature Simon Glass
2023-01-08  2:50 ` [PATCH v2 65/71] bootstd: Switch bootdev scanning to use labels Simon Glass
2023-01-08  2:50 ` [PATCH v2 66/71] bootstd: Allow scanning a single bootdev label Simon Glass
2023-01-08  2:50 ` [PATCH v2 67/71] bootstd: Drop the old bootflow_scan_first() Simon Glass
2023-01-08  2:50 ` [PATCH v2 68/71] bootstd: Record the bootdevs used during scanning Simon Glass
2023-01-08  2:50 ` [PATCH v2 69/71] bootstd: Add a little more logging of bootflows Simon Glass
2023-01-08  2:50 ` [PATCH v2 70/71] bootstd: Update documentation for new features Simon Glass
2023-01-08  2:50 ` [PATCH v2 71/71] rockchip: Convert rockpro64-rk3399 to use standard boot Simon Glass
2023-01-16  9:54   ` Kever Yang
2023-01-13 19:54 ` [PATCH v2 00/71] bootstd: Allow migration from distro_bootcmd scripts Heinrich Schuchardt
2023-01-13 20:32   ` Mark Kettenis
2023-01-13 21:05     ` Simon Glass
2023-01-14  1:58       ` Peter Robinson
2023-01-13 20:47   ` Tom Rini
2023-01-17 13:57 ` Tom Rini
2023-01-17 16:07   ` Simon Glass

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=20230108025047.522240-25-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot-custodians@lists.denx.de \
    --cc=u-boot@lists.denx.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.