Harmony OS development guide to avoid pits-source code download and compilation

Harmony OS development guide to avoid pits-source code download and compilation

This article introduces how to download the source code of the Hongmeng system, how to configure a compilation environment that can compile three target platforms ( Hi3516, Hi3518and Hi3861) at one time, and how to compile the source code into binary files for the three target platforms.

Summary of pits :

  1. Downloading the source code basically does not have too many pits, and it can proceed smoothly
  2. The main pitfall of compiling the source code is that the default version sconsdepends on python python33.7+, and Hongmeng Foundation depends on the compiled code . You need to install python 3.7+ and live in harmony with python2.7/python3.6 on the current system! There are generally two solutions:
    • Use virtualenvthe python environment that manages multiple versions. The advantage of this method is that it only takes effect in the current shell session and does not affect the system environment, other users and other shell sessions. The disadvantage is that the source active script is a little troublesome before use;
    • Use update-alternativesmultiple versions of python commands of the management system. This method requires switching the link of the system /usr/bin/pythonand /usr/bin/python3may affect aptthe normal use of python-dependent applications (for example ), other users and other shell sessions;

Prepare the environment

This section introduces the software and hardware environment required for downloading, compiling and programming the Hongmeng system.

Hardware environment

Development environment

Among them, the Linux host is used to download and compile the source code, and the Windows host is used to program the program to the board and edit the source code.

Software Environment

hardware Description
Linux host The actual physical machine is recommended, Ubuntu16.04 and above 64-bit system, Shell uses bash, and the virtual machine can also be used. How to install is not described in detail here.
Windows host Windows XP/Windows7/Windows10 system
Remote terminal Recommend MobaXterm (PuTTY, SecureCRT and other remote terminals are also available), which is used to log in to the Linux host on the Windows host to download and compile the source code
USB to serial chip driver Download link: http://www.hihope.org/download page, USB-to-Serial Comm Port.exe file (The PL2302 chip is integrated in the USB serial cable included with the AI ​​Camera and DIY IPC kit, and this driver needs to be installed. Identification). The CH340G chip is integrated on the WiFi IoT main control chip, and the driver can be automatically installed on the Internet.

Download source code

This section introduces how to download the source code of Hongmeng on the Linux host. All commands are executed on the Linux host through the remote terminal.

The method of "obtain from code warehouse" is used here, which is convenient for subsequent code update; you can also download the source code compression package from the official website (not introduced here).

Configure repo tool

If the repo command has not been configured on your Linux system, you need to download and configure the repo command line tool first:

mkdir ~/bin/
# sudo apt install curl # 如果没有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

Download Harmony OS source code

mkdir -p ~/harmonyos/openharmony && cd ~/harmonyos/openharmony
sudo apt install git python # repo工具本身是python脚本,它会调用git命令下载单个代码仓
# 开始前需要配置`user.name`和`user.email`,如果没有配置,使用如下命令进行配置:
# 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  # 以后每天同步远程仓的修改,只需要执行这一条命令即可

Configuration Environment

This section introduces how to configure the compilation and build environment of Hongmeng source code on the Linux host. All commands are executed on the Linux host through the remote terminal.

Install the file system packaging tool

  1. Run "mkfs.vfat", if the command is not found, you need to install

  2. Run "mcopy", if the command is not found, you need to install
sudo apt-get install dosfstools mtools  # 官方文档说明的两个文件系统打包工具
sudo apt-get install zip       # 官方文档虽然没有写,但是打包rootfs过程中需要使用

Download and configure the compilation tool chain

Use the following commands to download the gn, ninja, LLVM, and hc-gen packages respectively, modify them according to the official documents, in one step, no need to copy and paste repeatedly!

# 下载gn/ninja/LLVM/hc-gen包:
URL_PREFIX=https://repo.huaweicloud.com/harmonyos/compiler
wget $URL_PREFIX/gn/1523/linux/gn.1523.tar
wget $URL_PREFIX/ninja/1.9.0/linux/ninja.1.9.0.tar
wget $URL_PREFIX/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar
wget $URL_PREFIX/hc-gen/0.65/linux/hc-gen-0.65-linux.tar

# 编译 hi3861 需要 riscv 编译工具链
wget $URL_PREFIX/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz

# 解压gn/ninja/LLVM/hc-gen包:
tar -C ~/ -xvf gn.1523.tar
tar -C ~/ -xvf ninja.1.9.0.tar
tar -C ~/ -xvf llvm-linux-9.0.0-34042.tar
tar -C ~/ -xvf hc-gen-0.65-linux.tar
tar -C ~/ -xvf gcc_riscv32-linux-7.3.0.tar.gz

