当前位置:   article > 正文

OpenHarmony 4.0 本地OTA升级_openharmony 3.2 release ota升级

openharmony 3.2 release ota升级

一、环境说明

  • 系统版本:OpenHarmony 4.0 release
  • 设备平台:RK3568

二、OpenHarmony OTA介绍

  • OTA介绍:
    随着设备系统日新月异,用户如何及时获取系统的更新,体验新版本带来的新的体验,以及提升系统的稳定和安全性成为了每个厂商都面临的严峻问题。
    OTA(Over the Air)提供对设备远程升级的能力。升级子系统对用户屏蔽了底层芯片的差异,对外提供了统一的升级接口。基于接口进行二次开发后,可以让厂商的设备(如IP摄像头等)轻松支持远程升级能力,即通过移动通信的接口从远程服务器下载新的软件更新包,对自身系统进行升级,从而满足厂商的应用管理需求。

  • OpenHarmony OTA升级方式:
    从OTA包的升级方式来说分为本地升级和网络OTA升级。

    • 本地升级:将制作好的OTA包放入设备指定升级路径,在软件相关界面下执行升级或直接输入升级命令进行本地升级。
    • 网络OTA升级,设备通过网络从OTA服务器下载OTA包至本地设备,下载完成后在软件相关界面进行升级。
      可以看出本地OTA升级是网络OTA升级的一个环节。通常为了调试方便,验证设备OTA升级可行性,工程师会先进行本地OTA包升级。本文正是介绍OpenHarmony 本地OTA升级步骤。
  • OTA包类型
    从OTA包的类型来说,可分为全量OTA包、差分(增量)OTA包、变分区OTA包。

    • 全量OTA升级包:将所有目标版本的镜像均通过全量镜像的方式打包获得的升级包。
    • 差分OTA升级包:对源版本和目标版本差分,获得两个版本镜像之间的差异,以这种方式打包制作升级包。
    • 变分区OTA升级包:对分区表、镜像全量数据用于变分区处理和变分区后的镜像恢复的升级包。
  • OTA实现原理:利用升级包制作工具,将编译出的版本打包生成升级包。厂商设备集成 OTA 升级能力后,将升级包上传至服务器,通过升级应用下载升级包,触发并完成升级。
    OpenHarmony采用AB升级机制,即设备有一套备份的B系统,在A系统运行时,可以在正常使用的状态下,静默更新B系统,升级成功后,重启切换新系统,实现版本更新的机制。

  • OpenHarmony OTA升级的约束与限制

    • 支持基于Hi3861/Hi3516DV300/RK3568芯片的开源套件。
    • 对Hi3516DV300/RK3568开源套件,设备需要支持SD卡(VFAT格式)。
    • 生成升级包需要在linux系统下面执行。
    • 目前轻量和小型系统仅支持全量包升级,暂不支持差分包、变分区包升级。
    • AB 升级只适用于标准系统支持 AB 分区启动的设备。

三、OTA 全量包制作和本地升级

本章介绍OpenHarmony 4.0 OTA全量包的制作和本地升级步骤。

3.1 OTA 全量包制作

在运行脚本制作OTA包前,先安装必要的工具

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install bsdiff
$ sudo pip install xmltodict asn1crypto imgdiff cryptography e2fsdroid
  • 1
  • 2
  • 3
  • 4

3.1.1 添加差异(可省略)

为了验证OTA的升级成功与否,可在升级包制作前,对源码添加易于识别的差异,例如:
修改授权管理应用TAG信息
applications/standard/permission_manager/permissionmanager/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts

 import deviceInfo from '@ohos.deviceInfo';
 
-var TAG = "PermissionManager_Log:";
+var TAG = "PermissionManager_Log A:";
 const BG_COLOR = '#00000000'
  • 1
  • 2
  • 3
  • 4
  • 5

3.1.2 全量编译,生成images和updater_binary

全量编译源码

