OK6410A development board (three) 11 u-boot-2021.01 boot analysis U-boot image execution of some commands

Publisher:cloudy德德Latest update time:2022-09-22 Source: csdnKeywords:OK6410A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Registration of commands

2. Command call

3. Execution of commands

4. Command return


1 Command registration (taking help as an example)

cmd/help.c


 10 static int do_help(struct cmd_tbl *cmdtp, int flag, int argc,                    

 11            char *const argv[])                                                   

 12 {                                                                                

 13 #ifdef CONFIG_CMDLINE                                                            

 14     struct cmd_tbl *start = ll_entry_start(struct cmd_tbl, cmd);                 

 15     const int len = ll_entry_count(struct cmd_tbl, cmd);                         

 16     return _do_help(start, len, cmdtp, flag, argc, argv);                        

 17 #else                                                                            

 18     return 0;                                                                    

 19 #endif                                                                           

 20 }                                                                                

 21                                                                                  

 22 U_BOOT_CMD(                                                                      

 23     help,   CONFIG_SYS_MAXARGS, 1,  do_help,                                     

 24     "print command description/usage",                                           

 25     "n"                                                                         

 26     "   - print brief description of all commandsn"                             

 27     "help command ...n"                                                         

 28     "   - print detailed usage of 'command'"                                     

 29 );                                                                               


----------------------- The above code expands to the following code

----------------------- For details on how to register and search, please refer to __attribute__

----------------------- __attribute__ demo : https://github.com/lisider/attribute_sample


static int do_help(struct cmd_tbl *cmdtp, int flag, int argc,

     char *const argv[])

{


 struct cmd_tbl *start = ({ static char start[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_1"))); (struct cmd_tbl *)&start; });

 const int len = ({ struct cmd_tbl *start = ({ static char start[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_1"))); (struct cmd_tbl *)&start; }); struct cmd_tbl *end = ({ static char end[0] __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_3"))); (struct cmd_tbl *)&end; }); unsigned int _ll_result = end - start; _ll_result; });

 return _do_help(start, len, cmdtp, flag, argc, argv);


}


struct cmd_tbl _u_boot_list_2_cmd_2_help __attribute__((__aligned__(4))) __attribute__((unused, section(".u_boot_list_2_""cmd""_2_""help"))) = { "help", 16, 1 ? cmd_always_repeatable : cmd_never_repeatable, do_help, "print command description/usage", "n" " - print brief description of all commandsn" "help command ...n" " - print detailed usage of 'command'", 

# 22 "../cmd/help.c" 3 4

((void *)0)

# 22 "../cmd/help.c"

, };


2 Command call


When cmd_call is called

1. bootcmd

2. cmdline


All commands are called by cmd_call // cmd_call does not directly call do_xxx


Taking help as an example, the call stack of do_help is 

cmd_call

cmd_always_repeatable // Use this string as a keyword to search the entire text

do_help


common/command.c 564-585

564 /**                                                                              

565  * Call a command function. This should be the only route in U-Boot to call      

566  * a command, so that we can track whether we are waiting for input or           

567  * executing a command.                                                          

568  *                                                                               

569  * @param cmdtp     Pointer to the command to execute                            

570  * @param flag      Some flags normally 0 (see CMD_FLAG_.. above)                

571  * @param argc      Number of arguments (arg 0 must be the command text)         

572  * @param argv      Arguments                                                    

573  * @param repeatable    Can the command be repeated                              

574  * @return 0 if command succeeded, else non-zero (CMD_RET_...)                   

575  */                                                                              

576 static int cmd_call(struct cmd_tbl *cmdtp, int flag, int argc,                   

577             char *const argv[], int *repeatable)                                 

578 {                                                                                

579     int result;                                                                  

580                                                                                  

581     result = cmdtp->cmd_rep(cmdtp, flag, argc, argv, repeatable);                

582     if (result)                                                                  

583         debug("Command failed, result=%dn", result);                            

584     return result;                                                               

585 }  


3 Command execution (taking help as an example)

cmd/help.c


// Write whatever you want


 10 static int do_help(struct cmd_tbl *cmdtp, int flag, int argc,                    

 11            char *const argv[])                                                   

 12 {                                                                                

 13 #ifdef CONFIG_CMDLINE                                                            

 14     struct cmd_tbl *start = ll_entry_start(struct cmd_tbl, cmd);                 

 15     const int len = ll_entry_count(struct cmd_tbl, cmd);                         

 16     return _do_help(start, len, cmdtp, flag, argc, argv);                        

 17 #else                                                                            

 18     return 0;                                                                    

 19 #endif                                                                           

 20 }  


4 Command Response

cmd_call also checks when returning

Command return value

1. Correct is 0

2. Error is non-zero

Keywords:OK6410A Reference address:OK6410A development board (three) 11 u-boot-2021.01 boot analysis U-boot image execution of some commands

Previous article:OK6410A development board (three) 12 u-boot-2021.01 boot analysis U-boot image running part boot detailed analysis 1
Next article:OK6410A development board (three) 10 u-boot-2021.01 boot analysis U-boot image running part cmdline

Recommended ReadingLatest update time:2024-11-21 22:00

OK6410A Development Board (VIII) 33 linux-5.11 OK6410A Memory Management Phase 1
A stext symbol in arch/arm/kernel/head.S - __turn_mmu_on symbol ----At this time, MMU was turned on, and the era of virtual memory began process mrc p15, 0, r9, c0, c0 // Store cpuid in r9 __lookup_processor_type //According to the value in r9, get procinfo and store it in r5 movs r10, r5 // Get procinfo and s
[Microcontroller]
OK6410A Development Board (VIII) 86 linux-5.11 OK6410A Linux Debug Overview
Debugging scenarios There are so many debugging methods under Linux. We will choose different debugging methods for different scenarios. Now define the scene as follows 1. Fixed architecture 2. Fixed kernel configuration 3. Fixed releases 4. Fixed kernel version 5. Is there any virtual machine such as qemu?
[Microcontroller]
Development environment setup (I) OK6410A Development environment 1 Official environment OK
Boot from u-boot (1.1.6) in nand u-boot loads kernel (3.0.1) in nand, and then kernel starts The kernel mounts the third partition in nand (formatted as yaff2) as the root file system and executes /linuxrc /linuxrc is started as process 1 u-boot and boot mode u-boot (version U-Boot 1.1.6, u-boot.bin, 4062204 b
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号