fdt: Move header files into lib/libfdt
[oweals/u-boot.git] / lib / libfdt / fdt_wip.c
index 9fe988655fe342c49a293e7c68d3bcd83d2105b6..45fb9641206f4f74948c639004e7c8b92958a54e 100644 (file)
 
 #include "libfdt_internal.h"
 
+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
+                                       const char *name, int namelen,
+                                       uint32_t idx, 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 + idx))
+               return -FDT_ERR_NOSPACE;
+
+       memcpy((char *)propval + idx, 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)