$ ./build.sh --product-name=rk3568 --ccache
  • 1

得到系统镜像文件images和二进制升级文件updater_binary:

  • images:out\rk3568\packages\phone\images
out/rk3568/packages/phone/images/
├── boot_linux.img
├── chip_prod.img
├── config.cfg
├── MiniLoaderAll.bin
├── parameter.txt
├── ramdisk.img
├── resource.img
├── sys_prod.img
├── system.img
├── uboot.img
├── updater.img
├── userdata.img
└── vendor.img
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • updater_binary:out\rk3568\packages\phone\system\bin\updater_binary

3.1.3 制作OTA 全量包

进入OTA打包工具目录,并创建target_package、output_package和sign_cert文件夹

$ cd base/update/packaging_tools
$ mkdir target_package output_package sign_cert
  • 1
  • 2

sign_cert放入公钥:signing_cert.crt,取自base/update/updater/test/unittest/test_data/src/signing_cert.crt

target_package放入要打包生成OTA全量包的如下文件

  • 私钥:rsa_private_key2048.pem,取自base/update/updater/test/unittest/test_data/src/rsa_private_key2048.pem
  • 镜像文件:取自out/rk3568/packages/phone/images/
  • 二进制升级文件:updater_binary,取自out/rk3568/packages/phone/system/bin/updater_binary
  • 升级组件配置文件夹updater_config,其中放入:
    • 升级包支持的产品列表:BOARD.list,取自device/board/hisilicon/hispark_taurus/linux/updater/config/BOARD.list
#BOARD.list 添加一行"RK3568",内容如下:
HI3516
RK3568
  • 1
  • 2
  • 3

注意:HI3516必须有,否则OTA包校验失败而导致OTA升级失败,因为代码匹配BOARD时,固定了默认值:
base/updater/updater/utils/utils.cpp

std::string GetLocalBoardId()
  {
      return "HI3516";
  }
  • 1
  • 2
  • 3
  • 4
  • 升级包所支持的版本范围:VERSION.mbn,取自device/board/hisilicon/hispark_taurus/linux/updater/config/VERSION.mbn
    VERSION.mbn与设置的软件版本保持一致即可:
#VERSION.mbn 内容如下
OpenHarmony 4.0.10.15
  • 1
  • 2

软件版本信息

  • 组件配置文件:updater_specified_config.xml,device/board/hisilicon/hispark_taurus/linux/system/updater_specified_config.xml
    • 修改fileVersion为2(4.0更新的校验方式)
    • softVersion改为当前软件版本
    • compType改为0,表示全量(1 表示增量)
    • 修改img打包路径,/vendor.img./system.img
<?xml version="1.0"?>
<package>
    <head name="Component header information">
        <info fileVersion="02" prdID="RK3568" softVersion="4.0.10.15" date="2023-08-02" time="16:25">head info</info>
    </head>
    <group name = "Component information">
	<component compAddr="vendor" compId="12" resType="05" compType="0" compVer="1.0">./vendor.img</component>
	<component compAddr="system" compId="18" resType="05" compType="0" compVer="1.0">./system.img</component>
    </group>
</package>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

得target_package目录结构如下:

$ tree target_package/
target_package/
├── MiniLoaderAll.bin
├── boot_linux.img
├── chip_prod.img
├── config.cfg
├── eng_system.img
├── parameter.txt
├── ramdisk.img
├── resource.img
├── rsa_private_key2048.pem
├── sys_prod.img
├── system.img
├── uboot.img
├── updater.img
├── updater_binary
├── updater_config
│   ├── BOARD.list
│   ├── VERSION.mbn
│   └── updater_specified_config.xml
├── userdata.img
└── vendor.img
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • OTA全量包打包命令如下
    python3 build_update.py ./target_package/ ./output_package/ -pk ./target_package/rsa_private_key2048.pem
