Uboot版本:u-boot-2013.01
一、gd结构体的定义与使用
gd_t 和 bd_t 是u-boot中两个重要的数据结构,在初始化操作很多都要靠这两个数据结构来保存或传递。
gd_t 定义在/u-boot-2013.01/arch/arm/include/asm/global_data.h
bd_t 定义在 ./include/asm-arm/u-boot.h
1、gd_t : global data数据结构定义
位于文件/u-boot-2013.01/arch/arm/include/asm/global_data.h 中。其成员主要是一些全局的系统初始化参数。
当使用gd_t 时需用宏定义进行声明DECLARE_GLOBAL_DATA_PTR
![](https://img-blog.csdn.net/20160307154019489?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
从这个宏的定义可以看出,gd是一个保存在ARM的r8寄存器中的gd_t结构体的指针。指定占用寄存器R8。
- typedef struct global_data {
- bd_t *bd;
- unsigned long flags;
- unsigned int baudrate;
- unsigned long have_console;
- #ifdef CONFIG_PRE_CONSOLE_BUFFER
- unsigned long precon_buf_idx;
- #endif
- unsigned long env_addr;
- unsigned long env_valid;
- unsigned long fb_base;
- #ifdef CONFIG_FSL_ESDHC
- unsigned long sdhc_clk;
- #endif
- #ifdef CONFIG_AT91FAMILY
-
- 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
-
- 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;
- #endif
- unsigned long relocaddr;
- phys_size_t ram_size;
- unsigned long mon_len;
- unsigned long irq_sp;
- unsigned long start_addr_sp;
- unsigned long reloc_off;
- #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
- unsigned long tlb_addr;
- unsigned long tlb_size;
- #endif
- const void *fdt_blob;
- void **jt;
- char env_buf[32];
- #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
- unsigned long post_log_word;
- unsigned long post_log_res;
- unsigned long post_init_f_time;
- #endif
- } gd_t;
2.、bd_t :board info数据结构定义
位于文件u-boot-2013.01/arch/arm/include/asm/u-boot.h。保存板子参数。
- typedef struct bd_info {
- unsigned int bi_baudrate;
- ulong bi_arch_number;
- ulong bi_boot_params;
- unsigned long bi_arm_freq;
- unsigned long bi_dsp_freq;
- unsigned long bi_ddr_freq;
- struct
- {
- ulong start;
- ulong size;
- } bi_dram[CONFIG_NR_DRAM_BANKS];
- } bd_t;