android P OTA差分升级时报错记录

在android P版本中制作出了差分升级包和差分降级包,在执行差分升级时报错,日志如下:

[    7.974280] Verifying current system...
[    7.974298] failed to open emmc partition "/dev/block/platform/0.soc/fa507000.sdhci/by-name/boot": **No such file or directory**
[    8.356131] file "EMMC:/dev/block/platform/0.soc/fa507000.sdhci/by-name/boot:11044864:59b6b0595c184367de46d97fa567e620ad20b3c1:11044864:de5a6f5bbac9abd332a21416144f75537223b5e7" doesn't have any of expected sha1 sums; checking cache
[    8.356168] failed to stat "/cache/saved.file": No such file or directory
[    8.356209] failed to load cache file
[    8.356230] script aborted: E3005: "EMMC:/dev/block/platform/0.soc/fa507000.sdhci/by-name/boot:11044864:59b6b0595c184367de46d97fa567e620ad20b3c1:11044864:de5a6f5bbac9abd332a21416144f75537223b5e7" has unexpected contents.
[    8.356254] E:Error in /data/upgrade.zip (Status 7)

对应的updater-script脚本内容

ui_print("Verifying current system...");
apply_patch_check("EMMC:/dev/block/platform/0.soc/fa507000.sdhci/by-name/boot:11044864:59b6b0595c184367de46d97fa567e620ad20b3c1:11044864:de5a6f5bbac9abd332a21416144f75537223b5e7") 
|| abort("E3005: \"EMMC:/dev/block/platform/0.soc/fa507000.sdhci/by-name/boot:11044864:59b6b0595c184367de46d97fa567e620ad20b3c1:11044864:de5a6f5bbac9abd332a21416144f75537223b5e7\" has unexpected contents.");

代码打印异常的地方在android/boot/recovery/中的applypatch.cpp

static int LoadPartitionContents(const std::string& filename, FileContents* file) {
  std::vector<std::string> pieces = android::base::Split(filename, ":");
  if (pieces.size() < 4 || pieces.size() % 2 != 0 || pieces[0] != "EMMC") {
    printf("LoadPartitionContents called with bad filename \"%s\"\n", filename.c_str());
    return -1;
  }

  size_t pair_count = (pieces.size() - 2) / 2;  // # of (size, sha1) pairs in filename
  std::vector<std::pair<size_t, std::string>> pairs;
  for (size_t i = 0; i < pair_count; ++i) {
    size_t size;
    if (!android::base::ParseUint(pieces[i * 2 + 2], &size) || size == 0) {
      printf("LoadPartitionContents called with bad size \"%s\"\n", pieces[i * 2 + 2].c_str());
      return -1;
    }
    pairs.push_back({ size, pieces[i * 2 + 3] });
  }

  // Sort the pairs array so that they are in order of increasing size.
  std::sort(pairs.begin(), pairs.end());

  const char* partition = pieces[1].c_str();
  unique_file dev(ota_fopen(partition, "rb"));  ###fopen分区节点失败
  if (!dev) {
    printf("failed to open emmc partition \"%s\": %s\n", partition, strerror(errno));
    return -1;
  }

  SHA_CTX sha_ctx;
  SHA1_Init(&sha_ctx);

查看了一下,正在运行的设备中果然没有by-name/boot分区节点,只有by-name/boot_a,问题可能出在这里。
想着既然跟分区相关,那应该和fstab中的配置有关吧,修改一下fstab后,问题得到解决。

--------------------------- 分割线 --------------------------------
接着执行差分升级,又遇到另外一个system校验不通过问题

[   20.585518] failed to read blocks for diff
[   20.585536] failed to execute command [bsdiff 0 308806 83fd740b9f442ead28c97c11170edee811ecfc8b 57b5c6785db138b2c149b9fa38b7d24018c4f4a2 2,209853,211277 1425 2,209853,211278]
[   20.974211] deleting stash 67d0d452af7be9d984c6c3cf2bd69fe4141e9b91
[   20.974240] /dev/block/platform/0.soc/fa507000.sdhci/by-name/system image corrupted, attempting to recover...
[   20.974262] script aborted: unable to use metadata to correct errors
[   20.974282] E1004: system partition fails to recover
[   20.974300] E:Error in /data/0428_upgrade.zip (Status 7)

本地system分区基础上没修改什么代码,所以基础上排除代码本身的问题。
看了下网上的资料,说是out中的system.img和obj/target中的system.img不同,手动fastboot flash target zip包中的system.img和vendor.img后,再执行差分升级,就成功了。

且看到有人整理了在编译时替换img的脚本,本地调试了一下,确实可以用,贴出来给需要的人。

#!/usr/bin/env python
#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Given a target-files zipfile that does contain images (ie, does
have an IMAGES/ top-level subdirectory), replace the images to
the output dir.
Usage:  replace_img_from_target_files target_files output
"""

import sys

if sys.hexversion < 0x02070000:
  print >> sys.stderr, "Python 2.7 or newer is required."
  sys.exit(1)

import errno
import os
import re
import shutil
import subprocess
import tempfile
import zipfile

image_replace_list = ["boot.img","system.img","vendor.img"]

if not hasattr(os, "SEEK_SET"):
  os.SEEK_SET = 0

def main(argv):
  print "replace target images to output directory"
  if len(argv) != 2:
    print "must need two parameter, please check!"
    sys.exit(1)

  if not os.path.exists(argv[0]):
    print "Target file:%s is invalid" % argv[0]
    sys.exit(1)

  if not os.path.exists(argv[1]):
    print "Output dir:%s is invalid" % argv[1]
    sys.exit(1)

  zf = zipfile.ZipFile(argv[0], 'r')

  for img in zf.namelist():
    if img.find("IMAGES/") != -1:
      if img.find(".img") != -1:
        data = zf.read(img)
        name = img.replace("IMAGES/", '')
        if name in image_replace_list:
          print "Replace %s" % name
          name = '/'.join((argv[1], name))
          file = open(name, "w")
          file.write(data)
          file.close()

if __name__ == '__main__':
  main(sys.argv[1:])

对应的编译打包日志

replace target images to output directory
Replace boot.img
Replace system.img
Replace vendor.img
[100% 1006/1006] Package OTA: out/target/product/xxx/xxx.zip

到这里后,整个差分升级就成功了,没有再报错。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值