blob: 41b74dc52d2ff1ee751bba9333d6f517e4f829e3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassc8a311d2013-03-05 14:39:40 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassc8a311d2013-03-05 14:39:40 +00004 */
5
Simon Glass2d986c02017-03-28 10:27:17 -06006#ifndef __INITCALL_H
7#define __INITCALL_H
8
Simon Glassc8a311d2013-03-05 14:39:40 +00009typedef int (*init_fnc_t)(void);
10
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060012#ifdef CONFIG_EFI_APP
13#include <efi.h>
14#endif
15
Simon Glass315f60d2019-04-08 13:20:47 -060016/*
17 * To enable debugging. add #define DEBUG at the top of the including file.
18 *
19 * To find a symbol, use grep on u-boot.map
20 */
Alexander Graf47870af2019-01-31 16:06:23 +010021static inline int initcall_run_list(const init_fnc_t init_sequence[])
22{
23 const init_fnc_t *init_fnc_ptr;
24
25 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
26 unsigned long reloc_ofs = 0;
27 int ret;
28
Simon Glass001d1882019-04-08 13:20:41 -060029 /*
30 * Sandbox is relocated by the OS, so symbols always appear at
31 * the relocated address.
32 */
33 if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
Alexander Graf47870af2019-01-31 16:06:23 +010034 reloc_ofs = gd->reloc_off;
35#ifdef CONFIG_EFI_APP
36 reloc_ofs = (unsigned long)image_base;
37#endif
Simon Glass001d1882019-04-08 13:20:41 -060038 if (reloc_ofs)
Ovidiu Panaitfa840f12019-09-25 14:10:54 +030039 debug("initcall: %p (relocated to %p)\n",
40 (char *)*init_fnc_ptr - reloc_ofs,
41 (char *)*init_fnc_ptr);
Alexander Graf47870af2019-01-31 16:06:23 +010042 else
Ovidiu Panaitfa840f12019-09-25 14:10:54 +030043 debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs);
44
Alexander Graf47870af2019-01-31 16:06:23 +010045 ret = (*init_fnc_ptr)();
46 if (ret) {
47 printf("initcall sequence %p failed at call %p (err=%d)\n",
48 init_sequence,
49 (char *)*init_fnc_ptr - reloc_ofs, ret);
50 return -1;
51 }
52 }
53 return 0;
54}
Simon Glass2d986c02017-03-28 10:27:17 -060055
56#endif