Merge with /home/stefan/git/u-boot/denx-440-exceptions
[u-boot-openmoko.git] / libfdt / fdt_strerror.c
blob7f231ce460e79faab020e6337f86be137da306af
1 /*
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"
21 #include <fdt.h>
22 #include <libfdt.h>
24 #include "libfdt_internal.h"
26 struct errtabent {
27 const char *str;
30 #define ERRTABENT(val) \
31 [(val)] = { .str = #val, }
33 static struct errtabent errtable[] = {
34 ERRTABENT(FDT_ERR_NOTFOUND),
35 ERRTABENT(FDT_ERR_EXISTS),
36 ERRTABENT(FDT_ERR_NOSPACE),
38 ERRTABENT(FDT_ERR_BADOFFSET),
39 ERRTABENT(FDT_ERR_BADPATH),
40 ERRTABENT(FDT_ERR_BADSTATE),
42 ERRTABENT(FDT_ERR_TRUNCATED),
43 ERRTABENT(FDT_ERR_BADMAGIC),
44 ERRTABENT(FDT_ERR_BADVERSION),
45 ERRTABENT(FDT_ERR_BADSTRUCTURE),
46 ERRTABENT(FDT_ERR_BADLAYOUT),
48 #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
50 const char *fdt_strerror(int errval)
52 if (errval > 0)
53 return "<valid offset/length>";
54 else if (errval == 0)
55 return "<no error>";
56 else if (errval > -ERRTABSIZE) {
57 const char *s = errtable[-errval].str;
59 if (s)
60 return s;
63 return "<unknown error>";