Article Title: Learn how to execute UBOOT commands. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This should be helpful to me, so that I can better understand the uboot command execution process.
The details are as follows:
The U-Boot command provides users with interactive functions and has implemented dozens of commonly used commands. If the Development Board requires special operations, you can add a new U-Boot command.
Every U_Boot_CMD command is defined by the U_Boot_CMD macro. This macro is defined in the include/command. h header file. Each command defines a javas_tbl_t struct.
#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}
|
In this way, each U-Boot command has a struct to describe. Struct contains member variables: command name, maximum number of parameters, number of duplicates, command execution function, usage, and help.
The commands entered on the console are interpreted and executed by the program in common/command. c. (This is what I am looking for) find_cmd () is responsible for matching the input command and finding the corresponding command structure from the list.
Based on the basic framework of the U-Boot command, you can analyze the simple icache operation commands to learn how to add new commands.
(1) define the CACHE command. The flags of all U-Boot commands are defined in include/cmd_confdefs.h.
#define CFG_CMD_CACHE 0x00000010ULL /* icache, dcache */
|
If you have more commands, add the definition here.
(2) The operation function that implements the CACHE command. The following is the code of the icache command in the common/cmd_cache.c file.
# If (CONFIG_COMMANDS & CFG_CMD_CACHE) static int on_off (const char * s) {// This function parses the parameter to determine whether to enable or disable the cache if (strcmp (s, "on") = 0) {// The parameter is "on" return (1);} else if (strcmp (s, "off") = 0) {// The parameter is "off" return (0);} return (-1);} int do_icache (pai_tbl_t * handle TP, int flag, int argc, char * argv []) {// switch (argc) {case 2:/* The number of parameters of the instruction cache is 1, execute the open or close command cache operation */switch (on_off (argv [1]) {case 0: icache_disable (); // enable the command cache break; case 1: icache_enable (); // disable the command cache break;}/* fall trough */case 1: /* if the number of parameters is 0, obtain the command cache status */printf ("Instruction Cache is % s \ n", icache_status ()? "ON": "OFF"); return 0; default: // Other default conditions, print command instructions printf ("Usage: \ n % s \ n ", required TP-> usage); return 1;} return 0 ;}...... U_Boot_CMD (// use a macro to define the command icache, 2, 1, do_icache, // The command is icache, and the command execution function is do_icache () "icache-enable or disable instruction cache \ n ", // help information "[on, off] \ n" "-enable or disable instruction cache \ n ");...... # Endif
|
The u- Boot commands are described by struct _ U_Boot_cmd _ # name. You can understand the two definitions of U_Boot_CMD in include/command. h.
#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}
|
Also, do not forget to add the compiled target file to the common/Makefile.
(3) Open the command flag of the CONFIG_COMMANDS option. This program file starts with # if statement needs to pre-process whether to include this command function. The CONFIG_COMMANDS option is defined in the configuration file of the Development Board. For example, the SMDK2410 platform has the following definitions in include/configs/smdk2410.h.
/*********************************************************** * Command definition ***********************************************************/#define CONFIG_COMMANDS \ (CONFIG_CMD_DFL | \ CFG_CMD_CACHE | \ CFG_CMD_REGINFO | \ CFG_CMD_DATE | \ CFG_CMD_ELF)
|
Follow these three steps to add the new U-Boot command.