HarmonyOS Device Development experience based on Hi3861

Hello everyone, I am a non-famous Copy raiding lion, this should be the last Copy Raiding lion 2020 “Hello, World” — based on Harmony OS Hi3861 development board for Internet of Things application development actual situation. Copy Lion’s road to “Hello World” [1] has never been smooth, this attempt to launch (Copy) (bei) Internet of Things application also took a lot of twists and turns, finally ran through the buzzer version of “Jingle Bells”, I wish you all a happy New Year!

There is a decades-old “rule” in the programming world — you start with environment building. Sometimes environment building is relatively easy, such as learning HTML programming and having a browser. React Native requires NodeJS, Python, Java, and Android SDK to be installed. HarmonyOS Device development, on the other hand, requires complex environment setup, such as Linux compilation and Windows burning to the Device. If you also want to experience the Wifi module or other features like “Touch touch”, you will also need to provide a hotspot and other equipment. HarmonyOS provides a detailed setup documentation [2] and introduction to the Hi3861 development board [3], which should theoretically run “Hello, HarmonyOS Device” if you follow the documentation.

HarmonyOS Device development environment setup

However, everyone’s development habits or tool tastes are different, so there will be some differences between the actual setup environment and the official documentation. Since I had a few scumbag versions of cloud host resources, I chose to use them. Using the Linux cloud host as the compiler, I installed SFTP Drive on my local Window 10 computer to mount the Linux cloud host to the machine. Make burning time can read directly on Linux files; Through VSCode Remote SSH extension and HUAWEI DevEco Device Tool extension to develop debugging code, in addition, through a big guy to share the SSCOM serial port debugging Tool for more convenient debugging. If you happen to be in the same situation as me, or if you want to try my scaffolding ideas, let’s get started!

1. Windows environment (development, debugging, burning)

On Windows, we need to install VS Code and extensions (plug-ins), SFTP Drive(for direct access to Linux files when burning), CH341ser. EXE(USB to serial driver), SSCOm (optional, Aspect connection serial port debugging). I already have VS Code installed locally, so I don’t need to go into details. I believe you all have it installed. From several software and hardware development tutorials I have contacted, I recommend installing VS Code.

1.1 Remote – SSH[4]And SFTP Drive

You may have a question, these two things are access to the remote host files, install a line? At first I had the same idea, but later I found that: if you only install remote-SSSH, you can’t read the Remote file when burning the configuration. If only the SFTP Drive is installed, accessing remote files while editing code is very slow. If anyone here has a good plan for a big man, please do pass it on. I installed remote-SSH. If you want to experience more features, you can install Remote Development directly. Remote series is an extension developed by Giant Hardware for Remote Development. After installing remote-SSH, in order to log in to Linux password-free (with caution), we need to perform SSH key configuration.

Use the VSCode Remote extension and SFTP Drive to access the Remote host using your account and password to ensure normal access to the code and files in the Linux host.

During SSH key configuration, you can generate the key on the remote host or the local host, and then associate the configuration. Here we use a Windows machine using PowerShell Run ssh-keygen to generate the key to file C:\Users\ your username \.ssh\id_rsa(private key), and at the same time generate file C:\Users\ your username \.ssh\id_rsa.pub(public key), Use the SFTP Drive to copy the public key to the ~/. SSH directory on the remote host. Pub >> authorized_keys add authorized_keys to authorized_keys add authorized_keys to authorized_keys add to authorized_keys add to authorized_keys add to authorized_keys add to authorized_keys add to authorized_keys add to authorized_keys Note the following in this step:

cd ~/.ssh

cat id_rsa.pub >> authorized_keys Add public key

sudo chmod 600 authorized_keys

sudo chmod 700 ~/.ssh Add permissions to files and folders

sudo vim /etc/ssh/sshd_config Prepare to modify the SSHD configuration

# PubkeyAuthentication Yes Make sure this comment is released

sudo service sshd restart # restart SSHD

Copy the code
HarmonyOS Devic Environment -Remote Non-confidential Login

After the completion of VSCode and then open, if there is no accident to connect to the remote host, there is no need to enter the access password, completely say goodbye to the trouble of each connection to enter the password.

