Recovery介绍

Recovery介绍

Recovery相关源码路径/bootloader/recovery
编辑此区域
进入RecoveryMode的两种方式

开机过程中按下RecoveryKey键(一般为POWER和VOLUME+组合键)
系统指定进入RecoveryMode(如系统要求进入还原模式;OTA升级) # 与主系统通信 Recovery是一个独立的小系统,它与主系统通过/cache目录通信
/cache/recovery/command - INPUT - command line for tool, one arg per line
/cache/recovery/log - OUTPUT - combined log file from recovery run(s)

编辑此区域
支持的Command如下

The arguments which may be supplied in the recovery.command file:
--update_package=path - verify install an OTA package file
--wipe_data - erase user data (and cache), then reboot
--prompt_and_wipe_data - prompt the user that data is corrupt, with their consent erase user
data (and cache), then reboot
--wipe_cache - wipe cache (but not user data), then reboot
--show_text - show the recovery text menu, used by some bootloader (e.g. http://b/36872519).
--set_encrypted_filesystem=on|off - enables / diasables encrypted fs
--just_exit - do nothing; exit and reboot

编辑此区域
Recovery的两大功能,FactoryReset和OTA Install
编辑此区域
FACTORY RESET

1. user selects "factory reset"
2. main system writes "--wipe_data" to /cache/recovery/command
3. main system reboots into recovery
4. get_args() writes BCB with "boot-recovery" and "--wipe_data" -- after this, rebooting will restart the erase --
5. erase_volume() reformats /data
6. erase_volume() reformats /cache
7. finish_recovery() erases BCB -- after this, rebooting will restart the main system --
8. main() calls reboot() to boot main system

BCB:bootloader control block.是专门用于recovery和bootloader互相通信的一个flash块。存放在misc分区中

struct bootloader_message {
char command[32];
char status[32];
char recovery[768];

// The 'recovery' field used to be 1024 bytes.  It has only ever
// been used to store the recovery command line, so 768 bytes
// should be plenty.  We carve off the last 256 bytes to store the
// stage string (for multistage packages) and possible future
// expansion.
char stage[32];

// The 'reserved' field used to be 224 bytes when it was initially
// carved off from the 1024-byte recovery field. Bump it up to
// 1184-byte so that the entire bootloader_message struct rounds up
// to 2048-byte.
char reserved[1184];

};

编辑此区域
OTA INSTALL

1. main system downloads OTA package to /cache/some-filename.zip
2. main system writes "--update_package=/cache/some-filename.zip"
3. main system reboots into recovery
4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
-- after this, rebooting will attempt to reinstall the update --
5. install_package() attempts to install the update
NOTE: the package install must itself be restartable from any point
6. finish_recovery() erases BCB
-- after this, rebooting will (try to) restart the main system --
7. ** if install failed ** 7a. prompt_and_wait() shows an error icon and waits for the user 7b. the user reboots (pulling the battery, etc) into the main system

你可能感兴趣的:(android)