1*3d9640f5SHeinrich SchuchardtCommand definition 2*3d9640f5SHeinrich Schuchardt------------------ 30d498393Swdenk 40d498393SwdenkCommands are added to U-Boot by creating a new command structure. 5*3d9640f5SHeinrich SchuchardtThis is done by first including command.h, then using the U_BOOT_CMD() or the 6*3d9640f5SHeinrich SchuchardtU_BOOT_CMD_COMPLETE macro to fill in a cmd_tbl_t struct. 70d498393Swdenk 80d498393SwdenkU_BOOT_CMD(name, maxargs, repeatable, command, "usage", "help") 9*3d9640f5SHeinrich SchuchardtU_BOOT_CMD_COMPLETE(name, maxargs, repeatable, command, "usage, "help", comp) 100d498393Swdenk 11*3d9640f5SHeinrich Schuchardtname: The name of the command. THIS IS NOT a string. 120d498393Swdenk 13*3d9640f5SHeinrich Schuchardtmaxargs: The maximum number of arguments this function takes including 14*3d9640f5SHeinrich Schuchardt the command itself. 150d498393Swdenk 16*3d9640f5SHeinrich Schuchardtrepeatable: Either 0 or 1 to indicate if autorepeat is allowed. 17*3d9640f5SHeinrich Schuchardt 18*3d9640f5SHeinrich Schuchardtcommand: Pointer to the command function. This is the function that is 19*3d9640f5SHeinrich Schuchardt called when the command is issued. 20*3d9640f5SHeinrich Schuchardt 21*3d9640f5SHeinrich Schuchardtusage: Short description. This is a string. 22*3d9640f5SHeinrich Schuchardt 23*3d9640f5SHeinrich Schuchardthelp: Long description. This is a string. The long description is 24*3d9640f5SHeinrich Schuchardt only available if CONFIG_SYS_LONGHELP is defined. 25*3d9640f5SHeinrich Schuchardt 26*3d9640f5SHeinrich Schuchardtcomp: Pointer to the completion function. May be NULL. 27*3d9640f5SHeinrich Schuchardt This function is called if the user hits the TAB key while 28*3d9640f5SHeinrich Schuchardt entering the command arguments to complete the entry. Command 29*3d9640f5SHeinrich Schuchardt completion is only available if CONFIG_AUTO_COMPLETE is defined. 30*3d9640f5SHeinrich Schuchardt 31*3d9640f5SHeinrich SchuchardtCommand function 32*3d9640f5SHeinrich Schuchardt---------------- 33*3d9640f5SHeinrich Schuchardt 34*3d9640f5SHeinrich SchuchardtThe commmand function pointer has to be of type 35*3d9640f5SHeinrich Schuchardtint (*cmd)(struct cmd_tbl_s *cmdtp, int flag, int argc, const char *argv[]); 36*3d9640f5SHeinrich Schuchardt 37*3d9640f5SHeinrich Schuchardtcmdtp: Table entry describing the command (see above). 38*3d9640f5SHeinrich Schuchardt 39*3d9640f5SHeinrich Schuchardtflag: A bitmap which may contain the following bit: 40*3d9640f5SHeinrich Schuchardt CMD_FLAG_REPEAT - The last command is repeated. 41*3d9640f5SHeinrich Schuchardt CMD_FLAG_BOOTD - The command is called by the bootd command. 42*3d9640f5SHeinrich Schuchardt CMD_FLAG_ENV - The command is called by the run command. 43*3d9640f5SHeinrich Schuchardt 44*3d9640f5SHeinrich Schuchardtargc: Number of arguments including the command. 45*3d9640f5SHeinrich Schuchardt 46*3d9640f5SHeinrich Schuchardtargv: Arguments. 47*3d9640f5SHeinrich Schuchardt 48*3d9640f5SHeinrich SchuchardtAllowable return value are: 49*3d9640f5SHeinrich Schuchardt 50*3d9640f5SHeinrich SchuchardtCMD_SUCCESS The command was successfully executed. 51*3d9640f5SHeinrich Schuchardt 52*3d9640f5SHeinrich SchuchardtCMD_FAILURE The command failed. 53*3d9640f5SHeinrich Schuchardt 54*3d9640f5SHeinrich SchuchardtCMD_RET_USAGE The command was called with invalid parameters. This value 55*3d9640f5SHeinrich Schuchardt leads to the display of the usage string. 56*3d9640f5SHeinrich Schuchardt 57*3d9640f5SHeinrich SchuchardtCompletion function 58*3d9640f5SHeinrich Schuchardt------------------- 59*3d9640f5SHeinrich Schuchardt 60*3d9640f5SHeinrich SchuchardtThe completion function pointer has to be of type 61*3d9640f5SHeinrich Schuchardtint (*complete)(int argc, char *const argv[], char last_char, 62*3d9640f5SHeinrich Schuchardt int maxv, char *cmdv[]); 63*3d9640f5SHeinrich Schuchardt 64*3d9640f5SHeinrich Schuchardtargc: Number of arguments including the command. 65*3d9640f5SHeinrich Schuchardt 66*3d9640f5SHeinrich Schuchardtargv: Arguments. 67*3d9640f5SHeinrich Schuchardt 68*3d9640f5SHeinrich Schuchardtlast_char: The last character in the command line buffer. 69*3d9640f5SHeinrich Schuchardt 70*3d9640f5SHeinrich Schuchardtmaxv: Maximum number of possible completions that may be returned by 71*3d9640f5SHeinrich Schuchardt the function. 72*3d9640f5SHeinrich Schuchardt 73*3d9640f5SHeinrich Schuchardtcmdv: Used to return possible values for the last argument. The last 74*3d9640f5SHeinrich Schuchardt possible completion must be followed by NULL. 75*3d9640f5SHeinrich Schuchardt 76*3d9640f5SHeinrich SchuchardtThe function returns the number of possible completions (without the terminating 77*3d9640f5SHeinrich SchuchardtNULL value). 78*3d9640f5SHeinrich Schuchardt 79*3d9640f5SHeinrich SchuchardtBehind the scene 80*3d9640f5SHeinrich Schuchardt---------------- 810d498393Swdenk 82ef123c52SAlbert ARIBAUDThe structure created is named with a special prefix and placed by 83ef123c52SAlbert ARIBAUDthe linker in a special section using the linker lists mechanism 84ef123c52SAlbert ARIBAUD(see include/linker_lists.h) 850d498393Swdenk 860d498393SwdenkThis makes it possible for the final link to extract all commands 870d498393Swdenkcompiled into any object code and construct a static array so the 88ef123c52SAlbert ARIBAUDcommand array can be iterated over using the linker lists macros. 890d498393Swdenk 90ef123c52SAlbert ARIBAUDThe linker lists feature ensures that the linker does not discard 91ef123c52SAlbert ARIBAUDthese symbols when linking full U-Boot even though they are not 92ef123c52SAlbert ARIBAUDreferenced in the source code as such. 932d1d6583STom Rini 940d498393SwdenkIf a new board is defined do not forget to define the command section 954379ac61SMasahiro Yamadaby writing in u-boot.lds ($(srctree)/board/boardname/u-boot.lds) these 960d498393Swdenk3 lines: 970d498393Swdenk 986c7c946cSMarek Vasut .u_boot_list : { 99ef123c52SAlbert ARIBAUD KEEP(*(SORT(.u_boot_list*))); 1006c7c946cSMarek Vasut } 101