一、initcall_run_list()函数
u-boot初始化过程比较复杂。排除一些汇编代码外,复杂的初始化过程以一个个C语言函数来描述。这些函数的定义过程代表着u-boot启动过程中对硬件平台的初始化过程。在u-boot中,对这些函数调用过程放进了一个函数指针数组中,该数组的组成元素即为初始化函数名。对这些函数列表进行调用执行的操作,在u-boot中是由initcall_run_list()函数完成的。
在u-boot 目录/include/initcall.h文件中。
typedef int (*init_fnc_t)(void);
int initcall_run_list(const init_fnc_t init_sequence[]);
在u-boot 目录/lib/initcall.c文件中。
int initcall_run_list(const init_fnc_t init_sequence[])
{
const init_fnc_t *init_fnc_ptr;
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
unsigned long reloc_ofs = 0;
int ret;
if (gd->flags & GD_FLG_RELOC)
reloc_ofs = gd->reloc_off;
#ifdef CONFIG_EFI_APP
reloc_ofs = (unsigned long)image_base;
#endif
debug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs);
if (gd->flags & GD_FLG_RELOC)
debug(" (relocated to %p)\n", (char *)*init_fnc_ptr);
else
debug("\n");
ret = (*init_fnc_ptr)();
if (ret) {
printf("initcall sequence %p failed at call %p (err=%d)\n",
init_sequence,
(char *)*init_fnc_ptr - reloc_ofs, ret);
return -1;
}
}
return 0;
}
initcall_run_list函数的使用
在u-boot中该函数的使用位置主要有两个:
(1)在u-boot目录/common/board_f.c文件中的board_init_f()函数中进行了使用。如下:
(2)在u-boot目录/common/board_r.c文件中的 board_init_r()函数中进行了使用,如下:
搜索关注【嵌入式小生】wx公众号获取更多精彩内容>>>>