blob: 7f8e02b1ee21165b202db59dfa343a48c5af8650 [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),
Maxime Ripard610db702016-10-17 22:50:18 +020039 FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
40 FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040041};
David Gibsonfc7758e2008-07-09 14:10:24 +100042#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
Gerald Van Baren7cd5da02007-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 Gibsonfc7758e2008-07-09 14:10:24 +100050 else if (errval > -FDT_ERRTABSIZE) {
51 const char *s = fdt_errtable[-errval].str;
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040052
53 if (s)
54 return s;
55 }
56
57 return "<unknown error>";
58}