# 向 ~/.bashrc 中追加gn/ninja/LLVM/hc-gen路径配置:
cat <<EOF >> ~/.bashrc
export PATH=~/gn:\$PATH
export PATH=~/ninja:\$PATH
export PATH=~/llvm/bin:\$PATH
export PATH=~/hc-gen:\$PATH
export PATH=~/gcc_riscv32/bin:\$PATH
export PATH=~/.local/bin:\$PATH       # 用户pip二进制工具目录
EOF

# 生效环境变量
source ~/.bashrc

Install python3.8 and pip package manager

  • Install python3.8 and pip ( hi3861scons is required to compile the Hongmeng source code target platform, and the scons version installed by default requires python version >=3.7):, the sudo apt-get install python3.8 python3-pipdefault Python3 version on 18.04 is 3.6, you need to switch the default python to 3.7+, usually there are two Ways:

    • Use virtualenvmanagement, separate source corresponding active script to switch the default python version of the current shell session (recommended, the following operations are done in this way);
    • Use update-alternativesmanagement, and change the global Python script configuration (not recommended, run out of the need to switch back, otherwise it will affect apt package that rely python3 use);
  • Configure the pip package download source to speed up the domestic installation of the pip package:

    mkdir ~/.pip/
    cat <<EOF > ~/.pip/pip.conf
    [global]
    index-url = https://mirrors.huaweicloud.com/repository/pypi/simple
    trusted-host = mirrors.huaweicloud.com
    timeout = 120
    EOF

Prepare virtualenv

# 安装virtualenv
pip3 install virtualenv

# 创建使用python3.8为默认python解释器的virtualenv
mkdir ~/harmonyos/venv && virtualenv -p python3.8 ~/harmonyos/venv

# 激活 virtualenv,激活后的pip3 install会将包文件缓存到相应的子目录中
source ~/harmonyos/venv/bin/activate

# 安装 setuptools 和 kconfiglib
pip3 install setuptools kconfiglib

# 安装编译hi3861需要的pip包
pip3 install scons ecdsa pycryptodome
pip3 install --upgrade --ignore-installed six

# 可选:将激活脚本添加到 bashrc 中,下次登录默认自动激活此python虚拟环境,可以使用 deactivate 使虚拟环境无效
cat <<EOF >> ~/.bashrc
source ~/harmonyos/venv/bin/activate
EOF

Compile the source code

After activating the python virtual environment just created, openharmonyexecute in the source root directory ( directory):

$ source ~/harmonyos/venv/bin/activate # 激活虚拟环境,激活后 deactivate 命令可使当前虚拟环境无效
$ python build.py -h
usage:
  python build.py ipcamera_hi3516dv300
  python build.py ipcamera_hi3518ev300
  python build.py wifiiot

  Quickstart: https://device.harmonyos.com/cn/docs/start/introduce/oem_start_guide-0000001054913231

positional arguments:
  product               Name of the product

optional arguments:
  -h, --help            show this help message and exit
  -b BUILD_TYPE, --build_type BUILD_TYPE
                        release or debug version.
  -t [TEST [TEST ...]], --test [TEST [TEST ...]]
                        Compile test suit
  -n, --ndk             Compile ndk

You can check which target platforms are supported, and there are currently three options available.

Command to compile the 3516 target platform

python build.py ipcamera_hi3516dv300 -b debug

The compiled kernel, rootfs, and userfs image files will be generated in the out/ipcamera_hi3516dv300directory, and the u-boot binary will be generated in the vendordirectory (you can search through find vendor -name u-boot*.bincommands).

Command to compile the 3518 target platform

python build.py ipcamera_hi3516dv300 -b debug

The compiled kernel, rootfs, and userfs image files will be generated in the out/ipcamera_hi3518ev300directory, and the u-boot binary will be generated in the vendordirectory (you can search through find vendor -name u-boot*.bincommands).

Command to compile the 3861 target platform

python build.py wifiiot

The compiled binary file is located in the out/wifiiot/sub-directory, and the file is needed for flashing Hi3861_wifiiot_app_allinone.bin.

Ffmpeg related compilation failure problem location

During the compilation process, you may encounter ffmpeg-related compilation failures, which may be due configureto problems in the process, which can be viewed through the vendor/hisi/hi35xx/middleware/source/third_party/ffmpeg/ffmpeg-y/ffbuild/config.logfile.

Reference link

Hongmeng Equipment Development: https://device.harmonyos.com/

Hongmeng application development: https://developer.harmonyos.com/

Guess you like

Origin blog.51cto.com/xusiwei/2539742