initcall.h 1.2 KB

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