Patchwork [RFC,v0,01/10] device_tree: allow offsets for cell properties

login
register
mail settings
Submitter Peter A. G. Crosthwaite
Date Sept. 17, 2012, 9:02 a.m.
Message ID <3ad651bfaa7f433b2bb032d6ef3035b270894130.1347871922.git.peter.crosthwaite@petalogix.com>
Download mbox | patch
Permalink /patch/184330/
State New
Headers show

Comments

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

Patch

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;