同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Over the Air (OTA) is a technology that makes it easier for you to remotely update devices, such as IP cameras. Currently, the mini and small systems support update using a full package, but not a differential package. A full package contains all content of a new system, and a differential package contains the differences between the old and new systems.
Only the open-source suites for devices powered by Hi3861, Hi3518E V300, and Hi3516D V300 are supported.
Devices developed based on Hi3518E V300 and Hi3516D V300 must support the SD card in the Virtual Festival of Aerobatic Teams (VFAT) format.
NOTE: Generation of update packages can only be performed on the Linux system.
Download the OpenSSL tool, install it on a Windows PC, and configure environment variables.
Use the OpenSSL tool to generate a public/private key pair.
Keep the private key file properly as this file stores the private key used to sign the update package. You need to specify the private key file in the command used for preparing the update package. The public key is used to verify the signature of the update package during the upgrade, and it is stored as follows:
For the mini and small systems, the generated public key is preset in the code. The vendor needs to implement the HotaHalGetPubKey API to obtain the key. For the standard system, the generated public key is stored in the ./device/hisilicon/hi3516dv300/build/updater_config/signing_cert.crt file.
For the mini and small systems that use the Hi3518E V300 or Hi3516D V300 suite, also use the content in public_arr.txt to replace the content in g_pub_key in the device\hisilicon\third_party\uboot\u-boot-2020.01\product\hiupdate\verify\update_public_key.c file of the U-Boot module.
Example configuration for the public key of the U-Boot module:
static unsigned char g_pub_key[PUBKEY_LEN] = {
0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01,
0x00, 0xBF, 0xAA, 0xA5, 0xB3, 0xC2, 0x78, 0x5E,
}
Create the target_package folder with the following directory structure:
target_package
├── OTA.tag
├── config
├── {component_1}
├── {component_2}
├── ...
├── {component_N}
└── updater_config
└── updater_specified_config.xml
Place the components to be updated, including the image file (for example, rootfs.img), as {component_N} in the root directory of the target_package folder.
Configure the updater_specified_config.xml file in the update_config folder.
Example configuration of the updater_specified_config.xml file:
<?xml version="1.0"?>
<package>
<head name="Component header information">
<info fileVersion="01" prdID="hisi" softVersion="OpenHarmony x.x" date="202x.xx.xx" time="xx:xx:xx">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="config" compId="23" resType="5" compType="0" compVer="1.0">./config</component>
<component compAddr="bootloader" compId="24" resType="5" compType="0" compVer="1.0">./u-boot-xxxx.bin</component>
</group>
</package>
Table 1 Description of nodes in the component configuration file
NOTE: As mini and small systems do not support update using a differential package, compType must be set to 0, other than 1. For mini and small systems, an update package cannot be created by changing partitions.
Create the OTA.tag file, which contains the magic number of the update package. The magic number is as follows:
package_type:ota1234567890qwertw
Create the config file, and configure the bootargs and bootcmd information in the file.
Example configuration:
setenv bootargs 'mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M
(u-boot.bin),9M(kernel.bin),50M(rootfs_ext4.img),50M(userfs.img)' setenv bootcmd 'mmc read 0x0 0x82000000 0x800 0x4800;bootm 0x82000000'
Generate the update package.
python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key3072.pem -nz -nl2x
Create the target_package folder with the following directory structure:
target_package
├── {component_1}
├── {component_2}
├── ...
├── {component_N}
└── updater_config
├── BOARD.list
├── VERSION.mbn
└── updater_specified_config.xml
Place the components to be updated, including the image file (for example, system.img), as {component_N} in the root directory of the target_package folder.
Configure the component configuration file in the update_config folder.
Configure the list of products supported by the current update package in BOARD.list in the update_config folder.
Example configuration:
HI3516
HI3518
Configure the versions supported by the current update package in VERSION.mbn in the update_config folder.
Version number format: Hi3516DV300-eng 10 QP1A.XXXXXX.{Major version number (6 digits)}.XXX{Minor version number (3 digits)}
For example, Hi3516DV300-eng 10 QP1A.190711.020, where 190711 is the major version number, and 020 is the minor version number.
Example configuration:
Hi3516DV300-eng 10 QP1A.190711.001
Hi3516DV300-eng 10 QP1A.190711.020
Hi3518DV300-eng 10 QP1A.190711.021
For update using an incremental (differential) package, also prepare a source version package (source_package) in the same format as the target version package (target_package), and then compress it as a .zip file, that is, source_package.zip.
If you create an update package with partitions changed, also provide the partition table file named partition_file.xml. You can specify the file using the -pf parameter. For details about the configuration nodes, see the description below.
The partition table is generated with the image. The format is as follows:
<?xml version="1.0" encoding="GB2312" ?>
<Partition_Info>
<Part Sel="1" PartitionName="Image 1" FlashType="Flash type" FileSystem="File system type" Start="Start address of the partition" Length="Size of the partition" SelectFile="Actual path of the image"/>
<Part Sel="1" PartitionName="Image 2" FlashType="Flash type" FileSystem="File system type" Start="Start address of the partition" Length="Size of the partition" SelectFile="Actual path of the image"/>
</Partition_Info>
Table 2 Description of labels in the partition table
Generate the update package.
Full package
Run the following command:
python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key3072.pem
Incremental (differential) package
Run the following command:
python build_update.py ./target_package/ ./output_package/ -s ./source_package.zip -pk ./rsa_private_key3072.pem
Update package with partitions changed
Run the following command:
python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key3072.pem -pf ./partition_file.xml
Upload the update package to the vendor's OTA server.
For mini and small systems
If a vendor requests OTA capabilities, use the dynamic library libhota.so and include the header files hota_partition.h and hota_updater.h in base\update\ota_lite\interfaces\kits.
The libhota.so source code is stored in base\update\ota_lite\frameworks\source.
For details about how to use APIs, see API Application Scenario and OTA APIs in API Reference.
If the development board needs to be adapted, see the base\update\ota_lite\hals\hal_hota_board.h file.
For the standard system, see the Reference Specifications for details.
The update package is generated by following the instructions provided in Generating a Public/Private Key Pair and Generating an Update Package.
Download the update package for the current device, and then call the HotaInit function to initialize the OTA module.
Call the HotaWrite function to verify, parse, and write data streams into the device.
Call the HotaRestart function to restart the system for the update to take effect. Call the HotaCancel function if you want to cancel the update.
Perform an OTA update using the update package format and verification method provided by OpenHarmony.
int main(int argc, char **argv)
{
printf("this is update print!\r\n");
if (HotaInit(NULL, NULL) < 0) {
printf("ota update init fail!\r\n");
return -1;
}
int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("file open failed, fd = %d\r\n", fd);
(void)HotaCancel();
return -1;
}
int offset = 0;
int fileLen = lseek(fd, 0, SEEK_END);
int leftLen = fileLen;
while (leftLen > 0) {
if (lseek(fd, offset, SEEK_SET) < 0) {
close(fd);
printf("lseek fail!\r\n");
(void)HotaCancel();
return -1;
}
int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
(void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
if (read(fd, g_readBuf, tmpLen) < 0) {
close(fd);
printf("read fail!\r\n");
(void)HotaCancel();
return -1;
}
if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) {
printf("ota write fail!\r\n");
close(fd);
(void)HotaCancel();
return -1;
}
offset += READ_BUF_LEN;
leftLen -= tmpLen;
}
close(fd);
printf("ota write finish!\r\n");
printf("device will reboot in 10s...\r\n");
sleep(10);
(void)HotaRestart();
return 0;
}
The update package is generated in other ways instead of following the instructions provided in Generating a Public/Private Key Pair and Generating an Update Package.
Download the update package for the current device, and then call the HotaInit function to initialize the OTA module.
Call the HotaSetPackageType function to set the package type to NOT_USE_DEFAULT_PKG.
Call the HotaWrite function to write data streams into the device.
Call the HotaRead function to read data. Vendors can choose whether to verify the data.
(Optional) Call the HotaSetBootSettings function to set the startup tag used for entering the U-Boot mode during system restarting.
Call the HotaRestart function to restart the system for the update to take effect. Call the HotaCancel function if you want to cancel the update.
Perform an OTA update using the update package format and verification method not provided by OpenHarmony.
int main(int argc, char **argv)
{
printf("this is update print!\r\n");
if (HotaInit(NULL, NULL) < 0) {
printf("ota update init fail!\r\n");
(void)HotaCancel();
return -1;
}
(void)HotaSetPackageType(NOT_USE_DEFAULT_PKG);
int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("file open failed, fd = %d\r\n", fd);
(void)HotaCancel();
return -1;
}
int offset = 0;
int fileLen = lseek(fd, 0, SEEK_END);
int leftLen = fileLen;
while (leftLen > 0) {
if (lseek(fd, offset, SEEK_SET) < 0) {
close(fd);
printf("lseek fail!\r\n");
(void)HotaCancel();
return -1;
}
int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
(void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
if (read(fd, g_readBuf, tmpLen) < 0) {
close(fd);
printf("read fail!\r\n");
(void)HotaCancel();
return -1;
}
if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) {
printf("ota write fail!\r\n");
close(fd);
(void)HotaCancel();
return -1;
}
offset += READ_BUF_LEN;
leftLen -= tmpLen;
}
close(fd);
printf("ota write finish!\r\n");
leftLen = fileLen;
while (leftLen > 0) {
int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
(void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
if (HotaRead(offset, READ_BUF_LEN, (unsigned char *)g_readBuf) != 0) {}
printf("ota write fail!\r\n");
(void)HotaCancel();
return -1;
}
/* do your verify and parse */
offset += READ_BUF_LEN;
leftLen -= tmpLen;
}
/* set your boot settings */
(void)HotaSetBootSettings();
printf("device will reboot in 10s...\r\n");
sleep(10);
(void)HotaRestart();
return 0;
}
Vendor applications call APIs of the OTA module to perform functions such as signature verification of the update package, anti-rollback, burning and data flushing-to-disk. After the update is complete, the system automatically restarts.
For the mini and small systems that use the Hi3518E V300 or Hi3516D V300 open source suite, add the value of LOCAL_VERSION to the version that needs to implement the anti-rollback function. For example, for "ohos default 1.0"->"ohos default 1.1", add the value of LOCAL_VERSION in device\hisilicon\third_party\uboot\u-boot-2020.01\product\hiupdate\ota_update\ota_local_info.c.
Example for modification of the local version:
const char *get_local_version(void)
{
#if defined(CONFIG_TARGET_HI3516EV200) || \
defined(CONFIG_TARGET_HI3516DV300) || \
defined(CONFIG_TARGET_HI3518EV300)
#define LOCAL_VERSION "ohos default 1.0" /* increase: default release version */
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。