1*3e6106c4SLoGin // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
2*3e6106c4SLoGin /*
3*3e6106c4SLoGin * libfdt - Flat Device Tree manipulation
4*3e6106c4SLoGin * Copyright (C) 2006 David Gibson, IBM Corporation.
5*3e6106c4SLoGin * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6*3e6106c4SLoGin */
7*3e6106c4SLoGin #include "libfdt_env.h"
8*3e6106c4SLoGin
9*3e6106c4SLoGin #include <fdt.h>
10*3e6106c4SLoGin #include <libfdt.h>
11*3e6106c4SLoGin
12*3e6106c4SLoGin #include "libfdt_internal.h"
13*3e6106c4SLoGin
14*3e6106c4SLoGin struct fdt_errtabent {
15*3e6106c4SLoGin const char *str;
16*3e6106c4SLoGin };
17*3e6106c4SLoGin
18*3e6106c4SLoGin #define FDT_ERRTABENT(val) \
19*3e6106c4SLoGin [(val)] = { .str = #val, }
20*3e6106c4SLoGin
21*3e6106c4SLoGin static struct fdt_errtabent fdt_errtable[] = {
22*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_NOTFOUND),
23*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_EXISTS),
24*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_NOSPACE),
25*3e6106c4SLoGin
26*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADOFFSET),
27*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADPATH),
28*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
29*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADSTATE),
30*3e6106c4SLoGin
31*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_TRUNCATED),
32*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADMAGIC),
33*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADVERSION),
34*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
35*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
36*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_INTERNAL),
37*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADNCELLS),
38*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADVALUE),
39*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
40*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
41*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_BADFLAGS),
42*3e6106c4SLoGin FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
43*3e6106c4SLoGin };
44*3e6106c4SLoGin #define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
45*3e6106c4SLoGin
fdt_strerror(int errval)46*3e6106c4SLoGin const char *fdt_strerror(int errval)
47*3e6106c4SLoGin {
48*3e6106c4SLoGin if (errval > 0)
49*3e6106c4SLoGin return "<valid offset/length>";
50*3e6106c4SLoGin else if (errval == 0)
51*3e6106c4SLoGin return "<no error>";
52*3e6106c4SLoGin else if (-errval < FDT_ERRTABSIZE) {
53*3e6106c4SLoGin const char *s = fdt_errtable[-errval].str;
54*3e6106c4SLoGin
55*3e6106c4SLoGin if (s)
56*3e6106c4SLoGin return s;
57*3e6106c4SLoGin }
58*3e6106c4SLoGin
59*3e6106c4SLoGin return "<unknown error>";
60*3e6106c4SLoGin }
61