【转】Android Recovery模式
原文网址:http://leox.iteye.com/blog/975303
(muddogxp 原创,转载请注明)
Recovery简介
Android利用Recovery模式,进行恢复出厂设置,OTA升级,patch升级及firmware升级。
升级一般通过运行升级包中的META-INF/com/google/android/update-script脚本来执行自定义升级,脚本中是一组recovery系统能识别的UI控制,文件系统操作命令,例如write_raw_image(写FLASH分区),copy_dir(复制目录)。该包一般被下载至SDCARD和CACHE分区下。如果对该包内容感兴趣,可以从http://forum.xda-developers.com/showthread.php?t=442480下载JF升级包来看看。
升级中还涉及到包的数字签名,签名方式和普通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分区文件
/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
Recovery 工具通过NAND cache分区上的三个文件和主系统打交道。主系统(包括恢复出厂设置和OTA升级)可以写入recovery所需的命令,读出recovery过程中的LOG和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
<recovery command>\n
<recovery command>”
其中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后的行为流程。
没有床,见blog吧~
实际使用的例子:
adb shell "echo \"send_intent=xxx\" > /cache/recovery/command"
adb shell "echo \"--update_package=SDCARD:update.zip\" >> /cache/recovery/command"
adb shell sync
adb reboot recovery
【转】Android Recovery模式的更多相关文章
- android recovery模式及ROM制作
转自android recovery模式及ROM制作 1.总述 为了方便客户日后的固件升级,本周研究了一下android的recovery模式.网上有不少这类的资料,但都比较繁杂,没有一个系统的介绍与 ...
- Android Recovery模式学习体会
最近在学习Android的Recovery模式,感觉它和Windows的安全模式很相似.两者的工作原理都是只加载少量的系统组件(内核是必须的),使系统运行在最小模式,这样就可以在不影响当前系统 ...
- Android recovery UI实现分析
Android recovery模式为何物? 关于这个问题, baidu上已经有无数的答案.不理解的朋友先补习一下. 从纯技术角度来讲, recovery和android本质上是两个独立的rootfs ...
- Android系统Recovery模式的工作原理【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7464987 在使用update.zip包升级时怎样从主系统(main system)重启进 ...
- Fastboot模式和Recovery模式
http://blog.csdn.net/luoshengyang/article/details/29688041 在回答第一个问题之前,我们先来看看Android设备从硬件到系统的结构,如图1所示 ...
- android recovery 主系统代码分析
阅读完上一篇文章: http://blog.csdn.net/andyhuabing/article/details/9226569 我们已经清楚了如何进入正常模式和Recovery模式已有深刻理解了 ...
- [Android][Recovery] Recovery下找不到sdcard路径
做升级的时候,把更新包拷贝到sd卡中,然后调用接口进行重启升级 wossoneri.github.io File update_file = new File("/sdcard/update ...
- Android recovery支持adb shell
Android recovery支持adb shell 近期开发过程注意到recovery不支持adb shell.为了便于调试方便,决定添加此功能. 刚開始我们採用的是user版本号系统,进入rec ...
- FastBoot BootLoader Recovery 模式解释
理论上,所有的Android设备都存在着Fastboot/Bootloader模式,不过,由于Android操作系统的开源特性,各厂商的对 自家的相关Android设备都有着各自不同的Fastboot ...
随机推荐
- require.js优化器
项目发布前,require.js优化器可以合并require.js各个模块. 官网: http://requirejs.org/docs/optimization.html 安装 npm instal ...
- DataTbale取值
有一个DataTable数据 //创建DataTable对象 DataTable dt = new DataTable("Table_AX"); //为DataTable创建列 / ...
- 关键词:CodeSmith工具、Money类型、__UNKNOWN__
问题描述: 当数据库列类型有Money类型的时候,CodeSmith生成数据访问层会出错.有不能识别的类型.解决方法: 通过查找资料得知,数据库中的Money类型在DbType中是Currency(货 ...
- angularjs-ngModel 控制页面的宽度
js NiDialog.open({ windowClass: '', size:'elements', backdrop: 'static', keyboard: false, templateUr ...
- ASP.NET Excel数据导出数据库
/// <summary> /// 根據gridview導出excel /// </summary> /// <param name="ctl"> ...
- DATEDIFF interval=ms的用法
datediff(ms,@CurrDateTime,@Date)>0 当上面的日期超过24天,用上面的sql会有问题 要修改成如下: (CONVERT(VARCHAR,@CurrDateTime ...
- Spring 中各种通知
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 【POJ3461】【KMP】Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- Python中%s和%r的区别
早先使用Python工作的时候,对于格式化输出%s和%r的使用都是混着用的. 这一次就出错了: cu.execute("insert into ipPool values(null, '%r ...
- javascript——函数属性和方法
<script type="text/javascript"> //每个函数都包含两个属性:length 和 prototype //length:当前函数希望接受的命 ...