blob: 69ce268070510a398a847ed977486dfefd70646f [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
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass655306c2020-05-10 11:39:58 -060012#ifdef CONFIG_EFI_APP
13#include <efi.h>
14#endif
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glass655306c2020-05-10 11:39:58 -060016
Simon Glassc1442d62019-04-08 13:20:47 -060017/*
18 * To enable debugging. add #define DEBUG at the top of the including file.
19 *
20 * To find a symbol, use grep on u-boot.map
21 */
Alexander Graff204f012019-01-31 16:06:23 +010022static inline int initcall_run_list(const init_fnc_t init_sequence[])
23{
24 const init_fnc_t *init_fnc_ptr;
25
26 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
27 unsigned long reloc_ofs = 0;
28 int ret;
29
Simon Glass752707a2019-04-08 13:20:41 -060030 /*
31 * Sandbox is relocated by the OS, so symbols always appear at
32 * the relocated address.
33 */
34 if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
Alexander Graff204f012019-01-31 16:06:23 +010035 reloc_ofs = gd->reloc_off;
36#ifdef CONFIG_EFI_APP
37 reloc_ofs = (unsigned long)image_base;
38#endif
Simon Glass752707a2019-04-08 13:20:41 -060039 if (reloc_ofs)
Ovidiu Panait3136e3d2019-09-25 14:10:54 +030040 debug("initcall: %p (relocated to %p)\n",
41 (char *)*init_fnc_ptr - reloc_ofs,
42 (char *)*init_fnc_ptr);
Alexander Graff204f012019-01-31 16:06:23 +010043 else
Ovidiu Panait3136e3d2019-09-25 14:10:54 +030044 debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
45
Alexander Graff204f012019-01-31 16:06:23 +010046 ret = (*init_fnc_ptr)();
47 if (ret) {
48 printf("initcall sequence %p failed at call %p (err=%d)\n",
49 init_sequence,
50 (char *)*init_fnc_ptr - reloc_ofs, ret);
51 return -1;
52 }
53 }
54 return 0;
55}
Simon Glass5b668882017-03-28 10:27:17 -060056
57#endif