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