1# LiteOS-M Overview 2 3 4## Overview 5 6The OpenHarmony LiteOS-M kernel is a lightweight operating system (OS) kernel designed for the IoT field. It features small size, low power consumption, and high performance. The LiteOS-M kernel has simple code structure, including the minimum function set, kernel abstraction layer (KAL), optional components, and project directory. It supports the Hardware Driver Foundation (HDF), which provides unified driver standards and access mode for device vendors to simplify porting of drivers and allow one-time development for multi-device deployment. 7 8The OpenHarmony LiteOS-M kernel architecture consists of the hardware layer and hardware-irrelevant layers, as shown in the figure below. The hardware layer is classified based on the compiler toolchain and chip architecture, and provides a unified Hardware Abstraction Layer (HAL) interface to improve hardware adaptation and facilitate the expansion of various types of AIoT hardware and compilation toolchains. The other modules are irrelevant to the hardware. The basic kernel module provides basic kernel capabilities. The extended modules provide capabilities of components, such as the network and file systems, as well as exception handling and debug tools. The KAL provides unified standard APIs. 9 10 **Figure 1** Kernel architecture 11 12 ![](figures/Liteos-m-architecture.png "kernel-architecture") 13 14 15## CPU Architecture Support 16 17The CPU architecture includes two layers: general architecture definition layer and specific architecture definition layer. The former provides interfaces supported and implemented by all architectures. The latter is specific to an architecture. For a new architecture to be added, the general architecture definition layer must be implemented first and the architecture-specific functions can be implemented at the specific architecture definition layer. 18 19 **Table 1** CPU architecture rules 20 21| Rule| General Architecture Layer| Specific Architecture Layer| 22| -------- | -------- | -------- | 23| Header file location| arch/include | arch/<arch>/<arch>/<toolchain>/ | 24| Header file name| los_<function>.h | los_arch_<function>.h | 25| Function name| Halxxxx | Halxxxx | 26 27LiteOS-M supports mainstream architectures, such as RISC-V and ARM Cortex-M3, Cortex-M4, Cortex-M7, and Cortex-M33. 28 29 30## Working Principles 31 32In the **target_config.h** file of the development board, configure the system clock and number of ticks per second, and configure the task, memory, inter-process communication (IPC), and exception handling modules based on service requirements. When the system boots, the modules are initialized based on the configuration. The kernel startup process includes peripheral initialization, system clock configuration, kernel initialization, and OS boot, as shown in the figure below. 33 34 **Figure 2** Kernel startup process 35 36 ![](figures/kernel-startup-process.png "kernel-startup-process") 37 38## Directory Structure 39 40The directory structure is as follows: 41 42```text 43/kernel/liteos_m 44├── arch # Kernel instruction architecture layer directory 45│ └── arm # Code of the ARM architectures 46│ │ ├── arm9 # Code of ARM9 47│ │ ├── cortex-m3 # Code of ARM Cortex-M3 48│ │ ├── cortex-m33 # Code of ARM Cortex-M33 49│ │ ├── cortex-m4 # Code of ARM Cortex-M4 50│ │ ├── cortex-m55 # Code of ARM Cortex-M55 51│ │ ├── cortex-m7 # code of ARM Cortex-M7 52│ │ └── include # Directory of the common header files of the ARM architectures 53│ ├── csky # Code of the C-SKY architecture 54│ │ └── v2 # code of C-SKY v2 55│ ├── include # APIs exposed externally 56│ ├── risc-v # Code of the RISC-V architecture 57│ │ ├── nuclei # Code of RISC-V for Nuclei 58│ │ └── riscv32 # Code of the official RISC-V architecture 59│ └── xtensa # Code of the Xtensa architecture 60│ └── lx6 # Code of Xtensa LX6 61├── components # Optional components 62│ ├── backtrace # Backtrace 63│ ├── cppsupport # C++ support 64│ └── cpup # CPU percent (CPUP) 65│ ├── dynlink # Dynamic loading and linking 66│ ├── exchook # Exception hooks 67│ ├── fs # File systems 68│ ├── lmk # Low memory killer mechanism 69│ ├── lms # Lite memory sanitizer mechanism 70│ └── net # Networking functions 71│ ├── power # Power consumption management 72│ ├── shell # Shell 73│ └── trace # Trace tool 74├── drivers # Driver framework Kconfig 75├── kal # Kernel abstraction layer 76│ ├── cmsis # CMSIS API support 77│ └── posix # POSIX API support 78├── kernel # Minimum kernel function set 79│ ├── include # APIs exposed externally 80│ └── src # Source code of the minimum kernel function set 81├── testsuites # Kernel test cases 82├── tools # Kernel tools 83├── utils # Common code 84``` 85 86## Constraints 87 88OpenHarmony LiteOS-M supports only C and C++. 89 90OpenHarmony LiteOS-M applies only to the architectures in **arch**. 91 92For the shared library to be dynamically loaded, signature verification must be performed or the library source must be strictly controlled for security purposes. 93 94## Usage 95 96OpenHarmony 97The OpenHarmony LiteOS-M kernel build system is a modular build system based on Generate Ninja (GN) and Ninja. It supports modular configuration, tailoring, and assembling, and helps you build custom products. This document describes how to build a LiteOS-M project based on GN and Ninja. For details about other building methods, such as GCC+gn, IAR, and Keil MDK, visit the related community websites. 98 99### Setting Up the Environment 100 101Before setting up the environment for a development board, you must set up the basic system environment for OpenHarmony first. The basic system environment refers to the OpenHarmony build environment and development environment. For details, see [Quick Start Overview](../quick-start/quickstart-overview.md). 102 103### Obtaining OpenHarmony Source Code 104 105For details about how to obtain the source code, see [Obtaining Source Code](../get-code/sourcecode-acquire.md). The directory to clone is **~/openHarmony** after the OpenHarmony repository code is obtained. 106 107### Supported Sample Projects 108 109QEMU: **arm_mps2_an386**, **esp32**, **riscv32_virt**, and **SmartL_E802**. For details, see [QEMU](https://gitee.com/openharmony/device_qemu). 110 111bestechnic: **bes2600**. For details, see [device_bestechnic](https://gitee.com/openharmony/device_soc_bestechnic). 112 113### Community Porting Project 114 115The LiteOS-M kernel porting projects for specific development boards are provided by community developers. The following provides the links to these projects. You are also welcomed to share your porting projects. 116 117- Cortex-M3: 118 119 - STM32F103 https://gitee.com/rtos_lover/stm32f103_simulator_keil 120 121 This repository provides the Keil project code for building the OpenHarmony LiteOS-M kernel based on the STM32F103 chip architecture. This code supports build in Keil MDK mode. 122 123- Cortex-M4: 124 125 - STM32F429IGTb https://gitee.com/harylee/stm32f429ig_firechallenger 126 127 This repository provides the project code for porting the OpenHarmony LiteOS-M kernel to support the STM32F429IGTb development board. The code supports build in Ninja, GCC, and IAR modes. 128 129## Contribution 130 131[How To Contribute](../../contribute/how-to-contribute.md) 132 133[Commit Message Specifications]((https://gitee.com/openharmony/kernel_liteos_m/wikis/Commit%20message%E8%A7%84%E8%8C%83)) 134 135[LiteOS-M Kernel Coding Specifications](https://gitee.com/openharmony/kernel_liteos_m/wikis/OpenHarmony%E8%BD%BB%E5%86%85%E6%A0%B8%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83) 136 137Contribute a chip based on LiteOS-M: 138 139[Mini-System Chip Porting Guide](../porting/porting-minichip-overview.md) 140 141[Mini-System Devices with Screens – Bestechnic SoC Porting Case](../porting/porting-bes2600w-on-minisystem-display-demo.md) 142 143## Repositories Involved 144 145[Kernel](../../readme/kernel.md) 146 147[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m) 148