1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 The Chromium OS Authors.
10 #include <asm/global_data.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 static ulong calc_reloc_ofs(void)
17 return (ulong)image_base;
20 * Sandbox is relocated by the OS, so symbols always appear at
21 * the relocated address.
23 if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC))
30 * initcall_is_event() - Get the event number for an initcall
32 * func: Function pointer to check
33 * Return: Event number, if this is an event, else 0
35 static int initcall_is_event(init_fnc_t func)
37 ulong val = (ulong)func;
39 if ((val & INITCALL_IS_EVENT) == INITCALL_IS_EVENT)
40 return val & INITCALL_EVENT_TYPE;
46 * To enable debugging. add #define DEBUG at the top of the including file.
48 * To find a symbol, use grep on u-boot.map
50 int initcall_run_list(const init_fnc_t init_sequence[])
53 const init_fnc_t *ptr;
58 for (ptr = init_sequence; func = *ptr, func; ptr++) {
59 reloc_ofs = calc_reloc_ofs();
60 type = initcall_is_event(func);
63 if (!CONFIG_IS_ENABLED(EVENT))
65 debug("initcall: event %d/%s\n", type,
66 event_type_name(type));
67 } else if (reloc_ofs) {
68 debug("initcall: %p (relocated to %p)\n",
69 (char *)func - reloc_ofs, (char *)func);
71 debug("initcall: %p\n", (char *)func - reloc_ofs);
74 ret = type ? event_notify_null(type) : func();
80 if (CONFIG_IS_ENABLED(EVENT)) {
83 /* don't worry about buf size as we are dying here */
85 sprintf(buf, "event %d/%s", type,
86 event_type_name(type));
88 sprintf(buf, "call %p",
89 (char *)func - reloc_ofs);
92 printf("initcall failed at %s (err=%dE)\n", buf, ret);
94 printf("initcall failed at call %p (err=%d)\n",
95 (char *)func - reloc_ofs, ret);