From 18d66533ac773f59efc93e5c19971fad5e6af82f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:25 -0600 Subject: move CLI prototypes to cli.h and add comments 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 --- include/cli.h | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 include/cli.h (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h new file mode 100644 index 0000000000..0075bd44c9 --- /dev/null +++ b/include/cli.h @@ -0,0 +1,102 @@ +/* + * (C) Copyright 2014 Google, Inc + * Simon Glass + * + * 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 -- cgit From 6493ccc7cf2357081267effffa7d345e50d68d00 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:26 -0600 Subject: Split out simple parser and readline into separate files It doesn't make sense to have the simple parser and the readline code all in main. Split them out into separate files. Signed-off-by: Simon Glass --- include/cli.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h index 0075bd44c9..b04539f320 100644 --- a/include/cli.h +++ b/include/cli.h @@ -99,4 +99,9 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout); */ int parse_line(char *line, char *argv[]); +/** bootretry_dont_retry() - Indicate that we should not retry the boot */ +void bootretry_dont_retry(void); + +#define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) + #endif -- cgit From e1bf824dfd6881f6f633238c275bfa1e5d83c433 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:27 -0600 Subject: Add cli_ prefix to readline functions This makes it clear where the code resides. Signed-off-by: Simon Glass --- include/cli.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h index b04539f320..61f8aee4ad 100644 --- a/include/cli.h +++ b/include/cli.h @@ -53,7 +53,7 @@ int cli_simple_run_command_list(char *cmd, int flag); * @prompt: Prompt to display * @return command line length excluding terminator, or -ve on error */ -int readline(const char *const prompt); +int cli_readline(const char *const prompt); /** * readline_into_buffer() - read a line into a buffer @@ -78,7 +78,8 @@ int readline(const char *const prompt); * 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); +int cli_readline_into_buffer(const char *const prompt, char *buffer, + int timeout); /** * parse_line() - split a command line down into separate arguments @@ -97,7 +98,7 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout); * @args: Array to hold arguments * @return number of arguments */ -int parse_line(char *line, char *argv[]); +int cli_simple_parse_line(char *line, char *argv[]); /** bootretry_dont_retry() - Indicate that we should not retry the boot */ void bootretry_dont_retry(void); -- cgit From b26440f1fa243396000536028ea00e5e185b6b6a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:31 -0600 Subject: Rename bootretry functions and remove #ifdefs Add a bootretry_ prefix to these two functions, and remove the need for the #ifdef around everything (it moves to the Makefile). Signed-off-by: Simon Glass --- include/cli.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h index 61f8aee4ad..10dbc66651 100644 --- a/include/cli.h +++ b/include/cli.h @@ -100,9 +100,6 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer, */ int cli_simple_parse_line(char *line, char *argv[]); -/** bootretry_dont_retry() - Indicate that we should not retry the boot */ -void bootretry_dont_retry(void); - #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) #endif -- cgit From c1bb2cd0b6a3d1b152be3686601234b3a363772b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:34 -0600 Subject: main: Hide the hush/simple details inside cli.c Move these details from main (which doesn't care which parser is used) to cli.c where they belong. Signed-off-by: Simon Glass --- include/cli.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h index 10dbc66651..5158976b8d 100644 --- a/include/cli.h +++ b/include/cli.h @@ -14,7 +14,7 @@ * This will return if we get a timeout waiting for a command. See * CONFIG_BOOT_RETRY_TIME. */ -void cli_loop(void); +void cli_simple_loop(void); /** * cli_simple_run_command() - Execute a command with the simple CLI @@ -100,6 +100,17 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer, */ int cli_simple_parse_line(char *line, char *argv[]); +/** + * Go into the command loop + * + * This will return if we get a timeout waiting for a command, but only for + * the simple parser (not hush). See CONFIG_BOOT_RETRY_TIME. + */ +void cli_loop(void); + +/** Set up the command line interpreter ready for action */ +void cli_init(void); + #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) #endif -- cgit From affb215626f91e717088a27081d24c473895d47d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 10 Apr 2014 20:01:35 -0600 Subject: main: Make the execution path a little clearer in main.c bootdelay_process() never returns in some circumstances, whichs makes the control flow confusing. Change it so that the decision about how to execute the boot command is made in the main_loop() code, so it is easier to follow. Move CLI stuff to cli.c. Signed-off-by: Simon Glass --- include/cli.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/cli.h') diff --git a/include/cli.h b/include/cli.h index 5158976b8d..699426252c 100644 --- a/include/cli.h +++ b/include/cli.h @@ -100,6 +100,39 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer, */ int cli_simple_parse_line(char *line, char *argv[]); +#ifdef CONFIG_OF_CONTROL +/** + * cli_process_fdt() - process the boot command from the FDT + * + * If bootcmmd is defined in the /config node of the FDT, we use that + * as the boot command. Further, if bootsecure is set to 1 (in the same + * node) then we return true, indicating that the command should be executed + * as securely as possible, avoiding the CLI parser. + * + * @cmdp: On entry, the command that will be executed if the FDT does + * not have a command. Returns the command to execute after + * checking the FDT. + * @return true to execute securely, else false + */ +bool cli_process_fdt(const char **cmdp); + +/** cli_secure_boot_cmd() - execute a command as securely as possible + * + * This avoids using the parser, thus executing the command with the + * smallest amount of code. Parameters are not supported. + */ +void cli_secure_boot_cmd(const char *cmd); +#else +static inline bool cli_process_fdt(const char **cmdp) +{ + return false; +} + +static inline void cli_secure_boot_cmd(const char *cmd) +{ +} +#endif /* CONFIG_OF_CONTROL */ + /** * Go into the command loop * -- cgit