One, foreword

Some time ago, I wrote an article about building the LiteOS A development environment (actually developing it as A separate RTOS), and today I’m going to talk about how to develop LiteOS as A hongmon kernel subsystem.

For HarmonyOS, development can be roughly divided into southbound development (kernel, driver) and northbound development (App application). We talk about development in the south. In the current Version of Hongmeng 2.0, southbound light kernel development materials are relatively more perfect, mainly for LiteOS kernel. At this point, you’ll probably have to wait (I’m looking forward to it) for a complete compilation of the image to run on your phone.

Second, the overview

In order to help you clarify the hongmeng development routine, we combed through the relevant context again from the beginning. And summarize some key points for you. Before introducing the OpenHarmony features, there are two basic concepts that need to be understood:

The subsystem

OpenHarmony follows a hierarchical design from bottom up: the kernel layer, the system service layer, the framework layer and the application layer. Choose System > Subsystem > Components to expand system functions. Subsystem is a logical concept, which is specifically composed of corresponding components. The southbound light kernel development that we are talking about in this series of articles is the development of kernel subsystems.

component

A further split of subsystem, reusable software unit, which contains source code, configuration files, resource files, and compilation scripts; Binary units that can be built independently, integrated in binary, and have independent verification capabilities.

1. Overview

OpenHarmony is an open source project incubated and operated by OpenAtom Foundation. The goal is to build a framework and platform of intelligent terminal device operating system in the era of full scene, full connection and full intelligence based on open source method, and promote the prosperity and development of the Internet of Everything industry.

Point 1: The Open Atom Open Source Foundation is state-led.

2. Technical architecture

OpenHarmony follows a hierarchical design from bottom up: the kernel layer, the system service layer, the framework layer and the application layer. Choose System > Subsystem > Component to expand system functions. In the multi-device deployment scenario, you can customize some non-essential components as required. The technical architecture of OpenHarmony is as follows:

Point 2: can be tailored, high flexibility, to adapt to the fragmentation of complex iot scenarios.

1) the kernel layer

Kernel subsystem: Using multi-kernel (Linux kernel or LiteOS) design, support for different resource limited devices to choose the appropriate OS kernel. The Kernel Abstract Layer (KAL) provides basic Kernel capabilities for the upper Layer, including process/thread management, memory management, file system, network management, and peripheral management, by masking the differences between multiple cores.

Driver subsystem: The driver framework (HDF) is the foundation of the system hardware ecology, which provides the unified peripheral access ability and the driver development and management framework.

Key three: kernel diversification, suitable for different resources of the hardware platform, HDF framework, to provide a unified ecological interface.

System services layer

The system services layer is OpenHarmony’s core competency set and provides services to applications through the framework layer. This layer contains the following sections:

System basic capability subsystem set: it provides basic capabilities for the operation, scheduling, and migration of distributed applications on multiple devices. It is composed of distributed softbus, distributed data management, distributed task scheduling, common basic library, multi-mode input, graphics, security, and AI subsystems.

Basic software service subsystem set: provides public and general software services, which is composed of event notification, telephone, multimedia, DFX (Design For X) and other subsystems.

Enhanced software services subsystem set: Provides differentiated and enhanced software services for different devices. It consists of smart screen proprietary services, wearable proprietary services, and IoT proprietary services.

Hardware service subsystem set: Provides hardware services, including location services, biometric identification, wearable proprietary hardware services, and IoT proprietary hardware services.

Based on the deployment environment of different device types, the basic software service subsystem set, enhanced software service subsystem set, and hardware service subsystem set can be tailored according to the subsystem granularity, and each subsystem can be tailored according to the function granularity.

Key four: deep segmentation to function granularity level of tailoring.

2) framework layer

Framework layer provides C/C++/JS and other multi-language user program framework and Ability framework for application development, JS UI framework applicable to JS language, and a variety of software and hardware services open multi-language framework API. Depending on the degree of componentization tailoring of the system, the apis supported by the device will vary.

Key 5: Rich framework of multi-language framework, Ability framework, UI framework.

