[PATCH v3 57/70] bootstd: Allow hunting for bootdevs of a given priority

Simon Glass sjg at chromium.org
Tue Jan 17 18:48:07 CET 2023


Add a way to run the hunter function for a particular priority, so that
new bootdevs can be found.

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

(no changes since v1)

 boot/bootdev-uclass.c | 25 +++++++++++++++++++++++++
 include/bootdev.h     | 11 +++++++++++
 test/boot/bootdev.c   | 25 +++++++++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 7ac42afd7b3..e8686159f2b 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -742,6 +742,31 @@ int bootdev_hunt(const char *spec, bool show)
 	return result;
 }
 
+int bootdev_hunt_prio(enum bootdev_prio_t prio, bool show)
+{
+	struct bootdev_hunter *start;
+	int n_ent, i;
+	int result;
+
+	start = ll_entry_start(struct bootdev_hunter, bootdev_hunter);
+	n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter);
+	result = 0;
+
+	log_debug("Hunting for priority %d\n", prio);
+	for (i = 0; i < n_ent; i++) {
+		struct bootdev_hunter *info = start + i;
+		int ret;
+
+		if (prio != info->prio)
+			continue;
+		ret = bootdev_hunt_drv(info, i, show);
+		if (ret && ret != -ENOENT)
+			result = ret;
+	}
+
+	return result;
+}
+
 void bootdev_list_hunters(struct bootstd_priv *std)
 {
 	struct bootdev_hunter *orig, *start;
diff --git a/include/bootdev.h b/include/bootdev.h
index db03c5c032e..b7973fa5760 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -284,6 +284,17 @@ void bootdev_list_hunters(struct bootstd_priv *std);
  */
 int bootdev_hunt(const char *spec, bool show);
 
+/**
+ * bootdev_hunt_prio() - Hunt for bootdevs of a particular priority
+ *
+ * This runs all hunters which can find bootdevs of the given priority.
+ *
+ * @prio: Priority to use
+ * @show: true to show each hunter as it is used
+ * Returns: 0 if OK, -ve on error
+ */
+int bootdev_hunt_prio(enum bootdev_prio_t prio, 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 e6045b05d81..f9653633a68 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -363,3 +363,28 @@ static int bootdev_test_bootable(struct unit_test_state *uts)
 	return 0;
 }
 BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/* Check hunting for bootdev of a particular priority */
+static int bootdev_test_hunt_prio(struct unit_test_state *uts)
+{
+	test_set_skip_delays(true);
+
+	console_record_reset_enable();
+	ut_assertok(bootdev_hunt_prio(BOOTDEVP_2_SCAN_FAST, false));
+	ut_assert_nextline("scanning bus for devices...");
+	ut_assert_skip_to_line("            Type: Hard Disk");
+	ut_assert_nextlinen("            Capacity:");
+	ut_assert_console_end();
+
+	/* now try a different priority, verbosely */
+	ut_assertok(bootdev_hunt_prio(BOOTDEVP_3_SCAN_SLOW, true));
+	ut_assert_nextline("Hunting with: ide");
+	ut_assert_nextline("Bus 0: not available  ");
+	ut_assert_nextline("Hunting with: usb");
+	ut_assert_nextline(
+		"Bus usb at 1: scanning bus usb at 1 for devices... 5 USB Device(s) found");
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
-- 
2.39.0.246.g2a6d74b583-goog



More information about the U-Boot mailing list