From 36ad18a6db0eec546b83e6500ceb7593be53a1ed Mon Sep 17 00:00:00 2001 From: Minghuan Lian Date: Mon, 27 Aug 2012 19:38:59 -0500 Subject: 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 Signed-off-by: David Gibson --- lib/libfdt/fdt_rw.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/libfdt/fdt_rw.c') diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c index 5c27a67..5ed23d6 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; -- cgit v1.1