initcall.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifdef CONFIG_EFI_APP
  9. #include <efi.h>
  10. #endif
  11. /*
  12. * To enable debugging. add #define DEBUG at the top of the including file.
  13. *
  14. * To find a symbol, use grep on u-boot.map
  15. */
  16. static inline int initcall_run_list(const init_fnc_t init_sequence[])
  17. {
  18. const init_fnc_t *init_fnc_ptr;
  19. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  20. unsigned long reloc_ofs = 0;
  21. int ret;
  22. /*
  23. * Sandbox is relocated by the OS, so symbols always appear at
  24. * the relocated address.
  25. */
  26. if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
  27. reloc_ofs = gd->reloc_off;
  28. #ifdef CONFIG_EFI_APP
  29. reloc_ofs = (unsigned long)image_base;
  30. #endif
  31. if (reloc_ofs)
  32. debug("initcall: %p (relocated to %p)\n",
  33. (char *)*init_fnc_ptr - reloc_ofs,
  34. (char *)*init_fnc_ptr);
  35. else
  36. debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
  37. ret = (*init_fnc_ptr)();
  38. if (ret) {
  39. printf("initcall sequence %p failed at call %p (err=%d)\n",
  40. init_sequence,
  41. (char *)*init_fnc_ptr - reloc_ofs, ret);
  42. return -1;
  43. }
  44. }
  45. return 0;
  46. }
  47. #endif