packaging_tools$ python3 build_update.py ./target_package/ ./output_package/ -pk ./target_package/rsa_private_key2048.pem
2023-12-09 10:25:45 INFO : VERSION.mbn file parsing complete! path: ./target_package/updater_config/VERSION.mbn
2023-12-09 10:25:45 INFO : BOARD.list file parsing complete! path: ./target_package/updater_config/BOARD.list
2023-12-09 10:25:45 INFO : XML file parsing completed!
2023-12-09 10:25:45 INFO : []
2023-12-09 10:25:51 INFO : Image vendor full processing completed
2023-12-09 10:26:15 INFO : Image system full processing completed
2023-12-09 10:26:15 INFO : All full image processing completed! image count: 2
2023-12-09 10:26:16 INFO : Get hash content success! path: ./target_package/updater_config/VERSION.mbn
2023-12-09 10:26:16 INFO : Get hash content success! path: ./target_package/updater_config/BOARD.list
2023-12-09 10:26:17 INFO : Get hash content success! path: /home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/target_package/full_imagevendoro3df0vi_
2023-12-09 10:26:26 INFO : Get hash content success! path: /home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/target_package/full_imagesystemy76hegkf
2023-12-09 10:26:26 INFO : Write package header complete
2023-12-09 10:26:26 INFO : Add component b'/version_list'
2023-12-09 10:26:26 INFO : component information  StartOffset:180
2023-12-09 10:26:26 INFO : Add component b'/board_list'
2023-12-09 10:26:26 INFO : component information  StartOffset:267
2023-12-09 10:26:26 INFO : Add component b'/vendor'
2023-12-09 10:26:26 INFO : component information  StartOffset:354
2023-12-09 10:26:26 INFO : Add component b'/system'
2023-12-09 10:26:26 INFO : component information  StartOffset:441
2023-12-09 10:26:26 INFO : Write hashdata sign tlv complete
2023-12-09 10:26:26 INFO : .bin package header signing success! SignOffset: 806
2023-12-09 10:26:26 INFO : Add component to package  StartOffset:806
2023-12-09 10:26:26 INFO : Write component complete  ComponentSize:22
2023-12-09 10:26:26 INFO : Add component to package  StartOffset:828
2023-12-09 10:26:26 INFO : Write component complete  ComponentSize:14
2023-12-09 10:26:26 INFO : Add component to package  StartOffset:842
2023-12-09 10:26:27 INFO : Write component complete  ComponentSize:268431360
2023-12-09 10:26:27 INFO : Add component to package  StartOffset:268432202
2023-12-09 10:26:38 INFO : Write component complete  ComponentSize:1610608640
2023-12-09 10:26:38 INFO : Write update package complete
2023-12-09 10:26:38 INFO : Create update package .bin complete! path: /home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/output_package/update_bin-fqvz8mcy
2023-12-09 10:26:38 INFO : Verse-script.us generation complete!
2023-12-09 10:26:38 INFO : loadScript.us generation complete!
2023-12-09 10:26:38 INFO : []
2023-12-09 10:27:20 INFO : []
2023-12-09 10:27:23 INFO : Resource cleaning completed!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

得到生成的全量包:packaging_tools\output_package\updater_full.zip

3.2 OTA全量包本地升级

将制作好的全量包updater_full.zip放入设备,并设置reboot模式

> hdc file send xxx\OHOS\OpenHarmony_v4.0_Release\OTA_Package\output_package\updater_full.zip /data/updater/updater.zip
FileTransfer finish, Size:315251542, File count = 1, time:35248ms rate:8943.81kB/s

> hdc shell
#write_updater updater /data/updater/updater.zip 
#reboot updater
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

OpenHarmony 3.2 OTA本地升级

升级成功后,设备自动重启。

3.3 验证

打开桌面音乐应用
音乐
弹出用于授权弹框
在这里插入图片描述
使用IDE 过滤“PermissionManager_Log A”,结果如下

