u-boot命令寻找分析--find_cmd函数
生活随笔
收集整理的這篇文章主要介紹了
u-boot命令寻找分析--find_cmd函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/********************************************************************************/
u-boot命令尋找分析
/**************************************************************************** find command table entry for a command*/
cmd_tbl_t *find_cmd (const char *cmd)
{cmd_tbl_t *cmdtp;cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */const char *p;int len;int n_found = 0;/** Some commands allow length modifiers (like "cp.b");* compare command name only until first dot.*/len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);for (cmdtp = &__u_boot_cmd_start;cmdtp != &__u_boot_cmd_end;cmdtp++) {if (strncmp (cmd, cmdtp->name, len) == 0) {if (len == strlen (cmdtp->name))return cmdtp; /* full match */cmdtp_temp = cmdtp; /* abbreviated command ? */n_found++;}}if (n_found == 1) { /* exactly one match */return cmdtp_temp;}return NULL; /* not found or ambiguous command */
}for (cmdtp = &__u_boot_cmd_start;cmdtp != &__u_boot_cmd_end;cmdtp++)u-boot.lds的鏈接腳本之中也能傳遞變量
SECTIONS
{. = 0x00000000;. = ALIGN(4);.text :{cpu/arm920t/start.o (.text)board/100ask24x0/boot_init.o (.text)*(.text)}. = ALIGN(4);.rodata : { *(.rodata) }. = ALIGN(4);.data : { *(.data) }. = ALIGN(4);.got : { *(.got) }. = .;__u_boot_cmd_start = .;.u_boot_cmd : { *(.u_boot_cmd) }__u_boot_cmd_end = .;. = ALIGN(4);__bss_start = .;.bss : { *(.bss) }_end = .;
}#define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))#ifdef CFG_LONGHELP#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}#else /* no long help info */rep命令代表的是命令是否可重復
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage} nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
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"
#ifdef CONFIG_OF_FLAT_TREE"\tWhen booting a Linux kernel which requires a flat device-tree\n""\ta third argument is required which is the address of the of the\n""\tdevice-tree blob. To boot that kernel without an initrd image,\n""\tuse a '-' for the second argument. If you do not pass a third\n""\ta bd_info struct will be passed instead\n"
#endif
);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"}
在宏定義中 #是轉化為字符串的意思
下面這句的意思是設置該結構體段屬性為.u_boot_cmd
cmd_tbl_t __u_boot_cmd_bootm __attribute__ ((unused,section (".u_boot_cmd")))
因此只要是定義為 U_BOOT_CMD 類型的結構體都將被強制轉化為 段的屬性為 .u_boot_cmd 該屬性在鏈接腳本中定義了
因此在find_cmd中能夠使用
for (cmdtp = &__u_boot_cmd_start;cmdtp != &__u_boot_cmd_end;cmdtp++)
按照結構體的形式將命令挨個找出來
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的u-boot命令寻找分析--find_cmd函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 作者:周一懋(1982-),男,江苏汇誉
- 下一篇: 作者:熊赟,复旦大学计算机科学技术学院副