]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
fdtlib
authorVladimir Serbinenko <phcoder@gmail.com>
Sat, 20 Feb 2016 13:28:37 +0000 (14:28 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sat, 20 Feb 2016 13:28:37 +0000 (14:28 +0100)
grub-core/lib/fdt.c
include/grub/fdt.h

index c701aa956fabcfcf63cd1974615be28f241f39f9..bcff081317e5055d977ae1279cbf07e715883d16 100644 (file)
@@ -229,7 +229,7 @@ static int rearrange_blocks (void *fdt, unsigned int clearance)
   return 0;
 }
 
-static grub_uint32_t *find_prop (void *fdt, unsigned int nodeoffset,
+static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset,
                                 const char *name)
 {
   grub_uint32_t *prop = (void *) ((grub_addr_t) fdt
@@ -382,13 +382,19 @@ int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset,
     if (!token)
       return -1;
     skip_current = 1;
-    node_name = (const char *) token + 1;
+    node_name = (const char *) token + 4;
     if (grub_strcmp (node_name, name) == 0)
       return (int) ((grub_addr_t) token - (grub_addr_t) fdt
                    - grub_fdt_get_off_dt_struct (fdt));
   }
 }
 
+const char *
+grub_fdt_get_nodename (const void *fdt, unsigned int nodeoffset)
+{
+  return (const char *) fdt + grub_fdt_get_off_dt_struct(fdt) + nodeoffset + 4;
+}
+
 int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
                          const char *name)
 {
@@ -405,6 +411,24 @@ int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
   return add_subnode (fdt, parentoffset, name);
 }
 
+const void *
+grub_fdt_get_prop (const void *fdt, unsigned int nodeoffset, const char *name,
+                  grub_uint32_t *len)
+{
+  grub_uint32_t *prop;
+  if ((nodeoffset >= grub_fdt_get_size_dt_struct (fdt)) || (nodeoffset & 0x3)
+      || (grub_be_to_cpu32(*(grub_uint32_t *) ((grub_addr_t) fdt
+                                              + grub_fdt_get_off_dt_struct (fdt) + nodeoffset))
+          != FDT_BEGIN_NODE))
+    return 0;
+  prop = find_prop (fdt, nodeoffset, name);
+  if (!prop)
+    return 0;
+  if (len)
+    *len = grub_be_to_cpu32 (*(prop + 2));
+  return prop + 3;
+}
+
 int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
                       const void *val, grub_uint32_t len)
 {
index fcc2ed419cde0f245be3ce4c9c729fb3a44f2fcc..bdb36310411f52c95310640c53d1017e64eebaaf 100644 (file)
@@ -104,6 +104,10 @@ int grub_fdt_first_node (const void *fdt, unsigned int parentoffset);
 int grub_fdt_next_node (const void *fdt, unsigned int currentoffset);
 int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset,
                          const char *name);
+const char *
+grub_fdt_get_nodename (const void *fdt, unsigned int nodeoffset);
+const void *grub_fdt_get_prop (const void *fdt, unsigned int nodeoffset, const char *name,
+                              grub_uint32_t *len);
 
 int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name,
                      const void *val, grub_uint32_t len);