1*c0e032e0STom Rini /*
2*c0e032e0STom Rini * libfdt - Flat Device Tree manipulation
3*c0e032e0STom Rini * Copyright (C) 2006 David Gibson, IBM Corporation.
4*c0e032e0STom Rini *
5*c0e032e0STom Rini * libfdt is dual licensed: you can use it either under the terms of
6*c0e032e0STom Rini * the GPL, or the BSD license, at your option.
7*c0e032e0STom Rini *
8*c0e032e0STom Rini * a) This library is free software; you can redistribute it and/or
9*c0e032e0STom Rini * modify it under the terms of the GNU General Public License as
10*c0e032e0STom Rini * published by the Free Software Foundation; either version 2 of the
11*c0e032e0STom Rini * License, or (at your option) any later version.
12*c0e032e0STom Rini *
13*c0e032e0STom Rini * This library is distributed in the hope that it will be useful,
14*c0e032e0STom Rini * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*c0e032e0STom Rini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*c0e032e0STom Rini * GNU General Public License for more details.
17*c0e032e0STom Rini *
18*c0e032e0STom Rini * You should have received a copy of the GNU General Public
19*c0e032e0STom Rini * License along with this library; if not, write to the Free
20*c0e032e0STom Rini * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21*c0e032e0STom Rini * MA 02110-1301 USA
22*c0e032e0STom Rini *
23*c0e032e0STom Rini * Alternatively,
24*c0e032e0STom Rini *
25*c0e032e0STom Rini * b) Redistribution and use in source and binary forms, with or
26*c0e032e0STom Rini * without modification, are permitted provided that the following
27*c0e032e0STom Rini * conditions are met:
28*c0e032e0STom Rini *
29*c0e032e0STom Rini * 1. Redistributions of source code must retain the above
30*c0e032e0STom Rini * copyright notice, this list of conditions and the following
31*c0e032e0STom Rini * disclaimer.
32*c0e032e0STom Rini * 2. Redistributions in binary form must reproduce the above
33*c0e032e0STom Rini * copyright notice, this list of conditions and the following
34*c0e032e0STom Rini * disclaimer in the documentation and/or other materials
35*c0e032e0STom Rini * provided with the distribution.
36*c0e032e0STom Rini *
37*c0e032e0STom Rini * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
38*c0e032e0STom Rini * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
39*c0e032e0STom Rini * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40*c0e032e0STom Rini * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41*c0e032e0STom Rini * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
42*c0e032e0STom Rini * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43*c0e032e0STom Rini * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44*c0e032e0STom Rini * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45*c0e032e0STom Rini * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46*c0e032e0STom Rini * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47*c0e032e0STom Rini * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48*c0e032e0STom Rini * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49*c0e032e0STom Rini * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50*c0e032e0STom Rini */
51*c0e032e0STom Rini #include "libfdt_env.h"
52*c0e032e0STom Rini
53*c0e032e0STom Rini #include <fdt.h>
54*c0e032e0STom Rini #include <libfdt.h>
55*c0e032e0STom Rini
56*c0e032e0STom Rini #include "libfdt_internal.h"
57*c0e032e0STom Rini
58*c0e032e0STom Rini struct fdt_errtabent {
59*c0e032e0STom Rini const char *str;
60*c0e032e0STom Rini };
61*c0e032e0STom Rini
62*c0e032e0STom Rini #define FDT_ERRTABENT(val) \
63*c0e032e0STom Rini [(val)] = { .str = #val, }
64*c0e032e0STom Rini
65*c0e032e0STom Rini static struct fdt_errtabent fdt_errtable[] = {
66*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_NOTFOUND),
67*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_EXISTS),
68*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_NOSPACE),
69*c0e032e0STom Rini
70*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADOFFSET),
71*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADPATH),
72*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
73*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADSTATE),
74*c0e032e0STom Rini
75*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_TRUNCATED),
76*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADMAGIC),
77*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADVERSION),
78*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
79*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
80*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_INTERNAL),
81*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADNCELLS),
82*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADVALUE),
83*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
84*c0e032e0STom Rini FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
85*c0e032e0STom Rini };
86*c0e032e0STom Rini #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
87*c0e032e0STom Rini
fdt_strerror(int errval)88*c0e032e0STom Rini const char *fdt_strerror(int errval)
89*c0e032e0STom Rini {
90*c0e032e0STom Rini if (errval > 0)
91*c0e032e0STom Rini return "<valid offset/length>";
92*c0e032e0STom Rini else if (errval == 0)
93*c0e032e0STom Rini return "<no error>";
94*c0e032e0STom Rini else if (errval > -FDT_ERRTABSIZE) {
95*c0e032e0STom Rini const char *s = fdt_errtable[-errval].str;
96*c0e032e0STom Rini
97*c0e032e0STom Rini if (s)
98*c0e032e0STom Rini return s;
99*c0e032e0STom Rini }
100*c0e032e0STom Rini
101*c0e032e0STom Rini return "<unknown error>";
102*c0e032e0STom Rini }
103