您的位置:首页 > 其它

uboot-命令实现分析

2015-04-10 01:20 344 查看

uboot 命令实现分析

uboot 命令实现分析
命令实现

命令执行过程

1. 命令实现

命令由宏 U_BOOT_CMD 定义,该宏具体为

#ifdef  CFG_LONGHELP

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}

#else   /* no long help info */

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

#endif


其中

1. 数据类型为 cmd_tbl_t,该结构体为

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
};


2. 宏Struct_Section的定义为


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


即申明该结构体放置在段 .u_boot_cmd 中

使用宏 U_BOOT_CMD 定义命令,则生成一个 _u_boot_cmd命令名称 的结构体,该结构体代码放置的 .u_boot_cmd 代码段,其中

参数意义
name命令名称
maxargs最多参数
repeatable是否可重复
cmd命令实现函数指针
usage使用方法
help帮助信息

2. 命令执行过程

调用函数 run_command 解析输入命令

调用函数 parse_line 分解输入命令

调用 find_cmd 寻找命令结构体

执行 cmd 命令
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uboot