118d66533SSimon Glass /* 218d66533SSimon Glass * (C) Copyright 2014 Google, Inc 318d66533SSimon Glass * Simon Glass <sjg@chromium.org> 418d66533SSimon Glass * 518d66533SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 618d66533SSimon Glass */ 718d66533SSimon Glass 818d66533SSimon Glass #ifndef __CLI_H 918d66533SSimon Glass #define __CLI_H 1018d66533SSimon Glass 1118d66533SSimon Glass /** 1218d66533SSimon Glass * Go into the command loop 1318d66533SSimon Glass * 1418d66533SSimon Glass * This will return if we get a timeout waiting for a command. See 1518d66533SSimon Glass * CONFIG_BOOT_RETRY_TIME. 1618d66533SSimon Glass */ 1718d66533SSimon Glass void cli_loop(void); 1818d66533SSimon Glass 1918d66533SSimon Glass /** 2018d66533SSimon Glass * cli_simple_run_command() - Execute a command with the simple CLI 2118d66533SSimon Glass * 2218d66533SSimon Glass * @cmd: String containing the command to execute 2318d66533SSimon Glass * @flag Flag value - see CMD_FLAG_... 2418d66533SSimon Glass * @return 1 - command executed, repeatable 2518d66533SSimon Glass * 0 - command executed but not repeatable, interrupted commands are 2618d66533SSimon Glass * always considered not repeatable 2718d66533SSimon Glass * -1 - not executed (unrecognized, bootd recursion or too many args) 2818d66533SSimon Glass * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is 2918d66533SSimon Glass * considered unrecognized) 3018d66533SSimon Glass */ 3118d66533SSimon Glass int cli_simple_run_command(const char *cmd, int flag); 3218d66533SSimon Glass 3318d66533SSimon Glass /** 3418d66533SSimon Glass * cli_simple_run_command_list() - Execute a list of command 3518d66533SSimon Glass * 3618d66533SSimon Glass * The commands should be separated by ; or \n and will be executed 3718d66533SSimon Glass * by the built-in parser. 3818d66533SSimon Glass * 3918d66533SSimon Glass * This function cannot take a const char * for the command, since if it 4018d66533SSimon Glass * finds newlines in the string, it replaces them with \0. 4118d66533SSimon Glass * 4218d66533SSimon Glass * @param cmd String containing list of commands 4318d66533SSimon Glass * @param flag Execution flags (CMD_FLAG_...) 4418d66533SSimon Glass * @return 0 on success, or != 0 on error. 4518d66533SSimon Glass */ 4618d66533SSimon Glass int cli_simple_run_command_list(char *cmd, int flag); 4718d66533SSimon Glass 4818d66533SSimon Glass /** 4918d66533SSimon Glass * cli_readline() - read a line into the console_buffer 5018d66533SSimon Glass * 5118d66533SSimon Glass * This is a convenience function which calls cli_readline_into_buffer(). 5218d66533SSimon Glass * 5318d66533SSimon Glass * @prompt: Prompt to display 5418d66533SSimon Glass * @return command line length excluding terminator, or -ve on error 5518d66533SSimon Glass */ 56*e1bf824dSSimon Glass int cli_readline(const char *const prompt); 5718d66533SSimon Glass 5818d66533SSimon Glass /** 5918d66533SSimon Glass * readline_into_buffer() - read a line into a buffer 6018d66533SSimon Glass * 6118d66533SSimon Glass * Display the prompt, then read a command line into @buffer. The 6218d66533SSimon Glass * maximum line length is CONFIG_SYS_CBSIZE including a \0 terminator, which 6318d66533SSimon Glass * will always be added. 6418d66533SSimon Glass * 6518d66533SSimon Glass * The command is echoed as it is typed. Command editing is supported if 6618d66533SSimon Glass * CONFIG_CMDLINE_EDITING is defined. Tab auto-complete is supported if 6718d66533SSimon Glass * CONFIG_AUTO_COMPLETE is defined. If CONFIG_BOOT_RETRY_TIME is defined, 6818d66533SSimon Glass * then a timeout will be applied. 6918d66533SSimon Glass * 7018d66533SSimon Glass * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, 7118d66533SSimon Glass * time out when time goes past endtime (timebase time in ticks). 7218d66533SSimon Glass * 7318d66533SSimon Glass * @prompt: Prompt to display 7418d66533SSimon Glass * @buffer: Place to put the line that is entered 7518d66533SSimon Glass * @timeout: Timeout in milliseconds, 0 if none 7618d66533SSimon Glass * @return command line length excluding terminator, or -ve on error: of the 7718d66533SSimon Glass * timeout is exceeded (either CONFIG_BOOT_RETRY_TIME or the timeout 7818d66533SSimon Glass * parameter), then -2 is returned. If a break is detected (Ctrl-C) then 7918d66533SSimon Glass * -1 is returned. 8018d66533SSimon Glass */ 81*e1bf824dSSimon Glass int cli_readline_into_buffer(const char *const prompt, char *buffer, 82*e1bf824dSSimon Glass int timeout); 8318d66533SSimon Glass 8418d66533SSimon Glass /** 8518d66533SSimon Glass * parse_line() - split a command line down into separate arguments 8618d66533SSimon Glass * 8718d66533SSimon Glass * The argv[] array is filled with pointers into @line, and each argument 8818d66533SSimon Glass * is terminated by \0 (i.e. @line is changed in the process unless there 8918d66533SSimon Glass * is only one argument). 9018d66533SSimon Glass * 9118d66533SSimon Glass * #argv is terminated by a NULL after the last argument pointer. 9218d66533SSimon Glass * 9318d66533SSimon Glass * At most CONFIG_SYS_MAXARGS arguments are permited - if there are more 9418d66533SSimon Glass * than that then an error is printed, and this function returns 9518d66533SSimon Glass * CONFIG_SYS_MAXARGS, with argv[] set up to that point. 9618d66533SSimon Glass * 9718d66533SSimon Glass * @line: Command line to parse 9818d66533SSimon Glass * @args: Array to hold arguments 9918d66533SSimon Glass * @return number of arguments 10018d66533SSimon Glass */ 101*e1bf824dSSimon Glass int cli_simple_parse_line(char *line, char *argv[]); 10218d66533SSimon Glass 1036493ccc7SSimon Glass /** bootretry_dont_retry() - Indicate that we should not retry the boot */ 1046493ccc7SSimon Glass void bootretry_dont_retry(void); 1056493ccc7SSimon Glass 1066493ccc7SSimon Glass #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) 1076493ccc7SSimon Glass 10818d66533SSimon Glass #endif 109