fdt: Add a function to get the node offset of an alias
authorSimon Glass <sjg@chromium.org>
Wed, 23 Jul 2014 12:55:16 +0000 (06:55 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 23 Jul 2014 13:07:26 +0000 (14:07 +0100)
This simple function returns the node offset of a named alias.

Signed-off-by: Simon Glass <sjg@chromium.org>
include/fdtdec.h
lib/fdtdec.c

index f454f7e..856e6cf 100644 (file)
@@ -363,6 +363,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
  *
index 1b4ae9f..eb5aa20 100644 (file)
@@ -365,6 +365,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)
 {
        /*