blob: f89004c609f040bc2e8b2337000aa921fc6ad4b8 [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.
Roger Meier35084762013-07-27 01:12:38 +02004 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04005 */
Robert P. J. Day6feed2a2016-05-23 05:40:55 -04006#include <libfdt_env.h>
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04007
Bartlomiej Sieka8cf30802008-02-29 16:00:24 +01008#ifndef USE_HOSTCC
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04009#include <fdt.h>
10#include <libfdt.h>
Bartlomiej Sieka8cf30802008-02-29 16:00:24 +010011#else
12#include "fdt_host.h"
13#endif
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040014
15#include "libfdt_internal.h"
16
David Gibsonfc7758e2008-07-09 14:10:24 +100017struct fdt_errtabent {
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040018 const char *str;
19};
20
David Gibsonfc7758e2008-07-09 14:10:24 +100021#define FDT_ERRTABENT(val) \
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040022 [(val)] = { .str = #val, }
23
David Gibsonfc7758e2008-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 Baren7cd5da02007-03-31 11:59:59 -040028
David Gibsonfc7758e2008-07-09 14:10:24 +100029 FDT_ERRTABENT(FDT_ERR_BADOFFSET),
30 FDT_ERRTABENT(FDT_ERR_BADPATH),
Maxime Ripard610db702016-10-17 22:50:18 +020031 FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
David Gibsonfc7758e2008-07-09 14:10:24 +100032 FDT_ERRTABENT(FDT_ERR_BADSTATE),
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040033
David Gibsonfc7758e2008-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),
Simon Glass92688a02017-03-28 10:23:31 -060039 FDT_ERRTABENT(FDT_ERR_INTERNAL),
40 FDT_ERRTABENT(FDT_ERR_BADNCELLS),
41 FDT_ERRTABENT(FDT_ERR_BADVALUE),
Maxime Ripard610db702016-10-17 22:50:18 +020042 FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
43 FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040044};
David Gibsonfc7758e2008-07-09 14:10:24 +100045#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040046
47const char *fdt_strerror(int errval)
48{
49 if (errval > 0)
50 return "<valid offset/length>";
51 else if (errval == 0)
52 return "<no error>";
David Gibsonfc7758e2008-07-09 14:10:24 +100053 else if (errval > -FDT_ERRTABSIZE) {
54 const char *s = fdt_errtable[-errval].str;
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040055
56 if (s)
57 return s;
58 }
59
60 return "<unknown error>";
61}