bd_t、gd_t是u-boot中两个重要的数据结构,初始化操作中很多全局变量都要靠这两个数据结构来保存或传递。
两者分别定义在include/asm-arm/u-boot.h、include/asm-arm/global_data.h中。
一、bd_t 类型
struct bd_info 这个结构体类型,主要是用来保存板子参数。
使用typedef将这个结构体类型换别名为“bd_t”,其内容如下。
typedef struct bd_info {int bi_baudrate; /* serial console baudrate */unsigned long bi_ip_addr; /* IP Address *///开发板ID,该变量标识每一种开发板相关的ID,该值将传递给内核;//如果这个参数与内核配置的不相同,那么内核启动解压缩完成后//将出现“Error : a”错误; //开发板ID可以在内核arch/arm/tool/mach-types中查看ulong bi_arch_number; /* unique id for this board*///u-boot传递给内核的参数的保存地址ulong bi_boot_params; /* where this board expects params *///内存的起始地址及大小struct /* RAM configuration */{ulong start;ulong size;} bi_dram[CONFIG_NR_DRAM_BANKS];} bd_t;
二、gd_t 类型
结构体struct global_data,其成员主要是一些全局的系统初始化参数。
使用typedef将这个结构体类型换别名为“gd_t”,其内容如下。
typedef struct global_data {bd_t *bd; //与板子相关的结构,同上unsigned long flags; //指示标志,如设备已经初始化标志等unsigned long baudrate; //串口波特率unsigned long have_console; /* serial_init() was called */ //串口初始化标志#ifdef CONFIG_PRE_CONSOLE_BUFFER //宏未定义unsigned long precon_buf_idx; /* Pre-Console buffer index */#endifunsigned long env_addr; /* Address of Environment struct */ //环境变量参数地址unsigned long env_valid; /* Checksum of Environment valid? */ //检验环境变量参数是否有效unsigned long fb_base; /* base address of frame buffer */ // frame buffer基址#ifdef CONFIG_FSL_ESDHC //宏未在板子相关头文件中定义unsigned long sdhc_clk;#endif#ifdef CONFIG_AT91FAMILY //宏未在板子相关头文件中定义/* "static data" needed by at91's clock.c */unsigned long cpu_clk_rate_hz;unsigned long main_clk_rate_hz;unsigned long mck_rate_hz;unsigned long plla_rate_hz;unsigned long pllb_rate_hz;unsigned long at91_pllb_usb_init;#endif#ifdef CONFIG_ARM //宏未定义/* "static data" needed by most of timer.c on ARM platforms */unsigned long timer_rate_hz;unsigned long tbl;unsigned long tbu;unsigned long long timer_reset_value;unsigned long lastinc;#endif#ifdef CONFIG_IXP425 //宏未在板子相关头文件中定义unsigned long timestamp;#endifunsigned long relocaddr; /* Start address of U-Boot in RAM */ //u-boot自搬移至内存后的起始地址phys_size_t ram_size; /* RAM size */unsigned long mon_len; /* monitor len */unsigned long irq_sp; /* irq stack pointer */unsigned long start_addr_sp; /* start_addr_stackpointer */unsigned long reloc_off;#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) //宏未定义unsigned long tlb_addr;#endifconst void *fdt_blob; /* Our device tree, NULL if none */void **jt; /* jump table */char env_buf[32]; /* buffer for getenv() before reloc. */#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER) //宏未定义unsigned long post_log_word; /* Record POST activities */unsigned long post_log_res; /* success of POST test */unsigned long post_init_f_time; /* When post_init_f started */#endif }gd_t;
注意,在\include\asm-arm\global_data.h中定义了变量gd,它是gd_t指针类型的。
如下, DECLARE_GLOBAL_DATA_PTR定义了一个要放在寄存器r8中的全局变量,名字叫gd,类型是一个指向gd_t类型变量的指针。
#define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r8")