]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - libfdt/fdt_strerror.c
Merge with git://www.denx.de/git/u-boot.git
[karo-tx-uboot.git] / libfdt / fdt_strerror.c
1 /*
2  * libfdt - Flat Device Tree manipulation
3  * Copyright (C) 2006 David Gibson, IBM Corporation.
4  *
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.
9  *
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.
14  *
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
18  */
19 #include "config.h"
20 #if CONFIG_OF_LIBFDT
21
22 #include "libfdt_env.h"
23
24 #include <fdt.h>
25 #include <libfdt.h>
26
27 #include "libfdt_internal.h"
28
29 struct errtabent {
30         const char *str;
31 };
32
33 #define ERRTABENT(val) \
34         [(val)] = { .str = #val, }
35
36 static struct errtabent errtable[] = {
37         ERRTABENT(FDT_ERR_NOTFOUND),
38         ERRTABENT(FDT_ERR_EXISTS),
39         ERRTABENT(FDT_ERR_NOSPACE),
40
41         ERRTABENT(FDT_ERR_BADOFFSET),
42         ERRTABENT(FDT_ERR_BADPATH),
43         ERRTABENT(FDT_ERR_BADSTATE),
44
45         ERRTABENT(FDT_ERR_TRUNCATED),
46         ERRTABENT(FDT_ERR_BADMAGIC),
47         ERRTABENT(FDT_ERR_BADVERSION),
48         ERRTABENT(FDT_ERR_BADSTRUCTURE),
49         ERRTABENT(FDT_ERR_BADLAYOUT),
50 };
51 #define ERRTABSIZE      (sizeof(errtable) / sizeof(errtable[0]))
52
53 const char *fdt_strerror(int errval)
54 {
55         if (errval > 0)
56                 return "<valid offset/length>";
57         else if (errval == 0)
58                 return "<no error>";
59         else if (errval > -ERRTABSIZE) {
60                 const char *s = errtable[-errval].str;
61
62                 if (s)
63                         return s;
64         }
65
66         return "<unknown error>";
67 }
68
69 #endif /* CONFIG_OF_LIBFDT */