日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

u-boot中添加自定义命令

發布時間:2024/9/3 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 u-boot中添加自定义命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.u-boot命令機制 u-boot中,每個命令都使用一個struct cmd_tbl_s結構體定義,該定義在include/command.h中實現: struct cmd_tbl_s{ char *name,//u-boot中執行的命令 int maxargs,//命令所能帶的參數個數,最少為1 int repeatable,//該命令是否可重復 int (*cmd)(struct cmd_tbl_s *,int,int,char*[]),//指向該命令對應的源函數 char *usage,//命令的使用提示 char *help//在線幫助信息 }; u-boot中定義的命令能與具體的函數程序相對應,通過指針 ?int (*cmd)(struct cmd_tbl_s *,int,int,char*[]) 實現。
在include/command.h中定義了U_BOOT_CMD宏: #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 = {#name, maxargs, rep, cmd, usage}
“##”與"#"都是預編譯操作符,“##”有字符串連接功能,"#"表示后面緊跟的是一個字符串。 宏 U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)就是將 struct cmd_tbl_s{ char *name, int maxargs, int repeatable, int (*cmd)(struct cmd_tbl_s *,int,int,char*[]), char *usage, char *help }; 這樣的一個命令結構體放到U-BOOT連接腳本?board/xxx/u-boot.lds中定義的".u-boot_cmd"段所在的內存區域.當用戶在u-boot的shell中輸入命令時,就會在".u_boot_cmd"這個內存區域中查找,當該區域中某一個cmd_tbl_s命令結構體的 cmd_tbl_s.name和輸入的命令字符串相符時,就調用該命令結構體的cmd_tbl_s.cmd()函數. 2.添加自定義命令 自定義命令設為"myubootcmd",不可與u-boot命令重名, <1>添加命令行配置信息,在u-boot-1.3.2/include/configs/smdk2410.h中添加 #define CONFIG_CMD_MYUBOOT,如下: #define CONFIG_CMD_CACHE #define CONFIG_CMD_DATE #define CONFIG_CMD_ELF #define CONFIG_CMD_PING #define CONFIG_CMD_NET #define CONFIG_CMD_MYUBOOT <2>編寫命令行對應的源程序,u-boot-1.3.2/board/smdk2410/中添加文件myuboot.c,內容如下所示
#include #include #include #ifdef CONFIG_CMD_MYUBOOT void myubootcmd(void) { printf("Hello,my u-boot!\n"); }
U_BOOT_CMD( myuboot,//uboot命令 1,//不帶參數 2,//可重復 myubootcmd,//命令對應函數 "hello-my uboot command",//用法提示 "my uboot test command in u-boot 1.3.2\n"//在線幫助信息 ); #endif <3>添加編譯 ?u-boot-1.3.2/board/smdk2410/Makefile 中添加myuboot.o include $(TOPDIR)/config.mk
LIB = $(obj)lib$(BOARD).a
COBJS := smdk2410.o flash.o myuboot.o <4>編譯u-boot # make smdk2410_config CROSS_COMPILE=arm-linux- Configuring for smdk2410 board... # make ARCH=arm ?CROSS_COMPILE=arm-linux- all <5>運行 SMDK2410 # help myuboot myuboot my uboot test command in u-boot 1.3.2
SMDK2410 # myuboot Hello,my u-boot! SMDK2410 #

總結

以上是生活随笔為你收集整理的u-boot中添加自定义命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。