UBOOT之board.c分析(一)

本文详细分析了U-Boot中的board.c文件,涉及全局变量gd_t和bd_t的初始化,以及一系列初始化操作,如arch_cpu_init、board_init、interrupt_init、timer_init、env_init等。这些函数分别负责CPU识别、板级设置、中断初始化、定时器配置、环境变量初始化、波特率设置、串口初始化等。通过init_sequence数组,按顺序执行各种初始化任务,确保系统正确启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

############board.c在文件夹lib_arm中##################

gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
     为全局变量gd_t结构体指定起始地址,变量gd在include/asm-arm/global_data.h中定义:
    #define DECLARE_GLOBAL_DATA_PTR     register volatile  gd_t  *gd  asm ("r8")

memset ((void*)gd, 0, sizeof (gd_t));                           //清空gd_t结构体
gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));         //为gd_bd指定起始地址
memset (gd->bd, 0, sizeof (bd_t));                     //清空bd_t结构体

gd->flags |= GD_FLG_RELOC;                         //gd->flags 标记程序已经运行在ram中

monitor_flash_len = _bss_start - _armboot_start;    //计算程序的大小

GD_FLG_RELOC在include/asm-arm/global_data.h中定义:
#define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */

bd_t结构体在include/asm-arm/u-boot.h中定义

/*************初始化操作序列*************/
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
if ((*init_fnc_ptr)() != 0) {
hang ();
}
}

其中init_sequence是一个存放函数指针的数组,里面存放了一系列进行初始化操作的函数名,然后通过for循环一次调用这些函数。此数组就在就定义在lib_arm/board.c中,定义如下:
init_fnc_t *init_sequence[] = {
#if defined(CONFIG_ARCH_CPU_INIT)
arch_cpu_init, /* basic arch cpu dependent setup */
#endif
board_init, /* basic board dependent setup */
#if defined(CONFIG_USE_IRQ)
interrupt_init, /* set up exceptions */
#endif
timer_init, /* initialize timer */
#ifdef CONFIG_FSL_ESDHC
get_clocks,
#endif
env_init, /* initialize environment */
init_baudrate, /* initialze baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
display_banner, /* say that we are here */
#if defined(CONFIG_DISPLAY_CPUINFO)
print_cpuinfo, /* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
checkboard, /* display board info */
#endif
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
init_func_i2c,
#endif
dram_init, /* configure available RAM banks */
#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
arm_pci_init,
#endif
display_dram_config,
NULL,
};


依次说明各个函数的作用:
/************************    arch_cpu_init    *************************************/
这个函数在cpu/arm_cortexa8/s5pc1xx/clock_info.c中定义
int arch_cpu_init(void)
{
s5pc1xx_cpu_id = readl(S5PC1XX_PRO_ID);      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值