1.2 HUAWEI DevEco Device Tool and dependent Installation

HUAWEI DevEco Device Tool[5] is the HarmonyOS Device development Tool. “HarmonyOS One-stop Integrated Development Environment for Smart Devices, HarmonyOS components support on-demand customization, one-click build and burn, visual debugging, and distributed capabilities integration to help developers develop and innovate new hardware efficiently.”

Website: https://device.harmonyos.com/cn/ide [6], currently only supports Windows, that is why we need to use Windows native! In addition, HUAWEI DevEco Device Tool has not been installed on the VSCode extension market, so it can only be installed from VSIX. That is to say, we need to decompress the installation package downloaded from the official website. In addition, change the suffix of the.vsix file to.zip. Surprise – in DevEcoDeviceTool extension deveco tool you can get hiburn. exe, which can be used to burn (equivalent to not using VSCode) The extension to configure burning parameters in the program directly burning).

HarmonyOS Devic Setup – Obtain Hiburn. exe from DevEco Device Tool

According to the official documentation, we also need to:

  • Install Node.js(try not to install the latest one)
  • Install the JDK
  • Install the HPM
  • Install VSCode C/C++ extensions
  • Install CH341SER. EXE
  • Install the Jlink tool (optional, V6.54C or later)
  • Install HCC_RIScv32 (I did not install this successfully, so debugging is all by hand)

Given that I ran through “Hello, HarmonyOS” (which is why I got the development board), I have most of the environments, but I was stuck installing the Jlink tool for a long time, mainly due to network problems, which caused incomplete files to be downloaded. However, I managed to get it done, and then I got stuck installing hCC_RIScv32. Fortunately not the key, just give up! … Finally, the Windows part of the environment is built, you can directly burn other compiled programs!

2. Linux Environment (compiled)

The setup for HarmonyOS Device Linux is trivial compared to the Windows environment, so just follow the documentation. However, after practical practice, if you are Ubuntu 18.04, I would prefer to download and compile the source code of The Harmony OS development Guide by Runhe Xu [7]. If you like me still want to try to build environment on CentOS, then recommend the article of Hongmon community — install Hongmon LiteOS build environment in CentOS – Haisi Hi3861[8], also only take what I need – I only need to build part of the environment. My cloud host operating system is CentOS 7.6 64-bit, which is almost the same as that of the blogger. It is easy to complete the compilation according to the command line in the article.

HarmonyOS Devic environment setup – Compiled successfully

As the old saying goes: “If I have seen further, it is by standing upon the shoulders of giants”, so I combined teacher Xu and community articles to complete the compilation environment of HarmonyOS on CentOS.

2.1 Source code acquisition (one of several ways)

Configure the REPO tool

mkdir ~/bin/

# sudo apt install curl # sudo apt install curl

curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/bin/repo

chmod +x ~/bin/repo

echo 'export PATH=~/bin:$PATH'  >> ~/.bashrc

source ~/.bashrc

Copy the code
HarmonyOS Devic Environment Setup – Configure the REPO tool


# Download Harmony OS source code

mkdir -p ~/harmonyos/openharmony && cd ~/harmonyos/openharmony

sudo apt install --no-install-recommends git python The # repo tool itself is a Python script that calls git commands to download individual code silos

'user.name' and 'user.email' need to be configured before starting. If not, run the following command to configure them:

# git config --global user.name "yourname"

# git config --global user.email "your-email-address"

repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify

repo sync -c  # run this command to synchronize changes to the remote warehouse every day

Copy the code
HarmonyOS Devic Environment – Download HarmonyOS source code

2.2 Installing and Compiling the Basic Environment

Relying on Python 3.7+ and SCons[9] installations, I installed Python 3.9.0 by compiling my own.

# Download the Python source package

Wget HTTP: / / https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz

Unzip the source package

The tar XZVF Python - 3.9.0 TGZ

# install dependencies

yum groupinstall -y "Development tools"

yum install -y openssl-devel

yum install -y libffi libffi-devel

yum install -y bzip2-devel

yum install -y sqlite-devel

yum install -y readline-devel

yum install -y libuuid-devel

yum install -y uuid-devel

yum install -y xz-devel

