1.
U_BOOT_CMD(
mtdparts, 6, 0, do_jffs2_mtdparts,
"mtdparts- define flash/nand partitions\n",
"\n"
);
cmd_tbl_t __u_boot_cmd_mtdparts Struct_Section = {mtdparts, 6, 0, do_jffs2_mtdparts, usage, help};
以下从doc/README.command 翻译
要想在u-boot中添加命令,必须新建一个command structure。要想创建一个command structure,则首先包含 "command.h" 头文件,然后用U_BOOT_CMD宏填充 cmd_tbl_t struct。
经过宏展开后新创建的这个结构体的名字会__u_boot_cmd开头,然后连接器会把这个结构体连接到指定的section上。
这样link才能从代码中提取所有的命令,生成一个静态的array。这样就可以通过遍历一个以__u_boot_cmd_starty开头的数组找到所要的命令。
1.
struct cmd_tbl_s {
char *name; /* Command Name */
int maxargs; /* maximum number of arguments */
int repeatable; /* autorepeat allowed? */
/* Implementation function */
int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
char *usage; /* Usage message (short) */
char *help; /* Help message (long) */
#ifdef CONFIG_AUTO_COMPLETE
/* do auto completion on the arguments */
int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};
#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}
typedef struct cmd_tbl_s cmd_tbl_t;
extern cmd_tbl_t __u_boot_cmd_start;
extern cmd_tbl_t __u_boot_cmd_end;
这里要看的是##name和#name这两个操作.##name将字符直接跟在后面, #name会将name这个字符中以"..."的形式放置。
1.
U_BOOT_CMD(
tftpboot, 3, 1, do_tftpb,
"tftpboot- boot image via network using TFTP protocol\n",
"[loadAddress] [bootfilename]\n"
);
usage= "tftpboot- boot image via network using TFTP protocol\n";
help= "[loadAddress] [bootfilename]\n";
cmd_tbl_t __u_boot_cmd_tftpboot __attribute__ ((unused,section (".u_boot_cmd"))) = {"tftpboot", 3, 1, do_tftpb, "tftpboot- boot image via network using TFTP protocol\n",
"[loadAddress] [bootfilename]\n"};
int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
return netboot_common (TFTP, cmdtp, argc, argv);
}