[RFC] add alias support to fdt_path_offset

Kumar Gala galak at kernel.crashing.org
Tue Aug 5 08:25:17 EST 2008


Here's my attempt at adding alias support to fdt_path_offset()

I don't care for the path_buf[256], but not sure how else to do that.

(this is based on discussion on the u-boot list).

- k

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 69af7bb..1cc5bc6 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -135,8 +135,37 @@ int fdt_path_offset(const void *fdt, const char *path)

 	CHECK_HEADER(fdt);

-	if (*path != '/')
-		return -FDT_ERR_BADPATH;
+	/* see if we have an alias */
+	if (*path != '/') {
+		int i = 0, aliasoffset = fdt_path_offset(fdt, "/aliases");
+		char path_buf[256];
+		const char *q;
+
+		if (aliasoffset < 0)
+			return -FDT_ERR_BADPATH;
+
+		q = strchr(path, '/');
+		if (!q)
+			q = end;
+
+		while (p != q)
+			path_buf[i++] = *p++;
+		path_buf[i] = '\0';
+
+		p = fdt_getprop(fdt, aliasoffset, path_buf, NULL);
+
+		if (!p)
+			return -FDT_ERR_BADPATH;
+
+		i = 0;
+		while (*p)
+			path_buf[i++] = *p++;
+		while (*q)
+			path_buf[i++] = *q++;
+		path_buf[i] = '\0';
+
+		return fdt_path_offset(fdt, path_buf);
+	}

 	while (*p) {
 		const char *q;



More information about the devicetree-discuss mailing list