command.h 5.1 KB

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