在U boot 1 3 4中新增加命令

2021-05-06 10:17:24 字數 1534 閱讀 4893

前言:qljt跟u-boot的makefile裡面開發商相對應 ;qljt2440是我開發板的名字

原理:每個命令都有乙個命令結構體

struct cmd_tbl_s ;

去定義它。cmd為要呼叫的命令函式!name為該命令名字串,不要用""括起來,不要與現有函式同名。

在u-boot裡面有這樣的巨集

#define struct_section  __attribute__ ((unused,section (".u_boot_cmd")))

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

cmd_tbl_t __u_boot_cmd_##name struct_section =

巨集u_boot_cmd(name,maxargs,rep,cmd,usage,help)就是將

cmd_tbl_s這樣的乙個命令結構體放入記憶體.u_boot_cmd這個區域,.u_boot_cmd這個域在board/qljt2440/u-boot.lds中定義!在u-boot中的shell中,根據使用者輸入的命令,就會在.u_boot_cmd這個記憶體區域中查詢,當.u_boot_cmd中某乙個cmd_tbl_s命令結構體的cmd_tbl_s.name和輸入的命令字串相符時,就呼叫該命令

結構體的cmd_tbl_s.cmd( ….)函式!

怎樣新增命令函引數!

下面以新增 "hello word!" 命令為例!

(1)在include/configs/qljt2440.h中增加一項:

#define config_cmd_askenv

#define config_cmd_cache

#define config_cmd_date

#define config_cmd_dhcp

#define config_cmd_elf

#define config_cmd_ping

#define config_cmd_nand    //ql18

#define config_cmd_reginfo   //ql18

#define  config_cmd_helloword

(2)在 /board/qljt/qljt2440/ 目錄下新增 helloword.c 檔案

內容如下

/**!ql add for test add u-boot command

*/#include

#include

#ifdef config_cmd_helloword

void helloword(void)

u_boot_cmd(

hello,

1,2,

helloword,

"hell  - helloword command ",

" ql add u-boot command!/n"

);#endif

(3)在/board/qljt/qljt2440/ 目錄下的makefile 新增要編譯的目標檔案

(4)重新編譯u-boot,完畢!

u boot中新增命令

看下ping命令實現的例子 檔案common cmd net.c static int do ping cmd tbl t cmdtp,int flag,int argc,char const argv printf host s is alive n argv 1 return 0 u boot ...

U boot中mtdparts命令新增

在自己開發板的配置標頭檔案下面新增如下幾條語句就可以用kernel代替你的具體分割槽表,下面語句沒有其他的作用,就是為了方便你不用記那些位址範圍,省去了不少事情。在在arch arm lib board.c 中for 前面新增run command mtdparts default 0 define...

在命令提示符中新增PATH

在命令提示符中輸入set path path 你想加入的路徑 即可完成設定 設定的path只在當前視窗有效 echo path 可檢視當前的環境變數 set path d tools ffmpeg bin path 如下圖所示 若是經常使用的話可在系統中的環境變數中設定 在命令列中可用setx設定永...