README.commands 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Command definition
  2. ------------------
  3. Commands are added to U-Boot by creating a new command structure.
  4. This is done by first including command.h, then using the U_BOOT_CMD() or the
  5. U_BOOT_CMD_COMPLETE macro to fill in a cmd_tbl_t struct.
  6. U_BOOT_CMD(name, maxargs, repeatable, command, "usage", "help")
  7. U_BOOT_CMD_COMPLETE(name, maxargs, repeatable, command, "usage, "help", comp)
  8. name: The name of the command. THIS IS NOT a string.
  9. maxargs: The maximum number of arguments this function takes including
  10. the command itself.
  11. repeatable: Either 0 or 1 to indicate if autorepeat is allowed.
  12. command: Pointer to the command function. This is the function that is
  13. called when the command is issued.
  14. usage: Short description. This is a string.
  15. help: Long description. This is a string. The long description is
  16. only available if CONFIG_SYS_LONGHELP is defined.
  17. comp: Pointer to the completion function. May be NULL.
  18. This function is called if the user hits the TAB key while
  19. entering the command arguments to complete the entry. Command
  20. completion is only available if CONFIG_AUTO_COMPLETE is defined.
  21. Command function
  22. ----------------
  23. The commmand function pointer has to be of type
  24. int (*cmd)(struct cmd_tbl_s *cmdtp, int flag, int argc, const char *argv[]);
  25. cmdtp: Table entry describing the command (see above).
  26. flag: A bitmap which may contain the following bit:
  27. CMD_FLAG_REPEAT - The last command is repeated.
  28. CMD_FLAG_BOOTD - The command is called by the bootd command.
  29. CMD_FLAG_ENV - The command is called by the run command.
  30. argc: Number of arguments including the command.
  31. argv: Arguments.
  32. Allowable return value are:
  33. CMD_SUCCESS The command was successfully executed.
  34. CMD_FAILURE The command failed.
  35. CMD_RET_USAGE The command was called with invalid parameters. This value
  36. leads to the display of the usage string.
  37. Completion function
  38. -------------------
  39. The completion function pointer has to be of type
  40. int (*complete)(int argc, char *const argv[], char last_char,
  41. int maxv, char *cmdv[]);
  42. argc: Number of arguments including the command.
  43. argv: Arguments.
  44. last_char: The last character in the command line buffer.
  45. maxv: Maximum number of possible completions that may be returned by
  46. the function.
  47. cmdv: Used to return possible values for the last argument. The last
  48. possible completion must be followed by NULL.
  49. The function returns the number of possible completions (without the terminating
  50. NULL value).
  51. Behind the scene
  52. ----------------
  53. The structure created is named with a special prefix and placed by
  54. the linker in a special section using the linker lists mechanism
  55. (see include/linker_lists.h)
  56. This makes it possible for the final link to extract all commands
  57. compiled into any object code and construct a static array so the
  58. command array can be iterated over using the linker lists macros.
  59. The linker lists feature ensures that the linker does not discard
  60. these symbols when linking full U-Boot even though they are not
  61. referenced in the source code as such.
  62. If a new board is defined do not forget to define the command section
  63. by writing in u-boot.lds ($(srctree)/board/boardname/u-boot.lds) these
  64. 3 lines:
  65. .u_boot_list : {
  66. KEEP(*(SORT(.u_boot_list*)));
  67. }