All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] add alias support to fdt_path_offset
@ 2008-08-04 22:25 Kumar Gala
       [not found] ` <Pine.LNX.4.64.0808041722001.328-S0ohy4nlquecPGwCZ8RIISaugJOa9f/+@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Kumar Gala @ 2008-08-04 22:25 UTC (permalink / raw)
  To: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A
  Cc: gvb.uboot-Re5JQEeQqe8AvxtiuMwx3w

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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-08-05  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-04 22:25 [RFC] add alias support to fdt_path_offset Kumar Gala
     [not found] ` <Pine.LNX.4.64.0808041722001.328-S0ohy4nlquecPGwCZ8RIISaugJOa9f/+@public.gmane.org>
2008-08-05  3:58   ` David Gibson
     [not found]     ` <20080805035844.GB16526-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-08-05  4:02       ` M. Warner Losh
     [not found]         ` <20080804.220226.-1219852411.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2008-08-05  4:13           ` David Gibson
     [not found]             ` <20080805041306.GC16526-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-08-05  6:26               ` Kumar Gala

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.