From: Vladimir Serbinenko Date: Sat, 20 Feb 2016 13:28:37 +0000 (+0100) Subject: fdtlib X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=99291427d2486c32cbe9f0f658123a1448f53e8d;p=thirdparty%2Fgrub.git fdtlib --- diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c index c701aa956..bcff08131 100644 --- a/grub-core/lib/fdt.c +++ b/grub-core/lib/fdt.c @@ -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) { diff --git a/include/grub/fdt.h b/include/grub/fdt.h index fcc2ed419..bdb363104 100644 --- a/include/grub/fdt.h +++ b/include/grub/fdt.h @@ -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);