u-boot之命令分析(6)

u-boot之命令分析:
分析run_command
run_command
process_macros (token, finaltoken);  /*处理宏*/
/*解析传进来的命令和参数,并将他们提取出来*/
if ((argc = parse_line (finaltoken, argv)) == 0) {
rc = -1; /* no command at all */
continue;
}
/* Look up command in command table */
/*根据命令名到结构体段中查找,如果匹配,就把这个结构体取出来*/
cmdtp = find_cmd(argv[0])
for (cmdtp = &__u_boot_cmd_start;cmdtp != &__u_boot_cmd_end;cmdtp++)
{
if (strncmp (cmd, cmdtp->name, len) == 0) {
if (len == strlen (cmdtp->name))                     
return cmdtp; /* full match */
cmdtp_temp = cmdtp;/* abbreviated command ? */
n_found++;
}
}
分析cmd_tbl_t *cmdtp;
cmd_tbl_t结构体定义:
搜索.u_boot_cmd
在include/command中发现如下两个宏:
#define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))


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






对于do_bootm命令来说:
它如下定义:
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_bootm  __attribute__ ((unused,section (".u_boot_cmd"))) = {bootm, CFG_MAXARGS, 1, do_bootm, 短说明, 长说明}


说明:定义了一个cmd_tbl_t结构体,这个结构体被强制的安放在.u_boot_cmd这个段。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奔跑吧撸码兄弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值