关键词:
目录
title: u-boot(四)命令实现
tags: linux
date: 2018-09-25 23:13:05
---
u-boot(四)命令实现
命令是如何实现的?
- 输入命令
- 执行函数,根据命令去寻找函数
所以会有一个命令的结构体[name,fun]
分析run_command
函数原型如下 int run_command (const char *cmd, int flag)
处理
, 空格,;
等解析参数
parse_line (finaltoken, argv)
example: md.w 0 ------>argv[0]= "md.w", argv[1]=" 0" ?``` /* Extract arguments */ if ((argc = parse_line (finaltoken, argv)) == 0) rc = -1; /* no command at all */ continue; ?```
命令搜索
if ((cmdtp = find_cmd(argv[0])) == NULL)
,可以发现结构体struct cmd_tbl_s char *name; /* Command Name */ int maxargs; /* maximum number of arguments */ int repeatable; /* autorepeat allowed? */ /* Implementation function */ int (*cmd)(struct cmd_tbl_s *, int, int, char *[]); char *usage; /* Usage message (short) */ #ifdef CFG_LONGHELP char *help; /* Help message (long) */ #endif #ifdef CONFIG_AUTO_COMPLETE /* do auto completion on the arguments */ int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]); #endif ;
- repeatable 可重复,指的是直接按回车是否继续执行上次命令
- usage,短的help,指的是直接输入help查看的所有命令显示的帮助
- help,具体的help,指的是help cmd 查看的具体的信息
查看函数,可以发现是在
__u_boot_cmd_start
和__u_boot_cmd_end
中遍历,这个地址是在链接脚本中定义的,也就是命令这个东西,有一个特殊的属性,定位到某个地址.. = .; __u_boot_cmd_start = .; .u_boot_cmd : *(.u_boot_cmd) __u_boot_cmd_end = .;
搜索这个段属性
.u_boot_cmd
,在includecommand.h
有这么一个宏#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
再搜索下这个宏
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) cmd_tbl_t __u_boot_cmd_##name Struct_Section = #name, maxargs, rep, cmd, usage, help
再搜索一下这个
U_BOOT_CMD
,可以发现其实就是命令了,搜索下命令bootm
,在commoncmd_bootm.c
中U_BOOT_CMD( bootm, CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory ",//注意,下面的几个是没有逗号,是整体 "[addr [arg ...]] - boot application image stored in memory " " passing arguments ‘arg ...‘; when booting a Linux kernel, " " ‘arg‘ can be the address of an initrd image " );
尝试着展开这个宏,可以发现就是定义了一个段属性特殊的结构体,也就是命令结构体
cmd_tbl_t __u_boot_cmd_bootm Struct_Section= "bootm", CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory ", //下面的字符串是一个整体 "[addr [arg ...]] - boot application image stored in memory " " passing arguments ‘arg ...‘; when booting a Linux kernel, " " ‘arg‘ can be the address of an initrd image "
小结
U-boot 的命令是用结构体存储的,这些结构体是用特殊的段属性集合到一块区域里面去,分散在各个文件中
命令解析的时候是去这个段去搜索的,这个段属性的地址是从
__u_boot_cmd_start
到__u_boot_cmd_end
,在链接脚本中定义的.命令结构体
struct cmd_tbl_s ;
自定义一个命令
参考common/cmd_bootm.c
的头文件,编写源代码cmd_hello.c
代码
#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <asm/byteorder.h>
int do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int i ;
printf ("hello world %d
,", argc);
//打印下参数
for(i=0;i<argc;i++)
printf ("argv[%d] is %s
",i,argv[i]);
return 0;
U_BOOT_CMD(
hello, CFG_MAXARGS, 1, do_hello,
"this is short help for hello just test
",
"this is long help for hello just test
"
);
makefile
修改common
的makefile
,只需要在COBJS上加上cmd_hello.o
u-boot命令篇|usb与scsi命令实现擦除操作(代码片段)
U-Boot中自带的usb与scsi命令并没有擦除操作,但可通过usb与scsi命令实现以写代擦:mw.l0x400000000xffffffff0x8000usbwrite0x4000000000x8000mw.l0x400000000xffffffff0x8000scsiwrite0x4000000000x8000 查看详情
u-boot命令之信息查询命令(代码片段)
参考:U-Boot命令之信息查询命令作者:一只青木呀发布时间:2020-10-2011:21:16网址:https://blog.csdn.net/weixin_45309916/article/details/109177359目录U-Boot信息查询命令bdinfo命令printenv命令version命令进入uboot的命令行模式以后输 查看详情
u-boot命令之内存操作命令(代码片段)
参考:U-Boot命令之内存操作命令作者:一只青木呀发布时间:2020-10-2012:20:19网址:https://blog.csdn.net/weixin_45309916/article/details/109178410目录内存操作命令1、md命令2、nm命令3、mm命令4、mw命令5、cp命令6、cmp命令内存操作... 查看详情
u-boot命令之网络操作命令(代码片段)
参考:U-Boot命令之网络操作命令作者:一只青木呀发布时间:2020-10-2012:57:59网址:https://blog.csdn.net/weixin_45309916/article/details/109178659目录网络操作命令1、ping命令2、dhcp命令3、nfs命令4、tftp命令网络操作命令uboot是支... 查看详情
u-boot分析与使用(代码片段)
文章目录一、u-boot介绍二、u-boot源码结构三、u-boot打补丁、编译、烧写四、uboot功能、结构,结合Makefile进行分析五、u-boot分析之源码阶段六、u-boot分析之命令实现七、uboot启动内核一、u-boot介绍u-boot即通用的BootLoader,是... 查看详情
u-boot命令之nandboot操作命令(代码片段)
参考:U-Boot命令之BOOT操作命令作者:一只青木呀发布时间:2020-10-2021:26:57网址:https://blog.csdn.net/weixin_45309916/article/details/109185897目录NAND操作命令1、nandinfo命令2、nanddevice命令3、nanderase命令4、nand 查看详情
u-boot常用命令(resetgorunmtest)(代码片段)
参考:U-Boot命令之常用命令作者:一只青木呀发布时间:2020-10-2022:16:23网址:https://blog.csdn.net/weixin_45309916/article/details/109190028目录1、reset命令2、go命令3、run命令4、mtest命令uboot中还有其他一些常用的命令,比 查看详情
u-boot启动文件(代码片段)
目录u-boot(三)启动文件汇编C:_start_armboot代码摘要C:main_loop内核启动菜单处理(自定义实现)命令处理title:u-boot(三)启动文件tags:linuxdate:2018-09-2420:56:05---u-boot(三)启动文件汇编cpu/arm920t/start.Su-boot也是一个牛逼的单片机程序,所以也... 查看详情
u-boot命令之环境变量操作命令(代码片段)
参考:U-Boot命令之环境变量操作命令作者:一只青木呀发布时间:2020-10-2011:55:00网址:https://blog.csdn.net/weixin_45309916/article/details/109177707目录1、修改环境变量2、新建环境变量3、删除环境变量1、修改环境变量环境变... 查看详情
u-boot常用命令(代码片段)
u-boot常用命令查看u-boot所支持的命令查询命令u-boot版本环境变量板子相关信息环境变量操作内存操作网络操作EMMC和SD卡操作FAT格式文件系统操作EXT格式文件系统操作ubi格式文件系统操作boot操作bootzbootmbootUMS命令常用其他uboot环境... 查看详情
u-boot命令之(fat格式ext格式)文件系统操作命令(代码片段)
参考:U-Boot命令之FAT格式文件系统操作命令作者:一只青木呀发布时间:2020-10-2017:42:33网址:https://blog.csdn.net/weixin_45309916/article/details/109185273参考:U-Boot命令之EXT格式文件系统操作命令作者:一只青木呀发... 查看详情
u-boot命令之mmc(emmc和sd卡)操作命令(代码片段)
参考:U-Boot命令之EMMC和SD卡操作命令作者:一只青木呀发布时间:2020-10-2015:02:16网址:https://blog.csdn.net/weixin_45309916/article/details/109178989目录EMMC和SD卡操作命令1、mmcinfo命令2、mmcrescan命令3、mmclist命令4、 查看详情
u-boot命令篇|通用串行总线命令usb(代码片段)
UBOOT中一般USB的配置:#defineCONFIG_USB_OHCI#defineCONFIG_USB_STORAGE#defineCONFIG_CMD_USB#defineCONFIG_CMD_FAT#defineCONFIG_DOS_PARTITION#defineCONFIG_SUPPORT_VFAT UBOOT进入命令行输入help可以看到有很多内置的命令, 查看详情
u-boot学习
uboot源码下载: 所有版本的u-boot源代码压缩包都可以在ftp://ftp.denx.de/pub/u-boot/下载关于u-boot源代码的信息 http://www.denx.de/wiki/U-Boot/SourceCode获得U-Boot的最新版本 https://sourceforge.net/projects/uboot或者使用git拉取远程uboot仓库gi... 查看详情
u-boot的启动信息和命令使用(代码片段)
内容来自《【正点原子】I.MX6U嵌入式Linux驱动开发指南V1.5.2.pdf》,有删减。启动信息1U-Boot2016.03-gd3f0479(Aug072020-20:47:37+0800)23CPU:Freescalei.MX6ULLrev1.1792MHz(runningat396MHz)4CPU:Industrialtemperaturegrade(-40Cto 查看详情
u-boot-2014.10移植添加mtdparts命令和分区(代码片段)
添加mtdparts命令,改命令可以查看当前分区,在启动参数里面可以以分区名代表地址和长度grep"cmd_mtdpart"*-nR 搜索可知,mtdpart在cmd_mtdparts.c里面定义 common/Makefile:147:obj-$(CONFIG_CMD_MTDPARTS)+=cmd_mtdparts.o因此需要定义CONFI... 查看详情
u-boot命令篇|ext格式文件系统操作命令(代码片段)
uboot有ext2和ext4这两种格式的文件系统的操作命令,常用的就四个命令,分别是:ext2load、ext2ls、ext4load、ext4ls和ext4write。这些命令的含义和使用与fatload、fatls和fatwrite一样,只是ext2和ext4都是针对ext文件系统的... 查看详情
在u-boot中让lcd填充纯色(代码片段)
1.编译U-boot 准备好U-boot压缩包urbetter-u-boot-1.1.6-v1.0.tgz,输入命令:tar-xvf urbetter-u-boot-1.1.6-v1.0.tgz 进入U-boot目录,按顺序执行以下命令: makeclean makesmdk6410_config make 会报出很多/usr/local/arm/arm-none-linux-gnueabi... 查看详情