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) 2013 The Chromium OS Authors. |
Simon Glass | 82a5fa0 | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <initcall.h> |
Simon Glass | a459d66 | 2015-07-31 09:31:38 -0600 | [diff] [blame] | 8 | #include <efi.h> |
Simon Glass | 82a5fa0 | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 9 | |
Simon Glass | 8f77045 | 2014-05-20 06:01:43 -0600 | [diff] [blame] | 10 | DECLARE_GLOBAL_DATA_PTR; |
| 11 | |
| 12 | int initcall_run_list(const init_fnc_t init_sequence[]) |
Simon Glass | 82a5fa0 | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 13 | { |
Simon Glass | 8f77045 | 2014-05-20 06:01:43 -0600 | [diff] [blame] | 14 | const init_fnc_t *init_fnc_ptr; |
Simon Glass | 82a5fa0 | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 15 | |
| 16 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
Simon Glass | 8f77045 | 2014-05-20 06:01:43 -0600 | [diff] [blame] | 17 | unsigned long reloc_ofs = 0; |
Simon Glass | 5b3abbe | 2014-10-01 19:57:22 -0600 | [diff] [blame] | 18 | int ret; |
Simon Glass | 8f77045 | 2014-05-20 06:01:43 -0600 | [diff] [blame] | 19 | |
| 20 | if (gd->flags & GD_FLG_RELOC) |
| 21 | reloc_ofs = gd->reloc_off; |
Simon Glass | a459d66 | 2015-07-31 09:31:38 -0600 | [diff] [blame] | 22 | #ifdef CONFIG_EFI_APP |
| 23 | reloc_ofs = (unsigned long)image_base; |
| 24 | #endif |
Alexey Brodkin | 9f1c9c9 | 2014-12-28 01:35:57 +0300 | [diff] [blame] | 25 | debug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs); |
| 26 | if (gd->flags & GD_FLG_RELOC) |
| 27 | debug(" (relocated to %p)\n", (char *)*init_fnc_ptr); |
| 28 | else |
| 29 | debug("\n"); |
Simon Glass | 5b3abbe | 2014-10-01 19:57:22 -0600 | [diff] [blame] | 30 | ret = (*init_fnc_ptr)(); |
| 31 | if (ret) { |
| 32 | printf("initcall sequence %p failed at call %p (err=%d)\n", |
Simon Glass | 8f77045 | 2014-05-20 06:01:43 -0600 | [diff] [blame] | 33 | init_sequence, |
Simon Glass | 5b3abbe | 2014-10-01 19:57:22 -0600 | [diff] [blame] | 34 | (char *)*init_fnc_ptr - reloc_ofs, ret); |
Simon Glass | 82a5fa0 | 2013-03-05 14:39:40 +0000 | [diff] [blame] | 35 | return -1; |
| 36 | } |
| 37 | } |
| 38 | return 0; |
| 39 | } |