]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Add functions to retrieve strings
authorThierry Reding <treding@nvidia.com>
Tue, 26 Aug 2014 15:33:52 +0000 (17:33 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 22 Oct 2014 22:56:41 +0000 (16:56 -0600)
Given a device tree node, a property name and an index, the new function
fdt_get_string_index() will return in an output argument a pointer to
the index'th string in the property's value.

The fdt_get_string() is a shortcut for the above with the index being 0.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
include/libfdt.h
lib/libfdt/fdt_ro.c

index d0dea668eea22dfeed0811e5902a2c20b0ccd205..2dfc6d9e5ce796a232175987d7d51594b869bda8 100644 (file)
@@ -877,6 +877,33 @@ int fdt_count_strings(const void *fdt, int node, const char *property);
 int fdt_find_string(const void *fdt, int node, const char *property,
                    const char *string);
 
+/**
+ * fdt_get_string_index() - obtain the string at a given index in a string list
+ * @fdt: pointer to the device tree blob
+ * @node: offset of the node
+ * @property: name of the property containing the string list
+ * @index: index of the string to return
+ * @output: return location for the string
+ * @return: 0 if the string was found or a negative error code otherwise
+ */
+int fdt_get_string_index(const void *fdt, int node, const char *property,
+                        int index, const char **output);
+
+/**
+ * fdt_get_string() - obtain the string at a given index in a string list
+ * @fdt: pointer to the device tree blob
+ * @node: offset of the node
+ * @property: name of the property containing the string list
+ * @output: return location for the string
+ * @return: 0 if the string was found or a negative error code otherwise
+ *
+ * This is a shortcut for:
+ *
+ *     fdt_get_string_index(fdt, node, property, 0, output).
+ */
+int fdt_get_string(const void *fdt, int node, const char *property,
+                  const char **output);
+
 /**********************************************************************/
 /* Read-only functions (addressing related)                           */
 /**********************************************************************/
index fec4a0a141fdd3e556e4f7aede81417c0be81fdf..03733e574f71db1df2ebec2c08ec66dff95908d0 100644 (file)
@@ -537,6 +537,36 @@ int fdt_find_string(const void *fdt, int node, const char *property,
        return -FDT_ERR_NOTFOUND;
 }
 
+int fdt_get_string_index(const void *fdt, int node, const char *property,
+                        int index, const char **output)
+{
+       const char *list;
+       int length, i;
+
+       list = fdt_getprop(fdt, node, property, &length);
+
+       for (i = 0; i < length; i++) {
+               int len = strlen(list);
+
+               if (index == 0) {
+                       *output = list;
+                       return 0;
+               }
+
+               list += len + 1;
+               i += len;
+               index--;
+       }
+
+       return FDT_ERR_NOTFOUND;
+}
+
+int fdt_get_string(const void *fdt, int node, const char *property,
+                  const char **output)
+{
+       return fdt_get_string_index(fdt, node, property, 0, output);
+}
+
 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
                              const char *compatible)
 {