yum install -y gdbm-devel

yum install -y tk-devel

# config compile

cdPython - 3.9.0

./configure --prefix=/usr/local/python3

# compile Python

make -j8 && make install

# Create soft links

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

# validation

python3 --version

pip3 --version

Install Python 3 components that you rely on at compile time

pip3 install setuptools

pip3 install kconfiglib

pip3 install pycryptodome

pip3 install six --upgrade --ignore-installed six

pip3 install ecdsa

Copy the code
HarmonyOS Devic Setup – Python 3


Download the SCons source package

Wget HTTP: / / http://prdownloads.sourceforge.net/scons/scons-4.0.1.tar.gz

Unzip the source package

The tar - XZVF scons - 4.0.1. Tar. Gz

# installation

cdSCons 4.0.1 /

python3 setup.py install

# Create soft links

ln -s /usr/local/python3/bin/scons /usr/bin/scons

Copy the code
HarmonyOS Devic Setup – Install Scons

2.3 Installing the Compilation Tool Environment

The compilation tools we need to use are the cross-compiler GCC_riscv32, gn to generate ninja compilation scripts, and Ninja to execute ninja compilation scripts. I don’t know how they work, but I’m a firm believer in “Just Do IT”!

Download the cross-compile tool

Wget HTTP: / / https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz

Unzip toolchain

The tar - XVF gcc_riscv32 - Linux - 7.3.0. Tar. Gz

Install the cross-compile tool

mv gcc_riscv32 /usr/local/  Store according to personal preference

vi /etc/profile Export PATH=/usr/local/gcc_riscv32/bin:$PATH

/usr/local/gcc_riscv32/bin:$PATH = /usr/local/gcc_riscv32/bin:$PATH = /usr/local/gcc_riscv32/bin:$PATH

source /etc/profile

If it still doesn't work, try adding vim ~/.bashrc to the global variable

# validation

cd

riscv32-unknown-elf-gcc --version

Copy the code
HarmonyOS Devic Setup – Install gCC_RIScv32


Download the GN tool source package

wget https://repo.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tar

# decompression

tar -xvf gn.1523.tar

# installation

mv gn /usr/local/

ln -s /usr/local/gn/gn /usr/bin/gn

# validation

gn --version

Copy the code
HarmonyOS Devic Environment – Install the GN


# download ninja

Wget HTTP: / / https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar

# decompression

The tar XVF - ninja. 1.9.0. Tar

# installation

mv ninja /usr/local/

ln -s /usr/local/ninja/ninja /usr/bin/ninja

# validation

 ninja --version

Copy the code
HarmonyOS Devic Setup – Install Ninja

2.4 Compiling tests

With simple and tedious Ctrl C and Ctrl V, we have finally set up the Linux environment for HarmonyOS Device to compile. I can’t wait to try it out:

cd /root/harmonyos/openharmony

python3 build.py wifiiot

Copy the code
HarmonyOS Devic Environment Setup – Test compiled successfully

With the complete HarmonyOS Device environment now in place, we’re ready to compile and burn our own application. Next, we take a look at the development and debugging of the HarmonyOS Device by looking at some of the basic features of the Hi3861 suite.

The resources

[1]

“Hello World” Copy siege puma road: https://juejin.cn/post/6901366425241190407


[2]

Environment set up document: https://device.harmonyos.com/cn/docs/start/introduce/oem_quickstart_3861_build-0000001054781998


[3]

Hi3861 development board is introduced: https://device.harmonyos.com/cn/docs/start/introduce/oem_wifi_start_des-0000001050168548


[4]

Remote – SSH: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh


[5]

HUAWEI DevEco Device Tool: https://device.harmonyos.com/cn/ide


[6]

https://device.harmonyos.com/cn/ide: https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905


[7]

Harmony OS Development Guide – Download and compile the source code: https://gitee.com/hihopeorg/HarmonyOS-IoT-Application-Development/blob/master/01_envsetup/hos_source_code_download_and_c ompile.md


[8]

In CentOS install HongMeng LiteOS compile environment – haisi Hi3861: https://os.51cto.com/art/202011/630545.htm


[9]

SCons: https://scons.org/