Android's recovery mechanism "turn"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/fengying765/article/details/38301895

Android's recovery mechanism

Directory

1. Boot mode of the system 1

1.1 Android system Boot Mode 1

1.2 Boot mode of the System 2

2. Three parts in the recovery mode 3

3. Two communication interfaces in the recovery mode 3

3.1 Main system and recovery through/cache file Communication 3

3.2 Bootloader and Recovery communication via BCB (Bootloader Control Block) 4

4 basic flow of recovery mode 5

1. System startup mode 1.1 Android system boot mode

Typical Android systems have the following startup modes (for Android phones), and their entry methods and descriptions are described below:

1. General boot mode (normal mode)

Enter method: Press the Power key to start

Description: This is the normal way to start the phone

2. Safe Mode

Enter method: Press and hold the menu key, press the power button to start the phone until the phone starts to complete release the menu key

Description: Same as normal startup, but not registered with Google, so you cannot access the market or use your Google account

3. Boot modes (bootloader mode)

Access: Press and hold the camera key to activate the phone by pressing the power button

Description: You can install a new system image (DREAIMG.NBH) from the SD card and simply press the Power key again. To get root permission, downgrade the phone to use this mode.

4. Recovery Model (Recovery mode)

Access: Press and hold the home button to activate the phone by pressing the power button

Description: You can open the command interpreter (shell), refresh the image file (flash image), perform a backup, and so on. Of course it all depends on the recovery image version on your phone.

5. Diagnostic modes (diagnostic mode)

Access method: Press and hold the trackball, press the power button to start the phone

Description: For testing (press volume key to select items)

6. FastBoot mode

Enter method: Press and hold the return key, press the Power key to start the phone, until the screen appears fastboot words release the return button

The entry of different boot modes of the Android system is triggered in different situations, When we upgrade our Update.zip from the SD card, we enter the recovery mode which is one of them, other such as: The system crashes, or the command line Input startup command will enter the recovery or other startup mode.

1.2 Boot mode of the system

There are several modes that can be entered after booting the Android system:

1. MAGIC key (key combination): Key combination: If the user has just started to press the specified recovery key combination, the system will go directly into the recovery mode.

2. Recovery mode: Enter System "Settings", "System", have

A) network upgrade

b) Local upgrade

c) System Restore

Three ways to enter the recovery mode to complete the corresponding work.

3. Normal Mode:

If the user does not press any key combination during startup, Bootloader reads the boot control information block BCB (Bootloader control block) located in the Misc partition. It is a struct that holds the command to start commands. According to different commands, the system can also enter three different boot modes: Mainsystem, Recovery, Bootloader.

2. Three sections in the recovery mode

The work of recovery requires the cooperation of the whole software platform, from the communication architecture, there are mainly three parts.

L Mainsystem: The normal startup mode mentioned above (no command in BCB), is the normal working mode of Android with Boot.img boot system. When updating, our top-level operation in this mode is to use OTA or upgrade the Update.zip package from the SD card. Before restarting into recovery mode, a command is written to BCB to tell bootloader to enter recovery mode after a reboot.

L Recovery: When the system enters Recovery mode, the Recovery partition is loaded, and the partition contains Recovery.img (same as Boot.img, which contains the standard kernel and root file system). After entering this mode, the main thing is to run the recovery Service (/sbin/recovery) to do the corresponding operation (reboot, upgrade update.zip, erase cache partition, etc.).

L Bootloader: In addition to the normal load boot system, messages are obtained from the main system and recovery by reading the misc partition (BCB).

3. Two communication interfaces in the recovery mode

Communication between the above three entities in the recovery service is essential, and they have the following two communication interfaces.

3.1 Primary system and recovery through file communication under/cache

Recovery communicates with the main system through the three files in the/cache/recovery/directory. Specific as follows

L/cache/recovery/command: This file holds the command line that main system passes to recovery, and each line is a command that supports several combinations.

--send_intent=anystring//write the text out to Recovery/intent

