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_BADPHANDLE), 32 FDT_ERRTABENT(FDT_ERR_BADSTATE), 33 34 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), 39 FDT_ERRTABENT(FDT_ERR_BADOVERLAY), 40 FDT_ERRTABENT(FDT_ERR_NOPHANDLES), 41 }; 42 #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 43 44 const char *fdt_strerror(int errval) 45 { 46 if (errval > 0) 47 return "<valid offset/length>"; 48 else if (errval == 0) 49 return "<no error>"; 50 else if (errval > -FDT_ERRTABSIZE) { 51 const char *s = fdt_errtable[-errval].str; 52 53 if (s) 54 return s; 55 } 56 57 return "<unknown error>"; 58 } 59