summaryrefslogtreecommitdiff
path: root/drivers/block/sandbox-bootdev.c
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2026-07-03 10:14:32 -0600
committerTom Rini <[email protected]>2026-07-03 10:14:32 -0600
commit2569e25ddd5aa323cd87c7a3819c3a4f4b32302f (patch)
tree5c341a5b2908aab52ace915bde5b60ebdbe922d0 /drivers/block/sandbox-bootdev.c
parent683161607af99a12de83eb5702d1f2662a107ac1 (diff)
parent93e9af685fefc454580dcf567b03c139a2fe8ebc (diff)
Merge patch series "bootdev: few fixes for automatic boot"
[email protected] <[email protected]> says: This series addresses few findings in bootdev code. Patch 1 fix for automatic boots in case higher-priority bootdevs fail to be hunted. Patch 2 adds unit test for patch 1. Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'drivers/block/sandbox-bootdev.c')
-rw-r--r--drivers/block/sandbox-bootdev.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/drivers/block/sandbox-bootdev.c b/drivers/block/sandbox-bootdev.c
new file mode 100644
index 00000000000..15af0c17d1f
--- /dev/null
+++ b/drivers/block/sandbox-bootdev.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#define LOG_CATEGORY UCLASS_HOST
+
+#include <bootdev.h>
+#include <dm.h>
+#include <log.h>
+#include <sandbox_host.h>
+
+static int sandbox_bootdev_bind(struct udevice *dev)
+{
+ struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+
+ ucp->prio = BOOTDEVP_4_SCAN_FAST;
+
+ return 0;
+}
+
+/**
+ * sandbox_bootdev_hunt() - Hunt host bootdev.
+ *
+ * Note, this hunter exists for bootdev testing to simulate a failure
+ * mode. Do not use as an example of a real hunter.
+ *
+ * @info: Hunter details.
+ * @show: Enable extra printouts.
+ *
+ * Returns: 0 if OK, -ve on error (expected by the test)
+ */
+static int sandbox_bootdev_hunt(struct bootdev_hunter *info, bool show)
+{
+ struct udevice *dev;
+ struct uclass *uc;
+ int ret;
+
+ uclass_id_foreach_dev(UCLASS_HOST, dev, uc) {
+ struct host_sb_plat *plat = dev_get_plat(dev);
+
+ log_debug("hunting %s\n", plat->label);
+
+ if (plat->flags & HOST_FLAG_BROKEN) {
+ ret = -ETIME;
+ log_debug("cannot hunt sandbox device '%s': %d\n",
+ plat->label, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static const struct bootdev_ops sandbox_bootdev_ops = {
+};
+
+static const struct udevice_id sandbox_bootdev_ids[] = {
+ { .compatible = "u-boot,bootdev-sandbox" },
+ { }
+};
+
+U_BOOT_DRIVER(sandbox_bootdev) = {
+ .name = "sandbox_bootdev",
+ .id = UCLASS_BOOTDEV,
+ .ops = &sandbox_bootdev_ops,
+ .bind = sandbox_bootdev_bind,
+ .of_match = sandbox_bootdev_ids,
+};
+
+BOOTDEV_HUNTER(sandbox_bootdev_hunter) = {
+ .prio = BOOTDEVP_4_SCAN_FAST,
+ .uclass = UCLASS_HOST,
+ .hunt = sandbox_bootdev_hunt,
+ .drv = DM_DRIVER_REF(sandbox_bootdev),
+};