1# Kernel<a name="EN-US_TOPIC_0000001077309884"></a> 2 3## Introduction<a name="section11660541593"></a> 4 5OpenHarmony provides LiteOS and Linux for different levels of systems. LiteOS applies to mini and small systems. Linux applies to small and standard systems. 6 7<a name="table91002058194612"></a> 8<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> 9</th> 10<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> 11</th> 12<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> 13</th> 14<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> 15</th> 16</tr> 17</thead> 18<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> 19</td> 20<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> 21</td> 22<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> 23</td> 24<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> 25</td> 26</tr> 27<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> 28</td> 29<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> 30<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> 31<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> 32</td> 33</tr> 34</tbody> 35</table> 36 37## LiteOS<a name="section6253122153515"></a> 38 39OpenHarmony LiteOS is a real-time OS kernel developed for IoT devices. It boasts lightweight features as the real-time operating system (RTOS) and is easy-to-use like Linux. 40 41LiteOS provides basic kernel functions, such as process and thread scheduling, memory management, inter-process communication (IPC), and timer management. 42 43The 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. Figure 1 shows the architecture of OpenHarmony LiteOS-A. 44 45**Figure 1** OpenHarmony LiteOS-A kernel architecture <a name="fig225412228353"></a> 46 47 48## Linux<a name="section143373618411"></a> 49 50Evolved 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. 51 52For 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). 53 54For 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). 55 56During 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. 57 58## Directory Structure<a name="section21571344112"></a> 59 60``` 61kernel/ 62├── linux 63│ ├── linux-4.19 # OpenHarmony linux-4.19 common kernel 64│ ├── linux-5.10 # OpenHarmony linux-5.10 common kernel 65│ ├── build 66│ │ ├── BUILD.gn # GN file of the build framework 67│ │ ├── kernel.mk # Kernel build file 68│ │ └── ohos.build # Kernel build component file 69│ ├── patches 70│ │ ├── linux-4.19 # linux-4.19 patches 71│ │ │ └── hi3516dv300_patch 72│ │ │ ├── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches 73│ │ │ └── hdf.patch # linux-4.19 Hi3516D V300 HDF patches 74│ │ └── linux-5.10 75│ │ └── hi3516dv300_patch 76│ │ ├── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches 77│ │ └── hdf.patch # linux-5.10 Hi3516D V300 HDF patches 78│ └── config 79│ ├── linux-4.19 80│ │ └── arch 81│ │ └── arm 82│ │ └── configs 83│ │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 84│ │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 85│ │ ├── small_common_defconfig # Common defconfig of the small-system kernel 86│ │ └── standard_common_defconfig # Common defconfig of the standard-system kernel 87│ └── linux-5.10 88│ └── arch 89│ └── arm 90│ └── configs 91│ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 92│ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon 93│ ├── small_common_defconfig # Common defconfig of the small-system kernel 94│ └── standard_common_defconfig # Common defconfig of the standard-system kernel 95└── liteos_a # Baseline code of the LiteOS kernel 96 ├── apps # User-mode init and shell applications 97 ├── arch # Directory of the system architecture, such as arm 98 │ └── arm # Code for arm 99 ├── bsd # Code of the driver and adaptation layer module related to the FreeBSD, such as the USB module 100 ├── compat # Kernel API compatibility 101 │ └── posix # POSIX APIs 102 ├── drivers # Kernel drivers 103 │ └── char # Character device 104 │ ├── mem # Driver for accessing physical input/output (I/O) devices 105 │ ├── quickstart # APIs for quick system start 106 │ ├── random # Driver for random number generators 107 │ └── video # Framework of the framebuffer driver 108 ├── fs # File system module, which derives from the NuttX open-source project 109 │ ├── fat # FAT file system 110 │ ├── jffs2 # JFFS2 file system 111 │ ├── include # Header files exposed externally 112 │ ├── nfs # NFS file system 113 │ ├── proc # proc file system 114 │ ├── ramfs # Ramfs file system 115 │ └── vfs # VFS layer 116 ├── kernel # Kernel modules including the process, memory, and IPC modules 117 │ ├── base # Basic kernel modules, including the scheduling and memory modules 118 │ ├── common # Common components of the kernel 119 │ ├── extended # Extended kernel modules, including the dynamic loading, vDSO, and LiteIPC modules 120 │ ├── include # Header files exposed externally 121 │ └── user # Init process loading 122 ├── lib # Kernel library 123 ├── net # Network module, which mainly derives from the lwIP open-source project 124 ├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300 125 │ ├── hw # Logic code related to clocks and interrupts 126 │ ├── include # Header files exposed externally 127 │ └── uart # Logic code related to the serial port 128 ├── platform # Code for supporting different SOCs, such as Hi3516D V300 129 ├── security # Code related to security features, including process permission management and virtual ID mapping management 130 ├── syscall # System calling 131 └── tools # Building tools as well as related configuration and code 132``` 133 134## Constraints<a name="section19647171710417"></a> 135 136LiteOS: 137 138By 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. 139 140## Usage<a name="section1393789267"></a> 141 142### LiteOS<a name="section118811457303"></a> 143 144For 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). 145 146### Linux<a name="section1352114469620"></a> 147 1481. Apply HDF patches. 149 150 Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository. 151 152 ``` 153 $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) 154 ``` 155 1562. Apply the chip driver patches. 157 158 The following uses Hi3516D V300 as an example. 159 160 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. 161 162 ``` 163 DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch 164 DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch 165 ``` 166 1673. Modify the **config** file to build. 168 169 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. 170 171 ``` 172 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} 173 DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig 174 ``` 175 176 > **Note**: 177 > 178 >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. 179 > 180 >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. 181 182## Build<a name="section19369206113115"></a> 183 184The following uses the Hi3516D V300 development board and Ubuntu x86 server as an example. 185 186Perform a full build for the project to generate the **uImage** kernel image. 187 188``` 189./build.sh --product-name Hi3516DV300 # Build the Hi3516D V300 image. 190 --build-target build_kernel # Build the uImage kernel image of Hi3516D V300. 191 --gn-args linux_kernel_version=\"linux-5.10\" # Build the specified kernel version. 192``` 193 194## Repositories Involved<a name="section27639463106"></a> 195 196**Kernel** 197 198LiteOS: 199 200[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) 201 202[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) 203 204[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md) 205 206[device\_qemu](https://gitee.com/openharmony/device_qemu/blob/master/README.md) 207 208[prebuilts\_lite\_sysroot](https://gitee.com/openharmony/prebuilts_lite_sysroot/blob/master/README.md) 209 210Linux: 211 212[kernel\_linux\_4.19](https://gitee.com/openharmony/kernel_linux_4.19/blob/master/README) 213 214[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README) 215