OK6410A 开发板 (三) 11 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 命令的执行

本文主要是介绍OK6410A 开发板 (三) 11 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 命令的执行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.命令的注册
2.命令的调用
3.命令的执行
4.命令的返回
  • 1 命令的注册(以help为例)
cmd/help.c10 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. bootcmd2. cmdline所有的命令的调用都是  cmd_call 调用的 // cmd_call  不直接调用 do_xxx以help 为例 , do_help的调用堆栈为 
cmd_callcmd_always_repeatable // 以该 字符串为关键字 在  全文搜索do_helpcommon/command.c 564-585
564 /**                                                                              
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. 正确为02. 错误为非0

这篇关于OK6410A 开发板 (三) 11 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 命令的执行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1007933

相关文章

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

在MySQL执行UPDATE语句时遇到的错误1175的解决方案

《在MySQL执行UPDATE语句时遇到的错误1175的解决方案》MySQL安全更新模式(SafeUpdateMode)限制了UPDATE和DELETE操作,要求使用WHERE子句时必须基于主键或索引... mysql 中遇到的 Error Code: 1175 是由于启用了 安全更新模式(Safe Upd

docker如何删除悬空镜像

《docker如何删除悬空镜像》文章介绍了如何使用Docker命令删除悬空镜像,以提高服务器空间利用率,通过使用dockerimage命令结合filter和awk工具,可以过滤出没有Tag的镜像,并将... 目录docChina编程ker删除悬空镜像前言悬空镜像docker官方提供的方式自定义方式总结docker

Spring Boot整合log4j2日志配置的详细教程

《SpringBoot整合log4j2日志配置的详细教程》:本文主要介绍SpringBoot项目中整合Log4j2日志框架的步骤和配置,包括常用日志框架的比较、配置参数介绍、Log4j2配置详解... 目录前言一、常用日志框架二、配置参数介绍1. 日志级别2. 输出形式3. 日志格式3.1 PatternL

如何使用Spring boot的@Transactional进行事务管理

《如何使用Springboot的@Transactional进行事务管理》这篇文章介绍了SpringBoot中使用@Transactional注解进行声明式事务管理的详细信息,包括基本用法、核心配置... 目录一、前置条件二、基本用法1. 在方法上添加注解2. 在类上添加注解三、核心配置参数1. 传播行为(

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

Spring Boot Actuator使用说明

《SpringBootActuator使用说明》SpringBootActuator是一个用于监控和管理SpringBoot应用程序的强大工具,通过引入依赖并配置,可以启用默认的监控接口,... 目录项目里引入下面这个依赖使用场景总结说明:本文介绍Spring Boot Actuator的使用,关于Spri

MySQL 缓存机制与架构解析(最新推荐)

《MySQL缓存机制与架构解析(最新推荐)》本文详细介绍了MySQL的缓存机制和整体架构,包括一级缓存(InnoDBBufferPool)和二级缓存(QueryCache),文章还探讨了SQL... 目录一、mysql缓存机制概述二、MySQL整体架构三、SQL查询执行全流程四、MySQL 8.0为何移除查

在Rust中要用Struct和Enum组织数据的原因解析

《在Rust中要用Struct和Enum组织数据的原因解析》在Rust中,Struct和Enum是组织数据的核心工具,Struct用于将相关字段封装为单一实体,便于管理和扩展,Enum用于明确定义所有... 目录为什么在Rust中要用Struct和Enum组织数据?一、使用struct组织数据:将相关字段绑