Recovery升级过程–(一)
recovery 从bootloader中启动
- recovery程序入口
//bootable\recovery\recovery_main.cpp
int main(int argc, char** argv) {
...
load_volume_table();//加载system/etc/recovery.fstab,结果如下:
//[ 0.002447] 0 /vendor ext4 /dev/block/platform/soc/7824900.sdhci/by-name/vendor 0
//[ 0.002453] 1 / ext4 /dev/block/bootdevice/by-name/system 0
//[ 0.002458] 2 /cache ext4 /dev/block/bootdevice/by-name/cache 0
//[ 0.002466] 3 /vendor ext4 /dev/block/bootdevice/by-name/vendor 0
//[ 0.002471] 4 /data ext4 /dev/block/bootdevice/by-name/userdata 0
//[ 0.002476] 5 /sdcard vfat /dev/block/mmcblk1p1 0
//[ 0.002481] 6 /boot emmc /dev/block/bootdevice/by-name/boot 0
//[ 0.002485] 7 /recovery emmc /dev/block/bootdevice/by-name/recovery 0
//[ 0.002491] 8 /misc emmc /dev/block/bootdevice/by-name/misc 0
//[ 0.002496] 9 /tmp ramdisk ramdisk 0
has_cache = volume_for_mount_point(CACHE_ROOT) != nullptr;//检查Fstab中是否包含cache分区 true
...
auto ret = fastboot ? StartFastboot(device, args) : start_recovery(device, args);//是否进入fastboot ,根据启动recover参数而定。升级执行start_recovery
...
}
- 开始升级
//bootable\recovery\recovery.cpp
Device::BuiltinAction start_recovery(Device* device, const std::vector<std::string>& args){
//解析参数,如下:
//Command: "/system/bin/recovery" "--update_package=@/cache/recovery/block.map" "--locale=en-US"
...
status = install_package(update_package, should_wipe_cache, true, retry_count, ui);//调用install_package安装
...
}
- 安装逻辑
//bootable\recovery\install\install.cpp
int install_package(const std::string& path, bool should_wipe_cache, bool needs_mount,int retry_count, RecoveryUI* ui) {
...
if (needs_mount == true)
result = setup_install_mounts();//挂载/tmp及cache 分区
//调用really_install_package安装
result = really_install_package(path, &updater_wipe_cache, needs_mount, &log_buffer,
retry_count, &max_temperature, ui);
...
int result =
try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, ui);
...
}
//bootable\recovery\install\install.cpp
static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache,
std::vector<std::string>* log_buffer, int retry_count,
int* max_temperature, RecoveryUI* ui) {
//1.检查是否AB升级还是BLOCK升级
bool is_ab = android::base::GetBoolProperty("ro.build.ab_update", false);
...
//创建升级命令保存到args,如:
//"META-INF/com/google/android/update-binary" ,3,...
if (int update_status =is_ab ? SetUpAbUpdateCommands(package, zip, pipe_write.get(), &args) update_status != 0) {
log_buffer->push_back(android::base::StringPrintf("error: %d", kUpdateBinaryCommandFailure));
return update_status;
}
//fork一个update-binary进程升级
}
查源码中可以看到update-binary二进制文件是从bootable\recovery\updater编译得出
- update-binary入口
int main(int argc, char** argv) {
//解析META-INF/com/google/android/updater-script脚本
ZipString script_name(SCRIPT_NAME);
int find_err = FindEntry(za, script_name, &script_entry);
...
std::string script;
script.resize(script_entry.uncompressed_length);
int extract_err = ExtractToMemory(za, &script_entry, reinterpret_cast<uint8_t*>(&script[0]),
script_entry.uncompressed_length);
...
RegisterBuiltins();//注册控制流程的语句,如ifelse、assert、abort、stdout等
RegisterInstallFunctions();//mount、is_mounted、unmount、format等
RegisterBlockImageFunctions();//block_image_verify、block_image_update、block_image_recover、check_first_block、range_sha1
RegisterDynamicPartitionsFunctions();//unmap_partition、map_partition、update_dynamic_partitions
RegisterDeviceExtensions();//暂未实现
...
int error = ParseString(script, &root, &error_count);
State state(script, &updater_info);
//执行升级脚本
bool status = Evaluate(&state, root, &result);
}
- 脚本语法介绍:
#bootable\recovery\edify\expr.cpp
- The && and || operators can be used similarly; they evaluate their
second argument only if it's needed to determine the truth of the
expression. Their value is the value of the last-evaluated
argument:
file_exists("/data/system/bad") && delete("/data/system/bad")
file_exists("/data/system/missing") || create("/data/system/missing")
get_it() || "xxx" # returns value of get_it() if that value is
# true, otherwise returns "xxx"
2342

被折叠的 条评论
为什么被折叠?



