U boot 引導linux kernel過程

[在網絡上各位大俠的指導下,用u boot 成功引導linux。正在閱讀U boot源碼,第一次讀U boot 源碼,不少地方還不明白。本人會不定時修正文中謬論,也請各路大俠不吝賜教!]linux

 在u boot 中能夠使用bootm命令啓動 kernel,網絡上有大俠用go啓動kernel,本人尚不玩轉go。工做環境:MINI2440 + Ubuntu 10.04。下面是一些實測記錄,有些凌亂,各位看官見諒!網絡

1. 用go 指令執行未使用mkimage工具對linux進行壓縮,造成u-boot可引導的uImage.img文件。直接下載zImage.img
[u-boot@MINI2440]# usbslave 500000 30008000
USB host is connected. Waiting a download.
get downloadFileSize = 2517054 !!

Now, Downloading [ADDRESS:30008000h,TOTAL:2517054]
RECEIVED FILE SIZE: 2517054 (491KB/S, 5S)
[u-boot@MINI2440]# go 30008000
## Starting application at 0x30008000 ...
Uncompressing Linux..............................................................................................
-dead-

2. 用go指令執行用mkimage工做處理過的uImage.ing
[u-boot@MINI2440]# usbslave 50000 30008000
USB host is connected. Waiting a download.
get downloadFileSize = 2517114 !!

Now, Downloading [ADDRESS:30008000h,TOTAL:2517114]
RECEIVED FILE SIZE: 2517114 (614KB/S, 4S)
[u-boot@MINI2440]# go 30008040
## Starting application at 0x30008040 ...
Uncompressing Linux..............................................................................................
-dead-

3.用bootm指令執行用mkimage工做處理過的uImage.ing
[u-boot@MINI2440]# usbslave 500000 30008000
USB host is connected. Waiting a download.
get downloadFileSize = 2517114 !!

Now, Downloading [ADDRESS:30008000h,TOTAL:2517114]
RECEIVED FILE SIZE: 2517114 (614KB/S, 4S)
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...
   Image Name:   linux-2.6.32.2
   Created:      2011-03-03  11:05:18 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2517040 Bytes =  2.4 MB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.....
-olive-app

4.用bootm指令執行未用mkimage工做處理過的zImage.ing
[u-boot@MINI2440]# usbslave 500000 30008000
USB host is connected. Waiting a download.
get downloadFileSize = 2517054 !!

Now, Downloading [ADDRESS:30008000h,TOTAL:2517054]
RECEIVED FILE SIZE: 2517054 (614KB/S, 4S)
[u-boot@MINI2440]# bootm 30008000
Wrong Image Format for bootm command
ERROR: can't get kernel image!                                                  
[u-boot@MINI2440]# 函數


實踐證實:U boot只能啓動用mkimage處理過的kernel。mkimage 將一些kernel的基本信息加在kernel的頭部。經過在源碼添加printf作標記,發現啓動kernel是 /common/cmd_bootm.c中名爲do_bootm_linux的函數執行的。工具

在執行do_bootm_linux以前,其餘程序將kernel從nand、SD等介質上的kernel複製到RAM,若是kernel是壓縮的,還須要將其解壓。作必要的檢查後,使用do_bootm_linux啓動kernel。OK,讓咱們追蹤bootm的執行過程。ui

bootm的大體有7個過程。spa

1.參數檢查
2.boot_start()獲取kernel
3.禁止中斷
4.bootm_load_os()裝載kernel,若是kernel是壓縮的還須要將其解壓。
5. boot_fn = boot_os[images.os.os];
6. boot_fn(0, argc, argv, &images);
啓動linux kernel由do_bootm_linux()執行。
 
7. 啓動正常,boot_fn不會返回。

u boot使用函數指針,巧妙的將kernel須要的參數傳遞給kernel:
 void    (*theKernel)(int zero, int arch, uint params);

theKernel()函數的入口地址就是kernel image的入口地址。指針

theKernel = (void (*)(int, int, uint))images->ep;

theKernel (0, machid, bd->bi_boot_params);  //經過執行theKernel傳遞參數給linux kernel。
相關文章
相關標籤/搜索