initcall.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. if (reloc_ofs)
  29. debug("initcall: %p (relocated to %p)\n",
  30. (char *)*init_fnc_ptr - reloc_ofs,
  31. (char *)*init_fnc_ptr);
  32. else
  33. debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
  34. ret = (*init_fnc_ptr)();
  35. if (ret) {
  36. printf("initcall sequence %p failed at call %p (err=%d)\n",
  37. init_sequence,
  38. (char *)*init_fnc_ptr - reloc_ofs, ret);
  39. return -1;
  40. }
  41. }
  42. return 0;
  43. }
  44. #endif