bootstd: Add the concept of a bootdev hunter

Some bootdevs must be enumerated before they appear. For example, USB
bootdevs are not visible until USB is enumerated.

With standard boot this needs to happen automatically, since we only
want to enumerate a bus if it is needed.

Add a way to define bootdev 'hunters' which can be used to hunt for
bootdevs of a given type. Track which ones have been used and add a
command to list them.

Include a clang work-around which seems to be needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 1c2a79f..a8ca12a 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -221,3 +221,55 @@
 	return 0;
 }
 BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/* Check listing hunters */
+static int bootdev_test_hunter(struct unit_test_state *uts)
+{
+	struct bootstd_priv *std;
+
+	/* get access to the used hunters */
+	ut_assertok(bootstd_get_priv(&std));
+
+	console_record_reset_enable();
+	bootdev_list_hunters(std);
+	ut_assert_nextline("Prio  Used  Uclass           Hunter");
+	ut_assert_nextlinen("----");
+	ut_assert_nextline("(total hunters: 0)");
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/* Check 'bootdev hunt' command */
+static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
+{
+	struct bootstd_priv *std;
+
+	/* get access to the used hunters */
+	ut_assertok(bootstd_get_priv(&std));
+
+	console_record_reset_enable();
+	ut_assertok(run_command("bootdev hunt -l", 0));
+	ut_assert_nextline("Prio  Used  Uclass           Hunter");
+	ut_assert_nextlinen("----");
+	ut_assert_nextline("(total hunters: 0)");
+	ut_assert_console_end();
+
+	/* Scan all hunters */
+	ut_assertok(run_command("bootdev hunt", 0));
+	ut_assert_console_end();
+
+	/* List available hunters */
+	ut_assertok(run_command("bootdev hunt -l", 0));
+	ut_assert_nextlinen("Prio");
+	ut_assert_nextlinen("----");
+	ut_assert_nextline("(total hunters: 0)");
+	ut_assert_console_end();
+
+	ut_asserteq(0, std->hunters_used);
+
+	return 0;
+}
+BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
+	     UT_TESTF_ETH_BOOTDEV);