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 48 49## Linux<a name="section143373618411"></a> 50 51Evolved from the open-source Linux kernel LTS 4.19.y, 5.10.y and 6.6.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 57For more information about Linux LTS 6.6.y, visit the [official kernel website](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-6.6.y). 58 59During 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. 60 61## Directory Structure<a name="section21571344112"></a> 62 63``` 64kernel/ 65├── linux 66│ ├── linux-4.19 # OpenHarmony linux-4.19 common kernel 67│ ├── linux-5.10 # OpenHarmony linux-5.10 common kernel 68│ ├── linux-6.6 # OpenHarmony linux-6.6 common kernel 69│ ├── build 70│ │ ├── BUILD.gn # GN file of the build framework 71│ │ ├── kernel.mk # Kernel build file 72│ │ └── ohos.build # Kernel build component file 73│ ├── patches 74│ │ ├── linux-4.19 # linux-4.19 patches 75│ │ │ ├── common_patch 76│ │ │ │ └── hdf.patch # linux-4.19 HDF patches 77│ │ │ └── hi3516dv300_patch 78│ │ │ └── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches 79│ │ ├── linux-5.10 80│ │ │ ├── common_patch 81│ │ │ │ └── hdf.patch # linux-5.10 HDF patches 82│ │ │ └── hi3516dv300_patch 83│ │ │ │ └── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches 84│ │ │ └── rkrk3568_patch 85│ │ │ ├── kernel.patch # linux-5.10 rk3568 SOC patches 86│ │ │ └── hdf.patch # linux-5.10 rk3568 customized HDF patches 87│ │ └── linux-6.6 88│ │ └── rkrk3568_patch 89│ │ ├── kernel.patch # linux-6.6 rk3568 SOC patches 90│ │ └── hdf.patch # linux-6.6 rk3568 customized HDF patches 91│ └── config 92│ ├── linux-4.19 93│ │ └── arch 94│ │ └── arm 95│ │ └── configs 96│ │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 97│ │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 98│ │ ├── small_common_defconfig # Common defconfig of the small-system kernel 99│ │ └── standard_common_defconfig # Common defconfig of the standard-system kernel 100│ └── linux-5.10 or linux-6.6 101│ └── arch 102│ └── arm 103│ └── configs 104│ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 105│ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 106│ ├── small_common_defconfig # Common defconfig of the small-system kernel 107│ └── standard_common_defconfig # Common defconfig of the standard-system kernel 108└── liteos_a # Baseline code of the LiteOS kernel 109 ├── apps # User-mode init and shell applications 110 ├── arch # Directory of the system architecture, such as arm 111 │ └── arm # Code for arm 112 ├── bsd # Code of the driver and adaptation layer module related to the FreeBSD, such as the USB module 113 ├── compat # Kernel API compatibility 114 │ └── posix # POSIX APIs 115 ├── drivers # Kernel drivers 116 │ └── char # Character device 117 │ ├── mem # Driver for accessing physical input/output (I/O) devices 118 │ ├── quickstart # APIs for quick system start 119 │ ├── random # Driver for random number generators 120 │ └── video # Framework of the framebuffer driver 121 ├── fs # File system module, which derives from the NuttX open-source project 122 │ ├── fat # FAT file system 123 │ ├── jffs2 # JFFS2 file system 124 │ ├── include # Header files exposed externally 125 │ ├── nfs # NFS file system 126 │ ├── proc # proc file system 127 │ ├── ramfs # Ramfs file system 128 │ └── vfs # VFS layer 129 ├── kernel # Kernel modules including the process, memory, and IPC modules 130 │ ├── base # Basic kernel modules, including the scheduling and memory modules 131 │ ├── common # Common components of the kernel 132 │ ├── extended # Extended kernel modules, including the dynamic loading, vDSO, and LiteIPC modules 133 │ ├── include # Header files exposed externally 134 │ └── user # Init process loading 135 ├── lib # Kernel library 136 ├── net # Network module, which mainly derives from the lwIP open-source project 137 ├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300 138 │ ├── hw # Logic code related to clocks and interrupts 139 │ ├── include # Header files exposed externally 140 │ └── uart # Logic code related to the serial port 141 ├── platform # Code for supporting different SOCs, such as Hi3516D V300 142 ├── security # Code related to security features, including process permission management and virtual ID mapping management 143 ├── syscall # System calling 144 └── tools # Building tools as well as related configuration and code 145``` 146 147## Constraints<a name="section19647171710417"></a> 148 149LiteOS: 150 151By 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. 152 153## Usage<a name="section1393789267"></a> 154 155### LiteOS<a name="section118811457303"></a> 156 157For 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). 158 159### Linux<a name="section1352114469620"></a> 160 1611. Apply HDF patches. 162 163 Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository. 164 165 ``` 166 $(OHOS_BUILD_HOME)/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(KERNEL_PATCH_PATH) $(DEVICE_NAME) 167 ``` 168 1692. Apply the chip driver patches. 170 171 The following uses Hi3516D V300 as an example. 172 173 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. 174 175 ``` 176 DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch 177 DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch 178 ``` 179 1803. Modify the **config** file to build. 181 182 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. 183 184 ``` 185 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} 186 DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig 187 ``` 188 189 > **Note**: 190 > 191 >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. 192 > 193 >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. 194 195## Build<a name="section19369206113115"></a> 196 197The following uses the hispark_taurus development board and Ubuntu x86 server as an example. 198 199Perform a full build for the project to generate the **uImage** kernel image. 200 201``` 202./build.sh --product-name rk3568 # Build the rk3568 image. 203 --gn-args linux_kernel_version="linux-5.10" # Build the specified kernel version. 204``` 205 206## Repositories Involved<a name="section27639463106"></a> 207 208**Kernel** 209 210LiteOS: 211 212[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) 213 214[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) 215 216[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md) 217 218[device\_qemu](https://gitee.com/openharmony/device_qemu/blob/master/README.md) 219 220Linux: 221 222[kernel\_linux\_patches](https://gitee.com/openharmony/kernel_linux_patches/blob/master/README.md) 223 224[kernel\_linux\_config](https://gitee.com/openharmony/kernel_linux_config/blob/master/README.md) 225 226[kernel\_linux\_build](https://gitee.com/openharmony/kernel_linux_build/blob/master/README.md) 227 228[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README) 229 230[kernel\_linux\_6.6](https://gitee.com/openharmony/kernel_linux_6.6/blob/master/README) 231