CMD配置位于config_cmd_default.h configs/at91/sam9g10ek.h
头文件位于include/command.h
41 struct cmd_tbl_s {
42 char *name; /* Command Name */
43 int maxargs; /* maximum number of arguments */
44 int repeatable; /* autorepeat allowed? */
45 /* Implementation function */
46 int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
47 char *usage; /* Usage message (short) */
48 #ifdef CFG_LONGHELP
49 char *help; /* Help message (long) */
50 #endif
51 #ifdef CONFIG_AUTO_COMPLETE
52 /* do auto completion on the arguments */
53 int (*complete)(int argc, char *argv[], char last_char, int maxv, ch ar *cmdv[]);
54 #endif
55 };
56
57 typedef struct cmd_tbl_s cmd_tbl_t;
71 /*
72 * Monitor Command
73 *
74 * All commands use a common argument format:
75 *
76 * void function (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
77 */
78
79 typedef void command_t (cmd_tbl_t *, int, int, char *[]);
89 #define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))
91 #ifdef CFG_LONGHELP
92
93 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)
94 cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
95
96 #else /* no long help info */
97
98 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)
99 cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}
100
101 #endif /* CFG_LONGHELP */
以最简单的命令ersion为例介绍:
位于lib_arm/board.c
75 const char version_string[] =
76 U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;
common/command.c
31 int
32 do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
33 {
34 extern char version_string[];
35 printf ("
%s
", version_string);
36 return 0;
37 }
38
39 U_BOOT_CMD(
40 version, 1, 1, do_version,
41 "version - print monitor version
",
42 NULL
43 );
44