[U-Boot] [PATCH 13/22] dm: core: Scan the live tree when setting up driver model

Simon Glass sjg at chromium.org
Wed Jan 18 06:51:49 CET 2017


When starting up driver model with a live tree we need to scan the tree
for devices. Add code to handle this.

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

 drivers/core/root.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/core/root.c b/drivers/core/root.c
index cd09c55d9d2..b15376a9859 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -12,9 +12,13 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <libfdt.h>
+#include <livetree.h>
 #include <dm/device.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
+#include <dm/of.h>
+#include <dm/of_access.h>
+#include <dm/of_ref.h>
 #include <dm/platdata.h>
 #include <dm/root.h>
 #include <dm/uclass.h>
@@ -165,7 +169,11 @@ int dm_init(void)
 	if (ret)
 		return ret;
 #if CONFIG_IS_ENABLED(OF_CONTROL)
+# if defined(CONFIG_OF_LIVE)
+	DM_ROOT_NON_CONST->node_ref = of_node_to_ref(gd->of_root);
+# else
 	DM_ROOT_NON_CONST->of_offset = 0;
+# endif
 #endif
 	ret = device_probe(DM_ROOT_NON_CONST);
 	if (ret)
@@ -195,6 +203,36 @@ int dm_scan_platdata(bool pre_reloc_only)
 	return ret;
 }
 
+#ifdef CONFIG_OF_LIVE
+static int dm_scan_fdt_live(struct udevice *parent,
+			    struct device_node *node_parent,
+			    bool pre_reloc_only)
+{
+	struct device_node *np;
+	int ret = 0, err;
+
+	for (np = node_parent->child; np; np = np->sibling) {
+		if (pre_reloc_only &&
+		    !of_find_property(np, "u-boot,dm-pre-reloc", NULL))
+			continue;
+		if (!of_device_is_available(np)) {
+			dm_dbg("   - ignoring disabled device\n");
+			continue;
+		}
+		err = lists_bind_node(parent, np, NULL);
+		if (err && !ret) {
+			ret = err;
+			debug("%s: ret=%d\n", np->name, ret);
+		}
+	}
+
+	if (ret)
+		dm_warn("Some drivers failed to bind\n");
+
+	return ret;
+}
+#endif /* CONFIG_OF_LIVE */
+
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 /**
  * dm_scan_fdt_node() - Scan the device tree and bind drivers for a node
@@ -249,6 +287,12 @@ int dm_scan_fdt_dev(struct udevice *dev)
 
 int dm_scan_fdt(const void *blob, bool pre_reloc_only)
 {
+#ifdef CONFIG_OF_LIVE
+	if (of_use_livetree())
+		return dm_scan_fdt_live(gd->dm_root, gd->of_root,
+					pre_reloc_only);
+	else
+#endif
 	return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
 }
 #endif
-- 
2.11.0.483.g087da7b7c-goog



More information about the U-Boot mailing list