1# Obtaining Source Code
2
3
4## About OpenHarmony
5
6OpenHarmony is an open source project launched by the OpenAtom Foundation. The purpose of this project is to build an open, distributed operating system (OS) framework for smart IoT devices in the full-scenario, full-connectivity, and full-intelligence era.
7
8
9
10The open source code repositories are available at [https://openharmony.gitee.com](https://openharmony.gitee.com).
11
12
13## Overview of Source Code Acquisition
14
15This document describes how to acquire OpenHarmony source code and provides its directory structure. The OpenHarmony source code is open to you as [HPM parts](../hpm-part/hpm-part-about.md), which can be obtained in any of the following ways:
16
17- **Method 1**: Acquire the source code from the Gitee code repository. You can use the **repo** or **git** tool to download the latest code from the code repository.
18
19- **Method 2**: Acquire the source code from [DevEco Marketplace](https://repo.harmonyos.com/#/en/home). Visit [DevEco Marketplace](https://repo.harmonyos.com/#/en/home), search for your desired open source distribution, and download the component list (or customize components and download the component list). Then use the **hpm-cli** tool to download and install the components and compilation toolchain on your local PC.
20
21- **Method 3**: Download the compressed file of a distribution from a mirror site. This method provides a fast download speed, so you can also use this method for obtaining the source code of an earlier version.
22
23- **Method 4**: Acquire the source code from the GitHub image repository. You can use the **repo** or **git** tool to download the latest code from the code repository.
24
25
26## Method 1: Acquiring Source Code from the Gitee Code Repository
27
28
29### When to Use
30
31- You want to establish a baseline based on stable OpenHarmony releases and distribute the baseline to your customers.
32
33- You have interconnected your software with OpenHarmony and need official certification from OpenHarmony.
34
35- You want to contribute code to the OpenHarmony community after obtaining official OpenHarmony certification for chips, modules, and applications.
36
37- You need to rectify OpenHarmony issues.
38
39- You want to learn OpenHarmony source code.
40
41
42### Prerequisites
43
441. Register your account with Gitee.
45
462. Register an SSH public key for access to Gitee.
47
483. Install the [Git client](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [git-lfs](https://gitee.com/vcs-all-in-one/git-lfs?_from=gitee_search#downloading), and configure basic user information.
49
50   ```shell
51   git config --global user.name "yourname"
52   git config --global user.email "your-email-address"
53   git config --global credential.helper store
54   ```
55
564. Install the **repo** tool:
57
58   In this example, **~/bin** is used as an example installation directory. You can change the directory as needed.
59
60   ```shell
61   mkdir ~/bin
62   curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o ~/bin/repo
63   chmod a+x ~/bin/repo
64   pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
65   ```
66
675. Add the path of the **repo** tool to environment variables.
68
69   ```shell
70   vim ~/.bashrc               # Edit environment variables.
71   export PATH=~/bin:$PATH     # Add the path of the **repo** tool to the end of environment variables.
72   source ~/.bashrc            # Apply environment variables.
73   ```
74
75
76### Procedure
77
78
79> **NOTE**<br>
80>
81> Download the release code, which is more stable, if you want to develop commercial functionalities. Download the master code if you want to get quick access to the latest features for your development.
82
83- **Obtaining OpenHarmony release code**
84
85  For details about how to obtain the source code of an OpenHarmony release, see the [Release Notes](../../release-notes/Readme.md).
86
87- **Obtaining OpenHarmony master code**
88
89  Method 1 (recommended): Use the **repo** tool to download the source code over SSH. (You must have registered an SSH public key for access to Gitee.)
90
91  ```shell
92  repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify
93  repo sync -c
94  repo forall -c 'git lfs pull'
95  ```
96
97  Method 2: Use the **repo** tool to download the source code over HTTPS.
98
99
100  ```shell
101  repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
102  repo sync -c
103  repo forall -c 'git lfs pull'
104  ```
105
106
107## Method 2: Acquiring Source Code from DevEco Marketplace
108
109
110### When to Use
111
112If OpenHarmony is new to you, sample solutions are helpful to your development. You can obtain an open source distribution from [DevEco Marketplace](https://repo.harmonyos.com/#/en/home), or customize a distribution by adding or deleting components of an open source distribution. Then use the **hpm-cli** tool to download and install the components and compilation toolchain on your local PC.
113
114
115### Prerequisites
116
117You must install **Node.js** and HPM on your local PC. The installation procedure is as follows:
118
1191. Install **Node.js**.
120
121   Download **Node.js** from its official website, and install it on your local PC.
122
123   The [Node.js](https://nodejs.org/) version must be 12.x (including npm 6.14.4) or later. An LTS version is recommended.
124
1252. Install the **hpm-cli** tool using **npm** delivered with **Node.js**.
126
127   Open the CMD window, and run the following command:
128
129   ```shell
130   npm install -g @ohos/hpm-cli
131   ```
132
1333. Run the following command to check whether the installation is successful. If the HPM version is displayed, the installation is successful.
134
135   ```shell
136   hpm -V or hpm --version
137   ```
138
1394. Upgrade the HPM version as needed.
140
141   ```shell
142   npm update -g @ohos/hpm-cli
143   ```
144
145
146### Procedure
147
1481. Search for distributions.
149   1. Access [DevEco Marketplace](https://repo.harmonyos.com/#/en/home), and click **Device**. Then go to the **Open Source Distribution** page.
150   2. Enter a keyword, for example, **camera**, in the search box. All matched distributions are displayed.
151   3. Specify filter criteria, such as the OS, board, and kernel, to further filter the distributions.
152   4. Find your desired distribution, and click it to view details.
153
154         **Figure 1** HPM page
155
156         ![](figures/hpm-page.png "hpm-page")
157
1582. Learn more about the distribution.
159   1. Read carefully the information about the distribution to learn its application scenarios, features, components, usage, and customization methods.
160   2. Use either of the following modes to obtain the source code:
161      - Click **Download** if you want to download the distribution to your local PC.
162      - Click **Device component tailoring** if you want to add or delete components of the distribution.
163
164         **Figure 2** Example distribution
165
166         ![](figures/example-distribution.png "example-distribution")
167
1683. Customize components.
169   1. Access the **Device Component Tailoring** page.
170   2. Add or delete components.
171      - In the **Customizable Components** pane, click the plus sign. In the displayed dialog box, add required components.
172      - In the **Customizable Components** pane, click the minus sign next to a component to delete it.
173   3. Enter the basic information about your project, including the name, version, and description, on the right pane.
174   4. Click **Download**. The system generates the OpenHarmony code structure file (for example, **my_cust_dist.zip**) and saves it to your local PC.
175
176         **Figure 3** Customizing components
177
178         ![](figures/customizing-bundles.png "customizing-bundles")
179
1804. Install components.
181   1. Decompress the downloaded code structure file using CMD on Windows (or shell in Linux).
182   2. In the generated directory, run the **hpm install** command to download and install components. If the **Install successful** message is displayed, the command has been executed successfully.
183   3. The downloaded components will be stored in the **ohos_bundles** folder under the project directory. (The source code of some components will be copied to a specified directory after the components are installed.)
184
185
186## Method 3: Acquiring Source Code from a Mirror Site
187
188To ensure the download performance, you are advised to download the source code or the corresponding solution from the image library of the respective site listed in the table below.
189
190The table below provides only the sites for downloading the latest OpenHarmony LTS code. For details about how to obtain the source code of earlier versions, see the [Release Notes](../../release-notes/Readme.md).
191
192  **Table 1** Sites for acquiring source code
193
194| **LTS Code**| **Version**| **Site**| **SHA-256 Checksum**| **Software Package Size**|
195| -------- | -------- | -------- | -------- | -------- |
196| Full code base (for mini, small, and standard systems)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/code-v3.0-LTS.tar.gz) | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/code-v3.0-LTS.tar.gz.sha256)| 7.0 GB |
197| Standard system solution (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/standard.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/3.0/standard.tar.gz.sha256)| 973.7 MB |
198| Hi3861 solution (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_pegasus.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_pegasus.tar.gz.sha256)| 16.5 MB |
199| Hi3518 solution (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_aries.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_aries.tar.gz.sha256)| 158.1 MB |
200| Hi3516 solution-LiteOS (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus.tar.gz) | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus.tar.gz.sha256)| 248.9 MB |
201| Hi3516 solution-Linux (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus_linux.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus_linux.tar.gz.sha256) | 418.1 MB |
202| RELEASE-NOTES | 3.0 | [Download](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.0-LTS/en/release-notes/OpenHarmony-v3.0-LTS.md)| - | - |
203| **Source Code of the Latest Release**| **Version**| **Site**| **SHA-256 Checksum**| **Software Package Size**|
204| Full code base (for mini, small, and standard systems)       | 4.1 Release    | [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/code-v4.1-Release.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/code-v4.1-Release.tar.gz.sha256)| 31.6 GB |
205| Hi3861 solution (binary)       | 4.1 Release    | [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_pegasus.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_pegasus.tar.gz.sha256)| 29.2 MB |
206| Hi3516 solution-LiteOS (binary)| 4.1 Release    | [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_taurus_LiteOS.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_taurus_LiteOS.tar.gz.sha256) | 318.7 MB |
207| Hi3516 solution-Linux (binary) | 4.1 Release    | [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_taurus_Linux.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/hispark_taurus_Linux.tar.gz.sha256)| 215.8 MB |
208| RK3568 standard system solution (binary)       | 4.1 Release    | [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/dayu200_standard_arm32.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.1-Release/dayu200_standard_arm32.tar.gz.sha256)| 8.4 GB |
209| RELEASE-NOTES | 4.1 Release   | [Download](../../release-notes/OpenHarmony-v4.1-release.md)| - | - |
210| **Compiler Toolchain**| **Version**| **Site**| **SHA-256 Checksum**| **Software Package Size**|
211| Compiler toolchain| - | [Download](https://repo.huaweicloud.com/openharmony/os/2.0/tool_chain/)| - | - |
212
213
214## Method 4: Acquiring Source Code from the GitHub Image Repository
215
216> **NOTE**<br>
217> The image repository is synchronized at 23:00 (UTC +8:00) every day.
218
219
220Method 1 (recommended): Use the **repo** tool to download the source code over SSH. (You must have registered an SSH public key for access to GitHub. For details, see [Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).)
221
222```shell
223repo init -u git@github.com:openharmony/manifest.git -b master --no-repo-verify
224repo sync -c
225repo forall -c 'git lfs pull'
226```
227
228Method 2: Use the **repo** tool to download the source code over HTTPS.
229
230
231```shell
232repo init -u https://github.com/openharmony/manifest.git -b master --no-repo-verify
233repo sync -c
234repo forall -c 'git lfs pull'
235```
236
237
238## Source Code Directories
239
240The following table describes the OpenHarmony source code directories.
241
242  **Table 2** Source code directories
243
244| **Directory**| **Description**|
245| -------- | -------- |
246| applications | Application samples, for example, **camera**.|
247| base | Basic software service subsystem set and hardware service subsystem set.|
248| build | Component-based compilation, building, and configuration scripts.|
249| docs | Reference documents.|
250| domains | Enhanced software service subsystem set.|
251| drivers | Driver subsystem.|
252| foundation | Basic system capability subsystem set.|
253| kernel | Kernel subsystem.|
254| prebuilts | Compiler and tool chain subsystem.|
255| test | Test subsystem.|
256| third_party | Open source third-party software.|
257| utils | Commonly used development utilities.|
258| vendor | Vendor-provided software.|
259| build.py | Build script file.|
260
261<!--no_check-->