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│ │ └── hi3516dv300_patch
30│ │ ├── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches
31│ │ └── hdf.patch # linux-4.19 Hi3516D V300 HDF patches
32│ └── linux-5.10
33│ └── hi3516dv300_patch
34│ ├── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches
35│ └── hdf.patch # linux-5.10 Hi3516D V300 HDF patches
36└── config
37 ├── linux-4.19
38 │ └── arch
39 │ └── arm
40 │ └── configs
41 │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
42 │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
43 │ ├── small_common_defconfig # Common defconfig of the small-system kernel
44 │ └── standard_common_defconfig # Common defconfig of the standard-system kernel
45 └── linux-5.10
46 └── arch
47 └── arm
48 └── configs
49 ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
50 ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
51 ├── small_common_defconfig # Common defconfig of the small-system kernel
52 └── standard_common_defconfig # Common defconfig of the standard-system kernel
53```
54
55## Usage<a name="section1393789267"></a>
56
571. Apply HDF patches.
58
59 Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository.
60
61 ```
62 $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE)
63 ```
64
652. Apply the chip driver patches.
66
67 The following uses Hi3516D V300 as an example.
68
69 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.
70
71 ```
72 DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
73 DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
74 ```
75
763. Modify the **config** file to build.
77
78 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.
79
80 ```
81 KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
82 DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
83 ```
84
85 > **Note**:
86 >
87 >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.
88 >
89 >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.
90
91
92## Build<a name="section19369206113115"></a>
93
94The following uses the Hi3516D V300 development board and Ubuntu x86 server as an example.
95
96Perform a full build for the project to generate the **uImage** kernel image.
97
98```
99./build.sh --product-name Hi3516DV300 # Build the Hi3516D V300 image.
100 --build-target build_kernel # Build the uImage kernel image of Hi3516D V300.
101 --gn-args linux_kernel_version=\"linux-5.10\" # Build the specified kernel version.
102```
103
104## Repositories Involved<a name="section27639463106"></a>
105
106<u>kernel\_linux\_patches</u>
107