U_BOOT_CMD 命令数据结构
2012-03-25 01:18
483 查看
U_BOOT_CMD 命令数据结构
2010年08月19日 星期四 18:33
2010年08月19日 星期四 18:33
The user interface to U-Boot consists of a command line interpreter (CLI), much like a Linux shell prompt. When connected via a serial line you can interactively enter commands and see the results. 在Uboot的doc目录下的README.commands文件说明如下: Commands are added to U-Boot by creating a new command structure. This is done by first including command.h Then using the U_BOOT_CMD() macro to fill in a cmd_tbl_t struct. U_BOOT_CMD(name,maxargs,repeatable,command,"usage","help") name: is the name of the commad. THIS IS NOT a string. maxargs: the maximumn numbers of arguments this function takes command: Function pointer (*cmd)(struct cmd_tbl_s *, int, int, char *[ ]); usage: Short description. This is a string help: long description. This is a string **** Behind the scene ****** The structure created is named with a special prefix (__u_boot_cmd_) and placed by the linker in a special section. This makes it possible for the final link to extract all commands compiled into any object code and construct a static array so the command can be found in an array starting at __u_boot_cmd_start. If a new board is defined do not forget to define the command section by writing in u-boot.lds ($(TOPDIR)/board/boardname/u-boot.lds) these 3 lines: __u_boot_cmd_start = .; .u_boot_cmd : { *(.u_boot_cmd) } __u_boot_cmd_end = .; U-boot的命令用struct cmd_tbl_t来实现。cmd_tbl_t的主要数据成分是命令名称(name)和命令处理函数(cmd),此外还包括最大参数个数(maxargs),是否可重复执行(repeatable),使用方法和帮助信息(usage,help)等。这个数据结构在文件include/command.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} 举例如下: bootm命令定义如下: U_BOOT_CMD( bootm, CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory\n", "[addr [arg ...]]\n - boot application image stored in memory\n" "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" "\t'arg' can be the address of an initrd image\n" ); 用宏定义替换后就是: cmd_tbl_t __u_boot_cmd_bootm __attribute__ ((unused,section (".u_boot_cmd")))= { bootm, CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory\n", "[addr [arg ...]]\n - boot application image stored in memory\n" "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" "\t'arg' can be the address of an initrd image\n" } 这样就为bootm命令定义了一个cmd_tbl_t 结构。 但__attribute__ ((unused,section (".u_boot_cmd")))又是实现什么功能呢?基于什么考虑呢? 它是用来定义用户的命令, 每当初始化这样的一条命令, 就将在.u_boot_cmd段中增加一段数据。以便于find_cmd函数查找命令。u-boot中的readme文件对这个功能是这样描述的: construct a static array so the command can be found in an array starting at __u_boot_cmd_start. |
相关文章推荐
- U_BOOT_CMD 命令数据结构
- uboot下用do_run()函数来执行U_BOOT_CMD定义的命令
- U_BOOT_CMD命令的实现
- U-boot 添加命令 U_BOOT_CMD
- U_BOOT_CMD命令的实现
- U_BOOT_CMD命令的实现
- U-boot 添加命令 U_BOOT_CMD
- u-boot中bootargs和bootcmd常用命令(下)
- U-boot 添加命令 U_BOOT_CMD
- U_BOOT_CMD 命令实现分析
- U_BOOT_CMD命令的实现
- U_BOOT_CMD命令的实现
- uboot 的命令定义注意点,u-boot, cfg_cmd,cmd_confdefs.h
- U-boot 添加命令 U_BOOT_CMD(修正版本)以全志a33平台为例子
- U-boot 添加命令 U_BOOT_CMD
- u-boot命令-cmd编译过程
- 在uboot中加入cmd_run命令,运行环境变量
- U_BOOT_CMD命令的实现
- U-boot 添加命令 U_BOOT_CMD
- uboot命令的U_BOOT_CMD