Simon Glass | e7f59de | 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 | 7d2e233 | 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 | e7f59de | 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 | 7d2e233 | 2023-08-21 21:16:50 -0600 | [diff] [blame] | 35 | ulong reloc_ofs = calc_reloc_ofs(); |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 36 | const init_fnc_t *ptr; |
| 37 | init_fnc_t func; |
| 38 | int ret = 0; |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 39 | |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 40 | for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) { |
| 41 | if (reloc_ofs) { |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 42 | debug("initcall: %p (relocated to %p)\n", |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 43 | (char *)func - reloc_ofs, func); |
| 44 | } else { |
| 45 | debug("initcall: %p\n", (char *)func - reloc_ofs); |
| 46 | } |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 47 | |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 48 | ret = func(); |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 49 | if (ret) { |
| 50 | printf("initcall sequence %p failed at call %p (err=%d)\n", |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 51 | init_sequence, (char *)func - reloc_ofs, ret); |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 52 | return -1; |
| 53 | } |
| 54 | } |
Simon Glass | 468e372 | 2023-08-21 21:16:51 -0600 | [diff] [blame^] | 55 | |
Simon Glass | e7f59de | 2023-08-21 21:16:49 -0600 | [diff] [blame] | 56 | return 0; |
| 57 | } |