]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
fdt: Add a function to count strings
authorThierry Reding <treding@nvidia.com>
Tue, 26 Aug 2014 15:33:50 +0000 (17:33 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 22 Oct 2014 22:56:40 +0000 (16:56 -0600)
Given a device tree node and a property name, the fdt_count_strings()
function counts the number of strings found in the property value.

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

index a1ef1e15df3ddbd8abec45766b9f9038f334bcc1..cf97bf0b3b522d4c385aaab14170c0f1201c8d2a 100644 (file)
@@ -857,6 +857,15 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  */
 int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
 
+/**
+ * fdt_count_strings - count the number of strings 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
+ * @return: the number of strings in the given property
+ */
+int fdt_count_strings(const void *fdt, int node, const char *property);
+
 /**********************************************************************/
 /* Read-only functions (addressing related)                           */
 /**********************************************************************/
index 36af0435254b47cb0d2599836d1c81638266adf8..cb06a9b50d8509d30bad932737687af211e59dda 100644 (file)
@@ -491,6 +491,26 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
        return 0;
 }
 
+int fdt_count_strings(const void *fdt, int node, const char *property)
+{
+       int length, i, count = 0;
+       const char *list;
+
+       list = fdt_getprop(fdt, node, property, &length);
+       if (!list)
+               return -length;
+
+       for (i = 0; i < length; i++) {
+               int len = strlen(list);
+
+               list += len + 1;
+               i += len;
+               count++;
+       }
+
+       return count;
+}
+
 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
                              const char *compatible)
 {