initcall.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. */
  5. #ifndef __INITCALL_H
  6. #define __INITCALL_H
  7. typedef int (*init_fnc_t)(void);
  8. /*
  9. * To enable debugging. add #define DEBUG at the top of the including file.
  10. *
  11. * To find a symbol, use grep on u-boot.map
  12. */
  13. static inline int initcall_run_list(const init_fnc_t init_sequence[])
  14. {
  15. const init_fnc_t *init_fnc_ptr;
  16. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  17. unsigned long reloc_ofs = 0;
  18. int ret;
  19. /*
  20. * Sandbox is relocated by the OS, so symbols always appear at
  21. * the relocated address.
  22. */
  23. if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
  24. reloc_ofs = gd->reloc_off;
  25. #ifdef CONFIG_EFI_APP
  26. reloc_ofs = (unsigned long)image_base;
  27. #endif
  28. debug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs);
  29. if (reloc_ofs)
  30. debug(" (relocated to %p)\n", (char *)*init_fnc_ptr);
  31. else
  32. debug("\n");
  33. ret = (*init_fnc_ptr)();
  34. if (ret) {
  35. printf("initcall sequence %p failed at call %p (err=%d)\n",
  36. init_sequence,
  37. (char *)*init_fnc_ptr - reloc_ofs, ret);
  38. return -1;
  39. }
  40. }
  41. return 0;
  42. }
  43. #endif