Wei Dongshan uboot_kernel_root file system study notes 4.1-Lesson 004_root file system-Section 001_Build the root file system to start the first program

How a kernel starts the first application

  1. Mount the root file system first.
    If you delete the root file system in uboot:
    Insert picture description here
    start the kernel:
    Insert picture description here
    (1) The root file system has been deleted at this time, which is equivalent to an empty directory, so 2.打开设备the code cannot be started . The warning reported in the above figure is also consistent with the printed information in the code below.
    Insert picture description here
    (2) The second error message reported in the above figure corresponds to the printing information of the code below
    Insert picture description here
    (3) The third error message reported in the above figure corresponds to the printing information of the code below
    Insert picture description here
  2. The kernel calls the init_post function
static int noinline init_post(void)
  1. Turn on the device
sys_open((const char __user *) "/dev/console", O_RDWR, 0)
(void) sys_dup(0);
(void) sys_dup(0);

dev/console: Corresponding to the terminal, all standard input (printf)/standard output (scanf)/standard error (err); this corresponds to Uart0, for other devices it can be LCD screens, etc...

/*
 * We try each of these until one succeeds.
 *
 * The Bourne shell can be used instead of init if we are
 * trying to recover a really broken machine.
 */
if (execute_command) {
	run_init_process(execute_command);
	printk(KERN_WARNING "Failed to execute %s.  Attempting "
				"defaults...\n", execute_command);
}
  1. Then execute_commandthe source of the search
execute_command:
static int __init init_setup(char *str)
{
	unsigned int i;

	execute_command = str;										//execute_command在这里被命令行参数赋值“init=”
	/*
	 * In case LILO is going to boot us with default command line,
	 * it prepends "auto" before the whole cmdline which makes
	 * the shell think it should execute a script with such name.
	 * So we ignore all arguments entered _before_ init=... [MJ]
	 */
	for (i = 1; i < MAX_INIT_ARGS; i++)
		argv_init[i] = NULL;
	return 1;
}
__setup("init=", init_setup);									//命令行参数:init=//命令行启动init_setup函数

Continue to trace, since it is determined that execute_command is obtained by passing parameters to the kernel when uboot is started, what are the parameters passed by uboot? As can be seen from the figure belowexecute_command=/linuxrc
Insert picture description here

  1. Back to what was mentioned in 3.run_init_process(execute_command);
/*
 * We try each of these until one succeeds.
 *
 * The Bourne shell can be used instead of init if we are
 * trying to recover a really broken machine.
 */
if (execute_command) {
	run_init_process(execute_command);							//如果定义了execute_command就会启动对应的程序,进入该应用程序之后就会死循环,不会返回了。
	printk(KERN_WARNING "Failed to execute %s.  Attempting "
				"defaults...\n", execute_command);
}
  1. Continue to look at the subsequent part of the init_post function. If execute_command is not defined, the following code will be executed. Each of the following codes is a function.
run_init_process("/sbin/init");
run_init_process("/etc/init");
run_init_process("/bin/init");
run_init_process("/bin/sh");
  1. Summary
    The first application executed by the linux kernel is passed into the kernel in two ways: (1) the environment variables of uboot init=xxxx; (2) the /sbin/init /etc/init /bin/init /bin/shboot priority becomes lower in turn
  2. Enter the shell of the Linux system
    Insert picture description here

The ps (process status) command is used to provide information about the currently running process, including its process identification number (PID). A process, also called a task, is an execution (ie, running) instance of a program. The system assigns a unique PID to each process.
init: the first app program executed by the linux kernel, here is the linuxrc program-
sh: shell program is the console program
...

Guess you like

Origin blog.csdn.net/xiaoaojianghu09/article/details/104192704