08-05 20:26:14.659 1659-1659/? I A0fefe/JsApp: PermissionManager_Log A:ServiceExtensionAbility onCreate, ability name is com.ohos.permissionmanager.GrantAbility
08-05 20:26:14.664 1659-1659/? I A0fefe/JsApp: PermissionManager_Log A:ServiceExtensionAbility onRequest. start id is 1
08-05 20:26:14.664 1659-1659/? I A0fefe/JsApp: PermissionManager_Log A:want: {"deviceId":"","bundleName":"com.ohos.permissionmanager","abilityName":"com.ohos.permissionmanager.GrantAbility","moduleName":"permissionmanager","uri":"","type":"","flags":0,"action":"","parameters":{"component.startup.newRules":true,"moduleName":"permissionmanager","ohos.aafwk.param.callerPid":1625,"ohos.aafwk.param.callerToken":537601482,"ohos.aafwk.param.callerUid":20010030,"ohos.ability.params.callback":{"type":"RemoteObject","value":{}},"ohos.ability.params.token":{"type":"RemoteObject","value":{}},"ohos.user.grant.permission":["ohos.permission.DISTRIBUTED_DATASYNC"],"ohos.user.grant.permission.state":[1]},"entities":[]}
08-05 20:26:14.669 1659-1659/? I A0fefe/JsApp: PermissionManager_Log A:create window
  • 1
  • 2
  • 3
  • 4

说明全量OTA升级成功且生效。

3.4 异常

若升级失败,重启设备后取出/data/updater/log/updater_log,结合代码进行具体分析。

> hdc file recv /data/updater/log/updater_log C:\Users\xxx\Desktop\ota.log
  • 1

例如:
现象:OTA全量升级,升级进度条即将跑完时,提示升级失败。
log部分内容如下:

2017-08-05 12:24:11  [INFO]UPDATER pkg_upgradefile.cpp 306 : Component packedSize 1610608640 unpackedSize 1610608640 /system
2017-08-05 12:24:30  [INFO]UPDATER pkg_pkgfile.cpp 70 : ExtractFile /data/updater/build_tools.zip.tmp
2017-08-05 12:24:30  [INFO]UPDATER pkg_zipfile.cpp 578 : packedSize: 1067369 unpackedSize: 1067800  offset header: 314190358 data: 314190403
2017-08-05 12:24:30  [INFO]UPDATER pkg_zipfile.cpp 161 : LoadPackage /data/updater/build_tools.zip.tmp :1067800
2017-08-05 12:24:30  [INFO]UPDATER pkg_zipfile.cpp 634 : packedSize: 94 unpackedSize: 156  offset header: 0 data: 45 Verse-script.us
2017-08-05 12:24:30  [INFO]UPDATER pkg_zipfile.cpp 634 : packedSize: 1067341 unpackedSize: 1661888  offset header: 139 data: 183 updater_binary
2017-08-05 12:24:30  [INFO]UPDATER pkg_zipfile.cpp 634 : packedSize: 31 unpackedSize: 33  offset header: 1067524 data: 1067567 loadScript.us
2017-08-05 12:24:30  [INFO]UPDATER updater.cpp 211 : Package bin file verified. start to install package...
2017-08-05 12:24:30  [INFO]UPDATER pkg_pkgfile.cpp 70 : ExtractFile /board_list
2017-08-05 12:24:30  [INFO]UPDATER pkg_upgradefile.cpp 515 : Unpack /board_list data offset:1205 packedSize:6 unpackedSize:6
2017-08-05 12:24:30  [INFO]UPDATER updater_preprocess.cpp 86 : Check board list success 
2017-08-05 12:24:30  [INFO]UPDATER updater_preprocess.cpp 60 : current version:OpenHarmony 4.0.10.13
2017-08-05 12:24:30  [INFO]UPDATER pkg_pkgfile.cpp 70 : ExtractFile /version_list
2017-08-05 12:24:30  [INFO]UPDATER pkg_upgradefile.cpp 515 : Unpack /version_list data offset:1184 packedSize:21 unpackedSize:21
2017-08-05 12:24:30  [ERROR]UPDATER updater.cpp 213 : Version Check Fail...
2017-08-05 12:24:32  [INFO]UPDATER misc_info.cpp 94 : WriteUpdaterMiscMsg::misc path : /dev/block/platform/fe310000.sdhci/by-name/misc
2017-08-05 12:24:32  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 52
2017-08-05 12:24:34  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 76
2017-08-05 12:24:36  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 88
2017-08-05 12:24:38  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 94
2017-08-05 12:24:40  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 97
2017-08-05 12:24:42  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 98
2017-08-05 12:24:44  [INFO]UPDATER updater_ui_facade.cpp 101 : current progress 99
2017-08-05 12:24:46  [ERROR]UPDATER updater_main.cpp 417 : InstallUpdaterPackage failed! Pkg is /data/updater/updater.zip
2017-08-05 12:24:46  [ERROR]UPDATER utils.cpp 453 : open result file failed
2017-08-05 12:24:46  [ERROR]UPDATER dump.h 44 : 1
2017-08-05 12:24:46  [ERROR]UPDATER updater_main.cpp 437 : read result file error /data/updater/updater_result
2017-08-05 12:24:46  [INFO]UPDATER updater_main.cpp 455 : post over, writeBuffer = /data/updater/updater.zip|fail
2017-08-05 12:24:46  [INFO]UPDATER utils.cpp 465 : WriteDumpResult: /data/updater/updater.zip|fail
2017-08-05 12:25:00  [INFO]UPDATER updater_ui.cpp 103 : On Label Reboot
2017-08-05 12:25:00  [INFO]UPDATER utils.cpp 522 : updater mode
2017-08-05 12:25:00  [INFO]UPDATER mount.cpp 125 : /data already mounted
2017-08-05 12:25:00  [INFO]UPDATER mount.cpp 125 : /data/updater/log already mounted
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

