]> git.ipfire.org Git - people/ms/u-boot.git/blame - lib/libfdt/fdt_strerror.c
libfdt: Add overlay application function
[people/ms/u-boot.git] / lib / libfdt / fdt_strerror.c
CommitLineData
7cd5da0f
GVB
1/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
35084760 4 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
7cd5da0f 5 */
6feed2a5 6#include <libfdt_env.h>
7cd5da0f 7
8cf30809 8#ifndef USE_HOSTCC
7cd5da0f
GVB
9#include <fdt.h>
10#include <libfdt.h>
8cf30809
BS
11#else
12#include "fdt_host.h"
13#endif
7cd5da0f
GVB
14
15#include "libfdt_internal.h"
16
fc7758ee 17struct fdt_errtabent {
7cd5da0f
GVB
18 const char *str;
19};
20
fc7758ee 21#define FDT_ERRTABENT(val) \
7cd5da0f
GVB
22 [(val)] = { .str = #val, }
23
fc7758ee
DG
24static struct fdt_errtabent fdt_errtable[] = {
25 FDT_ERRTABENT(FDT_ERR_NOTFOUND),
26 FDT_ERRTABENT(FDT_ERR_EXISTS),
27 FDT_ERRTABENT(FDT_ERR_NOSPACE),
7cd5da0f 28
fc7758ee
DG
29 FDT_ERRTABENT(FDT_ERR_BADOFFSET),
30 FDT_ERRTABENT(FDT_ERR_BADPATH),
31 FDT_ERRTABENT(FDT_ERR_BADSTATE),
7cd5da0f 32
fc7758ee
DG
33 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),
7cd5da0f 38};
fc7758ee 39#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
7cd5da0f
GVB
40
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>";
fc7758ee
DG
47 else if (errval > -FDT_ERRTABSIZE) {
48 const char *s = fdt_errtable[-errval].str;
7cd5da0f
GVB
49
50 if (s)
51 return s;
52 }
53
54 return "<unknown error>";
55}