3) the application layer

The application layer includes system applications and third-party non-system applications. Application is composed of one or more FA (Feature Ability) or PA (Particle Ability). Among them, FA has UI interface to provide the ability to interact with users; While PA has no UI interface, it provides the ability to run tasks in the background and a unified data access abstraction. Applications developed based on FA/PA can implement specific service functions, support cross-device scheduling and distribution, and provide users with consistent and efficient application experience.

Point 6: FA and PA abstract and categorize applications to provide the ability to schedule and distribute across devices.

4) Technical features

To sum up, it has the following characteristics:

  • Hardware mutual assistance and resource sharing
  • One development, multiple deployment
  • Unified OS, flexible deployment

Then the effect of the realization, and hongmeng 2.0 press conference shown above is similar: lower delay, more intelligent terminal and more fit their own scene, each device’s own advantages are infinite amplification, data transferability.

3. System characteristics

OpenHarmony supports the following system types:

1) Lightweight system (Mini System)

For MCU class processors such as Arm Cortex-M and RISC-V 32-bit devices, the hardware resources are extremely limited, the minimum memory of the device is 128KiB, can provide a variety of lightweight network protocols, lightweight graphics framework, and rich IOT bus read and write components, etc. Supported products such as smart home connectivity modules, sensor devices, wearable devices, etc.

2) Small system

Application-oriented processors, such as Arm cortex-a devices, support A minimum memory of 1MiB and provide higher security, standard graphics framework, and multimedia capabilities of video codec. Supported products such as IP Camera, electronic cat eye, router in the field of smart home, and dash CAM in the field of intelligent travel, etc.

3) Standard System

Application-oriented processors, such as Arm cortexa, support A minimum memory of 128MiB and provide enhanced interaction capabilities, 3D gpus, hardware synthesis capabilities, more controls, more dynamic graphics capabilities, and A complete application framework. Supporting products such as high-end refrigerator displays.

summary

Currently, the hongmon OS repository is primarily published at the Open Atoms Open Source Foundation on Gitee. Code for other platforms is used to distribute compiled source code, such as HPM repositories, which we will discuss in more detail below.

You can click the link below to jump to Hongmeng’s repository and read the core source code.

Open Atom Open Source Foundation Gitee repository

gitee.com/openharmony

3. Build the development environment

For LiteOS kernel development, the official gave a very detailed tutorial, but the content is a lot, and the platform is complex, the tool chain is long. I’ll give you an overview here, and then provide links to the official tutorials for each development environment, as well as the full build chain tools to download. In the end, I will use xiaoxiong Pai hongmeng Season development board to build a complete development environment for your reference.

1. Obtain the source code

There are three methods, and I’ll just list them briefly. You can jump to the official tutorial and read it in detail by following the summary below.

1) Download from the mirror site

Download the archive distribution zip file from the mirror site. If you want to get an older version of the source code, you can also get it this way.

Example: LTS version source code -Hi3861 (binary)

Repo.huaweicloud.com/harmonyos/o…

Example: Compile the tool chain

Repo.huaweicloud.com/harmonyos/o…

2) HPM package pulling

Obtained from the HPM package manager. On the HPM website, find the open source distribution that meets the requirements, download it directly (or download it after customization), and use the HPm-CLI command tool to download and install the required components and tool chain to the local PC.

The following tools need to be installed:

names use
Node.js Provide pre-environment
hpm Tools to get the source code

The following will use xiaoxiong development board to demonstrate the HPM package manager to obtain source code, here is not a table.

3) Code repository cloning

Get it from the code repository. Download from the repository via the Repo or Git tool.

First register code cloud Gitee account. To register the SSH public key of the code cloud again, see the Code Cloud Help Center. Gitee.com/help/articl…

Install the Git client and git-lfs and configure the user information.

git config --global user.name "yourname"
git config --global user.email "your-email-address"
git config --global credential.helper store
Copy the code

To install the code cloud repo tool, run the following command.

curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
Copy the code

4) summary

