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 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

Java Spring ApplicationEvent 代码示例解析

《JavaSpringApplicationEvent代码示例解析》本文解析了Spring事件机制,涵盖核心概念(发布-订阅/观察者模式)、代码实现(事件定义、发布、监听)及高级应用(异步处理、... 目录一、Spring 事件机制核心概念1. 事件驱动架构模型2. 核心组件二、代码示例解析1. 事件定义

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

Python包管理工具核心指令uvx举例详细解析

《Python包管理工具核心指令uvx举例详细解析》:本文主要介绍Python包管理工具核心指令uvx的相关资料,uvx是uv工具链中用于临时运行Python命令行工具的高效执行器,依托Rust实... 目录一、uvx 的定位与核心功能二、uvx 的典型应用场景三、uvx 与传统工具对比四、uvx 的技术实

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.