编译版本差分包出来验证差分升级过程中发现有时候能成功升级有时候不能。
现象描述:adb reboot recovery,选择Apply update from ADB。 然后输入命令adb reboot sideload ./OTApackage.zip进行本地差分升级。升级过程中升级失败并且提示如下信息:
问题分析:更换debug版本固件,重复上述操作步骤,看到升级失败提示后提取recovery.log出来分析。
js
adb pull /tmp/recovery.log
把升级失败的日志和成功的日志进行对比发现存在如下区别:
js
成功部分日志
[ 28.880965] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for odm_b
[ 28.885833] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for product_b
[ 28.904324] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for system_b
[ 28.904664] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for system_dlkm_b
[ 28.906182] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for system_ext_b
[ 28.909221] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for vendor_b
[ 28.909635] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3447] Successfully created snapshot partition for vendor_dlkm_b
[ 28.909711] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for odm_b
[ 28.909750] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for product_b
[ 28.909788] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for system_b
[ 28.909826] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for system_dlkm_b
[ 28.909862] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for system_ext_b
[ 28.909900] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for vendor_b
[ 28.909937] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3459] Successfully created snapshot for vendor_dlkm_b
[ 29.161509] update_engine_sideload I 01-01 02:40:52 445 445 snapshot.cpp:3314] Successfully created all snapshots for target slot _b
js
失败部分日志
[ 6.701408] update_engine_sideload I 01-06 03:09:12 405 405 snapshot.cpp:3447] Successfully created snapshot partition for odm_b
[ 6.706411] update_engine_sideload I 01-06 03:09:12 405 405 snapshot.cpp:3447] Successfully created snapshot partition for product_b
[ 6.786439] update_engine_sideload I 01-06 03:09:12 405 405 snapshot.cpp:3447] Successfully created snapshot partition for system_b
[ 6.786776] update_engine_sideload I 01-06 03:09:12 405 405 snapshot.cpp:3447] Successfully created snapshot partition for system_dlkm_b
[ 6.788708] update_engine_sideload I 01-06 03:09:12 405 405 snapshot.cpp:3447] Successfully created snapshot partition for system_ext_b
[ 6.856357] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3447] Successfully created snapshot partition for vendor_b
[ 6.860247] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3447] Successfully created snapshot partition for vendor_dlkm_b
[ 6.860324] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3459] Successfully created snapshot for odm_b
[ 6.860361] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3459] Successfully created snapshot for product_b
[ 6.860398] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3459] Successfully created snapshot for system_b
[ 6.860434] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3459] Successfully created snapshot for system_dlkm_b
[ 6.860471] update_engine_sideload I 01-06 03:09:13 405 405 snapshot.cpp:3459] Successfully created snapshot for system_ext_b
[ 6.860565] update_engine_sideload E 01-06 03:09:13 405 405 fiemap_writer.cpp:664] Failed to create file at: /data/gsi/ota/vendor_b-cow-img.img: No such file or directory
[ 6.860606] update_engine_sideload E 01-06 03:09:13 405 405 split_fiemap_writer.cpp:68] Could not determine maximum file size for /data/gsi/ota/vendor_b-cow-img.img
可以看到失败的日志少了如下三行,合理推测升级失败原因可能和vendor_b、vendor_dlkm_b这两个分区快照创建失败有关。
js
Successfully created snapshot for vendor_b
Successfully created snapshot for vendor_dlkm_b
Successfully created all snapshots for target slot _b
目前安卓的升级机制是ab分区,平时的时候一个分区a是在用的,另一个分区b是空的,升级之前先在b分区准备好,然后再整体切换过去。升级完成之后就在使用b分区,a分区开始变成空的。如果你是在没有准备升级的过程中直接切换成另一个分区,机器会直接卡开机logo
js
fastboot getvar current-slot
fastboot set_active a\b
同时重点关注下面这两行日志,这两行日志是出现在理应出现Successfully created snapshot for vendor_b的位置出现的
js
update_engine_sideload E 01-06 03:09:13 405 405 fiemap_writer.cpp:664] Failed to create file at: /data/gsi/ota/vendor_b-cow-img.img: No such file or directory
update_engine_sideload E 01-06 03:09:13 405 405 split_fiemap_writer.cpp:68] Could not determine maximum file size for /data/gsi/ota/vendor_b-cow-img.img
通过关键词/data/gsi搜索,在网上搜到了这篇文章对Virtual A/B 分区工作方式的进一步探索 - LibXZR 的小本本,文章中提到升级内容默认会在super分区中创建临时的逻辑分区来进行存储,而在super分区空间不够用时,才会在/data下创建,同时也提到这些内容会创建在/data/gsi/ota路径下。
日志中正好提到Failed to create file at: /data/gsi/ota/vendor_b-cow-img.img: No such file or directory,是不是因为super分区不够才会升级失败的呢?查询发现当前设备设置的super分区是6g,尝试改成8g之后发现确实升级成功率会高很多,具体要设置多少才合适,是不是越大越好呢?在查阅谷歌官方文档和查找资料过程中,发现该项目实际采用的是虚拟ab分区,对super分区的要求如下
那么问题来了,不增加super分区升级会经常失败,但是谷歌又不推荐增加super分区。它的设计机制是使用/data的空间,但是日志中为什么在/data分区中创建文件失败了呢?
也是在查找资料过程中,发现安卓源码bootable/recovery/中有个updater_sample的app。尝试用这个app对设备进行差分升级,发现使用这种方式升级就能成功。那就是说在recovery模式下/data分区无法正常调用,但是在设备进系统使用的情况下是能使用的。