]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/FdtLib/fdt_wip.c
EmbeddedPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmbeddedPkg / Library / FdtLib / fdt_wip.c
index e009a88f5112d7c14403474852bb2cdee0f266f3..6e39807b87826b3cbed35defa7ee57cc7faa0a37 100644 (file)
 \r
 #include "libfdt_internal.h"\r
 \r
+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,\r
+                                       const char *name, int namelen,\r
+                                       uint32_t idx, const void *val,\r
+                                       int len)\r
+{\r
+       void *propval;\r
+       int proplen;\r
+\r
+       propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,\r
+                                       &proplen);\r
+       if (!propval)\r
+               return proplen;\r
+\r
+       if (proplen < (len + idx))\r
+               return -FDT_ERR_NOSPACE;\r
+\r
+       memcpy((char *)propval + idx, val, len);\r
+       return 0;\r
+}\r
+\r
 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\r
                        const void *val, int len)\r
 {\r
-       void *propval;\r
+       const void *propval;\r
        int proplen;\r
 \r
-       propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);\r
-       if (! propval)\r
+       propval = fdt_getprop(fdt, nodeoffset, name, &proplen);\r
+       if (!propval)\r
                return proplen;\r
 \r
        if (proplen != len)\r
                return -FDT_ERR_NOSPACE;\r
 \r
-       memcpy(propval, val, len);\r
-       return 0;\r
+       return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,\r
+                                                  strlen(name), 0,\r
+                                                  val, len);\r
 }\r
 \r
 static void _fdt_nop_region(void *start, int len)\r
 {\r
-       uint32_t *p;\r
+       fdt32_t *p;\r
 \r
        for (p = start; (char *)p < ((char *)start + len); p++)\r
                *p = cpu_to_fdt32(FDT_NOP);\r
@@ -86,7 +107,7 @@ int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
        int len;\r
 \r
        prop = fdt_get_property_w(fdt, nodeoffset, name, &len);\r
-       if (! prop)\r
+       if (!prop)\r
                return len;\r
 \r
        _fdt_nop_region(prop, len + sizeof(*prop));\r