首先將BootLoader 傳遞過(guò)來(lái)的r1(機(jī)器編號(hào))、r2(參數(shù)鏈表的物理地址)的值保存到r7、r8 中,再將r7 作為參數(shù)傳遞給解壓函數(shù)decompress_kernel()。在解壓函數(shù)中,再將r7 傳遞給全局變量__machine_arch_type。在跳到內(nèi)核(vmlinux)入口之前再將r7,r8 還原到r1,r2 中。
在文件 arch/arm/kernel/head.S[2]中,內(nèi)核(vmlinux)入口的部分代碼如下:
stext:
mrc p15, 0, r9, c0, c0
bl __lookup_processor_type
………
bl __lookup_machine_type
首先從處理器內(nèi)部特殊寄存器(CP15)中獲得ARM 內(nèi)核的類型,從處理器內(nèi)核描述符(proc_info_list)表(__proc_info_begin—__proc_info_end)中查詢有無(wú)此ARM 內(nèi)核的類型,如果無(wú)就出錯(cuò)退出。處理器內(nèi)核描述符定義在 include/asm-arm/procinfo.h中,具體的函數(shù)實(shí)現(xiàn)在 arch/arm/mm/proc-xxx.S中,在編譯連接過(guò)程中將各種處理器內(nèi)核描述符組合成表。接著從機(jī)器描述符(machine_desc)表(__mach_info_begin—__mach_info_end)中查詢有無(wú)r1 寄存器指定的機(jī)器編號(hào),如果沒(méi)有就出錯(cuò)退出。機(jī)器編號(hào)mach_type_xxx 在arch/arm/tools/mach-types文件中說(shuō)明,每個(gè)機(jī)器描述符中包括一個(gè)唯一的機(jī)器編號(hào),機(jī)器描述符的定義在 include/asm-arm/mach/arch.h中,具體實(shí)現(xiàn)在 arch/arm/mach-xxxx文件夾中,在編譯連接過(guò)程中將基于同一種處理器的不同機(jī)器描述符組合成表。例如,基于AT91RM9200 處理器的各種機(jī)器描述符可以參考 arch/arm/mach-at91rm9200/board-xxx.c,機(jī)器編號(hào)為262 的機(jī)器描述符如下所示:
MACHINE_START(AT91RM9200DK, “Atmel AT91RM9200-DK”)
/* Maintainer: SAN People/Atmel */
.phys_io = AT91_BASE_SYS,
.io_pg_offst = (AT91_VA_BASE_SYS 》》 18) & 0xfffc,
.boot_params = AT91_SDRAM_BASE + 0x100,
.timer = &at91rm9200_timer,
.map_io = dk_map_io,
.init_irq = dk_init_irq,
.init_machine = dk_board_init,
MACHINE_END
最后就是打開(kāi)MMU,并跳轉(zhuǎn)到 init/main.c的start_kernel(初始化系統(tǒng)。在 init/main.c中,函數(shù)start_kernel()的部分代碼如下:
{
……
setup_arch();
……
}
在 arch/arm/kernel/setup.c中,函數(shù)setup_arch()的部分代碼如下:
{
……
setup_processor();
mdesc=setup_machine(machine_arch_type);
……
parse_tags(tags);
……
}
setup_processor()函數(shù)從處理器內(nèi)核描述符表中找到匹配的描述符,并初始化一些處理器變量。setup_machine()用機(jī)器編號(hào)(在解壓函數(shù)decompress_kernel 中被賦值)作為參數(shù)返回機(jī)器描述符。從機(jī)器描述符中獲得內(nèi)核參數(shù)的物理地址,賦值給tags 變量。然后調(diào)用parse_tags()函數(shù)分析內(nèi)核參數(shù)鏈表,把各個(gè)參數(shù)值傳遞給全局變量。這樣內(nèi)核就收到了BootLoader 傳遞的參數(shù)。
5. 參數(shù)傳遞的驗(yàn)證和測(cè)試
參數(shù)傳遞的結(jié)果可以通過(guò)內(nèi)核啟動(dòng)的打印信息來(lái)驗(yàn)證。
Machine: Atmel AT91RM9200-DK
……
Kernel command line: console=ttyS0,115200 root=/dev/ram rw init=/linuxrc
……
Memory: 64MB = 64MB total
……
checking if image is initramfs.。.it isn‘’t (no cpio magic); looks like an initrd
Freeing initrd memory: 1024K
……
RAMDISK: Compressed image found at block 0
一個(gè)完備的BootLoader 是一個(gè)很復(fù)雜的工程,本文所介紹的只是嵌入式系統(tǒng)的BootLoaer 基本功能。任何一個(gè)BootLoader 都離不開(kāi)這個(gè)基本功能,內(nèi)核只有接收這些參數(shù)才能正確地啟動(dòng),同時(shí)也為內(nèi)核的移植和調(diào)試奠定了良好的基礎(chǔ)。
bootm命令中通過(guò)拷貝tag傳遞參數(shù)
為方便閱讀,進(jìn)行了少許修改,但功能不變,該函數(shù)參數(shù)為存放啟動(dòng)參數(shù)的地址
static void setup_linux_tag(ulong param_base)
{
struct tag *params = (struct tag *)param_base;
char *linux_cmd;
char *p;
memset(params, 0, sizeof(struct tag));
/* step1: setup start tag */
params-》hdr.tag = ATAG_CORE;
params-》hdr.size = tag_size(tag_core);
params-》u.core.flags = 0;
params-》u.core.pagesize = LINUX_PAGE_SIZE;
params-》u.core.rootdev = 0;
params = tag_next(params);
/* step2: setup cmdline tag */
params-》hdr.tag = ATAG_CMDLINE;
linux_cmd = getenv(“bootargs”);
for (p=linux_cmd; *p==‘ ’; p++) {/* do nothing */;}
params-》hdr.size = (sizeof(struct tag_header)+strlen(linux_cmd)+1+4) 》》 2;
memcpy(params-》u.cmdline.cmdline, linux_cmd, strlen(linux_cmd)+1);
params = tag_next(params);
/* step3: setup end tag */
params-》hdr.tag = ATAG_NONE;
params-》hdr.size = 0;
}
在uboot中,進(jìn)行設(shè)置tag的函數(shù)都在lib_arm/armlinux.c中,在這些函數(shù)前面是有ifdef的
#if defined (CONFIG_SETUP_MEMORY_TAGS) || /
defined (CONFIG_CMDLINE_TAG) || /
defined (CONFIG_INITRD_TAG) || /
defined (CONFIG_SERIAL_TAG) || /
defined (CONFIG_REVISION_TAG) || /
defined (CONFIG_LCD) || /
defined (CONFIG_VFD)
因此,如果你的bootm命令不能傳遞內(nèi)核參數(shù),就應(yīng)該是在你的board的config文件里沒(méi)有對(duì)上述的
宏進(jìn)行設(shè)置,定義一下即可
評(píng)論