Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
0002 /*
0003  * libfdt - Flat Device Tree manipulation
0004  * Copyright (C) 2006 David Gibson, IBM Corporation.
0005  */
0006 #include "libfdt_env.h"
0007 
0008 #include <fdt.h>
0009 #include <libfdt.h>
0010 
0011 #include "libfdt_internal.h"
0012 
0013 int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
0014                     const char *name, int namelen,
0015                     uint32_t idx, const void *val,
0016                     int len)
0017 {
0018     void *propval;
0019     int proplen;
0020 
0021     propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
0022                     &proplen);
0023     if (!propval)
0024         return proplen;
0025 
0026     if ((unsigned)proplen < (len + idx))
0027         return -FDT_ERR_NOSPACE;
0028 
0029     memcpy((char *)propval + idx, val, len);
0030     return 0;
0031 }
0032 
0033 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
0034             const void *val, int len)
0035 {
0036     const void *propval;
0037     int proplen;
0038 
0039     propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
0040     if (!propval)
0041         return proplen;
0042 
0043     if (proplen != len)
0044         return -FDT_ERR_NOSPACE;
0045 
0046     return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
0047                            strlen(name), 0,
0048                            val, len);
0049 }
0050 
0051 static void fdt_nop_region_(void *start, int len)
0052 {
0053     fdt32_t *p;
0054 
0055     for (p = start; (char *)p < ((char *)start + len); p++)
0056         *p = cpu_to_fdt32(FDT_NOP);
0057 }
0058 
0059 int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
0060 {
0061     struct fdt_property *prop;
0062     int len;
0063 
0064     prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
0065     if (!prop)
0066         return len;
0067 
0068     fdt_nop_region_(prop, len + sizeof(*prop));
0069 
0070     return 0;
0071 }
0072 
0073 int fdt_node_end_offset_(void *fdt, int offset)
0074 {
0075     int depth = 0;
0076 
0077     while ((offset >= 0) && (depth >= 0))
0078         offset = fdt_next_node(fdt, offset, &depth);
0079 
0080     return offset;
0081 }
0082 
0083 int fdt_nop_node(void *fdt, int nodeoffset)
0084 {
0085     int endoffset;
0086 
0087     endoffset = fdt_node_end_offset_(fdt, nodeoffset);
0088     if (endoffset < 0)
0089         return endoffset;
0090 
0091     fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
0092             endoffset - nodeoffset);
0093     return 0;
0094 }