[U-Boot] [PATCH 03/14] move CLI prototypes to cli.h and add comments

Simon Glass sjg at chromium.org
Fri Apr 11 04:01:25 CEST 2014


Move the CLI prototypes from common.h to cli.h as part of an effort to
reduce the size of common.h.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 board/ait/cam_enc_4xx/cam_enc_4xx.c |   1 +
 board/amcc/yucca/cmd_yucca.c        |   1 +
 board/eltec/elppc/misc.c            |   1 +
 board/eltec/mhpc/mhpc.c             |   1 +
 board/hymod/hymod.c                 |   1 +
 board/hymod/input.c                 |   1 +
 common/cli_hush.c                   |   1 +
 common/cmd_bedbug.c                 |   1 +
 common/cmd_dcr.c                    |   1 +
 common/cmd_i2c.c                    |   1 +
 common/cmd_mem.c                    |   1 +
 common/cmd_nvedit.c                 |   1 +
 common/cmd_pci.c                    |   1 +
 common/main.c                       |   1 +
 common/menu.c                       |   1 +
 drivers/ddr/fsl/interactive.c       |   1 +
 include/cli.h                       | 102 ++++++++++++++++++++++++++++++++++++
 include/common.h                    |   4 --
 18 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 include/cli.h

diff --git a/board/ait/cam_enc_4xx/cam_enc_4xx.c b/board/ait/cam_enc_4xx/cam_enc_4xx.c
index b5cc3ed..7c26ba0 100644
--- a/board/ait/cam_enc_4xx/cam_enc_4xx.c
+++ b/board/ait/cam_enc_4xx/cam_enc_4xx.c
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <errno.h>
 #include <linux/mtd/nand.h>
 #include <nand.h>
diff --git a/board/amcc/yucca/cmd_yucca.c b/board/amcc/yucca/cmd_yucca.c
index dc78b73..3257c29 100644
--- a/board/amcc/yucca/cmd_yucca.c
+++ b/board/amcc/yucca/cmd_yucca.c
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include "yucca.h"
 #include <i2c.h>
diff --git a/board/eltec/elppc/misc.c b/board/eltec/elppc/misc.c
index d80eaba..70d1f9a 100644
--- a/board/eltec/elppc/misc.c
+++ b/board/eltec/elppc/misc.c
@@ -7,6 +7,7 @@
 
 /* includes */
 #include <common.h>
+#include <cli.h>
 #include <linux/ctype.h>
 #include <pci.h>
 #include <net.h>
diff --git a/board/eltec/mhpc/mhpc.c b/board/eltec/mhpc/mhpc.c
index f3f564f..ff9e0ab 100644
--- a/board/eltec/mhpc/mhpc.c
+++ b/board/eltec/mhpc/mhpc.c
@@ -14,6 +14,7 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <cli.h>
 #include <linux/ctype.h>
 #include <commproc.h>
 #include "mpc8xx.h"
diff --git a/board/hymod/hymod.c b/board/hymod/hymod.c
index 5fec914..ea49e26 100644
--- a/board/hymod/hymod.c
+++ b/board/hymod/hymod.c
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <mpc8260.h>
 #include <mpc8260_irq.h>
 #include <ioports.h>
diff --git a/board/hymod/input.c b/board/hymod/input.c
index 184902c..23d3f19 100644
--- a/board/hymod/input.c
+++ b/board/hymod/input.c
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 
 int
 hymod_get_serno (const char *prompt)
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 070519f..48cec88 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -79,6 +79,7 @@
 #include <malloc.h>         /* malloc, free, realloc*/
 #include <linux/ctype.h>    /* isalpha, isdigit */
 #include <common.h>        /* readline */
+#include <cli.h>
 #include <cli_hush.h>
 #include <command.h>        /* find_cmd */
 #ifndef CONFIG_SYS_PROMPT_HUSH_PS2
diff --git a/common/cmd_bedbug.c b/common/cmd_bedbug.c
index 77b6e3e..f1a70ef 100644
--- a/common/cmd_bedbug.c
+++ b/common/cmd_bedbug.c
@@ -3,6 +3,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <linux/ctype.h>
 #include <net.h>
diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c
index 896f79f..c5bcb8b 100644
--- a/common/cmd_dcr.c
+++ b/common/cmd_dcr.c
@@ -10,6 +10,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <config.h>
 #include <command.h>
 
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index ebce7d4..8ccde68 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -66,6 +66,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <edid.h>
 #include <environment.h>
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 5b03c2d..4b8738b 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #ifdef CONFIG_HAS_DATAFLASH
 #include <dataflash.h>
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index c53601c..99a21b2 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -25,6 +25,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <environment.h>
 #include <search.h>
diff --git a/common/cmd_pci.c b/common/cmd_pci.c
index d3e7c08..ddda207 100644
--- a/common/cmd_pci.c
+++ b/common/cmd_pci.c
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <asm/processor.h>
 #include <asm/io.h>
diff --git a/common/main.c b/common/main.c
index 2eea9c5..815759a 100644
--- a/common/main.c
+++ b/common/main.c
@@ -12,6 +12,7 @@
 /* #define	DEBUG	*/
 
 #include <common.h>
