/*1* libfdt - Flat Device Tree manipulation2* Copyright (C) 2006 David Gibson, IBM Corporation.3*4* libfdt is dual licensed: you can use it either under the terms of5* the GPL, or the BSD license, at your option.6*7* a) This library is free software; you can redistribute it and/or8* modify it under the terms of the GNU General Public License as9* published by the Free Software Foundation; either version 2 of the10* License, or (at your option) any later version.11*12* This library is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public18* License along with this library; if not, write to the Free19* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,20* MA 02110-1301 USA21*22* Alternatively,23*24* b) Redistribution and use in source and binary forms, with or25* without modification, are permitted provided that the following26* conditions are met:27*28* 1. Redistributions of source code must retain the above29* copyright notice, this list of conditions and the following30* disclaimer.31* 2. Redistributions in binary form must reproduce the above32* copyright notice, this list of conditions and the following33* disclaimer in the documentation and/or other materials34* provided with the distribution.35*36* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND37* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,38* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF39* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE40* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR41* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,42* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT43* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;44* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)45* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN46* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR47* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,48* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.49*/50#include "libfdt_env.h"5152#include <fdt.h>53#include <libfdt.h>5455#include "libfdt_internal.h"5657int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,58const void *val, int len)59{60void *propval;61int proplen;6263propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);64if (! propval)65return proplen;6667if (proplen != len)68return -FDT_ERR_NOSPACE;6970memcpy(propval, val, len);71return 0;72}7374static void _fdt_nop_region(void *start, int len)75{76uint32_t *p;7778for (p = start; (char *)p < ((char *)start + len); p++)79*p = cpu_to_fdt32(FDT_NOP);80}8182int fdt_nop_property(void *fdt, int nodeoffset, const char *name)83{84struct fdt_property *prop;85int len;8687prop = fdt_get_property_w(fdt, nodeoffset, name, &len);88if (! prop)89return len;9091_fdt_nop_region(prop, len + sizeof(*prop));9293return 0;94}9596int _fdt_node_end_offset(void *fdt, int nodeoffset)97{98int level = 0;99uint32_t tag;100int offset, nextoffset;101102tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);103if (tag != FDT_BEGIN_NODE)104return -FDT_ERR_BADOFFSET;105do {106offset = nextoffset;107tag = fdt_next_tag(fdt, offset, &nextoffset);108109switch (tag) {110case FDT_END:111return offset;112113case FDT_BEGIN_NODE:114level++;115break;116117case FDT_END_NODE:118level--;119break;120121case FDT_PROP:122case FDT_NOP:123break;124125default:126return -FDT_ERR_BADSTRUCTURE;127}128} while (level >= 0);129130return nextoffset;131}132133int fdt_nop_node(void *fdt, int nodeoffset)134{135int endoffset;136137endoffset = _fdt_node_end_offset(fdt, nodeoffset);138if (endoffset < 0)139return endoffset;140141_fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),142endoffset - nodeoffset);143return 0;144}145146147