blob: b49c952f346023d4e5441f39c7f2b51ed394f995 [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 */
Gerald Van Baren8096b3b2007-04-20 22:46:53 -040019#include "config.h"
20#if CONFIG_OF_LIBFDT
21
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040022#include "libfdt_env.h"
23
24#include <fdt.h>
25#include <libfdt.h>
26
27#include "libfdt_internal.h"
28
29struct errtabent {
30 const char *str;
31};
32
33#define ERRTABENT(val) \
34 [(val)] = { .str = #val, }
35
36static 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
53const 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}
Gerald Van Baren8096b3b2007-04-20 22:46:53 -040068
69#endif /* CONFIG_OF_LIBFDT */