亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1098 | 回復(fù): 0
打印 上一主題 下一主題

U_BOOT_CMD 命令數(shù)據(jù)結(jié)構(gòu) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-12-21 08:41 |只看該作者 |倒序瀏覽

原文地址:http://hi.baidu.com/designhouse/blog/item/5d930df3ca2a85c60b46e0ef.html

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來實現(xiàn)。cmd_tbl_t的主要數(shù)據(jù)成分是命令名稱(name)和命令處理函數(shù)(cmd),此外還包括最大參數(shù)個數(shù)(maxargs),是否可重復(fù)執(zhí)行(repeatable),使用方法和幫助信息(usage,help)等。這個數(shù)據(jù)結(jié)構(gòu)在文件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 結(jié)構(gòu)。

但__attribute__ ((unused,section (".u_boot_cmd")))又是實現(xiàn)什么功能呢?基于什么考慮呢?
它是用來定義用戶的命令, 每當(dāng)初始化這樣的一條命令, 就將在.u_boot_cmd段中增加一段數(shù)據(jù)。以便于find_cmd函數(shù)查找命令。u-boot中的readme文件對這個功能是這樣描述的: construct a static array so the command can be found in an array starting at __u_boot_cmd_start.


您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP