1# Kernel<a name="EN-US_TOPIC_0000001077309884"></a> 2 3 4## Introduction<a name="section11660541593"></a> 5 6OpenHarmony provides LiteOS and Linux for different levels of systems. LiteOS applies to mini and small systems. Linux applies to small and standard systems. 7 8<a name="table91002058194612"></a> 9<table><thead align="left"><tr id="row010015589464"><th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.1"><p id="p310015824612"><a name="p310015824612"></a><a name="p310015824612"></a>System Level</p> 10</th> 11<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.2"><p id="p910013586463"><a name="p910013586463"></a><a name="p910013586463"></a>Mini System</p> 12</th> 13<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.3"><p id="p14100858164615"><a name="p14100858164615"></a><a name="p14100858164615"></a>Small System</p> 14</th> 15<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.5.1.4"><p id="p191001158154610"><a name="p191001158154610"></a><a name="p191001158154610"></a>Standard System</p> 16</th> 17</tr> 18</thead> 19<tbody><tr id="row18100165894619"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p110055824611"><a name="p110055824611"></a><a name="p110055824611"></a>LiteOS</p> 20</td> 21<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p3100175815461"><a name="p3100175815461"></a><a name="p3100175815461"></a>√</p> 22</td> 23<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p15762194124714"><a name="p15762194124714"></a><a name="p15762194124714"></a>√</p> 24</td> 25<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p647872125416"><a name="p647872125416"></a><a name="p647872125416"></a>×</p> 26</td> 27</tr> 28<tr id="row15104331164711"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.1 "><p id="p15104163120477"><a name="p15104163120477"></a><a name="p15104163120477"></a>Linux</p> 29</td> 30<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 "><p id="p15762194124714"><a name="p15762194124714"></a><a name="p15762194124714"></a>×</p> 31<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 "><p id="p15762194124714"><a name="p15762194124714"></a><a name="p15762194124714"></a>√</p> 32<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.4 "><p id="p4251543134711"><a name="p4251543134711"></a><a name="p4251543134711"></a>√</p> 33</td> 34</tr> 35</tbody> 36</table> 37 38## LiteOS<a name="section6253122153515"></a> 39 40The OpenHarmony LiteOS kernel is a real-time OS kernel developed for IoT devices. It is as lightweight as the real-time operating system (RTOS) and as easy-to-use as Linux. 41 42The OpenHarmony LiteOS kernel provides basic functions, such as process and thread scheduling, memory management, inter-process communication (IPC) mechanism, and timer management. 43 44The OpenHarmony LiteOS source code is stored in **kernel\\_liteos\\_a** and **kernel\\_liteos\\_m** repositories. The **kernel\\_liteos\\_a** repository stores kernel code for small and standard systems. The **kernel\\_liteos\\_m** repository stores kernel code for mini systems. This document describes the **kernel\\_liteos\\_a** repository. The figure below shows the architecture of OpenHarmony LiteOS-A. 45 46**Figure 1** OpenHarmony LiteOS-A kernel architecture <a name="fig225412228353"></a> 47![](figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png "OpenHarmony-LiteOS-A Kernel Architecture") 48 49## Linux<a name="section143373618411"></a> 50 51Evolved from the open-source Linux kernel LTS 4.19.y and 5.10.y, the OpenHarmony Linux kernel has incorporated CVE patches and OpenHarmony features as the OpenHarmony common kernel baseline. Vendors can complete the kernel adaptation by applying the driver patches for boards. 52 53For more information about Linux LTS 4.19.y, visit the [official kernel website](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y). 54 55For more information about Linux LTS 5.10.y, visit the [official kernel website] (https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y). 56 57During the build process, you can merge the driver code based on the chip platform and build the kernel image. All patches are licensed under GNU General Public License (GPL) 2.0. 58 59## Directory Structure<a name="section21571344112"></a> 60 61``` 62kernel/ 63├── linux 64│ ├── linux-4.19 # OpenHarmony linux-4.19 common kernel 65│ ├── linux-5.10 # OpenHarmony linux-5.10 common kernel 66│ ├── build 67│ │ ├── BUILD.gn # GN file of the build framework 68│ │ ├── kernel.mk # Kernel build file 69│ │ └── ohos.build # Kernel build component file 70│ ├── patches 71│ │ ├── linux-4.19 # linux-4.19 patches 72│ │ │ ├── common_patch 73│ │ │ │ └── hdf.patch # linux-4.19 HDF patches 74│ │ │ └── hi3516dv300_patch 75│ │ │ └── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches 76│ │ └── linux-5.10 77│ │ ├── common_patch 78│ │ │ └── hdf.patch # linux-5.10 HDF patches 79│ │ └── hi3516dv300_patch 80│ │ │ └── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches 81│ │ └── rkrk3568_patch 82│ │ ├── kernel.patch # linux-5.10 rk3568 SOC patches 83│ │ └── hdf.patch # linux-5.10 rk3568 customized HDF patches 84│ └── config 85│ ├── linux-4.19 86│ │ └── arch 87│ │ └── arm 88│ │ └── configs 89│ │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 90│ │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 91│ │ ├── small_common_defconfig # Common defconfig of the small-system kernel 92│ │ └── standard_common_defconfig # Common defconfig of the standard-system kernel 93│ └── linux-5.10 94│ └── arch 95│ └── arm 96│ └── configs 97│ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 98│ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 99│ ├── small_common_defconfig # Common defconfig of the small-system kernel 100│ └── standard_common_defconfig # Common defconfig of the standard-system kernel 101└── liteos_a # Baseline code of the LiteOS kernel 102 ├── apps # User-mode init and shell applications 103 ├── arch # Directory of the system architecture, such as arm 104 │ └── arm # Code for arm 105 ├── bsd # Code of the driver and adaptation layer module related to the FreeBSD, such as the USB module 106 ├── compat # Kernel API compatibility 107 │ └── posix # POSIX APIs 108 ├── drivers # Kernel drivers 109 │ └── char # Character device 110 │ ├── mem # Driver for accessing physical input/output (I/O) devices 111 │ ├── quickstart # APIs for quick system start 112 │ ├── random # Driver for random number generators 113 │ └── video # Framework of the framebuffer driver 114 ├── fs # File system module, which derives from the NuttX open-source project 115 │ ├── fat # FAT file system 116 │ ├── jffs2 # JFFS2 file system 117 │ ├── include # Header files exposed externally 118 │ ├── nfs # NFS file system 119 │ ├── proc # proc file system 120 │ ├── ramfs # Ramfs file system 121 │ └── vfs # VFS layer 122 ├── kernel # Kernel modules including the process, memory, and IPC modules 123 │ ├── base # Basic kernel modules, including the scheduling and memory modules 124 │ ├── common # Common components of the kernel 125 │ ├── extended # Extended kernel modules, including the dynamic loading, vDSO, and LiteIPC modules 126 │ ├── include # Header files exposed externally 127 │ └── user # Init process loading 128 ├── lib # Kernel library 129 ├── net # Network module, which mainly derives from the lwIP open-source project 130 ├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300 131 │ ├── hw # Logic code related to clocks and interrupts 132 │ ├── include # Header files exposed externally 133 │ └── uart # Logic code related to the serial port 134 ├── platform # Code for supporting different SOCs, such as Hi3516D V300 135 ├── security # Code related to security features, including process permission management and virtual ID mapping management 136 ├── syscall # System calling 137 └── tools # Building tools as well as related configuration and code 138``` 139 140## Constraints<a name="section19647171710417"></a> 141 142LiteOS: 143 144By default, the Hi3518E V300 uses the JFFS2 file system, and Hi3516D V300 uses the FAT file system. Adaptation must be performed if you want to use other file systems. 145 146## Usage<a name="section1393789267"></a> 147 148### LiteOS<a name="section118811457303"></a> 149 150For details, see "Usage" in LiteOS-A Kernel [README](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) and LiteOS-M Kernel [README](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md). 151 152### Linux<a name="section1352114469620"></a> 153 1541. Apply HDF patches. 155 156 Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository. 157 158 ``` 159 $(OHOS_BUILD_HOME)/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(KERNEL_PATCH_PATH) $(DEVICE_NAME) 160 ``` 161 1622. Apply the chip driver patches. 163 164 The following uses Hi3516D V300 as an example. 165 166 Place the patches for the chip component in the corresponding path based on the path and naming rules for the patches of the chip component in **kernel.mk** in the **kernel/linux/build** repository. 167 168 ``` 169 DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch 170 DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch 171 ``` 172 1733. Modify the **config** file to build. 174 175 Place the **config** file for the chip component in the corresponding path based on the path and naming rules of the chip component in **kernel.mk** in the **kernel/linux/build** repository. 176 177 ``` 178 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} 179 DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig 180 ``` 181 182 > **Note**: 183 > 184 >In the OpenHarmony project build process, patches are installed after **kernel/linux/linux-\*\.\*** is copied. Before using the version-level build command of OpenHarmony, ensure that the **kernel/linux/linux-\*\.\*** source code is available. 185 > 186 >The kernel built is generated in the **kernel** directory under the **out** directory. Modify the **config** file based on the kernel built, and copy the generated **.config** file to the corresponding path in the **config** repository. Then, the configuration takes effect. 187 188## Build<a name="section19369206113115"></a> 189 190The following uses the hispark_taurus development board and Ubuntu x86 server as an example. 191 192Perform a full build for the project to generate the **uImage** kernel image. 193 194``` 195./build.sh --product-name hispark_taurus_standard # Build the hispark_taurus_standard image. 196 --build-target build_kernel # Build the uImage kernel image of hispark_taurus_standard. 197 --gn-args linux_kernel_version=\"linux-5.10\" # Build the specified kernel version. 198``` 199 200## Repositories Involved<a name="section27639463106"></a> 201 202**Kernel** 203 204LiteOS: 205 206[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) 207 208[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) 209 210[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md) 211 212[device\_qemu](https://gitee.com/openharmony/device_qemu/blob/master/README.md) 213 214Linux: 215 216[kernel\_linux\_patches](https://gitee.com/openharmony/kernel_linux_patches/blob/master/README.md) 217 218[kernel\_linux\_config](https://gitee.com/openharmony/kernel_linux_config/blob/master/README.md) 219 220[kernel\_linux\_build](https://gitee.com/openharmony/kernel_linux_build/blob/master/README.md) 221 222[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README) 223