diff options
author | Minghuan Lian <Minghuan.Lian@freescale.com> | 2012-08-27 19:38:59 -0500 |
---|---|---|
committer | Gerald Van Baren <gvb@unssw.com> | 2012-10-15 19:15:39 -0400 |
commit | 36ad18a6db0eec546b83e6500ceb7593be53a1ed (patch) | |
tree | a16b8142752d256470579f69f4f5c924a3cb9214 /lib/libfdt | |
parent | 6528ff0109d81c1f21d20f9f1370782bccf87bcb (diff) |
libfdt: Add support for appending the values to a existing property
Some properties may contain multiple values, these values may need
to be added to the property respectively. this patch provides this
functionality. The main purpose of fdt_append_prop() is to append
the values to a existing property, or create a new property if it
dose not exist.
Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'lib/libfdt')
-rw-r--r-- | lib/libfdt/fdt_rw.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c index 5c27a677e35..5ed23d6f193 100644 --- a/lib/libfdt/fdt_rw.c +++ b/lib/libfdt/fdt_rw.c @@ -293,6 +293,33 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, return 0; } +int fdt_appendprop(void *fdt, int nodeoffset, const char *name, + const void *val, int len) +{ + struct fdt_property *prop; + int err, oldlen, newlen; + + FDT_RW_CHECK_HEADER(fdt); + + prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); + if (prop) { + newlen = len + oldlen; + err = _fdt_splice_struct(fdt, prop->data, + FDT_TAGALIGN(oldlen), + FDT_TAGALIGN(newlen)); + if (err) + return err; + prop->len = cpu_to_fdt32(newlen); + memcpy(prop->data + oldlen, val, len); + } else { + err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); + if (err) + return err; + memcpy(prop->data, val, len); + } + return 0; +} + int fdt_delprop(void *fdt, int nodeoffset, const char *name) { struct fdt_property *prop; |