您的位置:首页 > 其它

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

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

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

如果是默认启动的话我们知道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;
}
这样工作就做完了,是不是很简单呢,这里只是把程序的重要部分列出了,详细的就看下完整的源码吧!也会很简单的

转载请注明出处:/article/8604669.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: