# 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) - [How to Use](#section1781916234118) - [Method 3: Acquiring Source Code with a hpm-cli Tool](#section9459261856) - [When to Use](#section1854923620139) - [Preparations](#section4451113551114) - [Operations](#section1445143510117) - [Method 4: 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 \(recommended\)**: Download compressed files from an image site. - **Method 2**: Visit the HarmonyOS Package Manager \([HPM](https://hpm.harmonyos.com/#/en/home)\) platform, search for your desired solution, select or exclude bundles from the solution, and download it. - **Method 3**: Use an hpm-cli tool available on the [HPM](https://hpm.harmonyos.com/#/en/home) platform, and run related HPM commands to download your desired code. - **Method 4**: Use the **repo** or **git** tool to download your desired code from the code repository. ## Method 1: Acquiring Source Code from Image Sites You can download the source code or the corresponding solutions from the image library at the sites listed below. **Table 1** Acquiring source code from image sites

Content

Version Information

Site

SHA-256 Verification Code

XX full code base

1.0

Site

SHA-256 Verification Code

Hi3861 solutions (binary)

1.0

Site

SHA-256 Verification Code

Hi3518 solutions (binary)

1.0

Site

SHA-256 Verification Code

Hi3516 solutions (binary)

1.0

Site

SHA-256 Verification Code

RELEASE-NOTES

1.0

Site

-

## 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. The [HPM](https://hpm.harmonyos.com/#/en/home) platform provides a recommended solution. You can add or exclude bundles to quickly customize your system. ## How to Use 1. Search for a proper solution. 1. Access the [HPM](https://hpm.harmonyos.com/#/en/home) page, and click the **Solution** tab, as shown in the following figure. 2. Enter a keyword \("camera" as an example\) in the search box. All matched solutions are found. 3. Specify filter criteria, such as the bundle type \(example: **Board support** and **Kernel support**\), to further filter the solutions. 4. Click the solution you need to view its details. **Figure 1** HPM page ![](figures/en-us_image_0000001054919529.png) 2. Customize the solution. 1. Read the information under **Readme** to learn about the solution \(application scenarios, features, usage, and customization\), as shown in the following figure. 2. Click **Download** to download the solution to your local PC. 3. Click **Log in to custom** to customize the bundles for the solution. **Figure 2** Solution example ![](figures/en-us_image_0000001054719501.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 exclude it from the solution, 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, **name.zip**\) and saves it to your local PC. - The downloaded compressed package does not contain the original file of source code. You can import the package to the IDE, decompress it, and run the **hpm install** command to download all required bundles. - The downloaded bundles are stored in the **ohos\_bundles** folder in the project directory. **Figure 3** Customizing bundles ![](figures/en-us_image_0000001055679464.png) ## Method 3: Acquiring Source Code with a hpm-cli Tool ## When to Use - You have obtained bundle-specific source code from the HPM website, and want to independently upgrade one or more bundles in the source code. - You are familiar with OpenHarmony development and **hpm-cli** tools. ## Preparations You need to install the **Node.js** and hpm-cli tool 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 ``` ## Operations Add the bundle \(**@ohos/demo** as an example\) to your project as follows: 1. Go to the development directory and run the following command to create a development project using the default template: ``` hpm init -t default ``` 2. Run the following command to install the bundle \(**@ohos/demo** as an example\): ``` hpm install @ohos/demo ``` 3. Verify that the **hpm-cli** tool automatically downloads all dependent bundles from the server. If the download is successful, the message "Install successfully!" is displayed. ``` $ hpm install @ohos/demo Requesting: https://url.foo.bar/hpm/registry/api/bundles/@ohos/demo downloading @ohos/demo Requesting: https://lfcontentcenterdev....../bMAlLrYISLqdUTFFFCdgzA.tgz extract D:\demo\ohos_bundles\@ohos\demo\@ohos-demo-1.0.7.tgz Install successfully! ``` ## Method 4: 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. 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 Method 1 \(recommended\): Use the **repo** tool to download source 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 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 ``` ## 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