• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# OTA Update<a name="EN-US_TOPIC_0000001163932574"></a>
2
3## Introduction<a name="section753413913562"></a>
4
5Over 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.
6
7## Constraints<a name="section61232796162135"></a>
8
9-   Only the open-source suites for devices powered by Hi3861, Hi3518E V300, and Hi3516D V300 are supported.
10-   Devices developed based on Hi3518E V300 and Hi3516D V300 must support the SD card in the Virtual Festival of Aerobatic Teams \(VFAT\) format.
11
12    >![](../public_sys-resources/icon-note.gif) **NOTE:**
13    >Generation of update packages can only be performed on the Linux system.
14
15
16## Generating a Public/Private Key Pair<a name="section1392711588162135"></a>
17
181.  Download the  [OpenSSL](http://slproweb.com/products/Win32OpenSSL.html)  tool, install it on a Windows PC, and configure environment variables.
192.  Use the OpenSSL tool to generate a public/private key pair.
203.  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:
21
22    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.
23
244.  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.
25
26    Example configuration for the public key of the U-Boot module:
27
28    ```
29    static unsigned char g_pub_key[PUBKEY_LEN] = {
30        0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01,
31        0x00, 0xBF, 0xAA, 0xA5, 0xB3, 0xC2, 0x78, 0x5E,
32    }
33    ```
34
35
36## Generating an Update Package<a name="section704519924162135"></a>
37
38### Mini and Small Systems<a name="section527064658162135"></a>
39
401.  Create the  **target\_package**  folder with the following directory structure:
41
42    ```
43     target_package
44     ├── OTA.tag
45     ├── config
46     ├── {component_1}
47     ├── {component_2}
48     ├── ...
49     ├── {component_N}
50     └── updater_config
51         └── updater_specified_config.xml
52    ```
53
542.  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.
553.  Configure the  **updater\_specified\_config.xml**  file in the  **update\_config**  folder.
56
57    Example configuration of the  **updater\_specified\_config.xml**  file:
58
59    ```
60    <?xml version="1.0"?>
61    <package>
62        <head name="Component header information">
63            <info fileVersion="01" prdID="hisi" softVersion="OpenHarmony x.x" date="202x.xx.xx" time="xx:xx:xx">head info</info>
64        </head>
65        <group name="Component information">
66        <component compAddr="ota_tag" compId="27" resType="5" compType="0" compVer="1.0">./OTA.tag</component>
67        <component compAddr="config" compId="23" resType="5" compType="0" compVer="1.0">./config</component>
68        <component compAddr="bootloader" compId="24" resType="5" compType="0" compVer="1.0">./u-boot-xxxx.bin</component>
69        </group>
70    </package>
71    ```
72
73    **Table 1**  Description of nodes in the component configuration file
74
75    <a name="table252476175162135"></a>
76    <table><thead align="left"><tr id="row479509028162135"><th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.1"><p id="entry1406757300162135p0"><a name="entry1406757300162135p0"></a><a name="entry1406757300162135p0"></a>Type</p>
77    </th>
78    <th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.2"><p id="entry442152588162135p0"><a name="entry442152588162135p0"></a><a name="entry442152588162135p0"></a>Node Name</p>
79    </th>
80    <th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.3"><p id="entry1001010016162135p0"><a name="entry1001010016162135p0"></a><a name="entry1001010016162135p0"></a>Node Label</p>
81    </th>
82    <th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.4"><p id="entry523786033162135p0"><a name="entry523786033162135p0"></a><a name="entry523786033162135p0"></a>Mandatory</p>
83    </th>
84    <th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.5"><p id="entry1703280805162135p0"><a name="entry1703280805162135p0"></a><a name="entry1703280805162135p0"></a>Description</p>
85    </th>
86    </tr>
87    </thead>
88    <tbody><tr id="row1146183787162135"><td class="cellrowborder" rowspan="6" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p id="p1965185185211"><a name="p1965185185211"></a><a name="p1965185185211"></a>Header information (head node)</p>
89    </td>
90    <td class="cellrowborder" rowspan="6" valign="top" width="20%" headers="mcps1.1.6.1.2 "><p id="entry787291920162135p0"><a name="entry787291920162135p0"></a><a name="entry787291920162135p0"></a>info</p>
91    </td>
92    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.3 "><p id="entry1321423743162135p0"><a name="entry1321423743162135p0"></a><a name="entry1321423743162135p0"></a>/</p>
93    </td>
94    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p id="entry414082731162135p0"><a name="entry414082731162135p0"></a><a name="entry414082731162135p0"></a>Yes</p>
95    </td>
96    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p id="entry783609139162135p0"><a name="entry783609139162135p0"></a><a name="entry783609139162135p0"></a>Content of this node: head info</p>
97    </td>
98    </tr>
99    <tr id="row1958159196162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry1679905595162135p0"><a name="entry1679905595162135p0"></a><a name="entry1679905595162135p0"></a>fileVersion</p>
100    </td>
101    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry658282018162135p0"><a name="entry658282018162135p0"></a><a name="entry658282018162135p0"></a>Yes</p>
102    </td>
103    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1810096705162135p0"><a name="entry1810096705162135p0"></a><a name="entry1810096705162135p0"></a>This field is reserved and does not affect the generation of the update package.</p>
104    </td>
105    </tr>
106    <tr id="row147166457162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry1081707070162135p0"><a name="entry1081707070162135p0"></a><a name="entry1081707070162135p0"></a>prdID</p>
107    </td>
108    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry1297695863162135p0"><a name="entry1297695863162135p0"></a><a name="entry1297695863162135p0"></a>Yes</p>
109    </td>
110    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry876347577162135p0"><a name="entry876347577162135p0"></a><a name="entry876347577162135p0"></a>This field is reserved and does not affect the generation of the update package.</p>
111    </td>
112    </tr>
113    <tr id="row713278098162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry1527725234162135p0"><a name="entry1527725234162135p0"></a><a name="entry1527725234162135p0"></a>softVersion</p>
114    </td>
115    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry1298699378162135p0"><a name="entry1298699378162135p0"></a><a name="entry1298699378162135p0"></a>Yes</p>
116    </td>
117    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1986606994162135p0"><a name="entry1986606994162135p0"></a><a name="entry1986606994162135p0"></a>Software version number, that is, the version number of the update package. The version number must be within the range specified by <strong id="b1587416137107"><a name="b1587416137107"></a><a name="b1587416137107"></a>VERSION.mbn</strong>. Otherwise, an update package will not be generated.</p>
118    </td>
119    </tr>
120    <tr id="row1998569355162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry40037754162135p0"><a name="entry40037754162135p0"></a><a name="entry40037754162135p0"></a>date</p>
121    </td>
122    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry1867473067162135p0"><a name="entry1867473067162135p0"></a><a name="entry1867473067162135p0"></a>Yes</p>
123    </td>
124    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1898510646162135p0"><a name="entry1898510646162135p0"></a><a name="entry1898510646162135p0"></a>Date when the update package is generated. This field is reserved and does not affect the generation of the update package.</p>
125    </td>
126    </tr>
127    <tr id="row853604644162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry341395756162135p0"><a name="entry341395756162135p0"></a><a name="entry341395756162135p0"></a>time</p>
128    </td>
129    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry411979929162135p0"><a name="entry411979929162135p0"></a><a name="entry411979929162135p0"></a>Yes</p>
130    </td>
131    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1952723593162135p0"><a name="entry1952723593162135p0"></a><a name="entry1952723593162135p0"></a>Time when the update package is generated. This field is reserved and does not affect the generation of the update package.</p>
132    </td>
133    </tr>
134    <tr id="row311903547162135"><td class="cellrowborder" rowspan="5" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p id="entry1756487158162135p0"><a name="entry1756487158162135p0"></a><a name="entry1756487158162135p0"></a>Component information (group node)</p>
135    </td>
136    <td class="cellrowborder" rowspan="5" valign="top" width="20%" headers="mcps1.1.6.1.2 "><p id="entry2070156141162135p0"><a name="entry2070156141162135p0"></a><a name="entry2070156141162135p0"></a>component</p>
137    </td>
138    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.3 "><p id="entry894043714162135p0"><a name="entry894043714162135p0"></a><a name="entry894043714162135p0"></a>/</p>
139    </td>
140    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p id="entry1899300718162135p0"><a name="entry1899300718162135p0"></a><a name="entry1899300718162135p0"></a>Yes</p>
141    </td>
142    <td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p id="entry1457912275162135p0"><a name="entry1457912275162135p0"></a><a name="entry1457912275162135p0"></a>Content of this node: path of the component or image file to be packed into the update package. It is the root directory of the version package by default.</p>
143    </td>
144    </tr>
145    <tr id="row691331702162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry1271021967162135p0"><a name="entry1271021967162135p0"></a><a name="entry1271021967162135p0"></a>compAddr</p>
146    </td>
147    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry967575438162135p0"><a name="entry967575438162135p0"></a><a name="entry967575438162135p0"></a>Yes</p>
148    </td>
149    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry2010019875162135p0"><a name="entry2010019875162135p0"></a><a name="entry2010019875162135p0"></a>Name of the partition corresponding to the component, for example, <strong id="b19437823131512"><a name="b19437823131512"></a><a name="b19437823131512"></a>system</strong> or <strong id="b375692501514"><a name="b375692501514"></a><a name="b375692501514"></a>vendor</strong>.</p>
150    </td>
151    </tr>
152    <tr id="row849226815162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry21721216162135p0"><a name="entry21721216162135p0"></a><a name="entry21721216162135p0"></a>compId</p>
153    </td>
154    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry674558287162135p0"><a name="entry674558287162135p0"></a><a name="entry674558287162135p0"></a>Yes</p>
155    </td>
156    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1193039499162135p0"><a name="entry1193039499162135p0"></a><a name="entry1193039499162135p0"></a>Component ID, which must be unique.</p>
157    </td>
158    </tr>
159    <tr id="row813205598162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry897639380162135p0"><a name="entry897639380162135p0"></a><a name="entry897639380162135p0"></a>resType</p>
160    </td>
161    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry204468393162135p0"><a name="entry204468393162135p0"></a><a name="entry204468393162135p0"></a>Yes</p>
162    </td>
163    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry1005669355162135p0"><a name="entry1005669355162135p0"></a><a name="entry1005669355162135p0"></a>This field is reserved and does not affect the generation of the update package.</p>
164    </td>
165    </tr>
166    <tr id="row2087193735162135"><td class="cellrowborder" valign="top" headers="mcps1.1.6.1.1 "><p id="entry800634310162135p0"><a name="entry800634310162135p0"></a><a name="entry800634310162135p0"></a>compType</p>
167    </td>
168    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.2 "><p id="entry1484190922162135p0"><a name="entry1484190922162135p0"></a><a name="entry1484190922162135p0"></a>Yes</p>
169    </td>
170    <td class="cellrowborder" valign="top" headers="mcps1.1.6.1.3 "><p id="entry894563848162135p0"><a name="entry894563848162135p0"></a><a name="entry894563848162135p0"></a>Image type, which can be a full or differential package. The value <strong id="b16850185911295"><a name="b16850185911295"></a><a name="b16850185911295"></a>0</strong> indicates a full package, and value <strong id="b2095321320305"><a name="b2095321320305"></a><a name="b2095321320305"></a>1</strong> indicates a differential package.</p>
171    </td>
172    </tr>
173    </tbody>
174    </table>
175
176    >![](../public_sys-resources/icon-note.gif) **NOTE:**
177    >As mini and small systems do not support update using a differential package,  **compType**  must be set to  **0**, other than  **1**.
178    >For mini and small systems, an update package cannot be created by changing partitions.
179
1804.  Create the  **OTA.tag**  file, which contains the magic number of the update package. The magic number is as follows:
181
182    ```
183    package_type:ota1234567890qwertw
184    ```
185
1865.  Create the  **config**  file, and configure the  **bootargs**  and  **bootcmd**  information in the file.
187
188    Example configuration:
189
190    ```
191    setenv bootargs 'mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M
192    (u-boot.bin),9M(kernel.bin),50M(rootfs_ext4.img),50M(userfs.img)' setenv bootcmd 'mmc read 0x0 0x82000000 0x800 0x4800;bootm 0x82000000'
193    ```
194
1956.  Generate the update package.
196
197    ```
198    python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key3072.pem -nz -nl2x
199    ```
200
201    -   **./target\_package/**: path of  **target\_package**
202    -   **./output\_package/**: output path of the update package
203    -   **-pk ./rsa\_private\_key3072.pem**: path of the private key file
204    -   **-nz**:  **not zip**  mode
205    -   **-nl2**: non-standard system mode
206
207
208### Standard System<a name="section1291354584162135"></a>
209
2101.  Create the  **target\_package**  folder with the following directory structure:
211
212    ```
213    target_package
214    ├── {component_1}
215    ├── {component_2}
216    ├── ...
217    ├── {component_N}
218    └── updater_config
219            ├── BOARD.list
220            ├── VERSION.mbn
221            └── updater_specified_config.xml
222    ```
223
2242.  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.
225
2263.  Configure the component configuration file in the  **update\_config**  folder.
227
2284.  Configure the list of products supported by the current update package in  **BOARD.list**  in the  **update\_config**  folder.
229
230    Example configuration:
231
232    ```
233    HI3516
234    HI3518
235    ```
236
2375.  Configure the versions supported by the current update package in  **VERSION.mbn**  in the  **update\_config**  folder.
238
239    Version number format: Hi3516DV300-eng 10 QP1A.XXXXXX.\{Major version number \(6 digits\)\}.XXX\{Minor version number \(3 digits\)\}
240
241    For example, Hi3516DV300-eng 10 QP1A.190711.020, where  **190711**  is the major version number, and  **020**  is the minor version number.
242
243    Example configuration:
244
245    ```
246    Hi3516DV300-eng 10 QP1A.190711.001
247    Hi3516DV300-eng 10 QP1A.190711.020
248    Hi3518DV300-eng 10 QP1A.190711.021
249    ```
250
2516.  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**.
252
2537.  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.
254
255    The partition table is generated with the image. The format is as follows:
256
257    ```
258    <?xml version="1.0" encoding="GB2312" ?>
259    <Partition_Info>
260    <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"/>
261    <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"/>
262    </Partition_Info>
263    ```
264
265    **Table 2**  Description of labels in the partition table
266
267    <a name="table806330288162135"></a>
268    <table><thead align="left"><tr id="row682144517162135"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="entry387204270162135p0"><a name="entry387204270162135p0"></a><a name="entry387204270162135p0"></a>Label</p>
269    </th>
270    <th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="entry750055172162135p0"><a name="entry750055172162135p0"></a><a name="entry750055172162135p0"></a>Description</p>
271    </th>
272    </tr>
273    </thead>
274    <tbody><tr id="row1074495132162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry1271686486162135p0"><a name="entry1271686486162135p0"></a><a name="entry1271686486162135p0"></a>Sel</p>
275    </td>
276    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry1588639785162135p0"><a name="entry1588639785162135p0"></a><a name="entry1588639785162135p0"></a>Whether the partition is effective. The value <strong id="b156151453173416"><a name="b156151453173416"></a><a name="b156151453173416"></a>1</strong> indicates that the partition is effective, and value <strong id="b166297633517"><a name="b166297633517"></a><a name="b166297633517"></a>0</strong> indicates the opposite.</p>
277    </td>
278    </tr>
279    <tr id="row1838873028162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry405380697162135p0"><a name="entry405380697162135p0"></a><a name="entry405380697162135p0"></a>PartitionName</p>
280    </td>
281    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry539229490162135p0"><a name="entry539229490162135p0"></a><a name="entry539229490162135p0"></a>Partition name, for example, <strong id="b1173483114376"><a name="b1173483114376"></a><a name="b1173483114376"></a>fastboot</strong> or <strong id="b163708336376"><a name="b163708336376"></a><a name="b163708336376"></a>boot</strong>.</p>
282    </td>
283    </tr>
284    <tr id="row1321400941162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry360591364162135p0"><a name="entry360591364162135p0"></a><a name="entry360591364162135p0"></a>FlashType</p>
285    </td>
286    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry1536610466162135p0"><a name="entry1536610466162135p0"></a><a name="entry1536610466162135p0"></a>Flash type, for example, <strong id="b1711717453820"><a name="b1711717453820"></a><a name="b1711717453820"></a>emmc</strong> or <strong id="b86479117387"><a name="b86479117387"></a><a name="b86479117387"></a>ufs</strong>.</p>
287    </td>
288    </tr>
289    <tr id="row1724163696162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry278309753162135p0"><a name="entry278309753162135p0"></a><a name="entry278309753162135p0"></a>FileSystem</p>
290    </td>
291    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry218585771162135p0"><a name="entry218585771162135p0"></a><a name="entry218585771162135p0"></a>File system type, for example, <strong id="b63519206383"><a name="b63519206383"></a><a name="b63519206383"></a>ext3/4</strong> or <strong id="b172821252383"><a name="b172821252383"></a><a name="b172821252383"></a>f2fs</strong>. The value can also be <strong id="b63162773815"><a name="b63162773815"></a><a name="b63162773815"></a>none</strong>.</p>
292    </td>
293    </tr>
294    <tr id="row1809526161162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry1440557777162135p0"><a name="entry1440557777162135p0"></a><a name="entry1440557777162135p0"></a>Start</p>
295    </td>
296    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry814481339162135p0"><a name="entry814481339162135p0"></a><a name="entry814481339162135p0"></a>Start address of the partition, in MB. The start address of all partitions is <strong id="b1171284398"><a name="b1171284398"></a><a name="b1171284398"></a>0</strong>.</p>
297    </td>
298    </tr>
299    <tr id="row1052365500162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry463606592162135p0"><a name="entry463606592162135p0"></a><a name="entry463606592162135p0"></a>Length</p>
300    </td>
301    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry18613946162135p0"><a name="entry18613946162135p0"></a><a name="entry18613946162135p0"></a>Size of the partition, in MB.</p>
302    </td>
303    </tr>
304    <tr id="row2062761324162135"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="entry1424721291162135p0"><a name="entry1424721291162135p0"></a><a name="entry1424721291162135p0"></a>SelectFile</p>
305    </td>
306    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="entry1154631273162135p0"><a name="entry1154631273162135p0"></a><a name="entry1154631273162135p0"></a>Actual path of the image or file.</p>
307    </td>
308    </tr>
309    </tbody>
310    </table>
311
3128.  Generate the update package.
313
314    **Full package**
315
316    Run the following command:
317
318    ```
319    python build_update.py ./target_package/ ./output_package/ -pk ./rsa_private_key3072.pem
320    ```
321
322    -   **./target\_package/**: path of  **target\_package**
323    -   **./output\_package/**: output path of the update package
324    -   **-pk ./rsa\_private\_key3072.pem**: path of the private key file
325
326    **Incremental \(differential\) package**
327
328    Run the following command:
329
330    ```
331    python build_update.py ./target_package/ ./output_package/  -s ./source_package.zip  -pk ./rsa_private_key3072.pem
332    ```
333
334    -   **./target\_package/**: path of  **target\_package**
335    -   **./output\_package/**: output path of the update package
336    -   **-s ./source\_package.zip**: path of the  **source\_package.zip**  file. For update using a differential package, use the  **-s**  parameter to specify the source version package.
337    -   **-pk ./rsa\_private\_key3072.pem**: path of the private key file
338
339    **Update package with partitions changed**
340
341    Run the following command:
342
343    ```
344    python build_update.py  ./target_package/ ./output_package/  -pk ./rsa_private_key3072.pem  -pf ./partition_file.xml
345    ```
346
347    -   **./target\_package/**: path of  **target\_package**
348    -   **./output\_package/**: output path of the update package
349    -   **-pk ./rsa\_private\_key3072.pem**: path of the private key file
350    -   **-pf ./partition\_file.xml**: path of the partition table file
351
352
353## Uploading the Update Package<a name="section1040019352162135"></a>
354
355Upload the update package to the vendor's OTA server.
356
357## Downloading the Update Package<a name="section1870792413162135"></a>
358
3591.  Download the update package from the OTA server.
3602.  \(Optional\) Insert an SD card \(with a capacity greater than 100 MB\) if the device is developed based on Hi3518E V300 or Hi3516D V300.
361
362## Integrating OTA Update Capabilities<a name="section2107348555162135"></a>
363
3641.  For mini and small systems
365
366    -   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**.
367
368    -   The  **libhota.so**  source code is stored in  **base\\update\\ota\_lite\\frameworks\\source**.
369
370    -   For details about how to use APIs, see  _API Application Scenario_  and OTA APIs in  _API Reference_.
371
372    -   If the development board needs to be adapted, see the  **base\\update\\ota\_lite\\hals\\hal\_hota\_board.h**  file.
373
3742.  For the standard system, see the [Reference Specifications](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-update.md) for details.
375
376## API Application Scenario \(Default\)<a name="section1308521557162135"></a>
377
378The update package is generated by following the instructions provided in Generating a Public/Private Key Pair and Generating an Update Package.
379
380### **How to Develop**<a name="section2103641927162135"></a>
381
3821.  Download the update package for the current device, and then call the  **HotaInit**  function to initialize the OTA module.
383
3842.  Call the  **HotaWrite**  function to verify, parse, and write data streams into the device.
385
3863.  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.
387
388
389### **Sample Code**<a name="section1918621904162135"></a>
390
391Perform an OTA update using the update package format and verification method provided by OpenHarmony.
392
393```
394int main(int argc, char **argv)
395{
396    printf("this is update print!\r\n");
397    if (HotaInit(NULL, NULL) < 0) {
398        printf("ota update init fail!\r\n");
399        return -1;
400    }
401    int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR);
402    if (fd < 0) {
403        printf("file open failed, fd = %d\r\n", fd);
404        (void)HotaCancel();
405        return -1;
406    }
407    int offset = 0;
408    int fileLen = lseek(fd, 0, SEEK_END);
409    int leftLen = fileLen;
410    while (leftLen > 0) {
411        if (lseek(fd, offset, SEEK_SET) < 0) {
412            close(fd);
413            printf("lseek fail!\r\n");
414            (void)HotaCancel();
415            return -1;
416        }
417        int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
418        (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
419        if (read(fd, g_readBuf, tmpLen) < 0) {
420            close(fd);
421            printf("read fail!\r\n");
422            (void)HotaCancel();
423            return -1;
424        }
425        if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) {
426            printf("ota write fail!\r\n");
427            close(fd);
428            (void)HotaCancel();
429            return -1;
430        }
431        offset += READ_BUF_LEN;
432        leftLen -= tmpLen;
433    }
434    close(fd);
435    printf("ota write finish!\r\n");
436    printf("device will reboot in 10s...\r\n");
437    sleep(10);
438    (void)HotaRestart();
439    return 0;
440}
441```
442
443## API Application Scenario \(Custom\)<a name="section1332839930162135"></a>
444
445The 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.
446
447### **How to Develop**<a name="section2120976727162135"></a>
448
4491.  Download the update package for the current device, and then call the  **HotaInit**  function to initialize the OTA module.
450
4512.  Call the  **HotaSetPackageType**  function to set the package type to  **NOT\_USE\_DEFAULT\_PKG**.
452
4533.  Call the  **HotaWrite**  function to write data streams into the device.
454
4554.  Call the  **HotaRead**  function to read data. Vendors can choose whether to verify the data.
456
4575.  \(Optional\) Call the  **HotaSetBootSettings**  function to set the startup tag used for entering the U-Boot mode during system restarting.
458
4596.  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.
460
461
462### **Sample Code**<a name="section1743369672162135"></a>
463
464Perform an OTA update using the update package format and verification method not provided by OpenHarmony.
465
466```
467int main(int argc, char **argv)
468{
469    printf("this is update print!\r\n");
470    if (HotaInit(NULL, NULL) < 0) {
471        printf("ota update init fail!\r\n");
472        (void)HotaCancel();
473        return -1;
474    }
475    (void)HotaSetPackageType(NOT_USE_DEFAULT_PKG);
476    int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR);
477    if (fd < 0) {
478        printf("file open failed, fd = %d\r\n", fd);
479        (void)HotaCancel();
480        return -1;
481    }
482    int offset = 0;
483    int fileLen = lseek(fd, 0, SEEK_END);
484    int leftLen = fileLen;
485    while (leftLen > 0) {
486        if (lseek(fd, offset, SEEK_SET) < 0) {
487            close(fd);
488            printf("lseek fail!\r\n");
489            (void)HotaCancel();
490            return -1;
491        }
492        int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
493        (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
494        if (read(fd, g_readBuf, tmpLen) < 0) {
495            close(fd);
496            printf("read fail!\r\n");
497            (void)HotaCancel();
498            return -1;
499        }
500        if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) {
501            printf("ota write fail!\r\n");
502            close(fd);
503            (void)HotaCancel();
504            return -1;
505        }
506        offset += READ_BUF_LEN;
507        leftLen -= tmpLen;
508    }
509    close(fd);
510    printf("ota write finish!\r\n");
511    leftLen = fileLen;
512    while (leftLen > 0) {
513        int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen;
514        (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN);
515        if (HotaRead(offset, READ_BUF_LEN, (unsigned char *)g_readBuf) != 0) {}
516            printf("ota write fail!\r\n");
517            (void)HotaCancel();
518            return -1;
519        }
520        /* do your verify and parse */
521        offset += READ_BUF_LEN;
522        leftLen -= tmpLen;
523    }
524    /* set your boot settings */
525    (void)HotaSetBootSettings();
526    printf("device will reboot in 10s...\r\n");
527    sleep(10);
528    (void)HotaRestart();
529    return 0;
530}
531```
532
533## Upgrading the System<a name="section1704276175162135"></a>
534
535Vendor 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.
536
537For 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**.
538
539Example for modification of the local version:
540
541```
542const char *get_local_version(void)
543{
544#if defined(CONFIG_TARGET_HI3516EV200) || \
545    defined(CONFIG_TARGET_HI3516DV300) || \
546    defined(CONFIG_TARGET_HI3518EV300)
547#define LOCAL_VERSION "ohos default 1.0" /* increase: default release version */
548```
549
550