• Home
Name Date Size #Lines LOC

..--

figures/22-Oct-2025-

interfaces/kits/22-Oct-2025-1,6291,228

resources/22-Oct-2025-1,0921,069

services/22-Oct-2025-49,94439,734

test/22-Oct-2025-23,65718,970

utils/22-Oct-2025-3,1282,563

.gitattributesD22-Oct-2025795 1817

BUILD.gnD22-Oct-20253 KiB7974

LICENSED22-Oct-202512 KiB223188

OAT.xmlD22-Oct-20257.6 KiB10646

README.mdD22-Oct-20256.9 KiB13381

README_zh.mdD22-Oct-20256.2 KiB14187

bundle.jsonD22-Oct-202513.8 KiB348346

updater.mdD22-Oct-20257.1 KiB127103

updater_default_cfg.gniD22-Oct-20251.6 KiB5750

updater_ux_guide.mdD22-Oct-202517.5 KiB387354

README.md

1# Updater<a name="EN-US_TOPIC_0000001148614629"></a>
2
3-   [Introduction](#section184mcpsimp)
4-   [Directory Structure](#section198mcpsimp)
5-   [Usage](#section218mcpsimp)
6    -   [Usage Guidelines](#section220mcpsimp)
7
8-   [Repositories Involved](#section247mcpsimp)
9
10## Introduction<a name="section184mcpsimp"></a>
11
12The updater runs in the updater partition. It reads the misc partition information to obtain the update package status and verifies the update package to ensure that the update package is valid. Then, the updater parses the executable program from the update package, creates a subprocess, and starts the update program. After that, update operations will be automatically implemented by the update script.
13
14## Directory Structure<a name="section198mcpsimp"></a>
15
16```
17base/update/updater/
18├── resources           # UI image resources of the update subsystem
19├── services            # Service code of the updater
20│   ├── applypatch      # Update package data update code
21│   ├── fs_manager      # File system and partition management code
22│   ├── include         # Header files for the update subsystem
23│   ├── log             # Log module of the update subsystem
24│   ├── package         # Update packages
25│   ├── script          # Update scripts
26│   ├── diffpatch       # Differential package restore code
27│   ├── sparse_image    # Sparse image parsing code
28│   ├── ui              # UI code
29│   └── updater_binary  # Executable programs
30├── interfaces
31│   └── kits            # External APIs
32└── utils               # Common utilities of the update subsystem
33    └── include         # Header files for general functions of the update subsystem
34```
35
36## Usage<a name="section218mcpsimp"></a>
37
38### Usage Guidelines<a name="section220mcpsimp"></a>
39
40The updater runs in the updater partition. To ensure proper functioning of the updater, perform the following operations:
41
421. Create a updater partition.
43
44The updater partition is independent of other partitions. It is recommended that the size of the updater partition be greater than or equal to 20 MB. The updater partition image is an ext4 file system. Ensure that the  **config**  option of the ext4 file system in the system kernel is enabled.
45
462. Create the misc partition.
47
48The misc partition stores metadata required by the update subsystem during the update process. Such data includes update commands and records of resumable data transfer upon power-off. This partition is a raw partition and its size is about 1 MB. You do not need to create a file system for the misc partition, because the update subsystem can directly access this partition.
49
503. Prepare the partition configuration table.
51
52During the update process, the updater needs to operate the partitions through the partition configuration table. The default file name of the partition configuration table is  **fstab.updater**. You need to pack the  **fstab.updater**  file into the updater during compilation.
53
544. Start the updater.
55
56The init process in the updater partition has an independent configuration file named  **init.cfg**. The startup configuration of the updater is stored in this file.
57
585. Compile the updater.
59
60a. Add the updater configurations to the  **build/subsystem\_config.json**  file.
61
62Example configuration:
63
64```
65"updater": {
66"project": "hmf/updater",
67"path": "base/update/updater",
68"name": "updater",
69"dir": "base/update"
70},
71```
72
73b. Add the updater for the desired product.
74
75For example, to add the updater for Hi3516D V300, add the following code to the  **productdefine/common/products/Hi3516DV300.json**  file.
76
77```
78     "updater:updater":{},
79```
80
816. Compile the updater partition image.
82
83Add the compilation configuration to the  **build\_updater\_image.sh**  script, which is stored in the  **build**  repository and called by the OpenHarmony compilation system.
84
85## AB Streaming Update<a name="section218mcpsimp"></a>
86
87User devices may not always have sufficient space on the data partition for downloading OTA upgrade packages. Furthermore, entering the microsystem for upgrades sometimes impacts the user experience. To resolve these issues, OpenHarmony has introduced support for AB Streaming Updates. This feature allows downloading data chunks (Chunks) to be written directly to the inactive B partition, eliminating the need to store the chunks or the full update package on the data partition. Simultaneously, users can continue operating their devices on the active A partition while the update is applied to the inactive B partition, bypassing the need to enter the updater microsystem.
88
89### Key Technologies<a name="section220mcpsimp"></a>
90
911、 Supports independent AB partition upgrades, enabling seamless updates.
92
932、 Supports resumable streaming updates, allowing updates to continue after interruptions like network disconnections or user pauses.
94
953、 Supports multiple security checks, including hash verification for each data chunk and integrity verification for each image after the update.
96
974、 Supports exception rollback, ensuring the device automatically reverts to the stable partition upon upgrade failure for a consistent user experience.
98
995、 Supports customizable streaming data chunk size, adjustable based on the device's data partition capacity.
100
101### Packaging Process<a name="section220mcpsimp"></a>
102
103The AB Streaming Update modifies the packaging of standard AB differential or full OTA packages. new and diff operations larger than the specified data size requirement in this document are split into smaller chunks. All delta dependency files are then packaged into the update.bin file using the TLV format.
104
1051、 Split diff/new content exceeding 45KB
106
107Input parameters: pkgdiff, new commands.
108
109​Output: For the pkgdiff command, attempt to generate a diff file. If the diff file is larger than 45KB, split the pkgdiff operation into multiple smaller pkgdiff commands until each generated diff file is under 45KB. For the new command, directly check the block content size. Split any block not meeting the size requirement into multiple new commands.
110
1112、​Calculate img blocks excluding those operated on in the action list
112
113Input parameters: All blocks operated on in the action list, Total blocks of the img.
114
115Output: The complement set of the two. Sort the required copy blocks in ascending order. Group consecutive blocks into sets. Combine them into copy commands using the standard new command format.
116
1173、Package action, diff, etc., into update.bin per TLV format
118
119Input parameters: transfer.list, new.dat, patch.dat.
120
121Output: Package each line of the transfer.list as a chunk. Locate the dependent content in new.dat and patch.dat. Generate update.bin in TLV format.
122
123## Repositories Involved<a name="section247mcpsimp"></a>
124
125Update subsystem
126
127[**update\_updater**](https://gitee.com/openharmony/update_updater)
128
129[build](https://gitee.com/openharmony/build)
130
131[productdefine\_common](https://gitee.com/openharmony/productdefine_common)
132
133

README_zh.md

1# 升级包安装组件<a name="ZH-CN_TOPIC_0000001148614629"></a>
2
3-   [简介](#section184mcpsimp)
4-   [目录](#section198mcpsimp)
5-   [说明](#section218mcpsimp)
6    -   [使用说明](#section220mcpsimp)
7
8-   [相关仓](#section247mcpsimp)
9
10## 简介<a name="section184mcpsimp"></a>
11
12升级包安装组件运行在updater分区,其功能主要包括读取misc分区信息获取升级包状态,对升级包进行校验,确保升级包合法有效;然后从升级包中解析出升级的可执行程序,创建子进程并启动升级程序。具体升级的动作由升级脚本控制。
13
14更多升级子系统相关概念,请参考:[升级子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%8D%87%E7%BA%A7%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
15
16**图 1**  升级子系统架构图
17
18![](figures/Openharmony-updater-升级子系统架构图.png)
19
20## 目录<a name="section198mcpsimp"></a>
21
22```
23base/update/updater/
24├── resources           # 升级子系统用户界面图片资源目录
25├── services            # 组件服务层代码目录
26│   ├── applypatch      # 升级包数据更新代码目录
27│   ├── diffpatch       # 差分还原代码目录
28│   ├── etc             # 启动相关配置文件目录
29│   ├── flashd          # flashd模式镜像写入和升级功代码目录
30│   ├── fs_manager      # 文件系统和分区管理代码目录
31│   ├── hdi             # 硬件相关接口定义
32│   ├── include         # 升级子系统头文件目录
33│   ├── log             # 升级子系统日志模块目录
34│   ├── package         # 升级包管理模块目录
35│   ├── ptable_parse    # 分区表解析代码目录
36│   ├── script          # 升级脚本管理目录
37│   ├── ui              # 升级ui界面代码目录
38│   └── updater_binary  # 升级可执行程序目录
39├── interfaces
40│   └── kits            # 对外模块接口定义
41└── utils               # 升级子系统通用代码目录
42    └── include         # 升级子系统通用函数头文件目录
43```
44
45## 说明<a name="section218mcpsimp"></a>
46
47### 使用说明<a name="section220mcpsimp"></a>
48
49升级包安装组件运行在updater分区里,需要如下的操作
50
511、创建updater分区
52
53updater是一个独立的分区,分区大小建议不小于20MB。updater分区镜像是ext4 格式文件系统。确保系统内核ext4 文件系统的config 是打开状态。
54
552、创建misc分区
56
57misc 分区中存储了升级子系统在升级过程中需要的元数据\(metadata\),如升级命令,掉电续传记录等。 misc 分区的大小约1MB,是一个裸分区,无需制作文件系统, 升级子系统直接访问。
58
593、分区配置表
60
61升级包安装组件在运行过程中,需要通过分区配置表操作分区。默认的分区配置表文件名是fstab.updater,在编译的时候,打包到升级包安装组件中。
62
634、升级包安装组件启动
64
65updater分区的init 进程有单独的配置文件 init.cfg,升级包安装进程启动配置在该文件中。
66
675、升级包安装组件编译
68
69a、在build/subsystem\_config.json文件添加配置。
70
71如下:
72
73```
74"updater": {
75"project": "hmf/updater",
76"path": "base/update/updater",
77"name": "updater",
78"dir": "base/update"
79},
80```
81
82b、 产品中添加需要编译的组件
83
84以Hi3516DV300为例,在productdefine/common/products/Hi3516DV300.json 中添加updater:
85
86```
87     "updater:updater":{},
88```
89
906、updater分区镜像编译
91
92编译配置在build仓下,build\_updater\_image.sh 脚本中,该脚本由OHOS 编译系统调用。
93
94## AB流式升级<a name="section218mcpsimp"></a>
95
96用户设备并非在data分区上总是有足够的空间用于下载OTA升级包,同时用户有时候不需要进入小系统升级来影响设备体验。为了解决这些问题,OpenHarmony中添加了对AB流式升级的更新,可以在下载数据块Chunk写入备用B分区,而无需将数据块或者升级包存储到data分区;同时不需要进入updater小系统进行升级,用户设备操作在活跃A分区,更新在备用B分区。
97
98### 关键技术<a name="section220mcpsimp"></a>
99
1001、 支持AB分区独立升级,实现无缝更新。
101
1022、 支持流式升级断点续传,在网络断开连接、用户操作暂停等操作后,重新点击下载并更新可以实现继续更新。
103
1043、 支持多种安全校验,每个数据块Chunk会带有哈希校验,更新完后会对每个镜像进行完整性校验。
105
1064、 支持异常回滚机制,确保升级失败时自动恢复到稳定分区,确保用户体验。
107
1085、 支持流式传输数据块自定义,可以根据设备data分区大小自调整。
109
110### 做包流程<a name="section220mcpsimp"></a>
111
112在AB流式升级当中,修改的重点是在原AB差分或者全量升级包的基础上,对大于本文档数据大小要求的new和diff操作要进行更小的切片,并按照TLV格式把差分依赖文件都封装到update.bin文件中
113
1141、 切割内容大于45KB的diff/new
115
116输入参数:pkgdiff、new命令
117
118输出结果:对于pkgdiff命令尝试生成diff文件,如果diff文件大于45KB,就把pkgdiff命令分成多个pkgdiff,直到每个pkgdiff命令的diff文件大小都小于45KB。new命令直接判断block的内容大小,不满足大小的,就分割成多个new命令
119
1202、计算img总块除去action列表中操作的块
121
122输入参数:action列表中所有操作过的块,img总块
123
124输出参数:两者补集,即将需要copy的块进行升序排序,连续的组成集合,按照原有new的格式进行组合成copy命令
125
1263、根据TLV格式封装action及diff等内容到update.bin
127
128输入参数:transfer.listnew.datpatch.dat
129
130输出结果:将transfer.list每一行封装成一个chunk,依赖的内容在new.datpatch.dat中查找,并按TLV格式生成update.bin
131
132## 相关仓<a name="section247mcpsimp"></a>
133
134[升级子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%8D%87%E7%BA%A7%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
135
136[**update\_updater**](https://gitee.com/openharmony/update_updater)
137
138[build](https://gitee.com/openharmony/build)
139
140[productdefine\_common](https://gitee.com/openharmony/productdefine_common)
141