diff mbox

[U-Boot,v3,21/29] fdt: Add a function to get the node offset of an alias

Message ID 1406120124-9373-22-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass July 23, 2014, 12:55 p.m. UTC
This simple function returns the node offset of a named alias.

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

Changes in v3: None
Changes in v2: None

 include/fdtdec.h | 11 +++++++++++
 lib/fdtdec.c     | 15 +++++++++++++++
 2 files changed, 26 insertions(+)

Comments

Simon Glass July 26, 2014, 3:11 p.m. UTC | #1
On 23 July 2014 13:55, Simon Glass <sjg@chromium.org> wrote:
> This simple function returns the node offset of a named alias.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to dm/master.
diff mbox

Patch

diff --git a/include/fdtdec.h b/include/fdtdec.h
index f96b0d3..5f88938 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -365,6 +365,17 @@  int fdtdec_add_aliases_for_id(const void *blob, const char *name,
 int fdtdec_get_alias_seq(const void *blob, const char *base, int node,
 			 int *seqp);
 
+/**
+ * Get the offset of the given alias node
+ *
+ * This looks up an alias in /aliases then finds the offset of that node.
+ *
+ * @param blob		Device tree blob (if NULL, then error is returned)
+ * @param name		Alias name, e.g. "console"
+ * @return Node offset referred to by that alias, or -ve FDT_ERR_...
+ */
+int fdtdec_get_alias_node(const void *blob, const char *name);
+
 /*
  * Get the name for a compatible ID
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 3f3ed4e..c2f3645 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -367,6 +367,21 @@  int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
 	return -ENOENT;
 }
 
+int fdtdec_get_alias_node(const void *blob, const char *name)
+{
+	const char *prop;
+	int alias_node;
+	int len;
+
+	if (!blob)
+		return -FDT_ERR_NOTFOUND;
+	alias_node = fdt_path_offset(blob, "/aliases");
+	prop = fdt_getprop(blob, alias_node, name, &len);
+	if (!prop)
+		return -FDT_ERR_NOTFOUND;
+	return fdt_path_offset(blob, prop);
+}
+
 int fdtdec_check_fdt(void)
 {
 	/*