博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OK6410A 开发板 (三) 11 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 命令的执行
阅读量:4286 次
发布时间:2019-05-27

本文共 6060 字,大约阅读时间需要 20 分钟。

1.命令的注册2.命令的调用3.命令的执行4.命令的返回
  • 1 命令的注册(以help为例)
cmd/help.c 10 static int do_help(struct cmd_tbl *cmdtp, int flag, int argc,                     11            char *const argv[])                                                    12 {
13 #ifdef CONFIG_CMDLINE 14 struct cmd_tbl *start = ll_entry_start(struct cmd_tbl, cmd); 15 const int len = ll_entry_count(struct cmd_tbl, cmd); 16 return _do_help(start, len, cmdtp, flag, argc, argv); 17 #else 18 return 0; 19 #endif 20 } 21 22 U_BOOT_CMD( 23 help, CONFIG_SYS_MAXARGS, 1, do_help, 24 "print command description/usage", 25 "\n" 26 " - print brief description of all commands\n" 27 "help command ...\n" 28 " - print detailed usage of 'command'" 29 ); ----------------------- 以上的代码展开为以下代码----------------------- 具体怎么注册以及怎么查找的请参考 __attribute__----------------------- __attribute__ demo : https://github.com/lisider/attribute_samplestatic int do_help(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]){
struct cmd_tbl *start = ({
static char start[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_1"))); (struct cmd_tbl *)&start; }); const int len = ({
struct cmd_tbl *start = ({
static char start[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_1"))); (struct cmd_tbl *)&start; }); struct cmd_tbl *end = ({
static char end[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_3"))); (struct cmd_tbl *)&end; }); unsigned int _ll_result = end - start; _ll_result; }); return _do_help(start, len, cmdtp, flag, argc, argv);}struct cmd_tbl _u_boot_list_2_cmd_2_help __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_2_""help"))) = {
"help", 16, 1 ? cmd_always_repeatable : cmd_never_repeatable, do_help, "print command description/usage", "\n" " - print brief description of all commands\n" "help command ...\n" " - print detailed usage of 'command'", # 22 "../cmd/help.c" 3 4((void *)0)# 22 "../cmd/help.c", };
  • 2 命令的调用
cmd_call  被调用的时机	1. bootcmd	2. cmdline所有的命令的调用都是  cmd_call 调用的 // cmd_call  不直接调用 do_xxx以help 为例 , do_help的调用堆栈为 cmd_call	cmd_always_repeatable // 以该 字符串为关键字 在  全文搜索		do_helpcommon/command.c 564-585564 /**                                                                              565  * Call a command function. This should be the only route in U-Boot to call      566  * a command, so that we can track whether we are waiting for input or           567  * executing a command.                                                          568  *                                                                               569  * @param cmdtp     Pointer to the command to execute                            570  * @param flag      Some flags normally 0 (see CMD_FLAG_.. above)                571  * @param argc      Number of arguments (arg 0 must be the command text)         572  * @param argv      Arguments                                                    573  * @param repeatable    Can the command be repeated                              574  * @return 0 if command succeeded, else non-zero (CMD_RET_...)                   575  */                                                                              576 static int cmd_call(struct cmd_tbl *cmdtp, int flag, int argc,                   577             char *const argv[], int *repeatable)                                 578 {
579 int result; 580 581 result = cmdtp->cmd_rep(cmdtp, flag, argc, argv, repeatable); 582 if (result) 583 debug("Command failed, result=%d\n", result); 584 return result; 585 }
  • 3 命令的执行(以help为例)
cmd/help.c// 想怎么写,就怎么写 10 static int do_help(struct cmd_tbl *cmdtp, int flag, int argc,                     11            char *const argv[])                                                    12 {
13 #ifdef CONFIG_CMDLINE 14 struct cmd_tbl *start = ll_entry_start(struct cmd_tbl, cmd); 15 const int len = ll_entry_count(struct cmd_tbl, cmd); 16 return _do_help(start, len, cmdtp, flag, argc, argv); 17 #else 18 return 0; 19 #endif 20 }
  • 4 命令的返回
返回时也是 cmd_call 检查的命令的返回值	1. 正确为0	2. 错误为非0

转载地址:http://nbigi.baihongyu.com/

你可能感兴趣的文章
《图像处理实例》 之 拟合求交点
查看>>
《图像处理实例》 之 填充封闭区域
查看>>
《图像处理实例》 之 疏密程度统计
查看>>
支持向量机(理论+opencv实现)
查看>>
K-means算法(理论+opencv实现)
查看>>
高斯混合模型(理论+opencv实现)
查看>>
VS2015+Python3.5的配置
查看>>
分水岭算法(理论+opencv实现)
查看>>
《图像处理实例》 之 精确寻找一个圆
查看>>
opencv3.1+contrib的配置大总结(配置了两天,遇到问题无数)
查看>>
opencv小问题大智慧
查看>>
《图像处理实例》 之 车牌定位
查看>>
《opencv学习》 之 OTSU算法实现二值化
查看>>
《图像处理实例》 之 答题卡检测
查看>>
图像矩的初步探索(第十一天)
查看>>
《电路学习第一天》 之 电路设计之前的准备
查看>>
《电路学习第三天》 之 线性稳压电源的设计
查看>>
《图像处理实例》 之 目标旋转矫正(基于区域提取、DFT变换)
查看>>
不规则ROI的提取
查看>>
《图像处理实例》 之 提取特殊背景的直线
查看>>