# Source Code Acquisition - [About OpenHarmony](#section6370143622110) - [Overview of Source Code Acquisition](#section12763342204) - [Method 1: Acquiring Source Code from Image Sites](#section1186691118430) - [Method 2: Acquiring Source Code from the Bundle-specific HPM](#section463013147412) - [When to Use](#section123926431441) - [Prerequisites](#section42627508156) - [How to Use](#section1781916234118) - [Method 3: Acquiring Source Code from a Code Repository](#section537312010229) - [When to Use](#section1492115412228) - [Preparations](#section1076962313239) - [Operations](#section17162735266) - [Source Code Directories](#section1072115612811) ## About OpenHarmony OpenHarmony is an open-source version of HarmonyOS. It is donated by Huawei to OpenAtom Foundation. The first open-source version can run on 128 KB to 128 MB devices. You are welcomed to join the open-source community for continuous improvement. Access code repositories at [https://openharmony.gitee.com](https://openharmony.gitee.com). >![](public_sys-resources/icon-note.gif) **NOTE:** >Currently, OpenHarmony source code can be compiled only in a Linux environment. You may encounter exceptions in a Windows environment. >For example, while downloading and installing some bundles, you need to run Linux commands to set environment variables. However, if you do so in a Windows environment, an error may occur. To address this issue, change the shell of HPM to a third-party shell. For example, you can run the following command to change the shell to **sh.exe** of git: >hpm config set shellPath 'C:\\Program Files\\Git\\bin\\sh.exe' ## Overview of Source Code Acquisition This document describes how to acquire OpenHarmony source code and provides its directory structure. The OpenHarmony code is open to you as [bundles](../bundles/overview.md), which can be obtained in any of the following ways: - **Method 1**: Download the compressed file of a distribution from an image site. To obtain the source code of an earlier version, you are also advised to use this method. - **Method 2**: Obtain the source code from the HarmonyOS Package Manager \(HPM\). Visit the [HPM](https://hpm.harmonyos.com/#/en/home) website, search for your desired open-source distribution, and download the bundle list \(or customize bundles and download the bundle list\). Then use **hpm-cli** to download and install the bundles and compilation toolchain on your local PC. - **Method 3**: Use the **repo** or **git** tool to download your desired code from the code repository. ## Method 1: Acquiring Source Code from Image Sites To 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. >![](public_sys-resources/icon-note.gif) **NOTE:** >- The table below provides only the sites for downloading the source code of the latest OpenHarmony Master and LTS versions. For details about how to obtain the source code of other versions, see the [Release Notes](https://gitee.com/openharmony/docs/tree/master/en/release-notes). >- Currently, Master 1.0 is no longer maintained. You are advised to use the LTS version. **Table 1** Sites for acquiring source code from image sites

LTS Code

Version Information

Site

SHA-256 Verification Code

Full code base

1.1.0

Download

Download

Hi3861 solution (binary)

1.1.0

Download

Download

Hi3518 solution (binary)

1.1.0

Download

Download

Hi3516 solution (binary)

1.1.0

Download

Download

RELEASE-NOTES

1.1.0

Download

-

Master Code

Version Information

Site

SHA-256 Verification Code

Full code base

1.0 (no longer maintained)

Download

Download

Hi3861 solution (binary)

1.0 (no longer maintained)

Download

Download

Hi3518 solution (binary)

1.0 (no longer maintained)

Download

Download

Hi3516 solution (binary)

1.0 (no longer maintained)

Download

Download

RELEASE-NOTES

1.0 (no longer maintained)

Download

-

