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整合Redis注解实现增删改查功能(Redis注解使用)

《SpringBoot整合Redis注解实现增删改查功能(Redis注解使用)》文章介绍了如何使用SpringBoot整合Redis注解实现增删改查功能,包括配置、实体类、Repository、Se... 目录配置Redis连接定义实体类创建Repository接口增删改查操作示例插入数据查询数据删除数据更

Linux join命令的使用及说明

《Linuxjoin命令的使用及说明》`join`命令用于在Linux中按字段将两个文件进行连接,类似于SQL的JOIN,它需要两个文件按用于匹配的字段排序,并且第一个文件的换行符必须是LF,`jo... 目录一. 基本语法二. 数据准备三. 指定文件的连接key四.-a输出指定文件的所有行五.-o指定输出

Java中Redisson 的原理深度解析

《Java中Redisson的原理深度解析》Redisson是一个高性能的Redis客户端,它通过将Redis数据结构映射为Java对象和分布式对象,实现了在Java应用中方便地使用Redis,本文... 目录前言一、核心设计理念二、核心架构与通信层1. 基于 Netty 的异步非阻塞通信2. 编解码器三、

Linux jq命令的使用解读

《Linuxjq命令的使用解读》jq是一个强大的命令行工具,用于处理JSON数据,它可以用来查看、过滤、修改、格式化JSON数据,通过使用各种选项和过滤器,可以实现复杂的JSON处理任务... 目录一. 简介二. 选项2.1.2.2-c2.3-r2.4-R三. 字段提取3.1 普通字段3.2 数组字段四.

Linux kill正在执行的后台任务 kill进程组使用详解

《Linuxkill正在执行的后台任务kill进程组使用详解》文章介绍了两个脚本的功能和区别,以及执行这些脚本时遇到的进程管理问题,通过查看进程树、使用`kill`命令和`lsof`命令,分析了子... 目录零. 用到的命令一. 待执行的脚本二. 执行含子进程的脚本,并kill2.1 进程查看2.2 遇到的

Java HashMap的底层实现原理深度解析

《JavaHashMap的底层实现原理深度解析》HashMap基于数组+链表+红黑树结构,通过哈希算法和扩容机制优化性能,负载因子与树化阈值平衡效率,是Java开发必备的高效数据结构,本文给大家介绍... 目录一、概述:HashMap的宏观结构二、核心数据结构解析1. 数组(桶数组)2. 链表节点(Node

Java 虚拟线程的创建与使用深度解析

《Java虚拟线程的创建与使用深度解析》虚拟线程是Java19中以预览特性形式引入,Java21起正式发布的轻量级线程,本文给大家介绍Java虚拟线程的创建与使用,感兴趣的朋友一起看看吧... 目录一、虚拟线程简介1.1 什么是虚拟线程?1.2 为什么需要虚拟线程?二、虚拟线程与平台线程对比代码对比示例:三

一文解析C#中的StringSplitOptions枚举

《一文解析C#中的StringSplitOptions枚举》StringSplitOptions是C#中的一个枚举类型,用于控制string.Split()方法分割字符串时的行为,核心作用是处理分割后... 目录C#的StringSplitOptions枚举1.StringSplitOptions枚举的常用

Python函数作用域与闭包举例深度解析

《Python函数作用域与闭包举例深度解析》Python函数的作用域规则和闭包是编程中的关键概念,它们决定了变量的访问和生命周期,:本文主要介绍Python函数作用域与闭包的相关资料,文中通过代码... 目录1. 基础作用域访问示例1:访问全局变量示例2:访问外层函数变量2. 闭包基础示例3:简单闭包示例4

MyBatis延迟加载与多级缓存全解析

《MyBatis延迟加载与多级缓存全解析》文章介绍MyBatis的延迟加载与多级缓存机制,延迟加载按需加载关联数据提升性能,一级缓存会话级默认开启,二级缓存工厂级支持跨会话共享,增删改操作会清空对应缓... 目录MyBATis延迟加载策略一对多示例一对多示例MyBatis框架的缓存一级缓存二级缓存MyBat