Android利用Recovery模式,进行恢复出厂设置,OTA升级,patch升级及firmware升级。

升级一般通过运行升级包中的META-INF/com/google/android/update-script脚本来执行自定义升级,脚本中是一组recovery系统能识别的UI控制,文件系统操作命令,例如write_raw_image(写FLASH分区),copy_dir(复制目录)。该包一般被下载至SDCARD和CACHE分区下。

升级中还涉及到包的数字签名,签名方式和普通JAR文件签名差不错。公钥会被硬编译入recovery,编译时生成在:out/target/product/XX/obj/PACKAGING/ota_keys_inc_intermediates/keys.inc

G1中的三种启动模式

MAGIC KEY:

camera +

power:bootloader模式,ADP里则可以使用fastboot模式

home + power:recovery模式

正常启动

Bootloader正常启动,又有三种方式,按照BCB(Bootloader

Control Block, 下节介绍)中的command分类:

command == 'boot-recovery'

→ 启动recovery.img。recovery模式

command ==

'update-radio/hboot' → 更新firmware(bootloader)

其他 → 启动boot.img

Recovery涉及到的其他系统及文件

CACHE分区文件

Recovery

工具通过NAND

cache分区上的三个文件和主系统打交道。主系统(包括恢复出厂设置和OTA升级)可以写入recovery所需的命令,读出recovery过程中的LOG和intent。

/cache/recovery/command:

recovery命令,由主系统写入。所有命令如下:

--send_intent=anystring

- write the text out to recovery.intent

--update_package=root:path

- verify install an OTA package file

--wipe_data

- erase user data (and cache), then reboot

--wipe_cache

- wipe cache (but not user data), then reboot

/cache/recovery/log:recovery过程日志,由主系统读出

/cache/recovery/intent:recovery输出的intent

MISC分区内容

Bootloader Control Block

(BCB) 存放recovery

bootloader message。结构如下:

struct

bootloader_message {

char

command[32];

char

status[32];  // 未知用途

char

recovery[1024];

};

command可以有以下两个值

“boot-recovery”:标示recovery正在进行,或指示bootloader应该进入recovery

mode

“update-hboot/radio”:指示bootloader更新firmware

recovery内容

“recovery\n

\n

其中recovery

command为CACHE:/recovery/command命令

两种Recovery

Case

FACTORY

RESET(恢复出厂设置)

用户选择“恢复出厂设置”

设置系统将"--wipe_data"命令写入/cache/recovery/command

系统重启,并进入recover模式(/sbin/recovery)

get_args()

"boot-recovery"和"--wipe_data"写入BCB

erase_root()

格式化(擦除)DATA分区

erase_root()

格式化(擦除)CACHE分区

finish_recovery()

擦除BCB

重启系统

OTA

INSTALL(OTA升级)

升级系统下载

OTA包到/cache/some-filename.zip

升级系统写入recovery命令"--update_package=CACHE:some-filename.zip"

重启,并进入recovery模式

get_args()

将"boot-recovery"

"--update_package=..."

写入BCB

install_package()

作升级

finish_recovery()

擦除 BCB

**

如果安装包失败 **

prompt_and_wait() 等待用户操作,选择ALT+S或ALT+W

升级或恢复出厂设置

main()

调用

maybe_install_firmware_update()

如果包里有hboot/radio的firmware则继续,否则返回

"boot-recovery"

和 "--wipe_cache"

写入BCB

firmware image写入cache分区

"update-radio/hboot"

和 "--wipe_cache"

写入BCB

重启系统

bootloader自身更新firmware

bootloader

将 "boot-recovery"

写入BCB

erase_root()

擦除CACHE分区

清除

BCB

main()

调用 reboot()

重启系统

Recovery模式流程

/init

→ init.rc →

/sbin/recovery →

main():recovery.c

ui_init():ui.c

[UI initialize]

gr_init():minui/graphics.c

[set tty0 to graphic

mode, open fb0]

ev_init():minui/events.c

[open /dev/input/event*]

res_create_surface:minui/resource.c

[create surfaces for all bitmaps used later, include icons, bmps]

create

2 threads: progress/input_thread [create progress show and input

event handler thread]

get_args():recovery.c

get_bootloader_message():bootloader.c

[read mtdblock0(misc partition) 2nd page for

commandline]

check

if nand misc partition has boot message. If yes, fill argc/argv.

If

no, get arguments from /cache/recovery/command, and fill argc/argv.

set_bootloader_message():bootloader.c

[set bootloader message back to mtdblock0]

Parser

argv[] filled above

register_update_commands():commands.c

[ register all commands with name and hook function ]

registerCommand():commands.c

Register

command with name, hook, type, cookie.

Commands,

e.g: assert, delete, copy_dir, symlink, write_raw_image.

registerFunction():commands.c

Register

function with name, hook, cookie.

Function,

e.g: get_mark, matches, getprop, file_contains

install_package():

translate_root_path():roots.c

[ "SYSTEM:lib" and turns it into a string like

"/system/lib", translate the updater.zip path ]

