Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwa...@petalogix.com>
---
 device_tree.c |   10 +++++-----
 device_tree.h |    2 +-
 hw/arm_boot.c |    4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/device_tree.c b/device_tree.c
index d7a9b6b..92a383e 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -196,16 +196,16 @@ const void *qemu_devtree_getprop(void *fdt, const char 
*node_path,
 }
 
 uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,
-                                   const char *property)
+                                   const char *property, int offset)
 {
     int len;
     const uint32_t *p = qemu_devtree_getprop(fdt, node_path, property, &len);
-    if (len != 4) {
-        fprintf(stderr, "%s: %s/%s not 4 bytes long (not a cell?)\n",
-                __func__, node_path, property);
+    if (len < (offset+1)*4) {
+        fprintf(stderr, "%s: %s/%s not long enough to hold %d properties\n",
+                __func__, node_path, property, offset+1);
         exit(1);
     }
-    return be32_to_cpu(*p);
+    return be32_to_cpu(p[offset]);
 }
 
 uint32_t qemu_devtree_get_phandle(void *fdt, const char *path)
diff --git a/device_tree.h b/device_tree.h
index f7a3e6c..759e142 100644
--- a/device_tree.h
+++ b/device_tree.h
@@ -31,7 +31,7 @@ int qemu_devtree_setprop_phandle(void *fdt, const char 
*node_path,
 const void *qemu_devtree_getprop(void *fdt, const char *node_path,
                                  const char *property, int *lenp);
 uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,
-                                   const char *property);
+                                   const char *property, int offset);
 uint32_t qemu_devtree_get_phandle(void *fdt, const char *path);
 uint32_t qemu_devtree_alloc_phandle(void *fdt);
 int qemu_devtree_nop_node(void *fdt, const char *node_path);
diff --git a/hw/arm_boot.c b/hw/arm_boot.c
index a6e9143..051aee6 100644
--- a/hw/arm_boot.c
+++ b/hw/arm_boot.c
@@ -237,8 +237,8 @@ static int load_dtb(target_phys_addr_t addr, const struct 
arm_boot_info *binfo)
     }
     g_free(filename);
 
-    acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells");
-    scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells");
+    acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells", 0);
+    scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells", 0);
     if (acells == 0 || scells == 0) {
         fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 
0)\n");
         return -1;
-- 
1.7.0.4


Reply via email to