[PATCH] libfdt: Add support for appending the values to a existing property
David Gibson
david at gibson.dropbear.id.au
Wed Nov 9 15:49:14 EST 2011
On Wed, Sep 28, 2011 at 11:58:50AM +0800, Minghuan Lian wrote:
> 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.
Sorry, this somehow got stuck in the mailing list and I only saw it a
few days ago, despite being posted more than a month back.
Nice patch, and a feature we definitely want. Couple of little tweaks
would improve it, though.
>
> Signed-off-by: Minghuan Lian <Minghuan.Lian at freescale.com>
> ---
> libfdt/fdt_rw.c | 27 +++++++++++++++++++++++++++
> libfdt/libfdt.h | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 57 insertions(+), 0 deletions(-)
>
> diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
> index 994037b..0ee578e 100644
> --- a/libfdt/fdt_rw.c
> +++ b/libfdt/fdt_rw.c
> @@ -289,6 +289,33 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
> return 0;
> }
>
> +int fdt_append_prop(void *fdt, int nodeoffset, const char *name,
> + const void *val, int len)
I'd call it fdt_appendprop() without the extra underscore to match
setprop and getprop.
> +{
> + 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;
> +}
> +
Could you add fdt_appendprop_cell() and fdt_appendprop_string()
wrappers too, please.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
More information about the devicetree-discuss
mailing list