blob: 7f231ce460e79faab020e6337f86be137da306af [file] [log] [blame]
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04001/*
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 "libfdt_env.h"
20
21#include <fdt.h>
22#include <libfdt.h>
23
24#include "libfdt_internal.h"
25
26struct errtabent {
27 const char *str;
28};
29
30#define ERRTABENT(val) \
31 [(val)] = { .str = #val, }
32
33static struct errtabent errtable[] = {
34 ERRTABENT(FDT_ERR_NOTFOUND),
35 ERRTABENT(FDT_ERR_EXISTS),
36 ERRTABENT(FDT_ERR_NOSPACE),
37
38 ERRTABENT(FDT_ERR_BADOFFSET),
39 ERRTABENT(FDT_ERR_BADPATH),
40 ERRTABENT(FDT_ERR_BADSTATE),
41
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),
47};
48#define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
49
50const char *fdt_strerror(int errval)
51{
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;
58
59 if (s)
60 return s;
61 }
62
63 return "<unknown error>";
64}