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

相关文章

Spring Boot集成/输出/日志级别控制/持久化开发实践

《SpringBoot集成/输出/日志级别控制/持久化开发实践》SpringBoot默认集成Logback,支持灵活日志级别配置(INFO/DEBUG等),输出包含时间戳、级别、类名等信息,并可通过... 目录一、日志概述1.1、Spring Boot日志简介1.2、日志框架与默认配置1.3、日志的核心作用

破茧 JDBC:MyBatis 在 Spring Boot 中的轻量实践指南

《破茧JDBC:MyBatis在SpringBoot中的轻量实践指南》MyBatis是持久层框架,简化JDBC开发,通过接口+XML/注解实现数据访问,动态代理生成实现类,支持增删改查及参数... 目录一、什么是 MyBATis二、 MyBatis 入门2.1、创建项目2.2、配置数据库连接字符串2.3、入

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

Apache Ignite 与 Spring Boot 集成详细指南

《ApacheIgnite与SpringBoot集成详细指南》ApacheIgnite官方指南详解如何通过SpringBootStarter扩展实现自动配置,支持厚/轻客户端模式,简化Ign... 目录 一、背景:为什么需要这个集成? 二、两种集成方式(对应两种客户端模型) 三、方式一:自动配置 Thick

Linux如何查看文件权限的命令

《Linux如何查看文件权限的命令》Linux中使用ls-R命令递归查看指定目录及子目录下所有文件和文件夹的权限信息,以列表形式展示权限位、所有者、组等详细内容... 目录linux China编程查看文件权限命令输出结果示例这里是查看tomcat文件夹总结Linux 查看文件权限命令ls -l 文件或文件夹

全面解析Golang 中的 Gorilla CORS 中间件正确用法

《全面解析Golang中的GorillaCORS中间件正确用法》Golang中使用gorilla/mux路由器配合rs/cors中间件库可以优雅地解决这个问题,然而,很多人刚开始使用时会遇到配... 目录如何让 golang 中的 Gorilla CORS 中间件正确工作一、基础依赖二、错误用法(很多人一开

idea的终端(Terminal)cmd的命令换成linux的命令详解

《idea的终端(Terminal)cmd的命令换成linux的命令详解》本文介绍IDEA配置Git的步骤:安装Git、修改终端设置并重启IDEA,强调顺序,作为个人经验分享,希望提供参考并支持脚本之... 目录一编程、设置前二、前置条件三、android设置四、设置后总结一、php设置前二、前置条件

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一

解密SQL查询语句执行的过程

《解密SQL查询语句执行的过程》文章讲解了SQL语句的执行流程,涵盖解析、优化、执行三个核心阶段,并介绍执行计划查看方法EXPLAIN,同时提出性能优化技巧如合理使用索引、避免SELECT*、JOIN... 目录1. SQL语句的基本结构2. SQL语句的执行过程3. SQL语句的执行计划4. 常见的性能优

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499