在分析U-Boot第二階段的C函數(shù)之前,我們有必要先分析二個重要的數(shù)據(jù)結(jié)構(gòu),因為它們在第二階段中無處不在!知道它們的厲害了吧?究竟是誰那么厲害呢?
打開?lib_arm/board.c? 在第55行看到:
55?? ?DECLARE_GLOBAL_DATA_PTR;
這是什么意思呢?找遍board.c也沒找著它的第二次出現(xiàn),因為它只出現(xiàn)一次,而且僅需一次就夠了。從字義上翻譯,“聲明全局的數(shù)據(jù)結(jié)構(gòu)型指針”。大概可以猜到,它起著聲明的作用,在include/am-arm/global_data.h頭文件的第64行:
64??? #define DECLARE_GLOBAL_DATA_PTR???? register volatile gd_t *gd asm ("r8")
原來它的作用是,聲明gd這么一個全局的指針,這個指針指向gd_t結(jié)構(gòu)體類型,并且這個gd指針是保存在ARM的r8這個寄存器里面的。
gd_t : global data數(shù)據(jù)結(jié)構(gòu)定義,位于文件 include/asm-arm/global_data.h。其成員主要是一些全局的系統(tǒng)初始化參數(shù)。需要用到時用宏定義: DECLARE_GLOBAL_DATA_PTR,指定占用寄存器r8。原型如下:
typedef?structglobal_data
{bd_t??? *bd;
// bd指針指向bd_info這個結(jié)構(gòu)體,保存開發(fā)板的相關(guān)參數(shù)
unsigned long?flags;
//指示標(biāo)志,如設(shè)備已經(jīng)初始化標(biāo)志等
unsigned long?baudrate;???????? // 串口的波特率unsigned long?have_console;??? // 串口初始化標(biāo)志
/* Relocation Offset 重定位偏移,就是實際定向的位置與編譯連接時指定的位置之差,一般為0 */
unsigned long?reloc_off;unsigned long?env_addr;????? ?// Address of Environment struct ,環(huán)境參數(shù)地址unsigned long?env_valid;????? // 環(huán)境參數(shù)CRC檢驗有效標(biāo)志unsigned long?fb_base;?????? //base address of frame buffer 幀緩沖區(qū)基地址
#ifdef CONFIG_VFD?????????? //? include/configs/EmbedSky.h里面沒有此宏定義,故忽略unsigned char?vfd_type;?/* display type */#endif#if 0unsigned long?cpu_clk;??????????? ?/* CPU clock in Hz!??*/unsigned long?bus_clk;????????????/*??Bus? clock in?Hz!? */unsigned long?ram_size;??????? /* RAM size */unsigned long?reset_status;?? /* reset status register at boot */#endifvoid??**jt;/* jump table 跳轉(zhuǎn)表,用來"函數(shù)調(diào)用地址登記" */
}gd_t
______________________________________________________________________
bd_t : board info數(shù)據(jù)結(jié)構(gòu)定義,位于文件 include/asm-arm/u-boot.h定義,主要是保存開發(fā)板的相關(guān)參數(shù)。
typedef struct bd_info
{int???bi_baudrate;??????????????????????????/ /串口波特率unsigned long?bi_ip_addr;???????????// IP地址unsigned char?bi_enetaddr[6];??? // MAC地址struct environment_s??????? *bi_env;ulong????bi_arch_number;//板子ID號
ulong?????bi_boot_params;// 啟動參數(shù)
struct??????????????????????????????????????? //RAM?配置{ulong start;ulong size;//CONFIG_NR_DRAM_BANKS=1,即1 bank of DRAM
}?bi_dram[CONFIG_NR_DRAM_BANKS];
#ifdef CONFIG_HAS_ETH1??????????//? include/configs/EmbedSky.h里面沒有此宏定義,故忽略/*? 如果有第二塊網(wǎng)卡,指定MAC地址?? */unsigned char?? bi_enet1addr[6];#endif}bd_t
;
——————————————————————————————————————
U-Boot
啟動內(nèi)核時要給內(nèi)核傳遞參數(shù),這時就要使用gd_t
,bd_t
結(jié)構(gòu)體中的信息來設(shè)置標(biāo)記列表。