u-boot命令-cmd编译过程

来源:互联网 发布:法兰克福和慕尼黑 知乎 编辑:程序博客网 时间:2024/06/05 10:31

cmd_sf.c

  • 命令 sf
//cmd_sf.cU_BOOT_CMD(    sf,     5,      1,      do_spi_flash,    "SPI flash sub-system",    "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n"    "                 and chip select\n"    "sf read addr offset len    - read `len' bytes starting at\n"    "                 `offset' to memory at `addr'\n"    "sf write addr offset len   - write `len' bytes from memory\n"    "                 at `addr' to flash at `offset'\n"    "sf erase offset len        - erase `len' bytes from `offset'");#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}//展开之后cmd_tbl_t  __u_boot_cmd_sf  __attribute__ ((unused,section(".u_boot_cmd")))= {    "sf",     5,     1,     do_spi_flash,     "SPI flash sub-system",    "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n"    "                 and chip select\n"    "sf read addr offset len    - read `len' bytes starting at\n"    "                 `offset' to memory at `addr'\n"    "sf write addr offset len   - write `len' bytes from memory\n"    "                 at `addr' to flash at `offset'\n"    "sf erase offset len        - erase `len' bytes from `offset'" };

u-boot.lds

  • gcc 编译的时候指定 u-boot.lds
//u-boot.lds __u_boot_cmd_start = .; .u_boot_cmd : { *(.u_boot_cmd) } __u_boot_cmd_end = .;

编译后的结果

//u-boot.map                0x4084ef28                __u_boot_cmd_start = . .u_boot_cmd    0x4084ef28      0x420 *(.u_boot_cmd) .u_boot_cmd    0x4084ef28       0x30 common/libcommon.a(cmd_boot.o)                0x4084ef28                __u_boot_cmd_reset                0x4084ef40                __u_boot_cmd_go .u_boot_cmd    0x4084ef58       0x18 common/libcommon.a(cmd_bootm.o)                0x4084ef58                __u_boot_cmd_bootm .u_boot_cmd    0x4084ef70       0x18 common/libcommon.a(cmd_ddr_training_v2.o)                0x4084ef70                __u_boot_cmd_ddr .u_boot_cmd    0x4084ef88       0x18 common/libcommon.a(cmd_dec.o)                0x4084ef88                __u_boot_cmd_decjpg                  ... .u_boot_cmd    0x4084f288       0x18 common/libcommon.a(cmd_version.o)                0x4084f288                __u_boot_cmd_version .u_boot_cmd    0x4084f2a0       0xa8 common/libcommon.a(cmd_vo_hi3531a.o)                0x4084f2a0                __u_boot_cmd_setvobg                0x4084f2b8                __u_boot_cmd_stopvl                0x4084f2d0                __u_boot_cmd_startvl                0x4084f2e8                __u_boot_cmd_stopgx                0x4084f300                __u_boot_cmd_startgx                0x4084f318                __u_boot_cmd_stopvo                0x4084f330                __u_boot_cmd_startvo                0x4084f348                __u_boot_cmd_end = .                0x4084f348                . = ALIGN (0x4)//可见,这是  .u_boot_cmd 段, 第四列都是符号,表示这个标号占据了一段存储,并且从某个地址开始.   
//这样一来,凡通过U_BOOT_CMD定义的cmd_tbl_t变量会全部被放在.u_boot_cmd段当中(可以看UBOOT的链接脚本xxx.lds),具体怎么放是链接器的工作,可以从u-boot.map中看到.//__u_boot_cmd_sf 在u-boot.map 中存在//Uboot中所有变量都是存放在 段 .u_boot_cmd 中的//当用户输入一个命令时(需要与定义时的name变量同名),会在函数 find_cmd 中从__u_boot_cmd_start开始循环匹配,匹配到后就执行对应变量中的cmd项;如果直到__u_boot_cmd_end也没有发现,则匹配失败。//例如:用户输入bootm,会找到__u_boot_cmd_bootm这个变量,然后会取出cmd命令(这里注册的是do_bootm)来执行。
原创粉丝点击