spl: opensbi: wait for ack from secondary harts before entering OpenSBI
[platform/kernel/u-boot.git] / common / command.c
index 19f0534..ceca992 100644 (file)
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <command.h>
 #include <console.h>
+#include <env.h>
 #include <linux/ctype.h>
 
 /*
@@ -142,23 +143,38 @@ int cmd_usage(const cmd_tbl_t *cmdtp)
 }
 
 #ifdef CONFIG_AUTO_COMPLETE
+static char env_complete_buf[512];
 
 int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
 {
-       static char tmp_buf[512];
        int space;
 
        space = last_char == '\0' || isblank(last_char);
 
        if (space && argc == 1)
-               return env_complete("", maxv, cmdv, sizeof(tmp_buf), tmp_buf);
+               return env_complete("", maxv, cmdv, sizeof(env_complete_buf),
+                                   env_complete_buf, false);
 
        if (!space && argc == 2)
-               return env_complete(argv[1], maxv, cmdv, sizeof(tmp_buf), tmp_buf);
+               return env_complete(argv[1], maxv, cmdv,
+                                   sizeof(env_complete_buf),
+                                   env_complete_buf, false);
 
        return 0;
 }
 
+static int dollar_complete(int argc, char * const argv[], char last_char,
+                          int maxv, char *cmdv[])
+{
+       /* Make sure the last argument starts with a $. */
+       if (argc < 1 || argv[argc - 1][0] != '$' ||
+           last_char == '\0' || isblank(last_char))
+               return 0;
+
+       return env_complete(argv[argc - 1], maxv, cmdv, sizeof(env_complete_buf),
+                           env_complete_buf, true);
+}
+
 /*************************************************************************************/
 
 int complete_subcmdv(cmd_tbl_t *cmdtp, int count, int argc,
@@ -341,8 +357,13 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
        int i, j, k, len, seplen, argc;
        int cnt;
        char last_char;
+#ifdef CONFIG_CMDLINE_PS_SUPPORT
+       const char *ps_prompt = env_get("PS1");
+#else
+       const char *ps_prompt = CONFIG_SYS_PROMPT;
+#endif
 
-       if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
+       if (strcmp(prompt, ps_prompt) != 0)
                return 0;       /* not in normal console */
 
        cnt = strlen(buf);
@@ -357,9 +378,14 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
        /* separate into argv */
        argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv);
 
-       /* do the completion and return the possible completions */
-       i = complete_cmdv(argc, argv, last_char,
-                         sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+       /* first try a $ completion */
+       i = dollar_complete(argc, argv, last_char,
+                           sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+       if (!i) {
+               /* do the completion and return the possible completions */
+               i = complete_cmdv(argc, argv, last_char,
+                                 sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+       }
 
        /* no match; bell and out */
        if (i == 0) {
@@ -470,6 +496,11 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
        for (i = 0; i < size; i++) {
                ulong addr;
 
+               addr = (ulong)(cmdtp->cmd_rep) + gd->reloc_off;
+               cmdtp->cmd_rep =
+                       (int (*)(struct cmd_tbl_s *, int, int,
+                                char * const [], int *))addr;
+
                addr = (ulong)(cmdtp->cmd) + gd->reloc_off;
 #ifdef DEBUG_COMMANDS
                printf("Command \"%s\": 0x%08lx => 0x%08lx\n",
@@ -554,6 +585,20 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
        enum command_ret_t rc = CMD_RET_SUCCESS;
        cmd_tbl_t *cmdtp;
 
+#if defined(CONFIG_SYS_XTRACE)
+       char *xtrace;
+
+       xtrace = env_get("xtrace");
+       if (xtrace) {
+               puts("+");
+               for (int i = 0; i < argc; i++) {
+                       puts(" ");
+                       puts(argv[i]);
+               }
+               puts("\n");
+       }
+#endif
+
        /* Look up command in command table */
        cmdtp = find_cmd(argv[0]);
        if (cmdtp == NULL) {