Android A/B System OTA 升级以及报错处理

介绍

    A/B System OTA是Android 7.0引入的新的OTA方式,跟以前的OTA在升级流程上来说已经完全不一样了,我们都知道之前的OTA走的是recovery模式。A/B System 不同之处在于系统中有两个system分区,当然boot分区也是两个,A和B,当我们进行OTA升级的时候实际上只是对b分区进行升级,而我们正在运行的a分区是不受影响的。

 

OTA包制作

    制作流程跟以前是一样的,我简单提一下,首先就是make命令:

make otapackage

生成的target_files文件在out目录下:

out/target/product/xxx/obj/PACKAGING/target_files_intermediates/xxx.zip

OTA完整包在out下面,与system.img同一级目录,这里就不多说了。差分包的制作:

./build/tools/releasetools/ota_from_target_files -v --block -p out/host/linux-x86 -k build/target/product/security/testkey -i target_files_01.zip target_files_02.zip update.zip

生成的update.zip就是我们所需要的差分包。

 

OTA升级流程

    根据官方文档的说明,主要分为以下几步:

1、将上面生成的OTA包push到机器中,

adb push update.zip /data/ota_package/update.zip

2、解析OTA包,生成升级所需参数

ota.py update.zip

附上Python脚本

import sys
import zipfile
def main():
    if len(sys.argv) != 2:
        sys.stderr.write('Use: %s <ota_file.zip>\n' % sys.arv[0])
        return 1
    otazip = zipfile.ZipFile(sys.argv[1], 'r')
    payload_info = otazip.getinfo('payload.bin')
    payload_offset = payload_info.header_offset +len(payload_info.FileHeader())
    payload_size = payload_info.file_size
    payload_location = '/data/ota_package/update.zip'
    headers = otazip.read('payload_properties.txt')
    print (
        'update_engine_client --update --follow --payload=file://{payload_location}'
        ' --offset={payload_offset} --size={payload_size}'
        ' --headers="{headers}"').format(**locals())
    return 0
if __name__ == '__main__':
    sys.exit(main())

3、执行上面Python脚本解析之后的命令,shell环境中执行:

update_engine_client --update --follow
--payload=/data/ota_package/update.zip --offset=PAYLOAD_OFFSET
--size=PAYLOAD_SIZE --headers="HEADERS"

4、重启机器

 

升级过程中的报错及解决方案

    先贴上log


I update_engine: [0530/162336:INFO:delta_performer.cc(359)] Applying 21701 operations to partition "system"
E update_engine: [0530/162336:ERROR:delta_performer.cc(1060)] The hash of the source data on disk for this operation doesn't match the expected value. This could mean that the delta update payload was targeted for another version, or that the source partition was modified after it was installed, for example, by mounting a filesystem.
E update_engine: [0530/162336:ERROR:delta_performer.cc(1065)] Expected:   sha256|hex = 839ACF5296B9AB820DC822B6C09EBA896905531EB2C581093A357411F1A444A0
E update_engine: [0530/162336:ERROR:delta_performer.cc(1068)] Calculated: sha256|hex = 18AF8D6842A71554893F1DE65B87F2A9639FB390357C71D5383C6ED7A6051AFA
E update_engine: [0530/162336:ERROR:delta_performer.cc(1077)] Operation source (offset:size) in blocks: 0:2,193:1,218:456,23471:8,32769:1,32961:1,37333:4,37351:3,37554:3,37570:2,37951:1,37959:1,38111:1,38125:1,38129:1,38139:1,38147:1,38149:1,38151:2,38155:1,38157:1,38360:5,38372:1,38377:5,38384:1,38437:1,38442:1,38447:1,38452:1,38457:1,38462:1,38467:1
E update_engine: [0530/162336:ERROR:delta_performer.cc(1260)] ValidateSourceHash(source_hasher.raw_hash(), operation, error) failed.
E update_engine: [0530/162336:ERROR:delta_performer.cc(283)] Failed to perform SOURCE_BSDIFF operation 8, which is the operation 0 in partition "system"
E update_engine: [0530/162336:ERROR:download_action.cc(273)] Error 20 in DeltaPerformer's Write method when processing the received payload -- Terminating processing
I update_engine: [0530/162336:INFO:delta_performer.cc(299)] Discarding 113721 unused downloaded bytes
I update_engine: [0530/162336:INFO:multi_range_http_fetcher.cc(171)] Received transfer terminated.
I update_engine: [0530/162336:INFO:multi_range_http_fetcher.cc(123)] TransferEnded w/ code 200
I update_engine: [0530/162336:INFO:multi_range_http_fetcher.cc(125)] Terminating.
I update_engine: [0530/162336:INFO:action_processor.cc(116)] ActionProcessor: finished DownloadAction with code ErrorCode::kDownloadStateInitializationError
I update_engine: [0530/162336:INFO:action_processor.cc(121)] ActionProcessor: Aborting processing due to failure.
I update_engine: [0530/162336:INFO:update_attempter_android.cc(286)] Processing Done.
I update_engine: [0530/162336:INFO:update_attempter_android.cc(306)] Resetting update progress.

从log可以看出,是校验system的时候两次hash值不匹配导致的,造成这个错误的原因是我直接刷的out下面的system.img,而这个system.img与target_files中的system.img时间戳不同,导致校验失败。

解决方案就是用target_files中的system.img代替out下面的。

 

中间还有一个小插曲,adb remount也会导致同样的错误,可能是重新挂载分区会影响到校验结果,这个还在研究中。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值