wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1 | |
| 2 | Commands are added to U-Boot by creating a new command structure. |
Peter Meerwald | d2f9bcf | 2012-02-08 05:31:52 +0000 | [diff] [blame] | 3 | This is done by first including command.h, then using the U_BOOT_CMD() macro |
| 4 | to fill in a cmd_tbl_t struct. |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 5 | |
| 6 | U_BOOT_CMD(name,maxargs,repeatable,command,"usage","help") |
| 7 | |
| 8 | name: is the name of the commad. THIS IS NOT a string. |
Peter Meerwald | d2f9bcf | 2012-02-08 05:31:52 +0000 | [diff] [blame] | 9 | maxargs: the maximum number of arguments this function takes |
| 10 | repeatable: either 0 or 1 to indicate if autorepeat is allowed |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 11 | command: Function pointer (*cmd)(struct cmd_tbl_s *, int, int, char *[]); |
| 12 | usage: Short description. This is a string |
Peter Meerwald | d2f9bcf | 2012-02-08 05:31:52 +0000 | [diff] [blame] | 13 | help: Long description. This is a string |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 14 | |
| 15 | |
Peter Meerwald | d2f9bcf | 2012-02-08 05:31:52 +0000 | [diff] [blame] | 16 | **** Behind the scene ****** |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 17 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 18 | The structure created is named with a special prefix (__u_boot_list_cmd_) |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 19 | and placed by the linker in a special section. |
| 20 | |
| 21 | This makes it possible for the final link to extract all commands |
| 22 | compiled into any object code and construct a static array so the |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 23 | command can be found in an array starting at _u_boot_list_cmd__start. |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 24 | |
Tom Rini | a50f806 | 2012-09-20 06:02:43 +0000 | [diff] [blame] | 25 | To ensure that the linker does not discard these symbols when linking |
| 26 | full U-Boot we generate a list of all the commands we have built (based |
| 27 | on the sections mentioned above) and use that to force the linker to |
| 28 | first enter the symbol as undefined in the output object so that there |
| 29 | is then a need for the symbol to be kept (this is the UNDEF_SYM logic in |
| 30 | the Makefile). |
| 31 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 32 | If a new board is defined do not forget to define the command section |
| 33 | by writing in u-boot.lds ($(TOPDIR)/board/boardname/u-boot.lds) these |
| 34 | 3 lines: |
| 35 | |
Marek Vasut | 69c5e34 | 2012-10-12 10:27:04 +0000 | [diff] [blame] | 36 | .u_boot_list : { |
| 37 | #include "u-boot.lst"; |
| 38 | } |