[PATCH 15/20] bootwrapper: Add dt_get_path().

Scott Wood scottwood at freescale.com
Tue Aug 21 03:40:05 EST 2007


This will be used by the PlanetCore firmware support to construct
a linux,stdout-path from the serial node that it finds.
---
 arch/powerpc/boot/devtree.c |   29 +++++++++++++++++++++++++++++
 arch/powerpc/boot/ops.h     |    1 +
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/boot/devtree.c b/arch/powerpc/boot/devtree.c
index e1b8122..a92c8fb 100644
--- a/arch/powerpc/boot/devtree.c
+++ b/arch/powerpc/boot/devtree.c
@@ -331,3 +331,32 @@ int dt_is_compatible(void *node, const char *compat)
 
 	return 0;
 }
+
+/* Returns the start of the path within the provided buffer, or NULL on
+ * error.
+ */
+char *dt_get_path(void *node, char *buf, int len)
+{
+	char *name = (char *)prop_buf;
+	char *orig_buf = buf;
+
+	buf += len;
+	*--buf = 0;
+
+	while (node) {
+		int len = getprop(node, "name", name, MAX_PROP_LEN);
+		if (len <= 0)
+			break;
+
+		if (len + 1 > buf - orig_buf)
+			return NULL;
+
+		buf -= len + 1;
+		buf[0] = '/';
+		memcpy(buf + 1, name, len);
+
+		node = get_parent(node);
+	}
+
+	return buf;
+}
diff --git a/arch/powerpc/boot/ops.h b/arch/powerpc/boot/ops.h
index 45c2268..5efdf26 100644
--- a/arch/powerpc/boot/ops.h
+++ b/arch/powerpc/boot/ops.h
@@ -90,6 +90,7 @@ int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
 int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
 int dt_is_compatible(void *node, const char *compat);
 void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
+char *dt_get_path(void *node, char *buf, int len);
 
 static inline void *finddevice(const char *name)
 {
-- 
1.5.0.3




More information about the Linuxppc-dev mailing list