[PATCH 08/11] dm: core: Add an ofnode function to get the devicetree root

Simon Glass sjg at chromium.org
Sun Nov 29 01:50:07 CET 2020


This is needed in at least one place. Avoid the conditional code in root.c
by adding this inline function.

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

 drivers/core/root.c |  8 ++------
 include/dm/ofnode.h | 12 ++++++++++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/core/root.c b/drivers/core/root.c
index 5f10d7a39c7..9ee65504e6e 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -147,12 +147,8 @@ int dm_init(bool of_live)
 	ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
 	if (ret)
 		return ret;
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-	if (CONFIG_IS_ENABLED(OF_LIVE) && of_live)
-		DM_ROOT_NON_CONST->node = np_to_ofnode(gd_of_root());
-	else
-		DM_ROOT_NON_CONST->node = offset_to_ofnode(0);
-#endif
+	if (CONFIG_IS_ENABLED(OF_CONTROL))
+		DM_ROOT_NON_CONST->node = ofnode_root();
 	ret = device_probe(DM_ROOT_NON_CONST);
 	if (ret)
 		return ret;
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index ee8c44a71ec..53f04ac91d0 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -218,6 +218,18 @@ static inline ofnode ofnode_null(void)
 	return node;
 }
 
+static inline ofnode ofnode_root(void)
+{
+	ofnode node;
+
+	if (of_live_active())
+		node.np = gd_of_root();
+	else
+		node.of_offset = 0;
+
+	return node;
+}
+
 /**
  * ofnode_read_u32() - Read a 32-bit integer from a property
  *
-- 
2.29.2.454.gaff20da3a2-goog



More information about the U-Boot mailing list