Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * libfdt - Flat Device Tree manipulation |
| 3 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
Roger Meier | 3508476 | 2013-07-27 01:12:38 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 5 | */ |
| 6 | #include "libfdt_env.h" |
| 7 | |
Bartlomiej Sieka | 8cf3080 | 2008-02-29 16:00:24 +0100 | [diff] [blame] | 8 | #ifndef USE_HOSTCC |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 9 | #include <fdt.h> |
| 10 | #include <libfdt.h> |
Bartlomiej Sieka | 8cf3080 | 2008-02-29 16:00:24 +0100 | [diff] [blame] | 11 | #else |
| 12 | #include "fdt_host.h" |
| 13 | #endif |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 14 | |
| 15 | #include "libfdt_internal.h" |
| 16 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 17 | struct fdt_errtabent { |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 18 | const char *str; |
| 19 | }; |
| 20 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 21 | #define FDT_ERRTABENT(val) \ |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 22 | [(val)] = { .str = #val, } |
| 23 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 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), |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 28 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 29 | FDT_ERRTABENT(FDT_ERR_BADOFFSET), |
| 30 | FDT_ERRTABENT(FDT_ERR_BADPATH), |
| 31 | FDT_ERRTABENT(FDT_ERR_BADSTATE), |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 32 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 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), |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 38 | }; |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 39 | #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 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>"; |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 47 | else if (errval > -FDT_ERRTABSIZE) { |
| 48 | const char *s = fdt_errtable[-errval].str; |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 49 | |
| 50 | if (s) |
| 51 | return s; |
| 52 | } |
| 53 | |
| 54 | return "<unknown error>"; |
| 55 | } |