return -1;
}
-
/* Verify that property length accords with cell length */
if (NCELLS((unsigned int)value_len) != cells) {
WARN("Property length mismatch\n");
return 0;
}
+/*
+ * Read cells from a given property of the given node. Any number of 32-bit
+ * cells of the property can be read. The fdt pointer is updated. Returns 0 on
+ * success, and -1 on error.
+ */
+int fdtw_read_array(const void *dtb, int node, const char *prop,
+ unsigned int cells, void *value)
+{
+ const uint32_t *value_ptr;
+ int value_len;
+
+ assert(dtb != NULL);
+ assert(prop != NULL);
+ assert(value != NULL);
+ assert(node >= 0);
+
+ /* Access property and obtain its length (in bytes) */
+ value_ptr = fdt_getprop_namelen(dtb, node, prop, (int)strlen(prop),
+ &value_len);
+ if (value_ptr == NULL) {
+ WARN("Couldn't find property %s in dtb\n", prop);
+ return -1;
+ }
+
+ /* Verify that property length accords with cell length */
+ if (NCELLS((unsigned int)value_len) != cells) {
+ WARN("Property length mismatch\n");
+ return -1;
+ }
+
+ uint32_t *dst = value;
+
+ for (unsigned int i = 0U; i < cells; i++) {
+ dst[i] = fdt32_to_cpu(value_ptr[i]);
+ }
+
+ return 0;
+}
+
/*
* Read string from a given property of the given node. Up to 'size - 1'
* characters are read, and a NUL terminator is added. Returns 0 on success,
int fdtw_read_cells(const void *dtb, int node, const char *prop,
unsigned int cells, void *value);
+int fdtw_read_array(const void *dtb, int node, const char *prop,
+ unsigned int cells, void *value);
int fdtw_read_string(const void *dtb, int node, const char *prop,
char *str, size_t size);
int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,