blob: 81c5d24507359fda8314295cf29ae58b64461f90 [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 Glass468e3722023-08-21 21:16:51 -060036 const init_fnc_t *ptr;
37 init_fnc_t func;
38 int ret = 0;
Simon Glasse7f59de2023-08-21 21:16:49 -060039
Simon Glass468e3722023-08-21 21:16:51 -060040 for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) {
41 if (reloc_ofs) {
Simon Glasse7f59de2023-08-21 21:16:49 -060042 debug("initcall: %p (relocated to %p)\n",
Simon Glass468e3722023-08-21 21:16:51 -060043 (char *)func - reloc_ofs, func);
44 } else {
45 debug("initcall: %p\n", (char *)func - reloc_ofs);
46 }
Simon Glasse7f59de2023-08-21 21:16:49 -060047
Simon Glass468e3722023-08-21 21:16:51 -060048 ret = func();
Simon Glasse7f59de2023-08-21 21:16:49 -060049 if (ret) {
50 printf("initcall sequence %p failed at call %p (err=%d)\n",
Simon Glass468e3722023-08-21 21:16:51 -060051 init_sequence, (char *)func - reloc_ofs, ret);
Simon Glasse7f59de2023-08-21 21:16:49 -060052 return -1;
53 }
54 }
Simon Glass468e3722023-08-21 21:16:51 -060055
Simon Glasse7f59de2023-08-21 21:16:49 -060056 return 0;
57}