Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | c8a311d | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | c8a311d | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 2d986c0 | 2017-03-28 10:27:17 -0600 | [diff] [blame] | 6 | #ifndef __INITCALL_H |
| 7 | #define __INITCALL_H |
| 8 | |
Simon Glass | c8a311d | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 9 | typedef int (*init_fnc_t)(void); |
| 10 | |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame^] | 11 | #ifdef CONFIG_EFI_APP |
| 12 | #include <efi.h> |
| 13 | #endif |
| 14 | |
Simon Glass | 315f60d | 2019-04-08 13:20:47 -0600 | [diff] [blame] | 15 | /* |
| 16 | * To enable debugging. add #define DEBUG at the top of the including file. |
| 17 | * |
| 18 | * To find a symbol, use grep on u-boot.map |
| 19 | */ |
Alexander Graf | 47870af | 2019-01-31 16:06:23 +0100 | [diff] [blame] | 20 | static inline int initcall_run_list(const init_fnc_t init_sequence[]) |
| 21 | { |
| 22 | const init_fnc_t *init_fnc_ptr; |
| 23 | |
| 24 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
| 25 | unsigned long reloc_ofs = 0; |
| 26 | int ret; |
| 27 | |
Simon Glass | 001d188 | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 28 | /* |
| 29 | * Sandbox is relocated by the OS, so symbols always appear at |
| 30 | * the relocated address. |
| 31 | */ |
| 32 | if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) |
Alexander Graf | 47870af | 2019-01-31 16:06:23 +0100 | [diff] [blame] | 33 | reloc_ofs = gd->reloc_off; |
| 34 | #ifdef CONFIG_EFI_APP |
| 35 | reloc_ofs = (unsigned long)image_base; |
| 36 | #endif |
Simon Glass | 001d188 | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 37 | if (reloc_ofs) |
Ovidiu Panait | fa840f1 | 2019-09-25 14:10:54 +0300 | [diff] [blame] | 38 | debug("initcall: %p (relocated to %p)\n", |
| 39 | (char *)*init_fnc_ptr - reloc_ofs, |
| 40 | (char *)*init_fnc_ptr); |
Alexander Graf | 47870af | 2019-01-31 16:06:23 +0100 | [diff] [blame] | 41 | else |
Ovidiu Panait | fa840f1 | 2019-09-25 14:10:54 +0300 | [diff] [blame] | 42 | debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); |
| 43 | |
Alexander Graf | 47870af | 2019-01-31 16:06:23 +0100 | [diff] [blame] | 44 | ret = (*init_fnc_ptr)(); |
| 45 | if (ret) { |
| 46 | printf("initcall sequence %p failed at call %p (err=%d)\n", |
| 47 | init_sequence, |
| 48 | (char *)*init_fnc_ptr - reloc_ofs, ret); |
| 49 | return -1; |
| 50 | } |
| 51 | } |
| 52 | return 0; |
| 53 | } |
Simon Glass | 2d986c0 | 2017-03-28 10:27:17 -0600 | [diff] [blame] | 54 | |
| 55 | #endif |