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