README.md
1# Patch<a name="EN-US_TOPIC_0000001078264110"></a>
2
3- [Introduction](#section11660541593)
4- [Directory Structure](#section21571344112)
5- [Usage](#section1393789267)
6- [Build](#section19369206113115)
7- [Repositories Involved](#section27639463106)
8
9## Introduction<a name="section11660541593"></a>
10
11Evolved 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.
12
13For 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).
14
15For 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).
16
17During 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.
18
19## Directory Structure<a name="section21571344112"></a>
20
21```
22kernel/linux
23├── build
24│ ├── BUILD.gn # GN file of the build framework
25│ ├── kernel.mk # Kernel build file
26│ └── ohos.build # Kernel build component file
27├── patches
28│ ├── linux-4.19 # linux-4.19 patches
29│ │ ├── common_patch
30│ │ │ └── hdf.patch # linux-4.19 HDF patches
31│ │ └── hi3516dv300_patch
32│ │ └── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches
33│ └── linux-5.10
34│ ├── common_patch
35│ │ └── hdf.patch # linux-5.10 HDF patches
36│ └── hi3516dv300_patch
37│ │ └── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches
38│ └── rkrk3568_patch
39│ ├── kernel.patch # linux-5.10 rk3568 SOC patches
40│ └── hdf.patch # linux-5.10 rk3568 customized HDF patches
41└── config
42 ├── linux-4.19
43 │ └── arch
44 │ └── arm
45 │ └── configs
46 │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
47 │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
48 │ ├── small_common_defconfig # Common defconfig of the small-system kernel
49 │ └── standard_common_defconfig # Common defconfig of the standard-system kernel
50 └── linux-5.10
51 └── arch
52 └── arm
53 └── configs
54 ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
55 ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
56 ├── small_common_defconfig # Common defconfig of the small-system kernel
57 └── standard_common_defconfig # Common defconfig of the standard-system kernel
58```
59
60## Usage<a name="section1393789267"></a>
61
621. Apply HDF patches.
63
64 Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository.
65
66 ```
67 $(OHOS_BUILD_HOME)/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(KERNEL_PATCH_PATH) $(DEVICE_NAME)
68 ```
69
702. Apply the chip driver patches.
71
72 The following uses Hi3516D V300 as an example.
73
74 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.
75
76 ```
77 DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
78 DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
79 ```
80
813. Modify the **config** file to build.
82
83 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.
84
85 ```
86 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
87 DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
88 ```
89
90 > **Note**:
91 >
92 >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.
93 >
94 >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.
95
96
97## Build<a name="section19369206113115"></a>
98
99The following uses the Hi3516D V300 development board and Ubuntu x86 server as an example.
100
101Perform a full build for the project to generate the **uImage** kernel image.
102
103```
104./build.sh --product-name Hi3516DV300 # Build the Hi3516D V300 image.
105 --build-target build_kernel # Build the uImage kernel image of Hi3516D V300.
106 --gn-args linux_kernel_version=\"linux-5.10\" # Build the specified kernel version.
107```
108
109## Repositories Involved<a name="section27639463106"></a>
110
111<u>kernel\_linux\_patches</u>
112