平台: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
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節中,可以在連接配接腳本找到這個節。