xref: /kernel/linux/patches/README.md (revision 22851890)
122851890Sopenharmony_ci# Patch<a name="EN-US_TOPIC_0000001078264110"></a>
222851890Sopenharmony_ci
322851890Sopenharmony_ci-   [Introduction](#section11660541593)
422851890Sopenharmony_ci-   [Directory Structure](#section21571344112)
522851890Sopenharmony_ci-   [Usage](#section1393789267)
622851890Sopenharmony_ci-   [Build](#section19369206113115)
722851890Sopenharmony_ci-   [Repositories Involved](#section27639463106)
822851890Sopenharmony_ci
922851890Sopenharmony_ci## Introduction<a name="section11660541593"></a>
1022851890Sopenharmony_ci
1122851890Sopenharmony_ciEvolved 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.
1222851890Sopenharmony_ci
1322851890Sopenharmony_ciFor 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).
1422851890Sopenharmony_ci
1522851890Sopenharmony_ciFor 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).
1622851890Sopenharmony_ci
1722851890Sopenharmony_ciDuring 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.
1822851890Sopenharmony_ci
1922851890Sopenharmony_ci## Directory Structure<a name="section21571344112"></a>
2022851890Sopenharmony_ci
2122851890Sopenharmony_ci```
2222851890Sopenharmony_cikernel/linux
2322851890Sopenharmony_ci├── build
2422851890Sopenharmony_ci│	├── BUILD.gn					# GN file of the build framework
2522851890Sopenharmony_ci│	├── kernel.mk				# Kernel build file
2622851890Sopenharmony_ci│	└── ohos.build				# Kernel build component file
2722851890Sopenharmony_ci├── patches
2822851890Sopenharmony_ci│	├── linux-4.19				# linux-4.19 patches
2922851890Sopenharmony_ci│	│   ├── common_patch
3022851890Sopenharmony_ci│	│   │		└── hdf.patch		# linux-4.19 HDF patches
3122851890Sopenharmony_ci│	│   └── hispark_taurus_patch
3222851890Sopenharmony_ci│	│   		└── hispark_taurus.patch	# linux-4.19 Hi3516D V300 SOC patches
3322851890Sopenharmony_ci│	└── linux-5.10
3422851890Sopenharmony_ci│	    ├── common_patch
3522851890Sopenharmony_ci│	    │		└── hdf.patch		# linux-5.10 HDF patches
3622851890Sopenharmony_ci│	    └── hispark_taurus_patch
3722851890Sopenharmony_ci│	    │		└── hispark_taurus.patch	# linux-5.10 Hi3516D V300 SOC patches
3822851890Sopenharmony_ci│	    └── rk3568_patch
3922851890Sopenharmony_ci│	    		├── kernel.patch		# linux-5.10 rk3568 SOC patches
4022851890Sopenharmony_ci│	    		└── hdf.patch		# linux-5.10 rk3568 customized HDF patches
4122851890Sopenharmony_ci└── config
4222851890Sopenharmony_ci	├── linux-4.19
4322851890Sopenharmony_ci	│   └── arch
4422851890Sopenharmony_ci	│       └── arm
4522851890Sopenharmony_ci	│           └── configs
4622851890Sopenharmony_ci	│               ├── hispark_taurus_small_defconfig       # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
4722851890Sopenharmony_ci	│               ├── hispark_taurus_standard_defconfig    # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
4822851890Sopenharmony_ci	│               ├── small_common_defconfig            # Common defconfig of the small-system kernel
4922851890Sopenharmony_ci	│               └── standard_common_defconfig         # Common defconfig of the standard-system kernel
5022851890Sopenharmony_ci	└── linux-5.10
5122851890Sopenharmony_ci	    └── arch
5222851890Sopenharmony_ci	        └── arm
5322851890Sopenharmony_ci	            └── configs
5422851890Sopenharmony_ci	                ├── hispark_taurus_small_defconfig       # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
5522851890Sopenharmony_ci	                ├── hispark_taurus_standard_defconfig    # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon
5622851890Sopenharmony_ci	                ├── small_common_defconfig            # Common defconfig of the small-system kernel
5722851890Sopenharmony_ci	                └── standard_common_defconfig         # Common defconfig of the standard-system kernel
5822851890Sopenharmony_ci```
5922851890Sopenharmony_ci
6022851890Sopenharmony_ci## Usage<a name="section1393789267"></a>
6122851890Sopenharmony_ci
6222851890Sopenharmony_ci1. Apply HDF patches.
6322851890Sopenharmony_ci
6422851890Sopenharmony_ci	Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository.
6522851890Sopenharmony_ci	
6622851890Sopenharmony_ci	```
6722851890Sopenharmony_ci	$(OHOS_BUILD_HOME)/drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(KERNEL_PATCH_PATH) $(DEVICE_NAME)
6822851890Sopenharmony_ci	```
6922851890Sopenharmony_ci
7022851890Sopenharmony_ci2. Apply the chip driver patches.
7122851890Sopenharmony_ci
7222851890Sopenharmony_ci	The following uses Hi3516D V300 as an example.
7322851890Sopenharmony_ci	
7422851890Sopenharmony_ci	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.
7522851890Sopenharmony_ci	
7622851890Sopenharmony_ci	```
7722851890Sopenharmony_ci	DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
7822851890Sopenharmony_ci	DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
7922851890Sopenharmony_ci	```
8022851890Sopenharmony_ci
8122851890Sopenharmony_ci3. Modify the **config** file to build.
8222851890Sopenharmony_ci
8322851890Sopenharmony_ci	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.
8422851890Sopenharmony_ci	
8522851890Sopenharmony_ci	```
8622851890Sopenharmony_ci	KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
8722851890Sopenharmony_ci	DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
8822851890Sopenharmony_ci	```
8922851890Sopenharmony_ci	
9022851890Sopenharmony_ci	> **Note**:
9122851890Sopenharmony_ci	>
9222851890Sopenharmony_ci	>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.
9322851890Sopenharmony_ci	>
9422851890Sopenharmony_ci	>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.
9522851890Sopenharmony_ci
9622851890Sopenharmony_ci
9722851890Sopenharmony_ci## Build<a name="section19369206113115"></a>
9822851890Sopenharmony_ci
9922851890Sopenharmony_ciThe following uses the Hi3516D V300 development board and Ubuntu x86 server as an example.
10022851890Sopenharmony_ci
10122851890Sopenharmony_ciPerform a full build for the project to generate the **uImage** kernel image.
10222851890Sopenharmony_ci
10322851890Sopenharmony_ci```
10422851890Sopenharmony_ci./build.sh --product-name Hi3516DV300              # Build the Hi3516D V300 image.
10522851890Sopenharmony_ci    --build-target build_kernel                    # Build the uImage kernel image of Hi3516D V300.
10622851890Sopenharmony_ci    --gn-args linux_kernel_version=\"linux-5.10\"  # Build the specified kernel version.
10722851890Sopenharmony_ci```
10822851890Sopenharmony_ci
10922851890Sopenharmony_ci## Repositories Involved<a name="section27639463106"></a>
11022851890Sopenharmony_ci
11122851890Sopenharmony_ci<u>kernel\_linux\_patches</u>
112