How to realize the OTA upgrade of OpenHarmony

Introduction to OTAs

With the ever-changing equipment systems, how users can obtain system updates in a timely manner, experience the new experience brought by the new version, and improve the stability and security of the system has become a serious problem faced by every manufacturer. OTA (Over the Air) provides the ability to remotely upgrade devices. The upgrade subsystem shields the difference of the bottom chip from the user, and provides a unified upgrade interface to the outside world. After the secondary development based on the interface, the manufacturer's equipment (such as IP camera, etc.) can easily support the remote upgrade capability.

OTA upgrade package type

There are three common types of upgrade packages, mainly including: full upgrade package, differential upgrade package, and variable partition upgrade package.

• Full upgrade package: The upgrade package only includes the data related to the full upgrade of the image, which is used for the full upgrade of the image;

• Differential upgrade package: The upgrade package only includes data related to mirror differential upgrade, which is used for mirror differential upgrade;

• Changed partition upgrade: The upgrade package includes the partition table and the full data of the mirror image, which are used for changing partition processing and mirror recovery after changing partitions.

scope of application

OpenAtom OpenHarmony ("OpenHarmony") 3.1 Release does not support rich device upgrades. All the examples in this chapter are verified on OpenHarmony 3.2 Beta3. The upgrade method is full upgrade. The development board used is the HCPAD-100 development board designed by ArcherMind Technology based on RK3568 and The DAYU200 development board used by the OpenHarmony backbone. You can use the HCPAD-100 development board or DAYU200 development board to verify, the patch has been provided, other development boards may have differences, please verify by yourself.

OTA upgrade steps

1. Create an upgrade package (update_packaging_tools needs to be switched to the master branch)

1.1 Create the target version (target_package) folder, the file format is as follows:

1.2 Put the components to be upgraded, including image files (for example: system.img), etc., into the root directory of the target version folder, replacing the {component_N} part in the above structure.

1.3 Fill in the component configuration file in the "updater_config" folder.

1.3.1 Configure the list of products supported by the current upgrade package in the "updater_config" folder: BOARD.list.

RK3568

1.3.2 配置“updater_config”文件夹中当前升级包所支持的版本范围:VERSION.mbn。

版本名称格式:RK3568 QP1A.XXXXXX.{大版本号(6位)}.XXX{小版本号(3位)}。例如:RK3568 QP1A.190711.020。名称中“190711”为大版本号,“020”为小版本号。

配置例如下:

RK3568 QP1A.190711.001

1.4 创建“OTA.tag文件”,内容为OTA升级包的魔数,固定如下:

package_type:ota1234567890qwertw //可选

1.5 updater_binary二进制文件

updater_binary该文件为系统编译自动生成,路径:

out/rk3568/packages/phone/updater/bin/updater_binary

1.6 updater_specified_config.xml配置

<?xml version="1.0"?>
<package>    <head name="Component header information">        <info fileVersion="01" prdID="rk3568" softVersion="3.2.2" date="2022-12-07" time="16:25">head info</info>    </head>    <group name = "Component information">    <component compAddr="ota_tag" compId="27" resType="5" compType="0" compVer="1.0">OTA.tag</component>    <component compAddr="vendor" compId="12" resType="05" compType="0" compVer="1.0">vendor.img</component><component compAddr="system" compId="12" resType="05" compType="0" compVer="1.0">system.img</component>    </group></package>

1.7 执行升级包制作命令

python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key2048.pem

• ./target_package/:指定target_package路径。

• ./output_package/:指定升级包输出路径。

• -pk ./rsa_private_key3072.pem:指定私钥文件路径。

• 此处可以使用系统自带的证书:

device/board/hisilicon/hispark_taurus/linux/updater/config/rsa_private_key2048.pem

注:OpenHarmony 3.2 Beta3分支上base/update/packaging_tools仓制作updater升级包校验有BUG,会失败。开发者已经在master分支上修复,制作升级包前请同步master上最新代码。

2.配置服务器

搭建搜包服务器(OTA搜包服务器采用OpenSSL协议传输数据,所以必须使用HTTPS解析),服务器源码见附件sslserver目录。

3.配置网络

3.1 配置客户端服务器信息

为了方便调试,我们提供了本地可配置文件修改方案(patch见附件)。服务器搭建完成后,只需要在开发板配置服务地址,搜包地址,端口号等信息即可完成搜包,下载等功能。

配置路径:/system/etc/serverInfo.json

