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_check_header(const void *fdt)
28 if (fdt_magic(fdt) == FDT_MAGIC) {
30 if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
31 return -FDT_ERR_BADVERSION;
32 if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
33 return -FDT_ERR_BADVERSION;
34 } else if (fdt_magic(fdt) == SW_MAGIC) {
35 /* Unfinished sequential-write blob */
36 if (fdt_size_dt_struct(fdt) == 0)
37 return -FDT_ERR_BADSTATE;
39 return -FDT_ERR_BADMAGIC;
45 void *fdt_offset_ptr(const void *fdt, int offset, int len)
49 if (fdt_version(fdt) >= 0x11)
50 if (((offset + len) < offset)
51 || ((offset + len) > fdt_size_dt_struct(fdt)))
54 p = _fdt_offset_ptr(fdt, offset);
61 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
63 int len = strlen(s) + 1;
64 const char *last = strtab + tabsize - len;
67 for (p = strtab; p <= last; p++)
73 int fdt_move(const void *fdt, void *buf, int bufsize)
75 int err = _fdt_check_header(fdt);
80 if (fdt_totalsize(fdt) > bufsize)
81 return -FDT_ERR_NOSPACE;
83 memmove(buf, fdt, fdt_totalsize(fdt));