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