uboot startup process-run_main_loop to cmd_process processing instructions one

1. uboot startup

uboot command mode:uboot
After startup, you will enter
3
Seconds countdown, if in
3
Press the Enter key before the second countdown ends, then you will enter
uboot
command mode.

If the Enter key is not pressed after the uboot countdown is over, it will start automatically.
Linux
Inside
core, this function is caused by
run_main_loop
Function to complete.

2. The run_main_loop function is processed by cmd_process

1. run_main_loop function

run_main_loop
Function definition in file
common/board_r.c
, the function content is as follows:

static int run_main_loop(void)
{
#ifdef CONFIG_SANDBOX
sandbox_main_loop_init();
#endif
/* main_loop() can return to retry autoboot, if so just run it again */
for (;;)
main_loop();
return 0;
}

” for (;;)
and ” while(1)
The functions are the same, there is only one in the infinite loop
main_loop
function.

2. main_loop function

main_loop function is defined in
common/main.c
file inside.
code show as below:

void main_loop(void)
{
const char *s;

bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");

#ifndef CONFIG_SYS_GENERIC_BOARD
puts("Warning: Your board does not use generic board. Please read\
");
puts("doc/README.generic-board and take action. Boards not\
");
puts("upgraded by the late 2014 may break or be removed.\
");
#endif

#ifdef CONFIG_VERSION_VARIABLE
setenv("ver", version_string); /* set version variable */
#endif /* CONFIG_VERSION_VARIABLE */

cli_init();

run_preboot_environment_command();

#if defined(CONFIG_UPDATE_TFTP)
update_tftp(0UL, NULL, NULL);
#endif /* CONFIG_UPDATE_TFTP */

s = bootdelay_process();
if (cli_process_fdt( & amp;s))
cli_secure_boot_cmd(s);

autoboot_command(s);

cli_loop();
}

In the main_loop function:

Line 5 calls the bootstage_mark_name function to print out the startup progress.

No.
13
OK, if the macro is defined
CONFIG_VERSION_VARIABLE,
will execute the function
setenv
,set up

variable
ver
The value is
version_string
, that is, setting the version number environment variable.
version_string
defined in file

cmd/version.c
, defined as follows:

const char __weak version_string[] = U_BOOT_VERSION_STRING;

After searching and a series of analyses, it can be seen that Uboot prints as follows:

U-Boot 2016.03 (Jul 07 2023 – 17:11:27 + 0800)

No.
17
OK,
cli_init
Function, related to command initialization, initialization
hush shell
related variables.

No.
19
OK,
run_preboot_environment_command
Function to get environment variables
perboot
Content,
perboot
These are some pre-start commands, and this environment variable is generally not used.

No.
25
OK,
bootdelay_process
function, this function reads environment variables
bootdelay
and
bootcmd
Content,
Then
bootdelay
Assign the value to the global variable
stored_bootdelay
, the return value is an environment variable
bootcmd
value.

No.
Line 26,
If defined
CONFIG_OF_CONTROL
function
cli_process_fdt
will be realized if
Not defined
CONFIG_OF_CONTROL
function
cli_process_fdt
Return one directly
false
.
In this uboot
not defined in
CONFIG_OF_CONTROL
,therefore
cli_process_fdt
The function return value is
false
.

No.
29
OK,
autoboot_command
Function, this function is to check whether the countdown is over? Before the countdown ends there are
Not interrupted? This function is defined in the file
common/autoboot.c .

No.
74
OK
cli_loop function, this is the command processing function. If the key is pressed before the countdown ends, then it will be executed

The cli_loop function is responsible for receiving and processing input commands.

cli_loop
The function is
uboot
The command line processing function, we are in
uboot
Enter various commands into and perform various operations.

there is
cli_loop
To process, this function is defined in the file
common/cli.c
middle. The cli_loop function is as follows:

void cli_loop(void)
{
#ifdef CONFIG_SYS_HUSH_PARSER
parse_file_outer();
/* This point is never reached */
for (;;);
#else
cli_simple_loop();
#endif /*CONFIG_SYS_HUSH_PARSER*/
}

void cli_init(void)
{
#ifdef CONFIG_SYS_HUSH_PARSER
u_boot_hush_start();
#endif

#if defined(CONFIG_HUSH_INIT_VAR)
hush_init_var();
#endif
}

in file
include/configs/mx6_common.h
There are macros defined in
CONFIG_SYS_HUSH_PARSER
, and the punctual atomic
I.MX6ULL
Development board configuration header file
mx6ullevk.h
It will be quoted inside
mx_common.h
This header file, therefore,
Macro
CONFIG_SYS_HUSH_PARSER
There is a definition.

Line 4, executes the parse_file_outer function.

No.
6
OK, it is an infinite loop and will never be executed to this point.

function
parse_file_outer
defined in file
common/cli_hush.c
, the function content after removing the conditional compilation content

as follows:

int parse_file_outer(void)
{
 int rcode;
 struct in_str input;

 setup_file_in_str( & amp;input);
 rcode = parse_stream_outer( & amp;input, FLAG_PARSE_SEMICOLON);
 return rcode;
}

No.
6
OK, call the function
setup_file_in_str
Initialize variables
input
member variables.

No.
7
OK, call the function
parse_stream_outer
function, this function is
hush shell
The command interpreter is responsible for receiving commands
Command line input, then parsing and executing the corresponding commands and functions
parse_stream_outer
defined in file
common/cli_hush.c
, the simplified version of the function content is as follows:

static int parse_stream_outer(struct in_str *inp, int flag)
{
...

do {
...
    if (rcode != 1 & amp; & ctx.old_flag == 0) {
    {
        run_list(ctx.list_head);
    }
...

} while (rcode != -1 & amp; & amp; !(flag & amp; FLAG_EXIT_FROM_LOOP) & amp; & amp;
 (inp->peek != static_peek || b_peek(inp)));
...
}

No.
7~21
in line
do-while
The loop processes input commands.

No.
9
line call function
parse_stream
Perform command parsing.

No.
14
line call call
run_list
function to execute the parsed command.

function
run_list
will go through a series of function calls and finally call
cmd_process
function to handle commands.

3. Summary

The function calling relationship is as follows: