blob: a38c83efa441d87d7e4c8efcd77db701056e061e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass82a5fa02013-03-05 14:39:40 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass82a5fa02013-03-05 14:39:40 +00004 */
5
Simon Glass5b668882017-03-28 10:27:17 -06006#ifndef __INITCALL_H
7#define __INITCALL_H
8
Simon Glass82a5fa02013-03-05 14:39:40 +00009typedef int (*init_fnc_t)(void);
10
Alexander Graff204f012019-01-31 16:06:23 +010011#include <common.h>
12#include <initcall.h>
13#include <efi.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static inline int initcall_run_list(const init_fnc_t init_sequence[])
18{
19 const init_fnc_t *init_fnc_ptr;
20
21 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
22 unsigned long reloc_ofs = 0;
23 int ret;
24
Simon Glass752707a2019-04-08 13:20:41 -060025 /*
26 * Sandbox is relocated by the OS, so symbols always appear at
27 * the relocated address.
28 */
29 if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
Alexander Graff204f012019-01-31 16:06:23 +010030 reloc_ofs = gd->reloc_off;
31#ifdef CONFIG_EFI_APP
32 reloc_ofs = (unsigned long)image_base;
33#endif
34 debug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs);
Simon Glass752707a2019-04-08 13:20:41 -060035 if (reloc_ofs)
Alexander Graff204f012019-01-31 16:06:23 +010036 debug(" (relocated to %p)\n", (char *)*init_fnc_ptr);
37 else
38 debug("\n");
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}
Simon Glass5b668882017-03-28 10:27:17 -060049
50#endif