uboot 添加hello命令
平台:MPC8315(POWERPC)
1.在/common/ 目錄下創建自己的文件,最好前綴為cmd_.
cmd_hello.c
*********************************************************
#include<command.h>
#include<common.h>
#ifdef CONFIG_CMD_HELLO
int do_hello(cmd_tbl_t *cmdtp,int flag,int argc,char *argv)
{
printf("my test \n");
return 0;
}
U_BOOT_CMD(
hello,1,0,do_hello,"usage:test\n","help:test\n"
);
#endif
*********************************************************
2.在當前目錄下修改Makefile
在目標變量最後麵添加:
#ifdef CONFIG_CMD_HELLO
COBJS-y += cmd_hello.o
#endif
3.在頭文件mpc83xx.h中添加對CONFIG_CMD_HELLO的定義
#define CONFIG_CMD_HELLO
編譯下載後,在uboot中運行hello:
4.U_BOOT_CMD
它的定義在include/command.h中,
/**********************************************************/
#define Struct_Section __attribute__((unused, section(".u_boot_cmd"), aligned(4)))
#define U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
{#name, maxargs, rep, cmd, usage, _CMD_HELP(help) _CMD_COMPLETE(comp)}
#define U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = \
U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp)
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
/*******************************************************/
展開就是:#define U_BOOT_CMD(hello,1,0,do_hello,"usage:test\n","help:test\n")
cmd_tbl_t __u_boot_cmd_hello __attribute__((unused, section(".u_boot_cmd"), aligned(4)))
= {hello, 1, 0, do_hello, "usage:test\n","help:test\n" }
這兒定義了屬性,就是所有的命令都存儲在.u_boot_cmd節中,可以在連接腳本找到這個節。
最後更新:2017-04-03 12:53:54