exposing finding a command for subcommands
RFC 1/1 exposing finding a command for subcommands
How about something like this for exposing the command table code for subcommands. I'll follow this up with an example of usage based on the bootm subcommand patch
- k
A ---
common/command.c | 14 ++++++++++---- include/command.h | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-)
common/command.c +10 -4
@@ -341,10 +341,10 @@ cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {/*************************************************************************** * find command table entry for a command */ -cmd_tbl_t *find_cmd (const char *cmd) +cmd_tbl_t *__find_cmd (const char *cmd,cmd_tbl_t *table,int table_len) {cmd_tbl_t *cmdtp; -cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start;/*Init value */ +cmd_tbl_t *cmdtp_temp = table;/*Init value */ const char *p;int len;int n_found =0 ;
@@ -355,8 +355,8 @@ cmd_tbl_t *find_cmd (const char *cmd)*/ len = ((p =strchr (cmd,'.' )) ==NULL ) ?strlen (cmd) : (p - cmd); -for (cmdtp = &__u_boot_cmd_start; - cmdtp != &__u_boot_cmd_end; +for (cmdtp = table; + cmdtp != table + table_len; cmdtp++) {if (strncmp (cmd, cmdtp->name, len) ==0 ) {if (len ==strlen (cmdtp->name))
@@ -373,6 +373,12 @@ cmd_tbl_t *find_cmd (const char *cmd)return NULL ;/* not found or ambiguous command */ } +cmd_tbl_t *find_cmd (const char *cmd) +{ +int len = &__u_boot_cmd_end - &__u_boot_cmd_start; +return __find_cmd (cmd, &__u_boot_cmd_start, len); +} +#ifdef CONFIG_AUTO_COMPLETE int var_complete (int argc,char *argv[],char last_char,int maxv,char *cmdv[])
include/command.h +7 -0
@@ -62,6 +62,7 @@ extern cmd_tbl_t __u_boot_cmd_end;/* common/command.c */ cmd_tbl_t *find_cmd (const char *cmd); +cmd_tbl_t *__find_cmd (const char *cmd,cmd_tbl_t *table,int table_len);#ifdef CONFIG_AUTO_COMPLETE extern void install_auto_complete (void );
@@ -102,11 +103,17 @@ extern int cmd_get_data_size(char* arg, int default_size);#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} +#define U_BOOT_CMD_INIT (name,maxargs,rep,cmd,usage,help) \ +{#name, maxargs, rep, cmd, usage, help} +#else /* no long help info */ #define U_BOOT_CMD (name,maxargs,rep,cmd,usage,help) \ cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage} +#define U_BOOT_CMD_INIT (name,maxargs,rep,cmd,usage,help) \ +{#name, maxargs, rep, cmd, usage} +#endif /* CFG_LONGHELP */ #endif /* __COMMAND_H */
Signature · 1 line
1.5.5.1
RFC 1/1 exposing finding a command for subcommands
Here's an example of how we sould use this. Obviously the code after the if (cmd) would change.
- k
common/cmd_bootm.c +13 -0
@@ -377,10 +377,23 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)return 0 ; } +cmd_tbl_t cmd_bootm_sub[] = { +U_BOOT_CMD_INIT (start,CFG_MAXARGS ,1 ,BOOTM_STATE_START ,"" ,"" ), +U_BOOT_CMD_INIT (loados,CFG_MAXARGS ,1 ,BOOTM_STATE_LOADOS ,"" ,"" ), +U_BOOT_CMD_INIT (ramdisk,CFG_MAXARGS ,1 ,BOOTM_STATE_RAMDISK ,"" ,"" ), +}; + +int do_bootm_subcommand (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) {int ret =0 ;int state; +cmd_tbl_t *cmd; + + cmd =__find_cmd (argv[1 ], &cmd_bootm_sub[0 ],ARRAY_SIZE (cmd_bootm_sub)); + +if (cmd) +printf ("%s %d\n" , cmd->name, cmd->cmd);/* start */ if (strcmp (argv[1 ],"start" ) ==0 ) {
Dear Kumar Gala,
Quoted 3 lines · In message <[email protected]> you wrote:
How about something like this for exposing the command table code for subcommands. I'll follow this up with an example of usage based on the bootm subcommand patch
Looks good to me. Just a question:
common/command.c cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = { · line 344
Quoted 2 lines
common/command.c +1
-1-cmd_tbl_t *find_cmd (const char *cmd) +cmd_tbl_t *__find_cmd (const char *cmd,cmd_tbl_t *table,int table_len)
That means we would export __find_cmd() to other functions? We shouldn't do that - "__" names are reserved.
include/command.h extern int cmd_get_data_size(char* arg, int default_size); · line 108
Quoted 3 lines
include/command.h +3
-0+#define U_BOOT_CMD_INIT (name,maxargs,rep,cmd,usage,help) \ +{#name, maxargs, rep, cmd, usage, help} +
I think "INIT" is not a good name here. To me it sounds like a macro to use just once. How about "ENTRY" or "MKENT" or something like this?
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "Open the pod bay doors, HAL." - Dave Bowman, 2001