本文来了解 board_init_r 函数执行过程。_main函数会调用到 board_init_r 函数。
_main 函数会调用到 board_init_r 函数。
_main 函数在 uboot的 /arch/arm/lib/crt0.S 文件中。_main函数中,执行完 relocate_vectors 函数(即重定位中断向量表)后,然后清 BSS 段,之后就是调用 board_init_r函数。
前面有文章讲解了 board_init_f 函数,在此函数里面会调用一系列的函数来初始化一些外设和 gd 的成员变量。但是 board_init_f 函数并没有初始化所有的外设,还需要做一些后续工作,这些后续工作就是由 board_init_r 函数来完成的,board_init_r 函数定义在文件 common/board_r.c 中,关键的代码如下:
- void board_init_r(gd_t *new_gd, ulong dest_addr)
- {
- ......
- if (initcall_run_list(init_sequence_r))
- hang();
- ......
- }
- init_fnc_t init_sequence_r[] = {
- initr_trace,
- initr_reloc,
- initr_caches,
- initr_reloc_global_data,
- initr_barrier,
- initr_malloc,
- initr_console_record,
- bootstage_relocate,
- initr_bootstage,
- board_init, /* Setup chipselects */
- stdio_init_tables,
- initr_serial,
- initr_announce,
- INIT_FUNC_WATCHDOG_RESET
- INIT_FUNC_WATCHDOG_RESET
- INIT_FUNC_WATCHDOG_RESET
- power_init_board,
- initr_flash,
- INIT_FUNC_WATCHDOG_RESET
- initr_nand,
- initr_mmc,
- initr_env,
- INIT_FUNC_WATCHDOG_RESET
- initr_secondary_cpu,
- INIT_FUNC_WATCHDOG_RESET
- stdio_add_devices,
- initr_jumptable,
- console_init_r, /* fully init console as a device */
- INIT_FUNC_WATCHDOG_RESET
- interrupt_init,
- initr_enable_interrupts,
- initr_ethaddr,
- board_late_init,
- INIT_FUNC_WATCHDOG_RESET
- INIT_FUNC_WATCHDOG_RESET
- INIT_FUNC_WATCHDOG_RESET
- initr_net,
- INIT_FUNC_WATCHDOG_RESET
- run_main_loop,
- };
第 28 行,initr_jumptable 函数,初始化跳转表。
- In: serial
- Out: serial
- Err: serial
注意: 类似 CONFIG_CMD_SCSI这种带 CMD的是 uboot支持的 命令。配置是否使用该命令的文件是 mx6ull_alientek_nand.h。
initr_net->eth_initialize->board_eth_init()
串口打印如下:
Net: FEC1
uboot命令行模式:开发板上电时,uboot启动时会进入几秒的倒计时,如果在倒计时之前按下 "Enter"回车键,会进入 uboot命令行模式。uboot命令行模式下可以输入命令,开发板可以接收到 输入的命令。如下就是进入了uboot命令行模式:

以上就是 board_init_r函数大体执行过程。