mzOpenZipArchive():zip.c

[ open updater.zip file (uncompass) ]

handle_update_package():install.c

verify_jar_signature():verifier.c

[ verify signature with keys.inc key; verify manifest and zip

package archive ]

verifySignature()

[ verify the signature file: CERT.sf/rsa. ]

digestEntry():verifier.c

[ get SHA-1 digest of CERT.sf file ]

RSA_verify(public

key:keys.inc, signature:CERT.rsa, CERT.sf's digest):libc/rsa.c

[ Verify a 2048 bit RSA PKCS1.5 signature against an expected

SHA-1 hash. Use public key to decrypt the CERT.rsa to get

original SHA digest, then compare to digest of CERT.sf ]

verifyManifest()

[ Get manifest SHA1-Digest from CERT.sf. Then do  digest to

MANIFEST.MF. Compare them ]

verifyArchive()

[ verify all the files in update.zip with digest  listed in

MANIFEST.MF ]

find_update_script():install.c

[ find META-INF/com/google/android/update-script updater script ]

handle_update_script():install.c

[ read cmds from script file, and do parser, exec ]

parseAmendScript():amend.c

[ call yyparse() to parse to command ]

exeCommandList():install.c

exeCommand():execute.c

[ call command hook function ]

erase

DATA/CACHE partition

prompt_and_wait():recovery.c

[ wait for user input: 1) reboot 2) update.zip 3) wipe data ]

ui_key_xxx

get ALT+x keys

1)

do nothing

2)

install_package('SDCARD:update.zip')

3)

erase_root() →

format_root_device()   DATA/CACHE

may_install_firmware_update():firmware.c

[ remember_firmware_update() is called by write_hboot/radio_image

command, it stores the bootloader image to CACHE partition, and

write update-hboot/radio command to MISC partition for bootloader

message to let bootloader update itself after reboot ]

set_bootloader_message()

write_update_for_bootloader():bootloader.c

[ write firmware image into CACHE partition with update_header,

busyimage and failimage ]

finish_recovery():recovery.c

[ clear the recovery command and prepare to boot a (hopefully

working) system, copy our log file to cache as well (for the system

to read), and record any intent we were asked to communicate back to

the system. ]

reboot()

Recovery模式流程图

以下流程图绘制了系统从启动加载bootloader后的行为流程。

WIPE 清除手机的信息 就是格式化 然后你在刷你喜欢的ROM。

5、Wipe——清除

5-1、Wipe data/factory reset——清除内存数据和缓存数据

5-2、Wipe Dalvik-cache——清除缓存数据 + ext 分区内数据

5-3、Wipe SD:ext partition——只清除ext 分区内数据

5-4、Wipe battery stats——清除电池数据

5-5、Wipe rotate settings——清除传感器内设置的数据

分区

6、Partition sdcard——分区sd 卡

6-1、Partition SD——自动为sd 卡分区

6-2、Repair SD:ext——修复ext 分区

6-3、SD:ext2 to ext3——将ext2 分区转换为ext3 分区(推荐)

6-4、SD:ext3 to ext4——将ext3 分区转换为ext4 分区(C4 卡不推荐,C6 卡推荐)

想多了解 请看下面:

1、Reboot system now——重启

2、USB-MS toggle——在recovery 模式下直接连接USB,读取你的sd卡,这个非常方便。刷不成的话你还可以往sd卡拷贝别的ROM 进行补救,按小房子退出该模式。非常棒的功能,最近才发现的。2010.05.27.

3、Backup/Restore——备份和还原

3-1、Nand backup——Nand 备份

3-2、Nand + ext backup——Nand 备份(系统和ext 分区一同备份)

3-3、Nand restore——还原(就是还原3-1、3-2 的最后一次备份)

3-4、BART backup——BART 备份 (包括系统和ext 分区)

3-5、BART restore——还原最后一次的BART备份

Nand 备份类似于系统的备份 而BART 则像是PC 上ghost 的备份。

Nand 备份 它不会备份ext 分区(就是第二分区 没有分区的可以不管这个)

所以你的如果app2sd 了 那么装在第二分区的程序用Nand 恢复是办不到的

BAR T则可以备份到ext 分区 用BART 恢复则可以恢复整个系统 可以使它和你备份前一模一样,不会有一点文件信息的丢失(包括联系人、短信、图片、影音等,所以如果你装的东西比较多,那么备份和恢复会比较慢)

4、Flash zip from sdcard——从sd卡根目录的.zip ROM 刷机包刷机

5、Wipe——清除

5-1、Wipe data/factory reset——清除内存数据和缓存数据

5-2、Wipe Dalvik-cache——清除缓存数据 + ext 分区内数据

5-3、Wipe SD:ext partition——只清除ext 分区内数据

5-4、Wipe battery stats——清除电池数据

5-5、Wipe rotate settings——清除传感器内设置的数据

6、Partition sdcard——分区sd 卡

6-1、Partition SD——自动为sd 卡分区

6-2、Repair SD:ext——修复ext 分区

