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_check_header(const void *fdt)
31 if (fdt_magic(fdt) == FDT_MAGIC) {
33 if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
34 return -FDT_ERR_BADVERSION;
35 if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
36 return -FDT_ERR_BADVERSION;
37 } else if (fdt_magic(fdt) == SW_MAGIC) {
38 /* Unfinished sequential-write blob */
39 if (fdt_size_dt_struct(fdt) == 0)
40 return -FDT_ERR_BADSTATE;
42 return -FDT_ERR_BADMAGIC;
48 void *fdt_offset_ptr(const void *fdt, int offset, int len)
52 if (fdt_version(fdt) >= 0x11)
53 if (((offset + len) < offset)
54 || ((offset + len) > fdt_size_dt_struct(fdt)))
57 p = _fdt_offset_ptr(fdt, offset);
64 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
66 int len = strlen(s) + 1;
67 const char *last = strtab + tabsize - len;
70 for (p = strtab; p <= last; p++)
76 int fdt_move(const void *fdt, void *buf, int bufsize)
78 int err = fdt_check_header(fdt);
83 if (fdt_totalsize(fdt) > bufsize)
84 return -FDT_ERR_NOSPACE;
86 memmove(buf, fdt, fdt_totalsize(fdt));
90 #endif /* CONFIG_OF_LIBFDT */