cmd_tbl_t *find_cmd (const char *cmd)

/***************************************************************************
* find command table entry for a command
*/
cmd_tbl_t *find_cmd (const char *cmd)
{
cmd_tbl_t *cmdtp;
cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
const char *p;
int len;
int n_found = 0;

/*
* Some commands allow length modifiers (like "cp.b");
* compare command name only until first dot. //只比较'.'之前的字符串
*/
len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);

//搜索命令列表,如果完全匹配,返回cmd_tbl_t指针
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++;
   }
}
if (n_found == 1) {    /* exactly one match */
   return cmdtp_temp;
}

return NULL; /* not found or ambiguous command */
}

上面用到的&__u_boot_cmd_start和&__u_boot_cmd_end是命令列表的起始地址和结束地址。在链接脚本board/u-boot.lds中有定义:
.u_boot_cmd : {
   __u_boot_cmd_start = .;
   *(.u_boot_cmd)
   __u_boot_cmd_end = .;
}

命令列表到底是如何实现的呢?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值