-#define CMD_TBL_HELP MK_CMD_TBL_ENTRY( \
- "help", 1, CFG_MAXARGS, 1, do_help, \
- "help - print online help\n", \
- "[command ...]\n" \
- " - show help information (for 'command')\n" \
- "'help' prints online help for the monitor commands.\n\n" \
- "Without arguments, it prints a short usage message for all commands.\n\n" \
- "To get detailed help information for specific commands you can type\n" \
- "'help' with one or more command names as arguments.\n" \
- ),
-
-#define CMD_TBL_QUES MK_CMD_TBL_ENTRY( \
- "?", 1, CFG_MAXARGS, 1, do_help, \
- "? - alias for 'help'\n", \
- NULL \
- ),
-
-#define CMD_TBL_VERS MK_CMD_TBL_ENTRY( \
- "version", 4, 1, 1, do_version, \
- "version - print monitor version\n", \
- NULL \
- ),
-
-#define CMD_TBL_ECHO MK_CMD_TBL_ENTRY( \
- "echo", 4, CFG_MAXARGS, 1, do_echo, \
- "echo - echo args to console\n", \
- "[args..]\n" \
- " - echo args to console; \\c suppresses newline\n" \
- ),
-
-int
-do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+
+int _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
+{
+ int i;
+ int rcode = 0;
+
+ if (argc == 1) { /* show list of commands */
+ cmd_tbl_t *cmd_array[cmd_items];
+ int i, j, swaps;
+
+ /* Make array of commands from .uboot_cmd section */
+ cmdtp = cmd_start;
+ for (i = 0; i < cmd_items; i++) {
+ cmd_array[i] = cmdtp++;
+ }
+
+ /* Sort command list (trivial bubble sort) */
+ for (i = cmd_items - 1; i > 0; --i) {
+ swaps = 0;
+ for (j = 0; j < i; ++j) {
+ if (strcmp(cmd_array[j]->name,
+ cmd_array[j + 1]->name) > 0) {
+ cmd_tbl_t *tmp;
+ tmp = cmd_array[j];
+ cmd_array[j] = cmd_array[j + 1];
+ cmd_array[j + 1] = tmp;
+ ++swaps;
+ }
+ }
+ if (!swaps)
+ break;
+ }
+
+ /* print short help (usage) */
+ for (i = 0; i < cmd_items; i++) {
+ const char *usage = cmd_array[i]->usage;
+
+ /* allow user abort */
+ if (ctrlc())
+ return 1;
+ if (usage == NULL)
+ continue;
+ printf("%-*s- %s\n", CONFIG_SYS_HELP_CMD_WIDTH,
+ cmd_array[i]->name, usage);
+ }
+ return 0;
+ }
+ /*
+ * command help (long version)
+ */
+ for (i = 1; i < argc; ++i) {
+ cmdtp = find_cmd_tbl(argv[i], cmd_start, cmd_items);
+ if (cmdtp != NULL) {
+ rcode |= cmd_usage(cmdtp);
+ } else {
+ printf("Unknown command '%s' - try 'help' without arguments for list of all known commands\n\n",
+ argv[i]);
+ rcode = 1;
+ }
+ }
+ return rcode;
+}
+
+/* find command table entry for a command */
+cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len)
+{
+#ifdef CONFIG_CMDLINE
+ cmd_tbl_t *cmdtp;
+ cmd_tbl_t *cmdtp_temp = table; /* Init value */
+ const char *p;
+ int len;
+ int n_found = 0;
+
+ if (!cmd)
+ return NULL;
+ /*
+ * Some commands allow length modifiers (like "cp.b");
+ * compare command name only until first dot.
+ */
+ len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
+
+ for (cmdtp = table; cmdtp != table + table_len; cmdtp++) {
+ if (strncmp(cmd, cmdtp->name, len) == 0) {
+ if (len == strlen(cmdtp->name))
+ return cmdtp; /* full match */
+
+ cmdtp_temp = cmdtp; /* abbreviated command ? */
+ n_found++;
+ }
+ }
+ if (n_found == 1) { /* exactly one match */
+ return cmdtp_temp;
+ }
+#endif /* CONFIG_CMDLINE */
+
+ return NULL; /* not found or ambiguous command */
+}
+
+cmd_tbl_t *find_cmd(const char *cmd)
+{
+ cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
+ const int len = ll_entry_count(cmd_tbl_t, cmd);
+ return find_cmd_tbl(cmd, start, len);
+}
+
+int cmd_usage(const cmd_tbl_t *cmdtp)
+{
+ printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
+
+#ifdef CONFIG_SYS_LONGHELP
+ printf("Usage:\n%s ", cmdtp->name);
+
+ if (!cmdtp->help) {
+ puts ("- No additional help available.\n");
+ return 1;
+ }
+
+ puts(cmdtp->help);
+ putc('\n');
+#endif /* CONFIG_SYS_LONGHELP */
+ return 1;
+}
+
+#ifdef CONFIG_AUTO_COMPLETE
+
+int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])