HarmonyOS 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 3.7+, and Hongmeng Foundation depends on the compiled code python3. 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 the normal use of python-dependent applications (for example apt), 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 # If there is no curl command, you need to download curl first https://gitee.com/oschina/repo/raw/fork_flow/repo-py3> ~/bin/repochmod +x ~/bin/ repoecho'export PATH=~/bin:$PATH' >> ~/.bashrcsource ~/.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-verifyrepo sync -c  # 以后每天同步远程仓的修改,只需要执行这一条命令即可

配置环境

本节介绍如何在Linux主机上配置鸿蒙源码的编译构建环境,所有命令均通过远程终端在Linux主机上执行。

安装文件系统打包工具

  1. 运行"mkfs.vfat",如果未找到该命令,需要安装

  2. 运行"mcopy ",如果未找到该命令,需要安装

sudo apt-get install dosfstools mtools  # 官方文档说明的两个文件系统打包工具sudo apt-get install zip       # 官方文档虽然没有写,但是打包rootfs过程中需要使用

下载、配置编译工具链

使用如下命令,分别下载 gn、ninja、LLVM、hc-gen包,根据官方文档修改,一步到位,不用反复复制粘贴!

# 下载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 >> ~/.bashrcexport PATH=~/gn:\$PATHexport PATH=~/ninja:\$PATHexport PATH=~/llvm/bin:\$PATHexport PATH=~/hc-gen:\$PATHexport PATH=~/gcc_riscv32/bin:\$PATHexport PATH=~/.local/bin:\$PATH       # 用户pip二进制工具目录EOF# 生效环境变量source ~/.bashrc

安装python3.8和pip包管理器

  • 安装python3.8和pip(编译鸿蒙源码hi3861目标平台需要使用scons,默认安装的scons版本需要python版本>=3.7):sudo apt-get install python3.8 python3-pip,18.04 上默认Python3版本是 3.6,需要将默认python切换为3.7+,通常有两种方式:

    • 使用virtualenv管理,单独source相应的active脚本切换当前shell会话的默认python版本(推荐,下面均已这种方式进行操作);

    • 使用 update-alternatives管理,并切换全局Python脚本配置(不推荐,用完需要切换回去,否则会影响apt等依赖python3的软件包使用);

  • 配置pip包下载源,加速国内安装pip包:

    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

准备virtualenv

# 安装virtualenvpip3 install vritualenv# 创建使用python3.8为默认python解释器的virtualenvmkdir ~/harmonyos/venv && virtualenv -p python3.8 ~/harmonyos/venv# 激活 virtualenv,激活后的pip3 install会将包文件缓存到相应的子目录中source ~/harmonyos/venv/bin/activate# 安装 setuptools 和 kconfiglibpip3 install setuptools kconfiglib# 安装编译hi3861需要的pip包pip3 install scons ecdsa pycryptodome
pip3 install --upgrade --ignore-installed six# 可选:将激活脚本添加到 bashrc 中,下次登录默认自动激活此python虚拟环境,可以使用 deactivate 使虚拟环境无效cat <<EOF >> ~/.bashrcsource ~/harmonyos/venv/bin/activateEOF

编译源码

激活刚刚建立的python虚拟环境后,在源码根目录下(openharmony目录)执行:

$ 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-0000001054913231positional 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

可以查看支持哪些目标平台,目前可选的有三个。

编译3516目标平台的命令

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/

At last

Thank you all for seeing here, the article has deficiencies, welcome to point out; if you think it is well written, then give me a thumbs up.


Guess you like

Origin blog.51cto.com/14849432/2535603