xref: /utopia/UTPA2-700.0.x/projects/build/scripts/dtc/libfdt/fdt_strerror.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi /*
2*53ee8cc1Swenshuai.xi  * libfdt - Flat Device Tree manipulation
3*53ee8cc1Swenshuai.xi  * Copyright (C) 2006 David Gibson, IBM Corporation.
4*53ee8cc1Swenshuai.xi  *
5*53ee8cc1Swenshuai.xi  * libfdt is dual licensed: you can use it either under the terms of
6*53ee8cc1Swenshuai.xi  * the GPL, or the BSD license, at your option.
7*53ee8cc1Swenshuai.xi  *
8*53ee8cc1Swenshuai.xi  *  a) This library is free software; you can redistribute it and/or
9*53ee8cc1Swenshuai.xi  *     modify it under the terms of the GNU General Public License as
10*53ee8cc1Swenshuai.xi  *     published by the Free Software Foundation; either version 2 of the
11*53ee8cc1Swenshuai.xi  *     License, or (at your option) any later version.
12*53ee8cc1Swenshuai.xi  *
13*53ee8cc1Swenshuai.xi  *     This library is distributed in the hope that it will be useful,
14*53ee8cc1Swenshuai.xi  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
15*53ee8cc1Swenshuai.xi  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*53ee8cc1Swenshuai.xi  *     GNU General Public License for more details.
17*53ee8cc1Swenshuai.xi  *
18*53ee8cc1Swenshuai.xi  *     You should have received a copy of the GNU General Public
19*53ee8cc1Swenshuai.xi  *     License along with this library; if not, write to the Free
20*53ee8cc1Swenshuai.xi  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21*53ee8cc1Swenshuai.xi  *     MA 02110-1301 USA
22*53ee8cc1Swenshuai.xi  *
23*53ee8cc1Swenshuai.xi  * Alternatively,
24*53ee8cc1Swenshuai.xi  *
25*53ee8cc1Swenshuai.xi  *  b) Redistribution and use in source and binary forms, with or
26*53ee8cc1Swenshuai.xi  *     without modification, are permitted provided that the following
27*53ee8cc1Swenshuai.xi  *     conditions are met:
28*53ee8cc1Swenshuai.xi  *
29*53ee8cc1Swenshuai.xi  *     1. Redistributions of source code must retain the above
30*53ee8cc1Swenshuai.xi  *        copyright notice, this list of conditions and the following
31*53ee8cc1Swenshuai.xi  *        disclaimer.
32*53ee8cc1Swenshuai.xi  *     2. Redistributions in binary form must reproduce the above
33*53ee8cc1Swenshuai.xi  *        copyright notice, this list of conditions and the following
34*53ee8cc1Swenshuai.xi  *        disclaimer in the documentation and/or other materials
35*53ee8cc1Swenshuai.xi  *        provided with the distribution.
36*53ee8cc1Swenshuai.xi  *
37*53ee8cc1Swenshuai.xi  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
38*53ee8cc1Swenshuai.xi  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
39*53ee8cc1Swenshuai.xi  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40*53ee8cc1Swenshuai.xi  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41*53ee8cc1Swenshuai.xi  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
42*53ee8cc1Swenshuai.xi  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43*53ee8cc1Swenshuai.xi  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44*53ee8cc1Swenshuai.xi  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45*53ee8cc1Swenshuai.xi  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46*53ee8cc1Swenshuai.xi  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47*53ee8cc1Swenshuai.xi  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48*53ee8cc1Swenshuai.xi  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49*53ee8cc1Swenshuai.xi  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50*53ee8cc1Swenshuai.xi  */
51*53ee8cc1Swenshuai.xi #include "libfdt_env.h"
52*53ee8cc1Swenshuai.xi 
53*53ee8cc1Swenshuai.xi #include <fdt.h>
54*53ee8cc1Swenshuai.xi #include <libfdt.h>
55*53ee8cc1Swenshuai.xi 
56*53ee8cc1Swenshuai.xi #include "libfdt_internal.h"
57*53ee8cc1Swenshuai.xi 
58*53ee8cc1Swenshuai.xi struct fdt_errtabent {
59*53ee8cc1Swenshuai.xi 	const char *str;
60*53ee8cc1Swenshuai.xi };
61*53ee8cc1Swenshuai.xi 
62*53ee8cc1Swenshuai.xi #define FDT_ERRTABENT(val) \
63*53ee8cc1Swenshuai.xi 	[(val)] = { .str = #val, }
64*53ee8cc1Swenshuai.xi 
65*53ee8cc1Swenshuai.xi static struct fdt_errtabent fdt_errtable[] = {
66*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_NOTFOUND),
67*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_EXISTS),
68*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_NOSPACE),
69*53ee8cc1Swenshuai.xi 
70*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADOFFSET),
71*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADPATH),
72*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADSTATE),
73*53ee8cc1Swenshuai.xi 
74*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_TRUNCATED),
75*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADMAGIC),
76*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADVERSION),
77*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
78*53ee8cc1Swenshuai.xi 	FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
79*53ee8cc1Swenshuai.xi };
80*53ee8cc1Swenshuai.xi #define FDT_ERRTABSIZE	(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
81*53ee8cc1Swenshuai.xi 
fdt_strerror(int errval)82*53ee8cc1Swenshuai.xi const char *fdt_strerror(int errval)
83*53ee8cc1Swenshuai.xi {
84*53ee8cc1Swenshuai.xi 	if (errval > 0)
85*53ee8cc1Swenshuai.xi 		return "<valid offset/length>";
86*53ee8cc1Swenshuai.xi 	else if (errval == 0)
87*53ee8cc1Swenshuai.xi 		return "<no error>";
88*53ee8cc1Swenshuai.xi 	else if (errval > -FDT_ERRTABSIZE) {
89*53ee8cc1Swenshuai.xi 		const char *s = fdt_errtable[-errval].str;
90*53ee8cc1Swenshuai.xi 
91*53ee8cc1Swenshuai.xi 		if (s)
92*53ee8cc1Swenshuai.xi 			return s;
93*53ee8cc1Swenshuai.xi 	}
94*53ee8cc1Swenshuai.xi 
95*53ee8cc1Swenshuai.xi 	return "<unknown error>";
96*53ee8cc1Swenshuai.xi }
97