util.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm/ofnode.h>
  7. #include <dm/util.h>
  8. #include <linux/libfdt.h>
  9. #include <vsprintf.h>
  10. #ifdef CONFIG_DM_WARN
  11. void dm_warn(const char *fmt, ...)
  12. {
  13. va_list args;
  14. va_start(args, fmt);
  15. vprintf(fmt, args);
  16. va_end(args);
  17. }
  18. #endif
  19. int list_count_items(struct list_head *head)
  20. {
  21. struct list_head *node;
  22. int count = 0;
  23. list_for_each(node, head)
  24. count++;
  25. return count;
  26. }
  27. bool dm_fdt_pre_reloc(const void *blob, int offset)
  28. {
  29. if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
  30. return true;
  31. #ifdef CONFIG_TPL_BUILD
  32. if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
  33. return true;
  34. #elif defined(CONFIG_SPL_BUILD)
  35. if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL))
  36. return true;
  37. #else
  38. /*
  39. * In regular builds individual spl and tpl handling both
  40. * count as handled pre-relocation for later second init.
  41. */
  42. if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL) ||
  43. fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
  44. return true;
  45. #endif
  46. return false;
  47. }
  48. bool dm_ofnode_pre_reloc(ofnode node)
  49. {
  50. if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
  51. return true;
  52. #ifdef CONFIG_TPL_BUILD
  53. if (ofnode_read_bool(node, "u-boot,dm-tpl"))
  54. return true;
  55. #elif defined(CONFIG_SPL_BUILD)
  56. if (ofnode_read_bool(node, "u-boot,dm-spl"))
  57. return true;
  58. #else
  59. /*
  60. * In regular builds individual spl and tpl handling both
  61. * count as handled pre-relocation for later second init.
  62. */
  63. if (ofnode_read_bool(node, "u-boot,dm-spl") ||
  64. ofnode_read_bool(node, "u-boot,dm-tpl"))
  65. return true;
  66. #endif
  67. return false;
  68. }