diff options
author | Maxime Ripard <maxime.ripard@free-electrons.com> | 2016-07-05 10:26:43 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-08-20 11:35:04 -0400 |
commit | ea7b1a213e8b01befd05d94620add7cf84883876 (patch) | |
tree | c13650677e4b097ae9eb4dc5468745975086e51d /lib | |
parent | 2b941bf96dd66a5730f1dcbcb635e28930aa58fa (diff) |
libfdt: Add fdt_setprop_inplace_namelen_partial
Add a function to modify inplace only a portion of a property..
This is especially useful when the property is an array of values, and you
want to update one of them without changing the DT size.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfdt/fdt_wip.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/libfdt/fdt_wip.c b/lib/libfdt/fdt_wip.c index 9fe988655fe..216c51287d0 100644 --- a/lib/libfdt/fdt_wip.c +++ b/lib/libfdt/fdt_wip.c @@ -14,21 +14,42 @@ #include "libfdt_internal.h" +int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, + const char *name, int namelen, + uint32_t index, const void *val, + int len) +{ + void *propval; + int proplen; + + propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, + &proplen); + if (!propval) + return proplen; + + if (proplen < (len + index)) + return -FDT_ERR_NOSPACE; + + memcpy(propval + index, val, len); + return 0; +} + int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, const void *val, int len) { - void *propval; + const void *propval; int proplen; - propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen); + propval = fdt_getprop(fdt, nodeoffset, name, &proplen); if (!propval) return proplen; if (proplen != len) return -FDT_ERR_NOSPACE; - memcpy(propval, val, len); - return 0; + return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name, + strlen(name), 0, + val, len); } static void _fdt_nop_region(void *start, int len) |