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
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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Lotus launches ultra-900V hybrid technology "Luyao" to accelerate the "Win26" plan
- Send and receive emails from WAP websites on your mobile phone, real mobile email.
- High-power active power filter realized by multiple main circuits
- Frequency Source Overview
- Three elements of switching power supplies and digital devices
- Muddy tax control
- Online ESP32 Simulator
- 31 "Millions of Miles" Raspberry Pi Car——Ubuntu MATE System Installation
- ABB six-axis robot and Siemens 1500PLC user manual
- [Ateli Development Board AT32F421 Review] 7. Kuga registers jointly light up OLED
- Design and FPGA implementation of digital on-screen display control core.pdf