]> git.baikalelectronics.ru Git - uboot.git/commitdiff
dm: core: add ofnode_get_path()
authorMarek Behún <marek.behun@nic.cz>
Wed, 26 May 2021 12:08:18 +0000 (14:08 +0200)
committerJagan Teki <jagan@amarulasolutions.com>
Thu, 24 Jun 2021 06:23:00 +0000 (11:53 +0530)
Add function for retrieving full node path of a given ofnode.
This uses np->full_name if OF is live, otherwise a call to
fdt_get_path() is made.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index dd34cf8ca3ef68164f99a49ebefa2ab66d316668..eeeccfb44674f5b58c55d8e10628fdfd9795378c 100644 (file)
@@ -286,6 +286,31 @@ const char *ofnode_get_name(ofnode node)
        return fdt_get_name(gd->fdt_blob, ofnode_to_offset(node), NULL);
 }
 
+int ofnode_get_path(ofnode node, char *buf, int buflen)
+{
+       assert(ofnode_valid(node));
+
+       if (ofnode_is_np(node)) {
+               if (strlen(node.np->full_name) >= buflen)
+                       return -ENOSPC;
+
+               strcpy(buf, node.np->full_name);
+
+               return 0;
+       } else {
+               int res;
+
+               res = fdt_get_path(gd->fdt_blob, ofnode_to_offset(node), buf,
+                                  buflen);
+               if (!res)
+                       return res;
+               else if (res == -FDT_ERR_NOSPACE)
+                       return -ENOSPC;
+               else
+                       return -EINVAL;
+       }
+}
+
 ofnode ofnode_get_by_phandle(uint phandle)
 {
        ofnode node;
index e3fccb506ea5423a24c48a8dc4b59425a57ed820..3da05d8b2178e2b47dd382d478ce0eae1c0dbf29 100644 (file)
@@ -458,6 +458,16 @@ ofnode ofnode_get_parent(ofnode node);
  */
 const char *ofnode_get_name(ofnode node);
 
+/**
+ * ofnode_get_path() - get the full path of a node
+ *
+ * @node: valid node to look up
+ * @buf: buffer to write the node path into
+ * @buflen: buffer size
+ * @return 0 if OK, -ve on error
+ */
+int ofnode_get_path(ofnode node, char *buf, int buflen);
+
 /**
  * ofnode_get_by_phandle() - get ofnode from phandle
  *
index 9a69cf70c1e4fe71b9987973af26a1357ca827ae..94a4d2189e8e51c873b05775f9369af29ea07a25 100644 (file)
@@ -297,3 +297,24 @@ static int dm_test_ofnode_get_reg(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_ofnode_get_reg, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_get_path(struct unit_test_state *uts)
+{
+       const char *path = "/translation-test@8000/noxlatebus@3,300/dev@42";
+       char buf[64];
+       ofnode node;
+       int res;
+
+       node = ofnode_path(path);
+       ut_assert(ofnode_valid(node));
+
+       res = ofnode_get_path(node, buf, 64);
+       ut_asserteq(0, res);
+       ut_asserteq_str(path, buf);
+
+       res = ofnode_get_path(node, buf, 32);
+       ut_asserteq(-ENOSPC, res);
+
+       return 0;
+}
+DM_TEST(dm_test_ofnode_get_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);