command.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Definitions for Command Processor
  9. */
  10. #ifndef __COMMAND_H
  11. #define __COMMAND_H
  12. #include <linker_lists.h>
  13. #ifndef NULL
  14. #define NULL 0
  15. #endif
  16. /* Default to a width of 8 characters for help message command width */
  17. #ifndef CONFIG_SYS_HELP_CMD_WIDTH
  18. #define CONFIG_SYS_HELP_CMD_WIDTH 8
  19. #endif
  20. #ifndef __ASSEMBLY__
  21. /*
  22. * Monitor Command Table
  23. */
  24. struct cmd_tbl_s {
  25. char *name; /* Command Name */
  26. int maxargs; /* maximum number of arguments */
  27. int repeatable; /* autorepeat allowed? */
  28. /* Implementation function */
  29. int (*cmd)(struct cmd_tbl_s *, int, int, char * const []);
  30. char *usage; /* Usage message (short) */
  31. #ifdef CONFIG_SYS_LONGHELP
  32. char *help; /* Help message (long) */
  33. #endif
  34. #ifdef CONFIG_AUTO_COMPLETE
  35. /* do auto completion on the arguments */
  36. int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
  37. #endif
  38. };
  39. typedef struct cmd_tbl_s cmd_tbl_t;
  40. #if defined(CONFIG_CMD_RUN)
  41. extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  42. #endif
  43. /* common/command.c */
  44. int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
  45. flag, int argc, char * const argv[]);
  46. cmd_tbl_t *find_cmd(const char *cmd);
  47. cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
  48. extern int cmd_usage(const cmd_tbl_t *cmdtp);
  49. #ifdef CONFIG_AUTO_COMPLETE
  50. extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
  51. extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp);
  52. #endif
  53. /**
  54. * cmd_process_error() - report and process a possible error
  55. *
  56. * @cmdtp: Command which caused the error
  57. * @err: Error code (0 if none, -ve for error, like -EIO)
  58. * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found
  59. */
  60. int cmd_process_error(cmd_tbl_t *cmdtp, int err);
  61. /*
  62. * Monitor Command
  63. *
  64. * All commands use a common argument format:
  65. *
  66. * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  67. */
  68. #if defined(CONFIG_CMD_MEMORY) \
  69. || defined(CONFIG_CMD_I2C) \
  70. || defined(CONFIG_CMD_ITEST) \
  71. || defined(CONFIG_CMD_PCI) \
  72. || defined(CONFIG_CMD_PORTIO)
  73. #define CMD_DATA_SIZE
  74. extern int cmd_get_data_size(char* arg, int default_size);
  75. #endif
  76. #ifdef CONFIG_CMD_BOOTD
  77. extern int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  78. #endif
  79. #ifdef CONFIG_CMD_BOOTM
  80. extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  81. extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd);
  82. #else
  83. static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  84. {
  85. return 0;
  86. }
  87. #endif
  88. extern int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  89. extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
  90. char *const argv[]);
  91. extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  92. /*
  93. * Error codes that commands return to cmd_process(). We use the standard 0
  94. * and 1 for success and failure, but add one more case - failure with a
  95. * request to call cmd_usage(). But the cmd_process() function handles
  96. * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
  97. * This is just a convenience for commands to avoid them having to call
  98. * cmd_usage() all over the place.
  99. */
  100. enum command_ret_t {
  101. CMD_RET_SUCCESS, /* 0 = Success */
  102. CMD_RET_FAILURE, /* 1 = Failure */
  103. CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */
  104. };
  105. /**
  106. * Process a command with arguments. We look up the command and execute it
  107. * if valid. Otherwise we print a usage message.
  108. *
  109. * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
  110. * @param argc Number of arguments (arg 0 must be the command text)
  111. * @param argv Arguments
  112. * @param repeatable This function sets this to 0 if the command is not
  113. * repeatable. If the command is repeatable, the value
  114. * is left unchanged.
  115. * @param ticks If ticks is not null, this function set it to the
  116. * number of ticks the command took to complete.
  117. * @return 0 if the command succeeded, 1 if it failed
  118. */
  119. int cmd_process(int flag, int argc, char * const argv[],
  120. int *repeatable, unsigned long *ticks);
  121. #endif /* __ASSEMBLY__ */
  122. /*
  123. * Command Flags:
  124. */
  125. #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
  126. #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
  127. #ifdef CONFIG_AUTO_COMPLETE
  128. # define _CMD_COMPLETE(x) x,
  129. #else
  130. # define _CMD_COMPLETE(x)
  131. #endif
  132. #ifdef CONFIG_SYS_LONGHELP
  133. # define _CMD_HELP(x) x,
  134. #else
  135. # define _CMD_HELP(x)
  136. #endif
  137. #define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
  138. _usage, _help, _comp) \
  139. { #_name, _maxargs, _rep, _cmd, _usage, \
  140. _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
  141. #define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \
  142. U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
  143. _usage, _help, NULL)
  144. #define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, _comp) \
  145. ll_entry_declare(cmd_tbl_t, _name, cmd) = \
  146. U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
  147. _usage, _help, _comp);
  148. #define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \
  149. U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
  150. #if defined(CONFIG_NEEDS_MANUAL_RELOC)
  151. void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);
  152. #endif
  153. #endif /* __COMMAND_H */