1*18d66533SSimon Glass /* 2*18d66533SSimon Glass * (C) Copyright 2014 Google, Inc 3*18d66533SSimon Glass * Simon Glass <sjg@chromium.org> 4*18d66533SSimon Glass * 5*18d66533SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 6*18d66533SSimon Glass */ 7*18d66533SSimon Glass 8*18d66533SSimon Glass #ifndef __CLI_H 9*18d66533SSimon Glass #define __CLI_H 10*18d66533SSimon Glass 11*18d66533SSimon Glass /** 12*18d66533SSimon Glass * Go into the command loop 13*18d66533SSimon Glass * 14*18d66533SSimon Glass * This will return if we get a timeout waiting for a command. See 15*18d66533SSimon Glass * CONFIG_BOOT_RETRY_TIME. 16*18d66533SSimon Glass */ 17*18d66533SSimon Glass void cli_loop(void); 18*18d66533SSimon Glass 19*18d66533SSimon Glass /** 20*18d66533SSimon Glass * cli_simple_run_command() - Execute a command with the simple CLI 21*18d66533SSimon Glass * 22*18d66533SSimon Glass * @cmd: String containing the command to execute 23*18d66533SSimon Glass * @flag Flag value - see CMD_FLAG_... 24*18d66533SSimon Glass * @return 1 - command executed, repeatable 25*18d66533SSimon Glass * 0 - command executed but not repeatable, interrupted commands are 26*18d66533SSimon Glass * always considered not repeatable 27*18d66533SSimon Glass * -1 - not executed (unrecognized, bootd recursion or too many args) 28*18d66533SSimon Glass * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is 29*18d66533SSimon Glass * considered unrecognized) 30*18d66533SSimon Glass */ 31*18d66533SSimon Glass int cli_simple_run_command(const char *cmd, int flag); 32*18d66533SSimon Glass 33*18d66533SSimon Glass /** 34*18d66533SSimon Glass * cli_simple_run_command_list() - Execute a list of command 35*18d66533SSimon Glass * 36*18d66533SSimon Glass * The commands should be separated by ; or \n and will be executed 37*18d66533SSimon Glass * by the built-in parser. 38*18d66533SSimon Glass * 39*18d66533SSimon Glass * This function cannot take a const char * for the command, since if it 40*18d66533SSimon Glass * finds newlines in the string, it replaces them with \0. 41*18d66533SSimon Glass * 42*18d66533SSimon Glass * @param cmd String containing list of commands 43*18d66533SSimon Glass * @param flag Execution flags (CMD_FLAG_...) 44*18d66533SSimon Glass * @return 0 on success, or != 0 on error. 45*18d66533SSimon Glass */ 46*18d66533SSimon Glass int cli_simple_run_command_list(char *cmd, int flag); 47*18d66533SSimon Glass 48*18d66533SSimon Glass /** 49*18d66533SSimon Glass * cli_readline() - read a line into the console_buffer 50*18d66533SSimon Glass * 51*18d66533SSimon Glass * This is a convenience function which calls cli_readline_into_buffer(). 52*18d66533SSimon Glass * 53*18d66533SSimon Glass * @prompt: Prompt to display 54*18d66533SSimon Glass * @return command line length excluding terminator, or -ve on error 55*18d66533SSimon Glass */ 56*18d66533SSimon Glass int readline(const char *const prompt); 57*18d66533SSimon Glass 58*18d66533SSimon Glass /** 59*18d66533SSimon Glass * readline_into_buffer() - read a line into a buffer 60*18d66533SSimon Glass * 61*18d66533SSimon Glass * Display the prompt, then read a command line into @buffer. The 62*18d66533SSimon Glass * maximum line length is CONFIG_SYS_CBSIZE including a \0 terminator, which 63*18d66533SSimon Glass * will always be added. 64*18d66533SSimon Glass * 65*18d66533SSimon Glass * The command is echoed as it is typed. Command editing is supported if 66*18d66533SSimon Glass * CONFIG_CMDLINE_EDITING is defined. Tab auto-complete is supported if 67*18d66533SSimon Glass * CONFIG_AUTO_COMPLETE is defined. If CONFIG_BOOT_RETRY_TIME is defined, 68*18d66533SSimon Glass * then a timeout will be applied. 69*18d66533SSimon Glass * 70*18d66533SSimon Glass * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0, 71*18d66533SSimon Glass * time out when time goes past endtime (timebase time in ticks). 72*18d66533SSimon Glass * 73*18d66533SSimon Glass * @prompt: Prompt to display 74*18d66533SSimon Glass * @buffer: Place to put the line that is entered 75*18d66533SSimon Glass * @timeout: Timeout in milliseconds, 0 if none 76*18d66533SSimon Glass * @return command line length excluding terminator, or -ve on error: of the 77*18d66533SSimon Glass * timeout is exceeded (either CONFIG_BOOT_RETRY_TIME or the timeout 78*18d66533SSimon Glass * parameter), then -2 is returned. If a break is detected (Ctrl-C) then 79*18d66533SSimon Glass * -1 is returned. 80*18d66533SSimon Glass */ 81*18d66533SSimon Glass int readline_into_buffer(const char *const prompt, char *buffer, int timeout); 82*18d66533SSimon Glass 83*18d66533SSimon Glass /** 84*18d66533SSimon Glass * parse_line() - split a command line down into separate arguments 85*18d66533SSimon Glass * 86*18d66533SSimon Glass * The argv[] array is filled with pointers into @line, and each argument 87*18d66533SSimon Glass * is terminated by \0 (i.e. @line is changed in the process unless there 88*18d66533SSimon Glass * is only one argument). 89*18d66533SSimon Glass * 90*18d66533SSimon Glass * #argv is terminated by a NULL after the last argument pointer. 91*18d66533SSimon Glass * 92*18d66533SSimon Glass * At most CONFIG_SYS_MAXARGS arguments are permited - if there are more 93*18d66533SSimon Glass * than that then an error is printed, and this function returns 94*18d66533SSimon Glass * CONFIG_SYS_MAXARGS, with argv[] set up to that point. 95*18d66533SSimon Glass * 96*18d66533SSimon Glass * @line: Command line to parse 97*18d66533SSimon Glass * @args: Array to hold arguments 98*18d66533SSimon Glass * @return number of arguments 99*18d66533SSimon Glass */ 100*18d66533SSimon Glass int parse_line(char *line, char *argv[]); 101*18d66533SSimon Glass 102*18d66533SSimon Glass #endif 103