Simon Glass | afb5a8a | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2013 The Chromium OS Authors. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <efi.h> |
| 8 | #include <initcall.h> |
| 9 | #include <log.h> |
| 10 | #include <asm/global_data.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Simon Glass | 0e33bbf | 2023-08-21 21:16:50 -0600 | [diff] [blame^] | 14 | static ulong calc_reloc_ofs(void) |
| 15 | { |
| 16 | #ifdef CONFIG_EFI_APP |
| 17 | return (ulong)image_base; |
| 18 | #endif |
| 19 | /* |
| 20 | * Sandbox is relocated by the OS, so symbols always appear at |
| 21 | * the relocated address. |
| 22 | */ |
| 23 | if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) |
| 24 | return gd->reloc_off; |
| 25 | |
| 26 | return 0; |
| 27 | } |
Simon Glass | afb5a8a | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 28 | /* |
| 29 | * To enable debugging. add #define DEBUG at the top of the including file. |
| 30 | * |
| 31 | * To find a symbol, use grep on u-boot.map |
| 32 | */ |
| 33 | int initcall_run_list(const init_fnc_t init_sequence[]) |
| 34 | { |
Simon Glass | 0e33bbf | 2023-08-21 21:16:50 -0600 | [diff] [blame^] | 35 | ulong reloc_ofs = calc_reloc_ofs(); |
Simon Glass | afb5a8a | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 36 | const init_fnc_t *init_fnc_ptr; |
| 37 | |
| 38 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
Simon Glass | afb5a8a | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 39 | int ret; |
| 40 | |
Simon Glass | afb5a8a | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 41 | if (reloc_ofs) |
| 42 | debug("initcall: %p (relocated to %p)\n", |
| 43 | (char *)*init_fnc_ptr - reloc_ofs, |
| 44 | (char *)*init_fnc_ptr); |
| 45 | else |
| 46 | debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); |
| 47 | |
| 48 | ret = (*init_fnc_ptr)(); |
| 49 | if (ret) { |
| 50 | printf("initcall sequence %p failed at call %p (err=%d)\n", |
| 51 | init_sequence, |
| 52 | (char *)*init_fnc_ptr - reloc_ofs, ret); |
| 53 | return -1; |
| 54 | } |
| 55 | } |
| 56 | return 0; |
| 57 | } |