1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * (C) Copyright 2014 Google, Inc
4 * Simon Glass <sjg@chromium.org>
11 * Go into the command loop
13 * This will return if we get a timeout waiting for a command. See
14 * CONFIG_BOOT_RETRY_TIME.
16 void cli_simple_loop(void);
19 * cli_simple_run_command() - Execute a command with the simple CLI
21 * @cmd: String containing the command to execute
22 * @flag Flag value - see CMD_FLAG_...
23 * @return 1 - command executed, repeatable
24 * 0 - command executed but not repeatable, interrupted commands are
25 * always considered not repeatable
26 * -1 - not executed (unrecognized, bootd recursion or too many args)
27 * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
28 * considered unrecognized)
30 int cli_simple_run_command(const char *cmd, int flag);
33 * cli_simple_process_macros() - Expand $() and ${} format env. variables
35 * @param input Input string possible containing $() / ${} vars
36 * @param output Output string with $() / ${} vars expanded
38 void cli_simple_process_macros(const char *input, char *output);
41 * cli_simple_run_command_list() - Execute a list of command
43 * The commands should be separated by ; or \n and will be executed
44 * by the built-in parser.
46 * This function cannot take a const char * for the command, since if it
47 * finds newlines in the string, it replaces them with \0.
49 * @param cmd String containing list of commands
50 * @param flag Execution flags (CMD_FLAG_...)
51 * @return 0 on success, or != 0 on error.
53 int cli_simple_run_command_list(char *cmd, int flag);
56 * cli_readline() - read a line into the console_buffer
58 * This is a convenience function which calls cli_readline_into_buffer().
60 * @prompt: Prompt to display
61 * @return command line length excluding terminator, or -ve on error
63 int cli_readline(const char *const prompt);
66 * readline_into_buffer() - read a line into a buffer
68 * Display the prompt, then read a command line into @buffer. The
69 * maximum line length is CONFIG_SYS_CBSIZE including a \0 terminator, which
70 * will always be added.
72 * The command is echoed as it is typed. Command editing is supported if
73 * CONFIG_CMDLINE_EDITING is defined. Tab auto-complete is supported if
74 * CONFIG_AUTO_COMPLETE is defined. If CONFIG_BOOT_RETRY_TIME is defined,
75 * then a timeout will be applied.
77 * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
78 * time out when time goes past endtime (timebase time in ticks).
80 * @prompt: Prompt to display
81 * @buffer: Place to put the line that is entered
82 * @timeout: Timeout in milliseconds, 0 if none
83 * @return command line length excluding terminator, or -ve on error: of the
84 * timeout is exceeded (either CONFIG_BOOT_RETRY_TIME or the timeout
85 * parameter), then -2 is returned. If a break is detected (Ctrl-C) then
88 int cli_readline_into_buffer(const char *const prompt, char *buffer,
92 * parse_line() - split a command line down into separate arguments
94 * The argv[] array is filled with pointers into @line, and each argument
95 * is terminated by \0 (i.e. @line is changed in the process unless there
96 * is only one argument).
98 * #argv is terminated by a NULL after the last argument pointer.
100 * At most CONFIG_SYS_MAXARGS arguments are permited - if there are more
101 * than that then an error is printed, and this function returns
102 * CONFIG_SYS_MAXARGS, with argv[] set up to that point.
104 * @line: Command line to parse
105 * @args: Array to hold arguments
106 * @return number of arguments
108 int cli_simple_parse_line(char *line, char *argv[]);
110 #if CONFIG_IS_ENABLED(OF_CONTROL)
112 * cli_process_fdt() - process the boot command from the FDT
114 * If bootcmmd is defined in the /config node of the FDT, we use that
115 * as the boot command. Further, if bootsecure is set to 1 (in the same
116 * node) then we return true, indicating that the command should be executed
117 * as securely as possible, avoiding the CLI parser.
119 * @cmdp: On entry, the command that will be executed if the FDT does
120 * not have a command. Returns the command to execute after
122 * @return true to execute securely, else false
124 bool cli_process_fdt(const char **cmdp);
126 /** cli_secure_boot_cmd() - execute a command as securely as possible
128 * This avoids using the parser, thus executing the command with the
129 * smallest amount of code. Parameters are not supported.
131 void cli_secure_boot_cmd(const char *cmd);
133 static inline bool cli_process_fdt(const char **cmdp)
138 static inline void cli_secure_boot_cmd(const char *cmd)
141 #endif /* CONFIG_OF_CONTROL */
144 * Go into the command loop
146 * This will return if we get a timeout waiting for a command, but only for
147 * the simple parser (not hush). See CONFIG_BOOT_RETRY_TIME.
151 /** Set up the command line interpreter ready for action */
154 #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk())