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
19 #include "libfdt_env.h"
24 #include "libfdt_internal.h"
26 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
27 const void *val, int len)
32 propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
37 return -FDT_ERR_NOSPACE;
39 memcpy(propval, val, len);
43 static void nop_region(void *start, int len)
47 for (p = start; (void *)p < (start + len); p++)
48 *p = cpu_to_fdt32(FDT_NOP);
51 int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
53 struct fdt_property *prop;
56 prop = fdt_get_property(fdt, nodeoffset, name, &len);
60 nop_region(prop, len + sizeof(*prop));
65 int _fdt_node_end_offset(void *fdt, int nodeoffset)
69 int offset, nextoffset;
71 tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, NULL);
72 if (tag != FDT_BEGIN_NODE)
73 return -FDT_ERR_BADOFFSET;
76 tag = fdt_next_tag(fdt, offset, &nextoffset, NULL);
95 return -FDT_ERR_BADSTRUCTURE;
102 int fdt_nop_node(void *fdt, int nodeoffset)
106 endoffset = _fdt_node_end_offset(fdt, nodeoffset);
110 nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
115 * Replace a reserve map entry in the nth slot.
117 int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size)
119 struct fdt_reserve_entry *re;
124 err = fdt_num_reservemap(fdt, &used, &total);
129 return -FDT_ERR_NOSPACE;
130 re = (struct fdt_reserve_entry *)
131 (fdt + fdt_off_mem_rsvmap(fdt) +
132 (n * sizeof(struct fdt_reserve_entry)));
133 re->address = cpu_to_fdt64(addr);
134 re->size = cpu_to_fdt64(size);