2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libfdt_env.h"
27 #include "libfdt_internal.h"
29 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
30 const void *val, int len)
35 propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
40 return -FDT_ERR_NOSPACE;
42 memcpy(propval, val, len);
46 static void nop_region(void *start, int len)
50 for (p = start; (void *)p < (start + len); p++)
51 *p = cpu_to_fdt32(FDT_NOP);
54 int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
56 struct fdt_property *prop;
59 prop = fdt_get_property(fdt, nodeoffset, name, &len);
63 nop_region(prop, len + sizeof(*prop));
68 int _fdt_node_end_offset(void *fdt, int nodeoffset)
72 int offset, nextoffset;
74 tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, NULL);
75 if (tag != FDT_BEGIN_NODE)
76 return -FDT_ERR_BADOFFSET;
79 tag = fdt_next_tag(fdt, offset, &nextoffset, NULL);
98 return -FDT_ERR_BADSTRUCTURE;
100 } while (level >= 0);
105 int fdt_nop_node(void *fdt, int nodeoffset)
109 endoffset = _fdt_node_end_offset(fdt, nodeoffset);
113 nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
118 * Replace a reserve map entry in the nth slot.
120 int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size)
122 struct fdt_reserve_entry *re;
127 err = fdt_num_reservemap(fdt, &used, &total);
132 return -FDT_ERR_NOSPACE;
133 re = (struct fdt_reserve_entry *)
134 (fdt + fdt_off_mem_rsvmap(fdt) +
135 (n * sizeof(struct fdt_reserve_entry)));
136 re->address = cpu_to_fdt64(addr);
137 re->size = cpu_to_fdt64(size);
142 #endif /* CONFIG_OF_LIBFDT */