歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 圖解U-Boot:引導內核分析

圖解U-Boot:引導內核分析

日期:2017/3/1 10:27:21   编辑:Linux編程
U-Boot的命令為用戶提供了交互功能,並且已經實現了幾十個常用的命令。如果開發板需要很特殊的操作,可以添加新的U-Boot命令。U-Boot的每一個命令都是通過U_Boot_CMD宏定義的。這個宏在<include/command.h>頭文件中定義

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \

cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

其中:

  • name:命令的名字,他不是一個字符串,不能用雙引號括起來
  • maxargs:最大的參數個數
  • command:對應的函數指針
  • usage:一個字符串,簡短的使用說明
  • help:一個字符串,比較詳細的使用說明

對於bootm命令,其定義如下:

  1. U_BOOT_CMD(//bootm命令
  2. bootm, CFG_MAXARGS, 1, do_bootm,
  3. "bootm - boot application image from memory\n",
  4. "[addr [arg ...]]\n - boot application image stored in memory\n"
  5. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  6. "\t'arg' can be the address of an initrd image\n"
  7. #ifdef CONFIG_OF_FLAT_TREE
  8. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  9. "\ta third argument is required which is the address of the of the\n"
  10. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  11. "\tuse a '-' for the second argument. If you do not pass a third\n"
  12. "\ta bd_info struct will be passed instead\n"
  13. #endif
  14. );

bootm命令是用來引導經過U-Boot的工具mkimage打包後的kernel image的。U-Boot源代碼的tools/目錄下有mkimage工具,這個工具可以用來制作不壓縮或者壓縮的多種可啟動映象文件。 mkimage在制作映象文件的時候,是在原來的可執行映象文件的前面加上一個0x40字節的頭,記錄參數所指定的信息,這樣uboot才能識別這個映象是針對哪個CPU體系結構的,哪個OS的,哪種類型,加載內存中的哪個位置, 入口點在內存的那個位置以及映象名是什麼。

相關閱讀:

圖解U-Boot:第一階段源碼分析 http://www.linuxidc.com/Linux/2012-03/55963.htm

圖解U-Boot:第二階段源碼分析 http://www.linuxidc.com/Linux/2012-03/55964.htm

U-Boot正是通過bootm命令引導Linux內核的。bootm命令調用do_bootm函數,下面我們來分析一下:

Copyright © Linux教程網 All Rights Reserved