xref: /openbmc/u-boot/lib/libfdt/fdt_strerror.c (revision 23ff8633)
1 /*
2  * libfdt - Flat Device Tree manipulation
3  * Copyright (C) 2006 David Gibson, IBM Corporation.
4  * SPDX-License-Identifier:	GPL-2.0+ BSD-2-Clause
5  */
6 #include "libfdt_env.h"
7 
8 #ifndef USE_HOSTCC
9 #include <fdt.h>
10 #include <libfdt.h>
11 #else
12 #include "fdt_host.h"
13 #endif
14 
15 #include "libfdt_internal.h"
16 
17 struct fdt_errtabent {
18 	const char *str;
19 };
20 
21 #define FDT_ERRTABENT(val) \
22 	[(val)] = { .str = #val, }
23 
24 static struct fdt_errtabent fdt_errtable[] = {
25 	FDT_ERRTABENT(FDT_ERR_NOTFOUND),
26 	FDT_ERRTABENT(FDT_ERR_EXISTS),
27 	FDT_ERRTABENT(FDT_ERR_NOSPACE),
28 
29 	FDT_ERRTABENT(FDT_ERR_BADOFFSET),
30 	FDT_ERRTABENT(FDT_ERR_BADPATH),
31 	FDT_ERRTABENT(FDT_ERR_BADSTATE),
32 
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),
38 };
39 #define FDT_ERRTABSIZE	(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
40 
41 const char *fdt_strerror(int errval)
42 {
43 	if (errval > 0)
44 		return "<valid offset/length>";
45 	else if (errval == 0)
46 		return "<no error>";
47 	else if (errval > -FDT_ERRTABSIZE) {
48 		const char *s = fdt_errtable[-errval].str;
49 
50 		if (s)
51 			return s;
52 	}
53 
54 	return "<unknown error>";
55 }
56