您的位置:首页 > 其它

04-S3C2440u-boot学习之u-boot分析(4)之u-boot命令实现

2017-02-09 21:25 381 查看
参考《韦东山1期视频》第09课第4节
u-boot分析之u-boot命令实现.WMV


1解析命令:如存在;

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;
}
2提取命令参数

/* Extract arguments */
if ((argc = parse_line (finaltoken, argv)) == 0) {
rc = -1;	/* no command at all */
continue;
}
/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0])) == NULL) {
printf ("Unknown command '%s' - try 'help'\n", argv[0]);
rc = -1;	/* give up after bad command */
continue;
}
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
};


3增加一个hello命令

参考bootm,在common下创建hello_cmd.c

实现do_hello方法和U_BOOT_CMD

拷贝c文件到common目录下



修改common下的makefile文件:

增加cmd_hello.o



重新make。

执行hello。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: