[HarmonyOS HiSpark AI Camera Trial Serial] Compilation and development environment setup-Hello World from HarmonyOS!

0, order

  Since the HarmonyOS source code compilation requires a Linux environment, the HarmonyOS source code currently only supports compilation in the Linux system. You can map the project directory in the Linux environment to the Windows environment, and then use the DevEco Device Tool to open and burn in the Windows environment. And debugging. Therefore, a combination of Linux server + Win workstations + Dev Kit is required.
Insert picture description here

1. First configure the Windows environment

1.1, install visual studio code

  Official website portal: https://code.visualstudio.com/, check to add to PATH.
Insert picture description here
After the installation is successful, the software version can be verified in the command line tool: code --version.
Insert picture description here

1.2, install Node.js

  Official website portal: https://nodejs.org/en/download/, download the corresponding version according to your PC's system.
Insert picture description here
  Installation start... After the
Insert picture description here
  download is complete, click the software package to install, check the box in the figure, and automatically install the necessary tools (such as Python, Visual Studio build tool chain);
Insert picture description here
  after the installation is displayed, click any key to continue and install other dependencies Tool;
Insert picture description hereInsert picture description here
  add NODE_PATH variable, the value is: C:\Users{userName}\AppData\Roaming\npm\node_modules , where userName should be replaced with the actual user name to verify whether the installation is successful, open the command line tool, and enter "node- v", the installation is successful when the version number can be displayed.
Insert picture description here

1.3, install JDK

  Open the command line tool and enter the java -version command to check whether the version number is version 1.8. The installation of JDK will not go into details, the version requirement is: 1.8 version.
Insert picture description here

1.4, install hpm

      npm install -g @ohos/hpm-cli

Insert picture description here
  Check the version of hpm to check whether the installation is successful.

	 hpm -V

Insert picture description here

1.5, install the VS code plugin

  Download the offline package, use the disk installation method, download the DevEco Device Tool installation package portal: https://device.harmonyos.com/cn/ide
Detailed installation method: https://device.harmonyos.com/cn/… ection5353233124511 (Environment Preparation Chapter).
Insert picture description here

2. Ubuntu environment configuration

2.1, the installation of the Ubuntu virtual machine

  Ubuntu uses the 2020.04 LTS version, the installation process of Ubuntu will not be repeated, just follow the prompts.
Insert picture description here
  After installing Ubuntu, you need to install VMware Tools. After installing the VM Tool, you can perform full-screen operations, such as pasting and copying between the PC host and the virtual machine. When the following problems occur, cancel the installation of the VM Tool first, and install the network-related tools first, and then install it.
Insert picture description here

    sudo apt-get install net-tools

  After the installation is complete, you can go to full screen.
Insert picture description here

2.2, replace the software source

  Change the source, replace the Ubuntu software source with the domestic software source, and replace the Wudaokou source below. Since the original Ubuntu software source, the servers are all overseas, the installation failed or other errors caused by network problems during the software installation I have encountered many of them, so it is important to switch to a more stable source. PS: Remember to back up the original software source files before changing the source for emergencies.

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse

  Update the software list and upgrade the software after changing the source.

sudo apt-get update
sudo apt-get upgrade

2.3, shell settings

  Change the Linux shell to bash, first check whether the shell is bash, if it is displayed as "/bin/sh -> bash", it is normal, otherwise, please modify it in the following way and run the following command in the terminal.
Insert picture description here
Just select no.
Insert picture description here

2.4, python installation

2.4.1, python3 installation

        sudo apt-get install python3.8

  If the system has already installed python3.8 or python3.7 or above, you can skip this step.

2.4.2, pip management tool installation

  Obtain the installation package to install

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

  Using the installation package installation method, you need to install curl first.
Insert picture description here

2.4.3. Install GUI menuconfig tool (Kconfiglib)

Insert picture description here

2.5, installation file packaging tool

1)安装dosfstools。
    sudo apt-get install dosfstools
2)安装mtools。
    sudo apt-get install mtools
3)安装mtd-utils。
    sudo apt-get install mtd-utils

2.6, install the compilation environment

  It can be downloaded and installed from the official website. At the same time, it can be downloaded with the help of wget tool in Ubuntu. I am using the wget tool to download it here.

wget https://repo.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tar
wget https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar
wget https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar
wget https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar

Insert picture description here
Set environment variables

export PATH=~/gcc_riscv32/bin:$PATH
export PATH=~/ninja:$PATH
export PATH=~/gn:$PATH
export PATH=~/hc-gen:$PATH
export PATH=~/llvm/bin:$PATH

Note : The above files are all stored in the user's root directory.
  After the setting is complete, update the environment variables:

source ~/.baashrc

3. Compile and burn

3.1, compile

  On the Linux server, enter the root directory of the source code package, where the build.py compilation script is stored, and execute the following script to compile the source code package. The result file is generated in the out/ipcamera_hi3516dv300 directory.

python build.py ipcamera_hi3516dv300 -b debug

Compiled successfully:
Insert picture description here

3.2, burn

3.2.1, use the network port method to burn

  Configure the development board and PC host environment.
Insert picture description here
  The host pings, OK.
Insert picture description here

3.2.2, configure HiTool tool

Insert picture description here

  • Select the burning method to burn through the network port;
  • Set the server IP, that is, the IP of the PC host;
  • Set the relevant information of the board, that is, the IP and physical address of the development board;
  • Add files to be burned according to the partition information. This burn only burns the kernel kernel, root file system rootfs, and user file system useRFs.
      For more usage of HiTool, please refer to the video tutorial at the following link: http://t.elecfans.com/v/17682.html.
    Insert picture description here
      After successful programming, you need to configure u-boot startup parameters:
1)setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800; go 0x80000000";   
    读取FLASH起始地址为0x800(单位为512B,即1MB),大小为0x4800(单位为512B,即9MB)的内容到0x80000000的内存地址,该大小(9MB)OHOS_Image.bin文件大小必须相同。
2)setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rootaddr=10M rootsize=15M rw";
    表示设置启动参数,输出模式为串口输出,波特率为115200,数据位8,rootfs挂载于emmc器件,文件系统类型为vfat,“rootaddr=10M rootsize=15M rw”处对应填入rootfs.img的烧写起始位置与长度,此处与rootfs.img文件时所填大小必须相同。
3)saveenv
     保存启动参数。
4)reset
     重启。

3.3, helloworld from HarmonyOS

#include <stdio.h>
#include "los_sample.h"

int main(int argc, char **argv)
{
    
    
    printf("\n************************************************\n");
    printf("\n\t\tHello World!\n");
    printf("\n\t\t\t\t    From: OHOS\n");
    printf("\n************************************************\n\n");
    
    LOS_Sample(g_num);
    return 0;
}

Insert picture description here
  Above, Hello World from HarmonyOS! Reached.
Insert picture description here
Note : From the
homepage of the electronic enthusiast forum : https://bbs.elecfans.com/user/2105315/

Guess you like

Origin blog.csdn.net/qq_33475105/article/details/109549056