{    "serverIp": "115.126.57.xx", //服务器ip    "serverSearch": "115.126.57.xx", //搜包服务器    "serverPort":9556  //端口号}

3.2 Beta3分支默认route路由是关闭的,只要先打开route才能连接外网。搜包前先要替换toybox文件,配置好的toybox已在附件中提供,直接通过hdc_std file send toybox(路径) /system/bin/ 替换即可。

3.3 导入signing_cert.crt证书

hdc_std file send signing_cert.crt(路径) /data/ota_package

3.4 配置路由地址

hdc_std shell

route add default gw 10.51.11.1 dev eth1 //10.51.11.1是网关地址,根据实际情况配置,如果不知道如何查看网关,请联系你们的网络管理员。

ping www.huawei.com //ping确认是否可以联网

3.4 为了方便观察效果,可通过hdc_std shell power-shell setmode 602命令,将屏幕设置为常亮。

4. 升级客服端代码实例

需要权限:

ohos.permission.UPDATE_SYSTEM和ohos.permission.INTERNET,系统权限需要使用FULL_SDK.

4.1 获取在线升级对象

//调用方包名,若在设置中插入升级,可添加为设置应用的包名const PACKAGE_NAME = "com.ohos.ota.updateclient";let upgradeInfo = {  upgradeApp: PACKAGE_NAME,  businessType: {    vendor: "HZOS",    subType: 1  }}page.data.updater = client.getOnlineUpdater(upgradeInfo);

4.2 获取版本信息

4.2.1 获取升级任务信息

page.data.updater.getTaskInfo().then(taskInfo => {  //...}); //返回任务信息对象

4.2.2 检查新版本信息

page.data.updater.checkNewVersion().then(data => {  //...}); //返回搜包结果对象

4.2.3 获取新版本信息

page.data.updater.getNewVersionInfo().then(data => {  //...}); //返回新版本信息对象

4.3 版本下载

调用download(versionDigestInfo, downloadOptions) 下载新版本。

let versionDigestInfo = {  versionDigest: "versionDigest" // 检测结果中的版本摘要信息};let downloadOptions = {  allowNetwork: 1,  order: 1}page.data.updater.download(versionDigestInfo, downloadOptions).then(result => {  console.info(TAG + "updater download result: " + JSON.stringify(result));}).catch(error => {  console.error(TAG + "updater download error: " + JSON.stringify(error));});

4.4 安装新版本

调用upgrade(versionDigestInfo, upgradeOptions),安装新版本,开发板会重启进入系统升级页面,待系统升级完成。

clickInstall: function () {  if (page.data.pageType == "downSuccess") { // 下载成功,开始升级    page.upgrade();  }},upgrade() {  if (page.data.updater == undefined) {    //...    return;  }  page.data.updater.on(eventClassifyInfo, eventInfo => {    console.info(TAG + "upgrade eventInfo: " + JSON.stringify(eventInfo));    //...  });  let upgradeOptions = {    order: 2 //安装  }  page.data.updater.upgrade(versionDigestInfo, upgradeOptions).then(result => {    console.info(TAG + "upgrade result: " + JSON.stringify(result));  }).catch(error => {    console.error(TAG + "upgrade error: " + JSON.stringify(error));  });}

进入updater模式,升级过程中会提示“正在更新 请勿重启”。

升级完成后页面会提示“升级完成”,之后重启。

升级完成后,再次校验当前版本信息,提示当前已是最新版本。

OTA升级调试

正常模式:在该路径下data/updater/log获取updater_log、updater_stage_log、error_code.log三份日志文件。

updater模式:在该路径下tmp/获取updater.log、updater_stage.log、error_code.log三份日志文件。

updater.log搜索关键字fail即可快速定位问题。

总结

OpenHarmony OTA升级主要是搭建搜包服务器,制作升级包,了解OTA下载包管理,包解析,包管理的代码逻辑。同时,对于常见问题知道如何快速定位!

参考链接

升级客户端应用、服务器源码

https://gitee.com/wanfan_yyds/upgrade3.2

基于OpenHarmony 3.2 Beta3分支源码的patch

https://gitee.com/wanfan_yyds/update_updateservice/commit/44e28bb1d8d84b200348c5ad03f9f4ce3bad3e1e

https://gitee.com/wanfan_yyds/update_updater/commit/0fe02cec5b21bd3f9a47c4e5a0fd0e5790088703

参考文献

https://docs.openharmony.cn/pages/v3.2Beta/zh-cn/application-dev/reference/apis/js-apis-update.md/

https://gitee.com/openharmony/update_updater

https://gitee.com/openharmony/update_updateservice

https://gitee.com/openharmony/update_update_app

https://gitee.com/openharmony/update_packaging_tools

Guess you like

Origin blog.csdn.net/OpenHarmony_dev/article/details/128914005