blob: 3b7e1683d0d0a1e5395240245dfd8f5dac4bef2a [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),
31 FDT_ERRTABENT(FDT_ERR_BADSTATE),
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040032
David Gibsonfc7758e2008-07-09 14:10:24 +100033 FDT_ERRTABENT(FDT_ERR_TRUNCATED),
34 FDT_ERRTABENT(FDT_ERR_BADMAGIC),
35 FDT_ERRTABENT(FDT_ERR_BADVERSION),
36 FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
37 FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040038};
David Gibsonfc7758e2008-07-09 14:10:24 +100039#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040040
41const char *fdt_strerror(int errval)
42{
43 if (errval > 0)
44 return "<valid offset/length>";
45 else if (errval == 0)
46 return "<no error>";
David Gibsonfc7758e2008-07-09 14:10:24 +100047 else if (errval > -FDT_ERRTABSIZE) {
48 const char *s = fdt_errtable[-errval].str;
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040049
50 if (s)
51 return s;
52 }
53
54 return "<unknown error>";
55}