image: fix compiling without CMD_FDT
[oweals/u-boot.git] / common / command.c
index 972ae281c23215dc41170f819a796a4a97f1a420..2433a89e0a8e10f3098eb453e25db33f574436f5 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000-2009
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -11,6 +10,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <console.h>
 #include <linux/ctype.h>
 
 /*
@@ -84,6 +84,7 @@ int _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t *cmdtp, int flag,
 /* 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;
@@ -110,6 +111,7 @@ cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len)
        if (n_found == 1) {                     /* exactly one match */
                return cmdtp_temp;
        }
+#endif /* CONFIG_CMDLINE */
 
        return NULL;    /* not found or ambiguous command */
 }
@@ -161,6 +163,7 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
 
 static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
 {
+#ifdef CONFIG_CMDLINE
        cmd_tbl_t *cmdtp = ll_entry_start(cmd_tbl_t, cmd);
        const int count = ll_entry_count(cmd_tbl_t, cmd);
        const cmd_tbl_t *cmdend = cmdtp + count;
@@ -230,6 +233,9 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
 
        cmdv[n_found] = NULL;
        return n_found;
+#else
+       return 0;
+#endif
 }
 
 static int make_argv(char *s, int argvsz, char *argv[])
@@ -311,7 +317,7 @@ static int find_common_prefix(char * const argv[])
        return len;
 }
 
-static char tmp_buf[CONFIG_SYS_CBSIZE];        /* copy of console I/O buffer   */
+static char tmp_buf[CONFIG_SYS_CBSIZE + 1];    /* copy of console I/O buffer */
 
 int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
 {
@@ -541,10 +547,13 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
 
 int cmd_process_error(cmd_tbl_t *cmdtp, int err)
 {
+       if (err == CMD_RET_USAGE)
+               return CMD_RET_USAGE;
+
        if (err) {
                printf("Command '%s' failed: Error %d\n", cmdtp->name, err);
-               return 1;
+               return CMD_RET_FAILURE;
        }
 
-       return 0;
+       return CMD_RET_SUCCESS;
 }