blob: 7f8e02b1ee21165b202db59dfa343a48c5af8650 [file] [log] [blame]
Gerald Van Barenc0577a62007-03-31 11:59:59 -04001/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
Roger Meier3eaedea2013-07-27 01:12:38 +02004 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
Gerald Van Barenc0577a62007-03-31 11:59:59 -04005 */
Robert P. J. Day55019c52016-05-23 05:40:55 -04006#include <libfdt_env.h>
Gerald Van Barenc0577a62007-03-31 11:59:59 -04007
Bartlomiej Sieka61250862008-02-29 16:00:24 +01008#ifndef USE_HOSTCC
Gerald Van Barenc0577a62007-03-31 11:59:59 -04009#include <fdt.h>
10#include <libfdt.h>
Bartlomiej Sieka61250862008-02-29 16:00:24 +010011#else
12#include "fdt_host.h"
13#endif
Gerald Van Barenc0577a62007-03-31 11:59:59 -040014
15#include "libfdt_internal.h"
16
David Gibson9457d9d2008-07-09 14:10:24 +100017struct fdt_errtabent {
Gerald Van Barenc0577a62007-03-31 11:59:59 -040018 const char *str;
19};
20
David Gibson9457d9d2008-07-09 14:10:24 +100021#define FDT_ERRTABENT(val) \
Gerald Van Barenc0577a62007-03-31 11:59:59 -040022 [(val)] = { .str = #val, }
23
David Gibson9457d9d2008-07-09 14:10:24 +100024static struct fdt_errtabent fdt_errtable[] = {
25 FDT_ERRTABENT(FDT_ERR_NOTFOUND),
26 FDT_ERRTABENT(FDT_ERR_EXISTS),
27 FDT_ERRTABENT(FDT_ERR_NOSPACE),
Gerald Van Barenc0577a62007-03-31 11:59:59 -040028
David Gibson9457d9d2008-07-09 14:10:24 +100029 FDT_ERRTABENT(FDT_ERR_BADOFFSET),
30 FDT_ERRTABENT(FDT_ERR_BADPATH),
Maxime Ripard0b0490a2016-10-17 22:50:18 +020031 FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
David Gibson9457d9d2008-07-09 14:10:24 +100032 FDT_ERRTABENT(FDT_ERR_BADSTATE),
Gerald Van Barenc0577a62007-03-31 11:59:59 -040033
David Gibson9457d9d2008-07-09 14:10:24 +100034 FDT_ERRTABENT(FDT_ERR_TRUNCATED),
35 FDT_ERRTABENT(FDT_ERR_BADMAGIC),
36 FDT_ERRTABENT(FDT_ERR_BADVERSION),
37 FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
38 FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
Maxime Ripard0b0490a2016-10-17 22:50:18 +020039 FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
40 FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
Gerald Van Barenc0577a62007-03-31 11:59:59 -040041};
David Gibson9457d9d2008-07-09 14:10:24 +100042#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
Gerald Van Barenc0577a62007-03-31 11:59:59 -040043
44const char *fdt_strerror(int errval)
45{
46 if (errval > 0)
47 return "<valid offset/length>";
48 else if (errval == 0)
49 return "<no error>";
David Gibson9457d9d2008-07-09 14:10:24 +100050 else if (errval > -FDT_ERRTABSIZE) {
51 const char *s = fdt_errtable[-errval].str;
Gerald Van Barenc0577a62007-03-31 11:59:59 -040052
53 if (s)
54 return s;
55 }
56
57 return "<unknown error>";
58}