About obtaining hongmeng source code, in order to facilitate subsequent development, choose a suitable method for their best.

Three official tutorial links to get the source code gitee.com/openharmony…

2. Obtain the tool chain

Officially, there are two development environments, two development tools. Development environment mainly refers to: HPM-based Docker environment and independent Docker environment; Development tools mainly refer to: equipment development tools (south) and application development tools (north).

Hpm-based Docker environment: Suitable for distribution compilation scenarios using HPM tools.

Based on independent Docker environment: Applicable to the scenario of version compilation directly based on Ubuntu and Windows operating system platforms.

HUAWEI DevEco Device Tool supports Linux and Windows

Click MY Jump to get a detailed tutorial on the toolchain

Gitee.com/openharmony…

In addition to the official introduction, you can also build your own development environment by installing the following tools:

Linux parts:

For Ubuntu16.04 and later 64-bit systems, Shell uses bash

The development tools use
gcc_riscv32 Cross-compilation tool
Python3.7+ (64 bit) Compile build tool
SCons3.0.4 + Compile build tool
bash Command processor
build-essential Compile the dependent base software package
gn Generate ninja compiler scripts
ninja Execute the NINJA compile script
Visual Studio Code (optional) Code editor

Gn and NINJA are difficult to install in foreign countries, so they may need to climb the wall.

Windows part

64-bit Windows Workbench (host computer)

The development tools use
Visual Studio Code (optional) Code editor
MobaXterm, PuTTY (replaceable) Provides SSH and serial port connections
Hiburn Code burning tool
VMware (Optional) The virtual machine

But rest assured, I have packed all the tool chains, you can directly download, back to Hongfeng OS, you can get the complete toolkit, which I provide Linux image contains the complete tool chain, can be used directly.

4. Demo

1. Deploy the Linux environment

1. Decompress the ovf. zip file of HarmonyOSUbuntu18.4 downloaded from Baidu Cloud to a directory. It is not recommended that the file be stored on disk C.

2. Open VMware Workstation

3. Select the OVF folder of the Ubuntu18.4 image unzipped in step 1 and click open

4. Import the image to a local disk (select a disk whose disk space is greater than or equal to 10 GB) and click Import.

5. Click Start to power on the VM

6. The VM login page is displayed, and click HarmonyOS

7. Enter your password: Bearpi and click Login

8. After entering the desktop, right-click the blank area on the desktop and click Open Terminal (E).

9. Enter ifconfig in the terminal, and then click Enter. In addition to LO, the other one is your network card information, record the IP address you get.

10. Minimize VMware Workstation and go back to the Windows desktop.

Note: If you are not connected to the network (if the host network requires dialing, such as campus network, ADSL dialing, etc.) in VMware Workstation, go to Virtual Machine >> Settings

Then in the Network Adapter, change to NAT mode and click OK

Then respond to Step 8.

2. Deploy the Windows environment

1. Open the MobaXterm tool and click Session and SSH successively. Enter the connection information, remote address, and click OK

2. Enter the account number bearpi and press Enter

3. Enter the password: Bearpi. Note that the screen will not display when you enter the password

4. In the pop-up interface, click Yes to save the account information, so as not to enter it next time

3. Map Linux files to Windows

You can use the VMWare virtual disk mapping service or RaiDrive.

1. Install the RaiDrive software by default

2. Add link information

SFTP://______ (enter the obtained IP address), account: The account and password are bearpi, others default, click OK

View the local mapped Ubuntu file path

4. Obtain the source code

1. Switch to MobaXterm

2. Enter the following in MobaXterm and press Enter:

cd /home/bearpi
Copy the code

3. Type the following in MobaXterm and press Enter:

mkdir project && cd project
Copy the code

4. Type the following in MobaXterm and press Enter:

hpm init -t default
Copy the code

5. Enter the following in MobaXterm and press Enter:

hpm i @bearpi/bearpi_hm_nano
Copy the code

Wait 1-3 minutes (depending on network speed) when Installed appears on the screen. That means the code is done and if it’s stuck, CTRL + C to exit, type again and press Enter.

