]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Add a function to decode a variable-sized u32 array
authorSimon Glass <sjg@chromium.org>
Tue, 11 Nov 2014 01:00:19 +0000 (18:00 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 21 Nov 2014 06:24:11 +0000 (07:24 +0100)
Sometimes an array can be of variable size up to a maximum. Add a helper
function to decode this.

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

index 4ae77be9ba7c8bf09860606645db711db0911fb2..6b4000623d884d312a317341235ea10154da28b4 100644 (file)
@@ -444,6 +444,22 @@ int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name);
 int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
                u32 *array, int count);
 
+/**
+ * Look up a property in a node and return its contents in an integer
+ * array of given length. The property must exist but may have less data that
+ * expected (4*count bytes). It may have more, but this will be ignored.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param prop_name    name of property to find
+ * @param array                array to fill with data
+ * @param count                number of array elements
+ * @return number of array elements if ok, or -FDT_ERR_NOTFOUND if the
+ *             property is not found
+ */
+int fdtdec_get_int_array_count(const void *blob, int node,
+                              const char *prop_name, u32 *array, int count);
+
 /**
  * Look up a property in a node and return a pointer to its contents as a
  * unsigned int array of given length. The property must have at least enough
index 9714620ab3e211df006d440dc4f1abb6d03bb9b8..4aa227a0c3812b110040a30571c850d5b75a93aa 100644 (file)
@@ -485,6 +485,26 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
        return err;
 }
 
+int fdtdec_get_int_array_count(const void *blob, int node,
+                              const char *prop_name, u32 *array, int count)
+{
+       const u32 *cell;
+       int len, elems;
+       int i;
+
+       debug("%s: %s\n", __func__, prop_name);
+       cell = fdt_getprop(blob, node, prop_name, &len);
+       if (!cell)
+               return -FDT_ERR_NOTFOUND;
+       elems = len / sizeof(u32);
+       if (count > elems)
+               count = elems;
+       for (i = 0; i < count; i++)
+               array[i] = fdt32_to_cpu(cell[i]);
+
+       return count;
+}
+
 const u32 *fdtdec_locate_array(const void *blob, int node,
                               const char *prop_name, int count)
 {