initcall.h 1.3 KB

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