1. Add command
1.u-boot command format:
U_boot_cmd (Name,maxargs,repeatable,command, "usage", "help")
Name: command, not a string;
Maxargs: The maximum number of parameters;
Repeatable: commands are repeatable;
Command: The corresponding function pointer
2. In the Uboot/common directory, find a cmd_xxx.c file, copy the cmd_xxx.c file, and rename it to CMD_HELLO.C
CP cmd_xxx.c CMD_HELLO.C
3. Go to cmd_hello.c, modify
A: Modify macro U_boot_cmd
There are 6 U_boot_cmd macro parameters:
First parameter: The name of the added command
The second parameter: the command to add has a maximum of several parameters (note that if you set the number of parameters is 3, and the actual number of arguments is 4, then the execution command will output the Help information)
Third parameter: Repeat (1 repeat, 0 not repeat) (that is, when the ENTER key is pressed, the last command is automatically executed)
The fourth parameter: Execute the function, that is, run the command to do what exactly will be reflected in this function
Fifth parameter: Help information (short)
Sixth parameter: Help information (long)
B: Define the execution function
Execution function Format: int Do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Then add what you want to do in the function, such as printing a line of information
int Do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
printf ("Hello world\n");
return 0;
}
Add command in C:uboot the basic operation has been done, but one more step is to add the command into the Uboot,
The previous operation has added a cmd_hello.c file, but has not yet put the file into the Uboot code.
So, we need to add a line to the makfile of the common file under Uboot:
Cobjs-y + = cmd_hello.o
#include <command.h>#include<common.h>#ifdef Config_cmd_hellointDo_hello (cmd_tbl_t *CMDTP,intFlagintargcChar*argv) {printf ("my test \ n"); return 0;} U_boot_cmd (Hello,1,0, Do_hello,"usage:test\n","help:test\n");#endif
2. Uboot Command parsing
Uboot commands are basically implemented based on macro U_boot_cmd, so the macro is parsed:
By searching, we find u_boot_cmd the definition of the macro:
#define U_BOOT_CMD (NAME,MAXARGS,REP,CMD,USAGE,HELP) \
cmd_tbl_t __u_boot_cmd_# #name struct_section = {#name, Maxargs, rep, cmd, usage, help}
1. #define Struct_section __attribute__ ((Unused,section (". U_boot_cmd"))
The address at which the command is linked at the time of the link or where the command is stored is u_boot_cmd section.
2.typedef struct cmd_tbl_s cmd_tbl_t struct cmd_tbl_s {
Char *name; /* Command Name */
int Maxargs; /* Maximum number of arguments */
int repeatable; /* AutoRepeat allowed? */
/* Implementation function */
Int (*cmd) (struct cmd_tbl_s *, int, int, char *[]);
Char *usage; /* Usage Message (short) */
Char *help
}
Uboot Custom Add Command