fdt_strerror.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * libfdt - Flat Device Tree manipulation
  3. * Copyright (C) 2006 David Gibson, IBM Corporation.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation; either version 2.1 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "config.h"
  20. #if CONFIG_OF_LIBFDT
  21. #include "libfdt_env.h"
  22. #include <fdt.h>
  23. #include <libfdt.h>
  24. #include "libfdt_internal.h"
  25. struct errtabent {
  26. const char *str;
  27. };
  28. #define ERRTABENT(val) \
  29. [(val)] = { .str = #val, }
  30. static struct errtabent errtable[] = {
  31. ERRTABENT(FDT_ERR_NOTFOUND),
  32. ERRTABENT(FDT_ERR_EXISTS),
  33. ERRTABENT(FDT_ERR_NOSPACE),
  34. ERRTABENT(FDT_ERR_BADOFFSET),
  35. ERRTABENT(FDT_ERR_BADPATH),
  36. ERRTABENT(FDT_ERR_BADSTATE),
  37. ERRTABENT(FDT_ERR_TRUNCATED),
  38. ERRTABENT(FDT_ERR_BADMAGIC),
  39. ERRTABENT(FDT_ERR_BADVERSION),
  40. ERRTABENT(FDT_ERR_BADSTRUCTURE),
  41. ERRTABENT(FDT_ERR_BADLAYOUT),
  42. };
  43. #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0]))
  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 > -ERRTABSIZE) {
  51. const char *s = errtable[-errval].str;
  52. if (s)
  53. return s;
  54. }
  55. return "<unknown error>";
  56. }
  57. #endif /* CONFIG_OF_LIBFDT */