分析:从log可以看出升级至99%时,安装OTA包异常,问题原因是Version Check Fail…,于是检查updater_specified_config.xml和VERSION.mbn,版本信息错位的写为OpenHarmony 4.0.10.14。
解决方案:修改updater_specified_config.xml和VERSION.mbn中版本信息与设备当前软件版本OpenHarmony 4.0.10.13一致,重新制作OTA全量包后升级。

四、OTA差分包制作和升级

4.1、OTA 差分包制作

4.0 release 分支需合入PR
修改组件对应的块错误
base/update/packaging_tools/blocks_manager.py

--- a/blocks_manager.py
+++ b/blocks_manager.py
@@ -27,6 +27,12 @@ class BlocksManager(object):
     def __init__(self, range_data=None):
         self.monotonic = False
         if isinstance(range_data, str):
+            tmp_range = []
+            if range_data != "0":
+                for i in range_data.split():
+                    if i != "0":
+                        tmp_range.append(i) 
+                range_data = ' '.join(tmp_range)
             self.__parse_data_text(range_data)
         elif range_data:
             if len(range_data) % 2 != 0:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

4.1.1 添加差异(可省略)

为了方便后续验证差分包升级是否有效,添加差异方便验证:
applications/standard/permission_manager/permissionmanager/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts

 import deviceInfo from '@ohos.deviceInfo';
 
-var TAG = "PermissionManager_Log:";
+var TAG = "PermissionManager_Log B:";
 const BG_COLOR = '#00000000'
  • 1
  • 2
  • 3
  • 4
  • 5

4.1.2 全量编译,更新images和updater_binary

全量编译源码

$ ./build.sh -p rk3568 --ccache
  • 1

得到系统镜像文件images和二进制升级文件updater_binary:

  • images:out\rk3568\packages\phone\images
