command.h
/*
- Monitor Command Table
*/
struct cmd_tbl_s {
char name; / Command Name //命令名/
int maxargs; / maximum number of arguments //命令的最大参数个数/
int repeatable; / autorepeat allowed? //是否自动重复/
/ Implementation function */
int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);/命令执行函数/
char usage; / Usage message (short) */ /简单的使用说明/
#ifdef CFG_LONGHELP
char help; / Help message (long) / /详细使用说明/
#endif
#ifdef CONFIG_AUTO_COMPLETE /自动补全参数/
/ do auto completion on the arguments */
int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};
在文件include/command.h中定义了结构体cmd_tbl_s,各成员含义如上面注释。U-boot的每一条命令都将封装成结构体cmd_tbl_s存到链接文件中指定的.u_boot_cmd区。当向u-boot中添加命令时都将调用宏U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)来初始化一个cmd_tbl_s 结构体。
run_command就是运行命令的函数,该函数在文件common/main.c中实现
/* OK - call function to do the command */命令函数执行
if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
rc = -1;
}