Android Boot sub-system switch

Source: Internet
Author: User

Reprint Please indicate the source of the article and the author !

Source: http://blog.csdn.net/xl19862005

Everyone support my daughter-in-law shop: http://wen1991.taobao.com

Big Bear ( Xandy )


1. General statement

There are several subsystems in the Android system (recovery, factory, and power off charge), so how do these subsystems switch to the main system?

(Switching and booting of the recovery system has been written in another blog post.)

http://blog.csdn.net/xl19862005/article/details/8517918

I got a haircut today. Factory This subsystem startup process is now logged as follows

Because the platform currently used is 6572 of MTK, the code path will be different from other programs

Let's look at a diagram first:


The difference between entering the factory subsystem and the recovery system is:

Factory: Is activated and started in the INIT process.

recovery: The bootcmdline jumps to the corresponding address on the start

2, LK (uboot) detection factory mult key

In mediatek/platform/mt6572/lk/factory.c, this file has the following code

BOOL Factory_check_key_trigger (void) {//waitulong begin = Get_timer (0);p rintf ("\n%s Check Factory boot\n", Module_name) ;p rintf ("%s Wait 50ms for Special keys\n", module_name);/* If The boot reason is RESET, than we'll not enter Factory mode . */if (Mtk_detect_pmic_just_rst ()) {  return false;}    while (Get_timer (begin) <50)    {    if (Mtk_detect_key (Mt65xx_factory_key)) {printf ("%s Detect key\n", Module_ NAME);p rintf ("%s Enable factory mode\n", module_name); G_boot_mode = factory_boot;//video_printf ("%s:detect factory Mode!\n ", module_name); return TRUE;}} return FALSE;}
When factory key is detected, it is set here
G_boot_mode = Factory_boot;
G_boot_mode is a typedef-type global variable

The type is defined as follows:

typedef enum {    normal_boot = 0,    meta_boot = 1,    recovery_boot = 2,        sw_reboot = 3,  factory_boot = 4,
   
    advmeta_boot = 5,    ate_factory_boot = 6,    alarm_boot = 7, #if defined (mtk_kernel_power_off_charging)    KERNEL _power_off_charging_boot = 8,    low_power_off_charging_boot = 9, #endif        fastboot =,    download_boot = 100,    Unknown_boot} Bootmode;
   
You can see that the value of the factory_boot pattern defined here is 4!

3. Start the init process in kernel

After LK (uboot) boot the kernel, let's take a look at the Kernel_init function in this file in Kernel/init/main.c, which is a thread callback function,

In the Rest_init function in the same file

Kernel_thread (Kernel_init, NULL, CLONE_FS | Clone_sighand);

Register to the thread and get executed

The following code is in the Kernel_init:

    if (!ramdisk_execute_command)       Ramdisk_execute_command = "/init";    if (sys_access (const char __user *) Ramdisk_execute_command, 0)! = 0) {        ramdisk_execute_command = NULL;        Prepare_namespace ();    }
As you can see, the bin file path in this root directory is passed to Ramdisk_execute_command, the global character pointer, and the Init bin file in the root directory is/init

Packaged in ramdisk.img (see the file under the appropriate root directory for Android source compilation)

Let's take a look at the following code in the Init_post function:

    if (Ramdisk_execute_command) {        run_init_process (ramdisk_execute_command);        PRINTK (kern_warning "Failed to execute%s\n",                Ramdisk_execute_command);    }
In this case, the kernel will boot into the user space program.

In addition, the following code is in the mediatek/platform/mt6572/kernel/core/mt_boot.c file:

    /* CREATE proc entry At/proc/boot_mode */create_proc_read_entry (boot_mode, S_irugo, NULL, BOOT_MODE_PROC, NULL);
Here you create a property named "Boot_mode" that is used to pass parameters to the INIT program of the kernel and user space!

4. Init processsystem/core/init/init.c

This is the source code for the Init bin in the build root directory

The main function of this file is to prepare and initialize the various resources required for system startup ...

Here is the following code:

static int is_factory_boot (void) {    int fd;    size_t S;    Char Boot_mode;    FD = open ("/sys/class/boot/boot/boot/boot_mode", O_RDWR);    if (FD < 0) {        printf ("Fail to open:%s\n", "/sys/class/boot/boot/boot/boot_mode");        return 0;    }    s = Read (FD, (void *) &boot_mode, sizeof (Boot_mode));    Close (FD);    if (s <= 0) {ERROR ("could not read boot mode sys file\n");    return 0;    }    Factory mode, ' 4 '    //ATE Factory Mode, ' 6 '    if ((boot_mode! = ' 4 ') && (boot_mode! = ' 6 ')) {ERROR ("Unsup Ported Factory mode\n ");        return 0;    }    printf ("Factory Mode booting.....\n");    return 1;}

The properties file for the path "/sys/class/boot/boot/boot/boot_mode" is created in the kernel mt_boot.c this file, reading the properties of this file in init to get the system boot state

It can be seen that when Boot_mode is set to "4" (corresponding to the Factory_boot = 4 mentioned above) it will enter the factory subsystem.

    if (Is_factory_boot ())    {        ERROR ("This is Factory boot");        Property_set ("Sys.mtk.no.factoryimage", "1");        Init_parse_config_file ("/factory_init.rc");            INFO ("Reading project config file\n");        Init_parse_config_file ("/factory_init.project.rc");    }
Load factory_init.rc here to launch some of the services or tools needed under factory.

In addition, the implementation of the power-off charging function is implemented according to this architecture!











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.