summaryrefslogtreecommitdiffstats
path: root/common/command.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-10-01 10:15:38 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2007-10-01 10:15:38 +0200
commit1e3465553be1cb7cb982b69658b70fe6e68e9fbd (patch)
tree1ced9ac47790b1752bdae75d34693ad01be2e19c /common/command.c
parentc41b41f9e778e48f3afe7956870c7c7f1e10d006 (diff)
downloadbarebox-1e3465553be1cb7cb982b69658b70fe6e68e9fbd.tar.gz
barebox-1e3465553be1cb7cb982b69658b70fe6e68e9fbd.tar.xz
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"
Diffstat (limited to 'common/command.c')
-rw-r--r--common/command.c47
1 files changed, 46 insertions, 1 deletions
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++) {