xref: /rk3399_rockchip-uboot/include/cli.h (revision affb215626f91e717088a27081d24c473895d47d)
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  */
17c1bb2cd0SSimon Glass void cli_simple_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  */
56e1bf824dSSimon 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  */
81e1bf824dSSimon Glass int cli_readline_into_buffer(const char *const prompt, char *buffer,
82e1bf824dSSimon 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  */
101e1bf824dSSimon Glass int cli_simple_parse_line(char *line, char *argv[]);
10218d66533SSimon Glass 
103*affb2156SSimon Glass #ifdef CONFIG_OF_CONTROL
104*affb2156SSimon Glass /**
105*affb2156SSimon Glass  * cli_process_fdt() - process the boot command from the FDT
106*affb2156SSimon Glass  *
107*affb2156SSimon Glass  * If bootcmmd is defined in the /config node of the FDT, we use that
108*affb2156SSimon Glass  * as the boot command. Further, if bootsecure is set to 1 (in the same
109*affb2156SSimon Glass  * node) then we return true, indicating that the command should be executed
110*affb2156SSimon Glass  * as securely as possible, avoiding the CLI parser.
111*affb2156SSimon Glass  *
112*affb2156SSimon Glass  * @cmdp:	On entry, the command that will be executed if the FDT does
113*affb2156SSimon Glass  *		not have a command. Returns the command to execute after
114*affb2156SSimon Glass  *		checking the FDT.
115*affb2156SSimon Glass  * @return true to execute securely, else false
116*affb2156SSimon Glass  */
117*affb2156SSimon Glass bool cli_process_fdt(const char **cmdp);
118*affb2156SSimon Glass 
119*affb2156SSimon Glass /** cli_secure_boot_cmd() - execute a command as securely as possible
120*affb2156SSimon Glass  *
121*affb2156SSimon Glass  * This avoids using the parser, thus executing the command with the
122*affb2156SSimon Glass  * smallest amount of code. Parameters are not supported.
123*affb2156SSimon Glass  */
124*affb2156SSimon Glass void cli_secure_boot_cmd(const char *cmd);
125*affb2156SSimon Glass #else
126*affb2156SSimon Glass static inline bool cli_process_fdt(const char **cmdp)
127*affb2156SSimon Glass {
128*affb2156SSimon Glass 	return false;
129*affb2156SSimon Glass }
130*affb2156SSimon Glass 
131*affb2156SSimon Glass static inline void cli_secure_boot_cmd(const char *cmd)
132*affb2156SSimon Glass {
133*affb2156SSimon Glass }
134*affb2156SSimon Glass #endif /* CONFIG_OF_CONTROL */
135*affb2156SSimon Glass 
136c1bb2cd0SSimon Glass /**
137c1bb2cd0SSimon Glass  * Go into the command loop
138c1bb2cd0SSimon Glass  *
139c1bb2cd0SSimon Glass  * This will return if we get a timeout waiting for a command, but only for
140c1bb2cd0SSimon Glass  * the simple parser (not hush). See CONFIG_BOOT_RETRY_TIME.
141c1bb2cd0SSimon Glass  */
142c1bb2cd0SSimon Glass void cli_loop(void);
143c1bb2cd0SSimon Glass 
144c1bb2cd0SSimon Glass /** Set up the command line interpreter ready for action */
145c1bb2cd0SSimon Glass void cli_init(void);
146c1bb2cd0SSimon Glass 
1476493ccc7SSimon Glass #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk())
1486493ccc7SSimon Glass 
14918d66533SSimon Glass #endif
150