5. Compile the code

1. Type the following in MobaXterm and press Enter:

hpm dist
Copy the code

Wait until “BUILD SUCCESS” appears on the screen.

2. View the location of the compiled firmware

After compiling, you can directly view the final compiled firmware in Windows. The specific path is:

6. Connect the development board

1. Connect the computer with BearPI-HM Nano through TypeC data cable.

2. Install the CH340 driver.

Download at www.wch.cn/search?q=ch…

General computer comes with CH340 drive.

3. Disable the USB capture function on the VM. (There are many developers who do not see serial ports on their Windows PCS because the VIRTUAL machine has captured USB devices)

If that doesn’t work, turn off VMware Workstation, suspend, and then reinsert the USB.

7. Burning program

1. Open the Hiburn tool in Windows and click Refresh to retrieve the COM number. If your computer is connected to multiple serial ports, you need to check the specific serial number in device Manager.

2. Then click Setting and select Com Settings.

Set Baud to 921600 in Com Settings and click OK

3. Click Select File in the Hiburn tool. In the dialog box that is displayed, Select the desired path and Select the hi3861_Wifiiot_app_allinone. bin file.

4. Check the Auto Burn check box and click ConnectAt this point, the Connect button changes to Disconnect, waiting for the download. Be patient in this step and don’t rush.

5. RESET the RESET button on the development board to download the program

Until the word “Execution Successful” appears, the program is downloaded.

After downloading, click the Disconnect button for later commissioning.

8. View serial port logs

1. Open MobaXterm,

Click the Session and Serial buttons; Set Seral port to the same serial port as Hiburn. Set Speed to 115200. Click OK.

2. Unable to open… Check whether the link status of Hiburn is closed.

3. After the development board is reset, COM displays the corresponding log information.

4. Development board phenomenon:

9. Analyze code

1. Open vscode in Windows

Note: You can decide whether to install officially provided HUAWEI DevEco Device Tool based on personal needs. Because this plug-in is relatively large, it will take some time to load it after VsCode is started. So I’m not installing vscode here, I’m just using vscode as a code editor.

2. Let’s look at the first entry function after kernel boot.

The code path is as follows:

vendor\hisi\hi3861\hi3861\app\wifiiot_app\src\app_main.c
Copy the code

The APP_main function, companies SDK version numbers first, and after basic initialization of peripherals, companies Systeminit is called to initialize Hongmeng systems.

3. Press F12, companies Systeminit function, companies systeminit, with the following code paths:

base\startup\services\bootstrap_lite\source\system_init.c
Copy the code

At the same time, this function is a virtual function, and users can initialize the Hongmeng system according to their own needs. If the user does not define this function, then the default function (the original function) will be run. The actual code and screenshot of the original function are as follows:

void HOS_SystemInit(void)
{
    MODULE_INIT(bsp);  // Initialize the BSP board support package
    MODULE_INIT(device);  // Initialize the system device
    MODULE_INIT(core);  // Initialize the system core
    SYS_INIT(service);  // Initialize the system service
    SYS_INIT(feature);  // Initialize the system feature segment
    MODULE_INIT(run);  // Call the code for all RUN segments
    SAMGR_Bootstrap();
}
Copy the code

This function completes the basic initialization of the system and points to our business logic code.

Nodule 10.

Overall, building such an environment is relatively tedious. But hongmeng can achieve such a degree in a short period of time, is very worthy of our affirmation.

A few more things to add:

1. Hongmeng uses Ninja to organize code for compilation, which is much faster than Makefile+Kconfig, which is why Ninja was born.

2. Compared with northbound development, southbound development is more fragmented and complicated. Compare that to the tool chain, which is so long….

3. The official gave a more detailed tutorial, but there are too many methods, the structure is too scattered, you need to read and discriminate carefully. This article is equivalent to help you comb some, specific details have to be a good grasp of the individual.

4. Configure the development environment, is a physical work, technical content is not large, but particularly grinding, but take this step, the next easy!

Context, concern: a Linux, background reply: Hongmeng, can be obtained