uboot源码阅读(六)大佬的命令 uboot引导内核启动

大佬的命令下来了,不过并不是每个人都有资格去执行这样的命令,有资格的都是经过层层选拔了的。在江湖中你也是要不断努力拼搏的,否则,小弟永远都是小弟。

下面就是解析输入的字符串,然后在命令列表中找到相对应的命令。

如果是默认启动的话我们知道cmd字符串为:nand read.i c0008000 80000 500000;bootm c0008000

这里有两行命令,把flash上的数据读到ram中,最终调用bootm实现内核的启动。bootm是如何完成内核启动的后面还会有介绍。

int run_command (const char *cmd, int flag)
{
	while (*str) {

		/*
		 * Find separator, or string end
		 * Allow simple escape of ';' by writing "\;"
		 */
		for (inquotes = 0, sep = str; *sep; sep++) {//解析出一行命令,在这里有两行命令
			if ((*sep=='\'') &&
			    (*(sep-1) != '\\'))
				inquotes=!inquotes;

			if (!inquotes &&
			    (*sep == ';') &&	/* separator		*/
			    ( sep != str) &&	/* past string start	*/
			    (*(sep-1) != '\\'))	/* and NOT escaped	*/
				break;
		}

		/* find macros in this token and replace them */
		process_macros (token, finaltoken);//宏的处理,好像自己没在命令里面用到过宏

		/* Extract arguments */
		if ((argc = parse_line (finaltoken, argv)) == 0) { //把命令里面的字符串都解析出来,放入到argv里面
			rc = -1;	/* no command at all */
			continue;
		}

		/* Look up command in command table */
		if ((cmdtp = find_cmd(argv[0])) == NULL) {//把命令列表里面的命令进行前n个字符比较,如果只有一个匹配,就代表找到了
			printf ("Unknown command '%s' - try 'help'\n", argv[0]);
			rc = -1;	/* give up after bad command */
			continue;
		}

		/* found - check max args */
		if (argc > cmdtp->maxargs) { //命令找到了,但是输入的参数太多了,无法执行
			printf ("Usage:\n%s\n", cmdtp->usage);
			rc = -1;
			continue;
		}

		/* OK - call function to do the command */
		if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) { //条件都全了,那就执行命令吧!
			rc = -1;
		}
	}

	return rc ? rc : repeatable;
}
这样工作就做完了,是不是很简单呢,这里只是把程序的重要部分列出了,详细的就看下完整的源码吧!也会很简单的
转载请注明出处: http://blog.csdn.net/ecbtnrt/article/details/6630190
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值