6-3、SD:ext2 to ext3——将ext2 分区转换为ext3 分区(推荐)

6-4、SD:ext3 to ext4——将ext3 分区转换为ext4 分区(C4 卡不推荐,C6 卡推荐)

7、Other——其它

7-1、Fix apk uid mismatches——修复apk 程序

7-2、Move apps+dalv to SD——移动程序和虚拟缓存到sd 卡(这个可不是 app2sd)

7-3、Move recovery.log to SD——移动刷机日志文件到sd 卡(执行此操作后,sd 卡根目录会出现一个“recovery.log” 文件 即为刷机日志文件)

8、Power off——关机

android恢复出厂设置流程图,Android recovery模式相关推荐

  1. android 恢复出厂设置 代码,android恢复出厂设置以及系统升级流程

    http://www.bangchui.org/simple/?t5938.html ============================================= 恢复出厂设置流程概括: ...

  2. android 恢复出厂设置 界面,android恢复出厂设置流程概括

    恢复出厂设置流程概括 ============================================= 恢复出厂设置流程概括: 一. 设置模块中进行恢复出厂设置操作,系统一共做了两件事: 1 ...

  3. android 恢复出厂设置 时间,Android 恢复出厂设置后,时间不能恢复替:2013年1月1日...

    Android 恢复出厂设置后,时间不能恢复为:2013年1月1日 前言         欢迎大家我分享和推荐好用的代码段~~声明         欢迎转载,但请保留文章原始出处: CSDN:http ...

  4. android 恢复出厂设置 时间,Android 恢复出厂设置后,时间不能恢复为:2013年1月1日...

    前言         欢迎大家我分享和推荐好用的代码段~~声明         欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net 雨季o莫忧离:http://blog ...

  5. Android 恢复出厂设置(recovery)

    Android 恢复出厂设置基本流程 (1)遥控器/按键板后门键触发,或者应用里面从系统设置里面恢复出厂选项也可触发: // 后面以系统设置的应用触发为例 (2)选择恢复出厂设置之后,就会发送广播&q ...

  6. android恢复出厂设置,关机,重启以及系统升级和充电器连接广播

    恢复出厂设置 <uses-permission android:name="android.permission.MASTER_CLEAR" /> if (Build. ...

  7. Android 恢复出厂设置(系统时间不修改)

    Android恢复出厂设置时,只会将/data和/cache分区进行清除,时间和其他分区不会清除, 时间由rtc硬件模块来进行维护的,时间更新后会将时间信息写入此硬件模块,在系统启动时,RTC硬件驱动 ...

  8. Android恢复出厂设置流程分析【Android源码解析十】

    最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+framework层的流程: 在setting-->备份与重置--->恢复出厂设置--->重置手机---> ...

  9. android 恢复出厂设置代码流程(Good!)

    android的恢复出厂设置 文章问多一般都是从完整的recover mode讲起,恢复出厂设置只是 recovery mode下一个小部分. recovery mode流程分析的文章很多,比较完整的 ...

  10. android恢复出厂设置流程分析

    原文出自:http://blog.csdn.net/wdaming1986/article/details/11988531 最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+f ...

最新文章

  1. fopen时w与wb的区别
  2. Hadoop详解(三):HDFS完全分布式环境搭建
  3. SENet双塔模型:在推荐领域召回粗排的应用及其它
  4. 最in的一期,来自大厂的邀请|C课有道
  5. 再现暴力裁员!患病员工被关小黑屋,摄像头监控,工作量超其他人!
  6. Magento中调用JS文件的几种方法
  7. 极简主义2020UI设计正流行,欣赏下可临摹的案例模板!
  8. STM8L101+si4463低功耗和自动唤醒配置
  9. JS实现图片上传并显示
  10. 56个民族及民族代码的sql语句
  11. Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流)
  12. Linux——vi编辑器及文件内容操作
  13. 无监督图像分类《SCAN:Learning to Classify Images without》代码分析笔记(1):simclr
  14. 共轭复数,共轭根式,共轭矩阵,共轭方向,共轭方向法,共轭梯度法,共轭分布,共轭函数,傅里叶变换的共轭对称
  15. 最新面试必看的 数据库 知识大总结
  16. 51单片机学习——中断
  17. perl dbd mysql 5.7_perl-dbd-mysql
  18. WBS,工作分解结构
  19. Verilog——篮球24S计时器
  20. ISO的国家代码和语言代码

热门文章

  1. 提问的艺术,原文链接
  2. Kinect驱动识别及SDK下载问题
  3. [TcaplusDB] 行业新闻汇编(6月29日)
  4. Spatiotemporal Multi-Graph Convolution Network for Ride-Hailing Demand Forecasting
  5. 两金压降两金指什么_什么是两金压降
  6. amr文件怎么转换成mp3格式?
  7. android指纹采集sdk,SDK上的Android指纹23
  8. Visio 2013画直线问题总结(折线变直,交叉时产生的交叉桥)
  9. 转型只争朝夕!又一火电企业成立新能源公司
  10. CSDN实训 - 个人博客界面制作