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 | */ |
Robert P. J. Day | 6feed2a | 2016-05-23 05:40:55 -0400 | [diff] [blame] | 6 | #include <libfdt_env.h> |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 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), |
Maxime Ripard | 610db70 | 2016-10-17 22:50:18 +0200 | [diff] [blame] | 31 | FDT_ERRTABENT(FDT_ERR_BADPHANDLE), |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 32 | FDT_ERRTABENT(FDT_ERR_BADSTATE), |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 33 | |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 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), |
Maxime Ripard | 610db70 | 2016-10-17 22:50:18 +0200 | [diff] [blame] | 39 | FDT_ERRTABENT(FDT_ERR_BADOVERLAY), |
| 40 | FDT_ERRTABENT(FDT_ERR_NOPHANDLES), |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 41 | }; |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 42 | #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 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>"; |
David Gibson | fc7758e | 2008-07-09 14:10:24 +1000 | [diff] [blame] | 50 | else if (errval > -FDT_ERRTABSIZE) { |
| 51 | const char *s = fdt_errtable[-errval].str; |
Gerald Van Baren | 7cd5da0 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 52 | |
| 53 | if (s) |
| 54 | return s; |
| 55 | } |
| 56 | |
| 57 | return "<unknown error>"; |
| 58 | } |