u-boot学习(四):u-boot常用命令以及uboot命令的添加

来源:互联网 发布:卖肉漫画软件 编辑:程序博客网 时间:2024/06/06 07:27

(一)u-boot常用命令

u-boot的主要目的是启动内核,在启动内核之前,我们一般使用u-boot的命令来下载内核到内存、擦除、读写Flash,运行内存、NOR Flash、NAND Flash中的程序,查看、修改、比较内存中的数据等

help命令可以查看u-boot支持的命令有哪些:

<span style="font-size:14px;">?       - alias for 'help' autoscr - run script from memory  base    - print or set address offsetbdinfo  - print Board Info structureboot    - boot default, i.e., run 'bootcmd'  bootd   - boot default, i.e., run 'bootcmd'  bootelf - Boot from an ELF image in memorybootm   - boot application image from memory  bootp   - boot image via network using BootP/TFTP protocolbootvx  - Boot vxWorks from an ELF imagechpart  - change active partitioncmp     - memory compareconinfo - print console devices and informationcp      - memory copycrc32   - checksum calculationdate    - get/set/reset date & timedcache  - enable or disable data cacheecho    - echo args to consoleerase   - erase FLASH memoryflinfo  - print FLASH memory informationfsinfo  - print information about filesystemsfsload  - load binary file from a filesystem imagego      - start application at address 'addr'help    - print online helpicache  - enable or disable instruction cacheiminfo  - print header information for application imageimls    - list all images found in flashitest   - return true/false on integer compareloadb   - load binary file over serial line (kermit mode)loads   - load S-Record file over serial lineloadx   - load binary file over serial line (xmodem mode)loady   - load binary file over serial line (ymodem mode)loop    - infinite loop on address rangels      - list files in a directory (default /)md      - memory displaymenu - display a menu, to select the items to do somethingmm      - memory modify (auto-incrementing)mtdparts- define flash/nand partitionsmtest   - simple RAM testmw      - memory write (fill)nand    - NAND sub-systemnboot   - boot from NAND devicenfs     - boot image via network using NFS protocolnm      - memory modify (constant address)ping    - send ICMP ECHO_REQUEST to network hostprintenv- print environment variablesprotect - enable or disable FLASH write protectionrarpboot- boot image via network using RARP/TFTP protocolreset   - Perform RESET of the CPUrun     - run commands in an environment variablesaveenv - save environment variables to persistent storagesetenv  - set environment variablessleep   - delay execution for some timetftpboot- boot image via network using TFTP protocolusbslave - get file from host(PC)version - print monitor version</span>

这些命令包括下载文件到内存,擦除、读写Flash,运行内存、NOR Flash、NAND Flash中的程序,查看、修改、比较内存中的数据等。使用各种命令时,可以使用其开头的若干个字母代替它。比如tftpboot命令,可以使用t、tf、tftp等字母代替,只要其他命令不以这些字母开头即可。

1、帮助命令help

2、下载命令,u-boot支持串口下载、网络下载,相关命令有loadb、loads、loadx、loady和tftpboot、nfs。前几个支持串口下载。tftpboot命令使用TFTP协议从服务器下载文件,服务器IP地址为环境变量serverip。nfs命令使用NFS协议下载文件。

3、内存操作命令。常用的命令有:查看内存命令md、修改内存命令mm、填充内存命令mw、复制命令cp

4、NOR Flash操作命令。常用的命令有查看Flash信息的finfo命令、加/解写保护命令protect、擦除命令erase。由于NOR Flash的接口与一般内存相似,所以一些内存命令可以在NOR Flash上使用,比如mm、cp命令。

5、NAND Flash操作命令只有一个:nand,它根据不同的参数进行不同操作,比如擦除、读取、烧写等

6、环境变量命令:printenv、setenv等

7、启动命令:不带参数的boot、bootm命令都是执行环境变量bootcmd所指定的命令。

u-boot命令使用实例:制作内核映像文件(使用mkimage)、烧写内核映像文件uImage、烧写yaffs文件系统映像、烧写jffs2文件系统映像、执行程序(go)等,这些都会在以后构建嵌入式系统时用到。

(二)u-boot命令的添加

u-boot中每个命令都通过U_BOOT_CMD宏来定义,其格式如下:

<span style="font-size:14px;">#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}</span>
各项参数意义如下:

1、name:命令的名字,注意,它不是一个字符串(不要使用双引号括起来)。

2、maxargs:最大的参数个数。

3、repeatable:命令是否可重复,可重复是指运行一个命令后,下次敲回车即可再次运行。

4、command:对应的函数指针,类型为(*cmd)(struct cmd_tbl_s*, int, int, char *[])。

5、usage:简短的使用说明,这是个字符串。

6、help:较详细的使用说明,这是个字符串。

<span style="font-size:14px;">Struct_Section结构定义如下:</span>
<span style="font-size:14px;">#define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))</span>
对于每个使用U_BOOT_CMD宏来定义的命令,其实都是在“.u_boot_cmd”段中定义一个cmd_tbl_t结构。链接脚本u-boot.lds中有如下代码:

<span style="font-size:14px;">. = .;__u_boot_cmd_start = .;.u_boot_cmd : { *(.u_boot_cmd) }__u_boot_cmd_end = .;</span>
程序中就是根据命令的名字在内存段__u_boot_cmd_start~__u_boot_cmd_end找到它的cmd_tbl_t结构,然后调用它的函数。

因此添加u-boot命令就可以分为两步:添加实现命令的文件、修改Makefile。以clear命令为例。

1、在common目录下添加cmd_clear.c文件,其内容如下:

<span style="font-size:14px;">#include <common.h>#include <command.h>#include <net.h>voiddo_clear (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){printf("clear the screen.\n");printf("%c", '\f');}U_BOOT_CMD(clear, 1, 1, do_clear,"clear the uart com screen", "");</span>
2、修改common目录下的Makefile文件,在COBJS变量最后添加cmd_clear.o。

3、重新配置编译u-boot,将生成的u-boot.bin文件烧写到开发板上,即可使用clear命令。

相应的,可以添加任意的想要添加的命令。


参考:韦东山 《嵌入式Linux应用开发完全手册》
http://blog.csdn.net/linucos/article/details/5259061   



0 0
原创粉丝点击