cli.h 3.5 KB

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