xref: /openbmc/u-boot/doc/README.commands (revision 4379ac614809da2128f8bc1f62e3dde4daaf7deb)
10d498393Swdenk
20d498393SwdenkCommands are added to U-Boot by creating a new command structure.
300309c67SPeter MeerwaldThis is done by first including command.h, then using the U_BOOT_CMD() macro
400309c67SPeter Meerwaldto fill in a cmd_tbl_t struct.
50d498393Swdenk
60d498393SwdenkU_BOOT_CMD(name,maxargs,repeatable,command,"usage","help")
70d498393Swdenk
80d498393Swdenkname:	 is the name of the commad. THIS IS NOT a string.
900309c67SPeter Meerwaldmaxargs: the maximum number of arguments this function takes
1000309c67SPeter Meerwaldrepeatable: either 0 or 1 to indicate if autorepeat is allowed
110d498393Swdenkcommand: Function pointer (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
120d498393Swdenkusage:	 Short description. This is a string
1300309c67SPeter Meerwaldhelp:	 Long description. This is a string
140d498393Swdenk
150d498393Swdenk
1600309c67SPeter Meerwald**** Behind the scene ******
170d498393Swdenk
18ef123c52SAlbert ARIBAUDThe structure created is named with a special prefix and placed by
19ef123c52SAlbert ARIBAUDthe linker in a special section using the linker lists mechanism
20ef123c52SAlbert ARIBAUD(see include/linker_lists.h)
210d498393Swdenk
220d498393SwdenkThis makes it possible for the final link to extract all commands
230d498393Swdenkcompiled into any object code and construct a static array so the
24ef123c52SAlbert ARIBAUDcommand array can be iterated over using the linker lists macros.
250d498393Swdenk
26ef123c52SAlbert ARIBAUDThe linker lists feature ensures that the linker does not discard
27ef123c52SAlbert ARIBAUDthese symbols when linking full U-Boot even though they are not
28ef123c52SAlbert ARIBAUDreferenced in the source code as such.
292d1d6583STom Rini
300d498393SwdenkIf a new board is defined do not forget to define the command section
31*4379ac61SMasahiro Yamadaby writing in u-boot.lds ($(srctree)/board/boardname/u-boot.lds) these
320d498393Swdenk3 lines:
330d498393Swdenk
346c7c946cSMarek Vasut	.u_boot_list : {
35ef123c52SAlbert ARIBAUD		KEEP(*(SORT(.u_boot_list*)));
366c7c946cSMarek Vasut	}
37