blob: 89a68b2444feeb09a8388c47f66f1f36ce4f72b8 [file] [log] [blame]
Simon Glasse7f59de2023-08-21 21:16:49 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2013 The Chromium OS Authors.
4 */
5
6#include <common.h>
7#include <efi.h>
8#include <initcall.h>
9#include <log.h>
10#include <asm/global_data.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
Simon Glass7d2e2332023-08-21 21:16:50 -060014static ulong calc_reloc_ofs(void)
15{
16#ifdef CONFIG_EFI_APP
17 return (ulong)image_base;
18#endif
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 return gd->reloc_off;
25
26 return 0;
27}
Simon Glasse7f59de2023-08-21 21:16:49 -060028/*
29 * To enable debugging. add #define DEBUG at the top of the including file.
30 *
31 * To find a symbol, use grep on u-boot.map
32 */
33int initcall_run_list(const init_fnc_t init_sequence[])
34{
Simon Glass7d2e2332023-08-21 21:16:50 -060035 ulong reloc_ofs = calc_reloc_ofs();
Simon Glasse7f59de2023-08-21 21:16:49 -060036 const init_fnc_t *init_fnc_ptr;
37
38 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
Simon Glasse7f59de2023-08-21 21:16:49 -060039 int ret;
40
Simon Glasse7f59de2023-08-21 21:16:49 -060041 if (reloc_ofs)
42 debug("initcall: %p (relocated to %p)\n",
43 (char *)*init_fnc_ptr - reloc_ofs,
44 (char *)*init_fnc_ptr);
45 else
46 debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
47
48 ret = (*init_fnc_ptr)();
49 if (ret) {
50 printf("initcall sequence %p failed at call %p (err=%d)\n",
51 init_sequence,
52 (char *)*init_fnc_ptr - reloc_ofs, ret);
53 return -1;
54 }
55 }
56 return 0;
57}