]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Add a system bootdev for strange boot methods
authorSimon Glass <sjg@chromium.org>
Mon, 25 Apr 2022 05:31:18 +0000 (23:31 -0600)
committerTom Rini <trini@konsulko.com>
Mon, 25 Apr 2022 14:00:04 +0000 (10:00 -0400)
Some boot methods don't act on a single bootdev but instead do their own
thing. An example is EFI bootmgr which scan various devices using its own
logic. Add a bootdev to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/Makefile
boot/bootstd-uclass.c
boot/system_bootdev.c [new file with mode: 0644]

index 4f9267687fa834af6c8300727dc2afc4777ac28f..7325dbc1dd6de56281dcc369a63382b7cbb22e51 100644 (file)
@@ -19,7 +19,7 @@ obj-y += image.o image-board.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 
-obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o system_bootdev.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
index 266bd7cb2e32f58cb80852e92ceb5fd589d3f81d..3c6c32ae604c11c3a87fa968a8d79d2b1f860783 100644 (file)
@@ -150,6 +150,12 @@ int dm_scan_other(bool pre_reloc_only)
                }
        }
 
+       /* Create the system bootdev too */
+       ret = device_bind_driver(bootstd, "system_bootdev", "system-bootdev",
+                                &dev);
+       if (ret)
+               return log_msg_ret("sys", ret);
+
        return 0;
 }
 
diff --git a/boot/system_bootdev.c b/boot/system_bootdev.c
new file mode 100644 (file)
index 0000000..432d203
--- /dev/null
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootdevice for system, used for bootmeths not tied to any partition device
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include <common.h>
+#include <bootdev.h>
+#include <bootflow.h>
+#include <bootmeth.h>
+#include <command.h>
+#include <distro.h>
+#include <dm.h>
+#include <log.h>
+#include <net.h>
+
+static int system_get_bootflow(struct udevice *dev, struct bootflow_iter *iter,
+                              struct bootflow *bflow)
+{
+       int ret;
+
+       /* Must be an bootstd device */
+       ret = bootflow_iter_uses_system(iter);
+       if (ret)
+               return log_msg_ret("net", ret);
+
+       ret = bootmeth_check(bflow->method, iter);
+       if (ret)
+               return log_msg_ret("check", ret);
+
+       ret = bootmeth_read_bootflow(bflow->method, bflow);
+       if (ret)
+               return log_msg_ret("method", ret);
+
+       return 0;
+}
+
+static int system_bootdev_bind(struct udevice *dev)
+{
+       struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+
+       ucp->prio = BOOTDEVP_6_SYSTEM;
+
+       return 0;
+}
+
+struct bootdev_ops system_bootdev_ops = {
+       .get_bootflow   = system_get_bootflow,
+};
+
+static const struct udevice_id system_bootdev_ids[] = {
+       { .compatible = "u-boot,bootdev-system" },
+       { }
+};
+
+U_BOOT_DRIVER(system_bootdev) = {
+       .name           = "system_bootdev",
+       .id             = UCLASS_BOOTDEV,
+       .ops            = &system_bootdev_ops,
+       .bind           = system_bootdev_bind,
+       .of_match       = system_bootdev_ids,
+};