03-S3C2440u-boot学习之u-boot分析之u-boot命令实现

来源:互联网 发布:linux hadoop 下载 编辑:程序博客网 时间:2024/06/06 04:22

参考《韦东山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*/intmaxargs;/* maximum number of arguments*/intrepeatable;/* autorepeat allowed?*//* Implementation function*/int(*cmd)(struct cmd_tbl_s *, int, int, char *[]);char*usage;/* Usage message(short)*/#ifdefCFG_LONGHELPchar*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。









0 0
原创粉丝点击