At the end of recovery, the defined intent string is passed as a parameter in the Finish_recovery function and written to the/cache/recovery/intent;

-update_package=root:path//verify Install an OTA (on the Air) package file

When the Main system writes this command, it means that it needs to be upgraded, and after entering recovery mode, the commands in the file are read and written to BCB, and then the actions of the Update.zip package are updated accordingly.

--wipe_data//erase user data (and cache), then reboot.

Erase user data. The cache partition must be erased when the data partition is erased.

--wipe_cache//wipe Cache (but not user data) and then reboot.

Erase the cache partition.

--set_encrypted_filesystem=on|off-enables/diasables Encrypted FS

Enable/disable Encrypted File system

--just_exit-do nothing; Exit and reboot

Exit and restart

L/cache/recovery/log:recovery mode in the work of log printing. During the recovery service run, stdout and stderr are relocated to/tmp/recovery.log before recovery exits to/cache/recovery/log for viewing.

L/cache/recovery/intent:recovery the information passed to the main system. The effect is unknown.

Upper-level apps can be called by Android Standard Recoverysystem class (located in frameworks/base/core/java/android/os/ Recoverysystem.java) interface to complete communication with recovery mode, as shown in:

The main interfaces in this class are as follows:

InstallPackage () reboot device install specified upgrade package, write "--update_package=/path/xxx.zip" in/cache/recovery/command

Rebootwipeuserdata () Restarts the device and clears the user data partition, which also becomes a "factory reset",

Write "--wipe_data" in/cache/recovery/command.

Rebootwipecache () reboot into recovery mode, clear cache partition, write "--wipe_data" in/cache/recovery/command

Verifypackage () This interface is primarily used to verify that the downloaded upgrade package complies with the Android signature authentication.

After the interface is called, the system restarts, goes to recovery mode, and then the recovery process reads the instructions in the/cache/recovery/command to perform the appropriate operation, such as installing the upgrade package or restoring the factory settings.

3.2 Bootloader and Recovery communication via BCB (Bootloader Control Block)

BCB is the communication interface between bootloader and recovery, and also the communication interface between bootloader and main system. The misc partition, which is stored in Flash, occupies three page, which is itself a struct, and the specific members and members have the following meanings, in the/bootloader/revocery/bootloader.h file:

struct bootloader_message{

Char command[32];

Char status[32];

Char recovery[1024];

};

l Command field: Linux updates this value when it restarts into recovery mode or updates radio, bootloader firmware, and bootloader updates this value when the firmware update is complete. In addition, when the recovery is completed after a successful update, the value of this member is cleared to prevent the restart from entering recovery mode again.

L Status field: After the corresponding update is completed, Bootloader writes the execution result to this field.

L Recovery field: can be written by the main system or by the recovery service program. The content format of the file is:

"Recovery\n

<recovery command>\n

<recovery command> "

The file stores a string that must start with recovery\n, otherwise all content fields of this field are ignored. The section after "recovery\n" is the command supported by/cache/recovery/command. It can be understood as a backup of the command operation during the recovery operation. The procedure for recovery operations is to read the BCB and then read the/cache/recovery/command and then re-write the two back to BCB so that the operation is performed before entering the main system. Before entering main system after the operation, Recovery also empties the command and recovery domains of the BCB, ensuring that the recovery mode is no longer entered after a reboot.

4 basic flow of recovery mode

The basic flow of recovery mode is as follows:

1. Select "Settings", "System", "System Restore";

2. Main system writes "--wipe_data" to/cache/recovery/command;

3. Main system reboot into recovery mode;

4. The Get_args () function writes "Boot-recovery" and "--wipe_data" to BCB, and then begins erasing;

-After this, rebooting'll restart the erase--

5. Erase_volume () reformat the/data partition

6. Erase_volume () reformat the/cache partition

7. Finish_recovery () clears the BCB and then call reboot () enters main system.

The flowchart is as follows:

Android's recovery mechanism "turn"

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.