## Method 2: Acquiring Source Code from the Bundle-specific HPM ## When to Use If OpenHarmony is new to you, sample solutions are helpful to your development. You can obtain an open-source distribution from the [HPM](https://hpm.harmonyos.com/#/en/home) platform, or customize a distribution by adding or deleting bundles of an open-source distribution. Then use **hpm-cli** to download and install the bundles and compilation toolchain on your local PC. ## Prerequisites You must install **Node.js** and HPM on your local PC. The installation procedure is as follows: 1. Install **Node.js**. Download **Node.js** from its official website and install it on your local PC. You are advised to install [Node.js](https://nodejs.org/) 12.x \(including npm 6.14.4\) or a later version \(12.13.0 or later is recommended\). 2. Install the hpm-cli tool using **npm** delivered with **Node.js**. Open the CMD window and run the following command: ``` npm install -g @ohos/hpm-cli ``` 3. Run the following command to check whether the installation is successful. If the HPM version is displayed, the installation is successful. ``` hpm -V or hpm --version ``` 4. Run the following command to upgrade the HPM version: ``` npm update -g @ohos/hpm-cli ``` ## How to Use 1. Search for distributions. 1. Access the [HPM](https://hpm.harmonyos.com/#/en/home) page, and click the **Distribution** tab, as shown in the following figure. 2. Enter a keyword \("camera" as an example\) in the search box. All matched distributions are found. 3. Specify filter criteria, such as the bundle type \(example: **Board support** and **Kernel support**\), to further filter the distributions. 4. Locate your desired distribution and click it to view details. **Figure 1** HPM page ![](figures/en-us_image_0000001086781056.png) 2. Learn more about the distribution. 1. Read carefully the information about the distribution to learn its application scenarios, features, bundles, usage, and customization methods, as shown in the following figure. 2. Click **Download** to download the distribution to your local PC. 3. Click **Custom** to add or delete bundles of the distribution. **Figure 2** Example distribution ![](figures/en-us_image_0000001086461836.png) 3. Customize bundles. 1. Access the **Custom solution** page, as shown in the following figure. 2. Set the toggle switch next to a specific optional bundle to delete it from the distribution, or click **Add bundle** to add new bundles. 3. Enter the basic information about your project, including the bundle name, version, and description, on the right pane. 4. Click **Download**. The system then generates the OpenHarmony code structure file \(for example, **my\_cust\_dist.zip**\) and saves it to your local PC. **Figure 3** Customizing bundles ![](figures/en-us_image_0000001133359093.png) 4. Download and install bundles. 1. Decompress the downloaded file using the CLI tool CMD \(shell in Linux\). 2. In the generated directory, run the **hpm install** command. 3. The downloaded bundles are stored in the **ohos\_bundles** folder under the project directory. \(The source code of some bundles will be copied to a specified directory after the bundles are installed.\) ## Method 3: Acquiring Source Code from a Code Repository ## When to Use - You want to establish a baseline based on stable OpenHarmony releases and distribute the baseline to your customers. - You have interconnected your software with OpenHarmony and need official certification from OpenHarmony. - You want to contribute code to the OpenHarmony ecosystem after chips, modules, and applications are certified by OpenHarmony. - You need to address OpenHarmony issues. - You want to learn OpenHarmony source code. ## Preparations 1. Register your account with gitee. 2. Register an SSH public key. For details, visit [https://gitee.com/help/articles/4181](https://gitee.com/help/articles/4181). 3. Install the git client and configure basic information. ``` git config --global user.name "yourname" git config --global user.email "your-email-address" git config --global credential.helper store ``` 4. Run the following commands to install the **repo** tool: ``` curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo chmod a+x /usr/local/bin/repo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests ``` ## Operations >![](public_sys-resources/icon-note.gif) **NOTE:** >You can obtain the latest features from the master code, and develop commercial functionalities based on the release code. - **Obtaining OpenHarmony master code** Method 1 \(recommended\): Use the **repo** tool to download the master code. ``` repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify repo sync -c ``` Method 2: Run the **git clone** command to clone a single code repository. Go to the [code repository homepage](https://gitee.com/openharmony), select the code repository to be cloned, and run the following command: ``` git clone https://gitee.com/openharmony/manifest.git -b master ``` - **Obtaining OpenHarmony\_1.0.1\_release code** Use the **repo** tool to download the release code. ``` repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony_1.0.1_release --no-repo-verify repo sync -c ``` - Obtaining the source code of other OpenHarmony releases For details about how to obtain the source code of other releases, see the [Release Notes](https://gitee.com/openharmony/docs/blob/master/en/release-notes/OpenHarmony-Release-Notes.md). ## Source Code Directories The following table describes the OpenHarmony source code directories. **Table 2** Directory description

Name

Description

applications

Application samples, including wifi-iot and ip-camera

base

Basic software service subsystem set and hardware service subsystem set

build

Bundle-based compilation, building, and configuration scripts

docs

Reference documents

domains

Enhanced software service subsystem set

drivers

Driver subsystem

foundation

Basic system capability subsystem set

kernel

Kernel subsystem

prebuilts

Compiler and tool chain subsystem

test

Testing subsystem

third_party

Open-source third-party software

utils

Commonly used development tools

vendor

Vendor-provided software

build.py

Compilation script file