学习韦东山uboot之uboot命令

uboot的命令分析
在控制台可以看出,在每一行都会有一个前缀,这个是在readline函数的参数传入宏
CFG_PROMPT,查看这个宏可以知道,100ask的uboot会用“OpenJTAG>”来做前缀
读取一行之后,就运行run_command
run_command里会分析输入的命令,然后利用find_cmd来查找命令,最后运行
这个命令的回调函数。
看代码时首先看数据结构,以下是命令列表的结构
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
};
typedef struct cmd_tbl_s    cmd_tbl_t;

结构体很简单,就不做介绍了
不过,可以依据这个结构体,来构造一个自己的命令看看
在定义CMD时,我们需要把命令存在u_boot_cmd段里,在运行find_cmd的时候,实际上就是
遍历u_boot_cmd这个段
搜索bootm时,可以看出命令的代码一般存在common文件夹里,随便看一个例如bootm
可以看出,利用U_BOOT_CMD这个宏来实现把bootm放在u_boot_cmd的段里
U_BOOT_CMD(
     bootm,    CFG_MAXARGS,    1,    do_bootm,
     "bootm   - boot application image from memory\n",
     "[addr [arg ...]]\n    - boot application image stored in memory\n"
     "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
     "\t'arg' can be the address of an initrd image\n"
#ifdef CONFIG_OF_FLAT_TREE
    "\tWhen booting a Linux kernel which requires a flat device-tree\n"
    "\ta third argument is required which is the address of the of the\n"
    "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
    "\tuse a '-' for the second argument. If you do not pass a third\n"
    "\ta bd_info struct will be passed instead\n"
#endif
);

#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装入即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值