From 1e3465553be1cb7cb982b69658b70fe6e68e9fbd Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 1 Oct 2007 10:15:38 +0200 Subject: Add register_command() to register a command in runtime. This is only needed when modules are enabled, so the change is inside "#ifdef CONFIG_MODULE" --- common/command.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'common/command.c') diff --git a/common/command.c b/common/command.c index f86bf50d75..5d8577f9eb 100644 --- a/common/command.c +++ b/common/command.c @@ -198,6 +198,35 @@ U_BOOT_CMD_START(help) U_BOOT_CMD_HELP(cmd_help_help) U_BOOT_CMD_END +#ifdef CONFIG_MODULE +struct cmd_list { + cmd_tbl_t *cmd; + struct cmd_list *next; +}; + +static struct cmd_list *cmd_list; + +int register_command(cmd_tbl_t *cmd) +{ + struct cmd_list *c = cmd_list; + + debug("register command %s\n", cmd->name); + + if (!c) { + cmd_list = (struct cmd_list *)xzalloc(sizeof(struct cmd_list)); + cmd_list->cmd = cmd; + return 0; + } + + while (c->next) + c = c->next; + + c->next = (struct cmd_list *)xzalloc(sizeof(struct cmd_list)); + c->next->cmd = cmd; + + return 0; +} +#endif /*************************************************************************** * find command table entry for a command @@ -208,9 +237,25 @@ cmd_tbl_t *find_cmd (const char *cmd) cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */ int len; int n_found = 0; - +#ifdef CONFIG_MODULE + struct cmd_list *list = cmd_list; +#endif len = strlen (cmd); +#ifdef CONFIG_MODULE + while(list) { + cmdtp = list->cmd; + if (strncmp (cmd, cmdtp->name, len) == 0) { + if (len == strlen (cmdtp->name)) + return cmdtp; /* full match */ + + cmdtp_temp = cmdtp; /* abbreviated command ? */ + n_found++; + } + list = list->next; + } +#endif + for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { -- cgit v1.2.3