U Boot新增命令的方法

2021-09-07 08:18:43 字數 967 閱讀 1286

下面以新增menu命令為例分析u-boot新增命令的方法。

(1)在common目錄下新建cmd_menu.c檔案

習慣上把通用命令源**放在common目錄下,與開發板專有命令有關的源**則放在board/目錄下,命名方式只是習慣而已。為了方便閱讀和查詢習慣以「cmd_《命 令名》.c」為檔名。

(2)定義「menu」命令

在cmd_menu.c中使用如下的**定義「menu」命令:

u_boot_cmd(

menu, 3, 0, do_menu,

"menu - display a menu, to select the items to do something\n",

" - display a menu, to select the items to do something"

其中u_boot_cmd命令格式如下:

1 u_boot_cmd(name,maxargs,rep,cmd,usage,help)

各個引數的意義如下:

name:命令名,非字串,但在u_boot_cmd中用「#」符號轉化為字串

maxargs:命令的最大引數個數

rep:是否自動重複(按enter鍵是否會重複執行)

cmd:該命令對應的響應函式

usage:簡短的使用說明(字串)

help:較詳細的使用說明(字串)

在記憶體中儲存命令的help欄位會占用一定的記憶體,通過配置u-boot可以選擇是否儲存help欄位。若在include/configs/mx51_bbg.h中定義了config_sys_longhelp巨集,則在u-boot中使用help命令檢視某個命令的幫助資訊時將顯示usage和help欄位的內容,否則就只顯示usage欄位的內容。

u_boot_cmd巨集在include/command.h中定義:

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

uboot新增命令

u boot cmd是乙個巨集定義,具體功能是定義乙個struct cmd tbl s的結構體變數,u boot cmd巨集傳遞的引數是該結構體變數的成員變數。通過u boot cmd定義的變數會通過指令碼鏈結到uboot指定的乙個section中,然後可以通過find cmd遍歷這個section...

新增乙個uboot命令的方法

1 在common目錄下新增乙個檔案,比如cmd menu.c,並編輯裡面的內容 if defined config cmd menu int do menu cmd tbl t cmdtp,int flag,int argc,char argv u boot cmd endif 2 在commom...

U boot 新增命令 U BOOT CMD

u boot的每乙個命令都是通過u boot cmd巨集定義的。這個巨集在include command.h標頭檔案中定義,每乙個命令定義乙個cmd tbl t結構體。命令巨集u boot cmd define u boot cmd name,maxargs,rep,cmd,usage,help c...