summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/fdt_decode.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index 4e889db0eb..adad546fb0 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -20,9 +20,11 @@
*/
#include <common.h>
-#include <serial.h>
-#include <libfdt.h>
+
#include <fdt_decode.h>
+#include <libfdt.h>
+#include <malloc.h>
+#include <serial.h>
/* we need a generic GPIO interface here */
#include <asm/arch/gpio.h>
@@ -676,3 +678,23 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
config->width = get_int(blob, node, "width", 8);
return fdt_decode_gpio(blob, node, "wp-gpio", &config->wp_gpio);
}
+
+void *fdt_decode_alloc_region(const void *blob, int node,
+ const char *prop_name, size_t *size)
+{
+ const addr_t *cell;
+ void *ptr;
+ int len;
+
+ debug("fdt_decode_alloc: %s\n", prop_name);
+ cell = fdt_getprop(blob, node, prop_name, &len);
+ if (!cell || (len != sizeof(addr_t) * 2))
+ return NULL;
+
+ ptr = (void *)addr_to_cpu(*cell);
+ *size = size_to_cpu(cell[1]);
+ debug("fdt_decode_alloc: size=%zx\n", *size);
+ if (!ptr)
+ ptr = malloc(*size);
+ return ptr;
+}