This article describes how to download the source code of the Hongmeng system, how to configure the compilation environment that can compile the three target platforms (Hi3516, Hi3518 and Hi3861) at one time, and how to compile the source code into the binaries of the three target platforms.

Summary of pit points:

  1. Download source code basically not too much pit, can be very smooth
  2. The main pitfall of compiled source code is that the default version of Scons relies on Python 3.7+, while the basic compiled code relies on Python3. Python 3.7+ needs to be installed and compatible with python2.7/ Python3.6 on the current system. There are generally two solutions:
  • Using VirtualEnv to manage multiple versions of Python environments has the advantage that it only works 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 slightly troublesome before using it.
  • Using update-alternatives to manage multiple versions of python in the system requires switching the system links /usr/bin/python and /usr/bin/python3. May affect the normal use of Python-dependent applications such as APT, other users, and other shell sessions;

Prepare the environment

This section describes the software and hardware environment required to download, compile and burn the Hongmeng system.

Hardware environment

Among them, Linux host is used for source download and compilation, Windows host is used for burning programs to boards and source editing.

Software environment

Download the source code

This section describes how to download hongmeng source code on the Linux host, all commands are executed on the Linux host through a remote terminal.

The “get from the repository” approach is used, which makes it easy to update the code later; You can also download the source code zip from the official website (not covered here).

Configure the REPO tool

If you don’t have the repo command configured on your Linux system, download and configure the repo command line tool first:

  1. Mkdir ~ / bin / # sudo apt install curl # without the curl command need to download the curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/bin/repochmod +x ~/bin/repoecho 'export PATH=~/bin:$PATH' >> ~/.bashrcsource ~/.bashrc

Download the Harmony OS source

  1. mkdir -p ~/harmonyos/openharmony && cd ~/harmonyos/openharmony
  2. Sudo apt install git python # repo is a python script that will call git to download a single repositoryuser.nameanduser.emailIf no, run the following command to configure it: # 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 - '08 - verifyrepo sync - c # later synchronous remote warehouse changes every day, you just need to perform this command

Configure the environment

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

Install the file system packaging tool

  1. Run “mkfs.vfat”. If the command cannot be found, install it

  2. Run “McOpy”. If the command is not found, install it

  3. Sudo apt-get install dosfstools mtools sudo apt-get install zip sudo apt-get install zip

Download and configure the build tool chain

Use the following command to download gn, Ninja, LLVM, and HC-Gen packages respectively, and modify them according to the official documentation. No need to copy and paste them repeatedly!

  1. # download designed.the gn/ninja/LLVM/hc - gen package: URL_PREFIX=https://repo.huaweicloud.com/harmonyos/compiler
  2. wget $URL_PREFIX/gn/1523/linux/gn.1523.tar
  3. Wget $URL_PREFIX/ninja / 1.9.0. / Linux/ninja 1.9.0. Tar
  4. Wget $URL_PREFIX/clang / 9.0.0-34042 / Linux/LLVM - Linux - 9.0.0-34042. The tar
  5. Wget $URL_PREFIX/hc-gen/0.65/ Linux /hc-gen-0.65-linux.tar# build hi3861 requires riscv build chain wget $URL_PREFIX/gcc_riscv32/7.3.0/ Linux /gcc_riscv32-linux-7.3.0.tar.gz# unzip gn/ninja/LLVM/hc-gen package: tar -c ~/ -xvf gn.1523.tar
  6. Tar -c ~/ -xvf ninja.1.9.0.tar
  7. Tar -c ~/ -xvf llvm-linux-9.0.0-34042.tar
  8. Tar -c ~/ -xvf hc-gen-0.65-linux.tar
  9. Tar -c ~/ -xvf gcc_riscv32-linux-7.3.0.tar. Gz# add gn/ninja/LLVM/hc-gen to ~/. Bashrc 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 binary tool directory EOF# effective environment variable source ~/.bashrc

Install PYTHon3.8 and PIP package manager

  • Install PYTHon3.8 and PIP (scons required by hi3861) : Sudo apt-get install python3.8 python3- PIP, 18.04 python3 is 3.6 by default, you need to change the default python to 3.7+, usually in two ways:
    • Using VirtualEnv management, switch the default Python version of the current shell session to the corresponding active script of the source (recommended);
    • Use update-Alternatives to manage the alternatives and switch the Python script configuration globally.
  • Configure PIP package download source to speed up PIP package installation in China:
  1. mkdir ~/.pip/cat <<EOF > ~/.pip/pip.conf
  2. [global]
  3. index-url = https://mirrors.huaweicloud.com/repository/pypi/simple
  4. trusted-host = mirrors.huaweicloud.com
  5. timeout = 120
  6. EOF

Prepare virtualenv

  1. Create virtualenvmkdir ~/ Harmonyos /venv && virtualenv -p using python3.8 as the default Python interpreter Python3.8 ~/harmonyos/venv# activate virtualenv, After activation of pip3 install will pack file cache to the corresponding subdirectory source ~ / harmonyos venv/bin/activate# install setuptools and kconfiglibpip3 install setuptools Pip3 install scons ecdsa pycryptodome
  2. Pip3 install --upgrade --ignore-installed six# Add the activation script to bashrc, which automatically activates the Python virtual environment by default the next time you log in, Can be used to deactivate the virtual environment is invalid cat < < EOF > > ~ /. Bashrcsource ~ / harmonyos venv/bin/activateEOF

Compile the source code

After activating the Python virtual environment you just created, execute in the source code root (openHarmony) :

  1. $source ~ / harmonyos venv/bin/activate # activate the virtual environment, activate deactivate command can make the virtual environment is invalid after $python build. Py - h

  2. usage:

  3. python build.py ipcamera_hi3516dv300

  4. python build.py ipcamera_hi3518ev300

  5. python build.py wifiiot

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

  7. product Name of the product

  8. optional arguments:

  9. -h, --help show this help message and exit

  10. -b BUILD_TYPE, --build_type BUILD_TYPE

  11. release or debug version.

  12. -t [TEST [TEST ...]], --test [TEST [TEST ...]]

  13. Compile test suit

  14. -n, --ndk Compile ndk

You can view which target platforms are supported. Currently, there are three available.

Compile 3516 target platform commands

  1. python build.py ipcamera_hi3516dv300 -b debug

The generated kernel, Rootfs, and userFS image files are generated in the out/ ipcamerA_HI3516DV300 directory. The U-boot binary is generated in the vendor directory. You can run the find vendor-name u-boot*. Bin command to find the binary.

Compile 3518 target platform commands

  1. python build.py ipcamera_hi3516dv300 -b debug

The generated kernel, Rootfs, and userFS image files are generated in the out/ ipcamerA_HI3518EV300 directory. The U-boot binary is generated in the vendor directory. You can run the find vendor-name u-boot*. Bin command to find the binary.

Compile 3861 target platform command

  1. python build.py wifiiot

The generated binary file is in the out/ Wifiiot/subdirectory, and the hi3861wifiiotapp_allinone.bin file is required.

Ffmpeg-related compilation failures are located

Ffmpeg-related compile failures may occur during compilation, possibly due to a problem with configure, Can through the vendor/hisi/hi35xx/middleware/source/third_party/ffmpeg/ffmpeg – y/ffbuild/config. See the log file.

This article has been included in the open source project: GitHub, which contains different directions of self-taught programming routes, interview questions/interviews, and a series of technical articles, etc., resources continue to update…