out/rk3568/packages/phone/images/
├── boot_linux.img
├── chip_prod.img
├── config.cfg
├── MiniLoaderAll.bin
├── parameter.txt
├── ramdisk.img
├── resource.img
├── sys_prod.img
├── system.img
├── uboot.img
├── updater.img
├── userdata.img
└── vendor.img
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • updater_binary:out\rk3568\packages\phone\system\bin\updater_binary

4.2、制作OTA差分包

4.2.1、创建lib文件夹,放入差分镜像二进制工具

packaging_tools$mkdir lib
packaging_tools$cp -rf ../../../out/rk3568/clang_x64/updater/updater/diff lib/
packaging_tools$ cp -rf ../../../out/rk3568/clang_x64/thirdparty/e2fsprogs/* lib/
  • 1
  • 2
  • 3

得到lib文件夹内容如下:

packaging_tools$ tree lib
lib
├── diff		#取自out/rk3568/clang_x64/updater/updater/
├── e2fsck		#及以下.so文件取自out/rk3568/clang_x64/thirdparty/e2fsprogs
├── e2fsdroid
├── libext2_blkid.so
├── libext2_com_err.so
├── libext2_e2p.so
├── libext2_misc.so
├── libext2_quota.so
├── libext2_uuid.so
├── libext2fs.so
└── mke2fs
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

4.2.2、packaging_tools目录下copy 上一次target_package作为制作差分包的source_package

packaging_tools$ cp -rf target_package/ source_package
  • 1

更新target_package目录文件

  • 替换镜像文件:
packaging_tools$ cp -rf ../../../out/rk3568/packages/phone/images/* target_package/
  • 1
  • 替换二进制升级文件:
packaging_tools$ cp -rf ../../../out/rk3568/packages/phone/system/bin/updater_binary target_package/updater_binary
  • 1
  • 更新target_package/updater_config/updater_specified_config.xml softVersioncompType
#updater_specified_config.xml, 修改softVersion需大于当前系统版本; compType设为1,表示增量;内容如下:
<?xml version="1.0"?>
<package>
    <head name="Component header information">
        <info fileVersion="01" prdID="RK3568" softVersion="4.0.10.16" date="2023-08-02" time="16:25">head info</info>
    </head>
    <group name = "Component information">
	<component compAddr="vendor" compId="12" resType="05" compType="1" compVer="1.0">./vendor.img</component>
	<component compAddr="system" compId="18" resType="05" compType="1" compVer="1.0">./system.img</component>
    </group>
</package>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

4.2.3、OTA差分包打包制作

命令如下:
python3 build_update.py ./target_package/ ./output_package/ -s ./source_package/ -pk ./target_package/rsa_private_key2048.pem

packaging_tools$ python3 build_update.py ./target_package/ ./output_package/ -s ./source_package/ -pk ./target_package/rsa_private_key2048.pem
2023-12-09 11:13:03 INFO : VERSION.mbn file parsing complete! path: ./target_package/updater_config/VERSION.mbn
2023-12-09 11:13:03 INFO : BOARD.list file parsing complete! path: ./target_package/updater_config/BOARD.list
2023-12-09 11:13:03 INFO : XML file parsing completed!
2023-12-09 11:13:03 INFO : []
2023-12-09 11:13:03 INFO : []
2023-12-09 11:13:03 INFO : Apply DIFF type!
2023-12-09 11:13:03 INFO : Apply DIFF type!
2023-12-09 11:13:03 INFO : Apply DIFF type!
...
hoosedialog/input_method_choose_dialog.hap <blocks_manager.BlocksManager object at 0x7f219c499bb0>)
2023-12-09 11:13:40 INFO : Get hash content success! path: ./target_package/updater_config/VERSION.mbn
2023-12-09 11:13:40 INFO : Get hash content success! path: ./target_package/updater_config/BOARD.list
2023-12-09 11:13:40 INFO : Write package header complete
2023-12-09 11:13:40 INFO : Add component b'/version_list'
2023-12-09 11:13:40 INFO : component information  StartOffset:180
2023-12-09 11:13:40 INFO : Add component b'/board_list'
2023-12-09 11:13:40 INFO : component information  StartOffset:267
2023-12-09 11:13:40 INFO : Write hashdata sign tlv complete
2023-12-09 11:13:40 INFO : .bin package header signing success! SignOffset: 632
2023-12-09 11:13:40 INFO : Add component to package  StartOffset:632
2023-12-09 11:13:40 INFO : Write component complete  ComponentSize:22
2023-12-09 11:13:40 INFO : Add component to package  StartOffset:654
2023-12-09 11:13:40 INFO : Write component complete  ComponentSize:14
2023-12-09 11:13:40 INFO : Write update package complete
2023-12-09 11:13:40 INFO : Create update package .bin complete! path: /home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/output_package/update_bin-lt9vc35q
2023-12-09 11:13:40 INFO : Verse-script.us generation complete!
2023-12-09 11:13:40 INFO : loadScript.us generation complete!
2023-12-09 11:13:40 INFO : []
2023-12-09 11:13:40 INFO : []
2023-12-09 11:13:41 INFO : Resource cleaning completed!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

得到差分包output_package/updater_diff.zip

4.3 差分包升级

升级方法同全量包,将制作好的差分包updater_diff.zip放入设备,并设置reboot模式

> hdc file send xxx\OHOS\OpenHarmony_v4.0_Release\OTA_Package\output_package\updater_diff.zip /data/updater/updater.zip
FileTransfer finish, Size:315251542, File count = 1, time:35248ms rate:8943.81kB/s

> hdc shell
#write_updater updater /data/updater/updater.zip 
#reboot updater
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4.4 验证

使用IDE 过滤“PermissionManager_Log”,结果如下

08-05 20:26:14.659 1659-1659/? I A0fefe/JsApp: PermissionManager_Log B:ServiceExtensionAbility onCreate, ability name is com.ohos.permissionmanager.GrantAbility
08-05 20:26:14.664 1659-1659/? I A0fefe/JsApp: PermissionManager_Log B:ServiceExtensionAbility onRequest. start id is 1
08-05 20:26:14.664 1659-1659/? I A0fefe/JsApp: PermissionManager_Log B:want: 
...
  • 1
  • 2
  • 3
  • 4

说明增量OTA升级成功且生效。

五、报错处理

5.1、ModuleNotFoundError: No module named ‘xmltodict’

sudo pip install xmltodict
  • 1

5.2、ModuleNotFoundError: No module named ‘asn1crypto’

sudo pip install asn1crypto
  • 1

5.3、FileNotFoundError: [Errno 2] No such file or directory: ‘/home/…/OpenHarmony_v4.0_release/base/update/packaging_tools/lib/e2fsdroid’

packaging_tools下创建lib文件夹,放入以下文件

packaging_tools$ tree lib
lib
├── diff		#取自out/rk3568/clang_x64/updater/updater/
├── e2fsck		#及以下.so文件取自out/rk3568/clang_x64/thirdparty/e2fsprogs
├── e2fsdroid
├── libext2_blkid.so
├── libext2_com_err.so
├── libext2_e2p.so
├── libext2_misc.so
├── libext2_quota.so
├── libext2_uuid.so
├── libext2fs.so
└── mke2fs
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

5.4 、There is no incremental image, the - S parameter is not required!

packaging_tools$ python3 build_update.py ./target_package/ ./output_package/ -s ./source_package/ -pk ./target_package/rsa_private_key2048.pem
2023-12-09 11:05:58 INFO : VERSION.mbn file parsing complete! path: ./target_package/updater_config/VERSION.mbn
2023-12-09 11:05:58 INFO : BOARD.list file parsing complete! path: ./target_package/updater_config/BOARD.list
2023-12-09 11:05:58 INFO : XML file parsing completed!
2023-12-09 11:05:58 INFO : []
2023-12-09 11:05:58 ERROR : There is no incremental image, the - S parameter is not required!
2023-12-09 11:05:58 ERROR : Uncaught exception
Traceback (most recent call last):
  File "build_update.py", line 897, in <module>
    main()
  File "build_update.py", line 861, in main
    if incremental_processing(
  File "build_update.py", line 768, in incremental_processing
    raise RuntimeError
RuntimeError
2023-12-09 11:05:58 INFO : Exception occurred, Resource cleaning completed!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

制作差分包,未检测到差异镜像,检查target_package/updater_config/updater_specified_config.xml softVersioncompType;softVersion需大于当前版本,compType为1。

5.5 raise RuntimeError

packaging_tools$ python3 build_update.py ./target_package/ ./output_package/ -s ./source_package/ -pk ./target_package/rsa_private_key2048.pem
2023-12-07 10:05:38 INFO : VERSION.mbn file parsing complete! path: ./target_package/updater_config/VERSION.mbn
2023-12-07 10:05:38 INFO : BOARD.list file parsing complete! path: ./target_package/updater_config/BOARD.list
2023-12-07 10:05:38 INFO : XML file parsing completed!
2023-12-07 10:05:38 INFO : []
2023-12-07 10:05:38 ERROR : Uncaught exception
Traceback (most recent call last):
  File "build_update.py", line 897, in <module>
    main()
  File "build_update.py", line 861, in main
    if incremental_processing(
  File "build_update.py", line 757, in incremental_processing
    if increment_image_processing(
  File "build_update.py", line 654, in increment_image_processing
    IncUpdateImage(each_src_image_path, each_src_map_path)
  File "/home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/image_class.py", line 128, in __init__
    self.parse_raw_image_file(image_path, map_path)
  File "/home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/image_class.py", line 167, in parse_raw_image_file
    self.parse_block_map_file(map_path, f_r)
  File "/home/xxx/ohos/OpenHarmony_v4.0_release/base/update/packaging_tools/image_class.py", line 188, in parse_block_map_file
    raise RuntimeError
RuntimeError
2023-12-07 10:05:38 INFO : Exception occurred, Resource cleaning completed!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

4.0 release分支,合入PR:
修改组件对应的块错误
base/update/packaging_tools/blocks_manager.py

--- a/blocks_manager.py
+++ b/blocks_manager.py
@@ -27,6 +27,12 @@ class BlocksManager(object):
     def __init__(self, range_data=None):
         self.monotonic = False
         if isinstance(range_data, str):
+            tmp_range = []
+            if range_data != "0":
+                for i in range_data.split():
+                    if i != "0":
+                        tmp_range.append(i) 
+                range_data = ' '.join(tmp_range)
             self.__parse_data_text(range_data)
         elif range_data:
             if len(range_data) % 2 != 0:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

5.6 IndentationError: unindent does not match any outer indentation level

packaging_tools$ python3 build_update.py ./target_package/ ./output_package/ -pk ./target_package/rsa_private_key2048.pem
2024-01-23 15:59:18 ERROR : Uncaught exception
Traceback (most recent call last):
  File "build_update.py", line 55, in <module>
    import patch_package_process
  File "/home/xxx/OpenHarmony_4.0r/base/update/packaging_tools/patch_package_process.py", line 23, in <module>
    from blocks_manager import BlocksManager
  File "/home/xxx/OpenHarmony_4.0r/base/update/packaging_tools/blocks_manager.py", line 31
    if range_data != "0":
                        ^
IndentationError: unindent does not match any outer indentation level
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

/blocks_manager.py line 31附近存在代码格式缩进错误,查看文件:
在这里插入图片描述
更正缩进格式后运行正常。

六、参考资料

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/329359
推荐阅读
相关标签
  

闽ICP备14008679号