+#include <cli.h>
 #include <command.h>
 #include <fdtdec.h>
 #include <cli_hush.h>
diff --git a/common/menu.c b/common/menu.c
index ba393ad..88d4697 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <malloc.h>
 #include <errno.h>
 #include <linux/list.h>
diff --git a/drivers/ddr/fsl/interactive.c b/drivers/ddr/fsl/interactive.c
index ebf3ed6..3b311b1 100644
--- a/drivers/ddr/fsl/interactive.c
+++ b/drivers/ddr/fsl/interactive.c
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <cli.h>
 #include <linux/ctype.h>
 #include <asm/types.h>
 #include <asm/io.h>
diff --git a/include/cli.h b/include/cli.h
new file mode 100644
index 0000000..0075bd4
--- /dev/null
+++ b/include/cli.h
@@ -0,0 +1,102 @@
+/*
+ * (C) Copyright 2014 Google, Inc
+ * Simon Glass <sjg at chromium.org>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __CLI_H
+#define __CLI_H
+
+/**
+ * Go into the command loop
+ *
+ * This will return if we get a timeout waiting for a command. See
+ * CONFIG_BOOT_RETRY_TIME.
+ */
+void cli_loop(void);
+
+/**
+ * cli_simple_run_command() - Execute a command with the simple CLI
+ *
+ * @cmd:	String containing the command to execute
+ * @flag	Flag value - see CMD_FLAG_...
+ * @return 1  - command executed, repeatable
+ *	0  - command executed but not repeatable, interrupted commands are
+ *	     always considered not repeatable
+ *	-1 - not executed (unrecognized, bootd recursion or too many args)
+ *           (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
+ *           considered unrecognized)
+ */
+int cli_simple_run_command(const char *cmd, int flag);
+
+/**
+ * cli_simple_run_command_list() - Execute a list of command
+ *
+ * The commands should be separated by ; or \n and will be executed
+ * by the built-in parser.
+ *
+ * This function cannot take a const char * for the command, since if it
+ * finds newlines in the string, it replaces them with \0.
+ *
+ * @param cmd	String containing list of commands
+ * @param flag	Execution flags (CMD_FLAG_...)
+ * @return 0 on success, or != 0 on error.
+ */
+int cli_simple_run_command_list(char *cmd, int flag);
+
+/**
+ * cli_readline() - read a line into the console_buffer
+ *
+ * This is a convenience function which calls cli_readline_into_buffer().
+ *
+ * @prompt: Prompt to display
+ * @return command line length excluding terminator, or -ve on error
+ */
+int readline(const char *const prompt);
+
+/**
+ * readline_into_buffer() - read a line into a buffer
+ *
+ * Display the prompt, then read a command line into @buffer. The
+ * maximum line length is CONFIG_SYS_CBSIZE including a \0 terminator, which
+ * will always be added.
+ *
+ * The command is echoed as it is typed. Command editing is supported if
+ * CONFIG_CMDLINE_EDITING is defined. Tab auto-complete is supported if
+ * CONFIG_AUTO_COMPLETE is defined. If CONFIG_BOOT_RETRY_TIME is defined,
+ * then a timeout will be applied.
+ *
+ * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
+ * time out when time goes past endtime (timebase time in ticks).
+ *
+ * @prompt:	Prompt to display
+ * @buffer:	Place to put the line that is entered
+ * @timeout:	Timeout in milliseconds, 0 if none
+ * @return command line length excluding terminator, or -ve on error: of the
+ * timeout is exceeded (either CONFIG_BOOT_RETRY_TIME or the timeout
+ * parameter), then -2 is returned. If a break is detected (Ctrl-C) then
+ * -1 is returned.
+ */
+int readline_into_buffer(const char *const prompt, char *buffer, int timeout);
+
+/**
+ * parse_line() - split a command line down into separate arguments
+ *
+ * The argv[] array is filled with pointers into @line, and each argument
+ * is terminated by \0 (i.e. @line is changed in the process unless there
+ * is only one argument).
+ *
+ * #argv is terminated by a NULL after the last argument pointer.
+ *
+ * At most CONFIG_SYS_MAXARGS arguments are permited - if there are more
+ * than that then an error is printed, and this function returns
+ * CONFIG_SYS_MAXARGS, with argv[] set up to that point.
+ *
+ * @line:	Command line to parse
+ * @args:	Array to hold arguments
+ * @return number of arguments
+ */
+int parse_line(char *line, char *argv[]);
+
+#endif
diff --git a/include/common.h b/include/common.h
index cbd3c9e..abe57c6 100644
--- a/include/common.h
+++ b/include/common.h
@@ -286,10 +286,6 @@ int run_command(const char *cmd, int flag);
  * @return 0 on success, or != 0 on error.
  */
 int run_command_list(const char *cmd, int len, int flag);
-int	readline	(const char *const prompt);
-int	readline_into_buffer(const char *const prompt, char *buffer,
-			int timeout);
-int	parse_line (char *, char *[]);
 void	init_cmd_timeout(void);
 void	reset_cmd_timeout(void);
 extern char console_buffer[];
-- 
1.9.1.423.g4596e3a



More information about the U-Boot mailing list