提交 e65de216 编写于 作者: O openharmony_ci 提交者: Gitee

!699 cherry pick master to LTS3.0, modify kernel readme

Merge pull request !699 from Zachery Wu/OpenHarmony-3.0-LTS
# Linux内核编译与构建指导<a name="ZH-CN_TOPIC_0000001076416924"></a>
- [开发示例1](#section19369206113115)
- [场景1:版本级编译原生方式](#section1025111193220)
- [场景2:单独编译修改后的内核](#section17446652173211)
## 开发示例1<a name="section19369206113115"></a>
以hi3516dv300开源开发板+ubuntu x86主机开发环境为例。
### 场景1:版本级编译原生方式<a name="section1025111193220"></a>
以hi3516dv300开源开发板+ubuntu x86主机开发环境为例
使用工程的全量编译命令,编译生成uImage内核镜像
```
./build.sh --product-name Hi3516DV300 # 编译hi3516dv300的uImage内核镜像
./build.sh --product-name Hi3516DV300 # 编译hi3516dv300镜像
--build-target build_kernel # 编译hi3516dv300的uImage内核镜像
--gn-args linux_kernel_version=\"linux-5.10\" # 编译指定内核版本
```
### 场景2:单独编译修改后的内核<a name="section17446652173211"></a>
1. 准备工作
1. 按[开发板Patch使用指导](kernel-standard-patch.md)打入所需补丁。
2. 准备编译环境,可以使用开源arm clang/gcc编译器。
进入工程主目录配置环境变量:
```
export PATH=`pwd`/prebuilts/clang/host/linux-x86/clang-r353983c/bin:`pwd`/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin/:$PATH # 配置编译环境
MAKE_OPTIONES="ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CC=clang HOSTCC=clang" # 使用工程项目自带的clang环境
```
2. 修改内核代码或内核config (OpenHarmony提供对应平台的defconfig供参考)。
3. 创建编译目录及生成内核.config。
```
make ${MAKE_OPTIONES} hi3516dv300_emmc_smp_hos_l2_defconfig # 使用自带的默认config 构建内核
```
4. 编译生成对应的内核Image。
```
make ${MAKE_OPTIONES} -j32 uImage # 编译uImage内核镜像
```
......@@ -15,7 +15,4 @@ LTS为长期支持版本,“长期支持”体现在对该版本内核的长
## OpenHarmony内核版本选择<a name="section2716416191715"></a>
OpenHarmony中的Linux内核从LTS版本中选择合适的版本作为内核基础版本,目前较多设备使用的4.19内核。4.4\~4.14LTS内核较旧,对新特性支持不足,且按计划在2023年左右会陆续不再维护,可使用周期较短,不适合作为首发版本。5.4LTS版本在已发产品中未广泛使用,4.19更为大家熟悉也可减少适配内核的周期,更新版本内核也会持续发布。
OpenHarmony 中的Linux内核推荐参考内存≥128MB的设备选用。
OpenHarmony中Linux内核从LTS版本中选择合适的版本作为内核的基础版本,目前已完成对Linux-4.19及Linux-5.10完成适配及支持。
# OpenHarmony开发板Patch使用指导<a name="ZH-CN_TOPIC_0000001081980461"></a>
Patch文件位于工程项目源码路径:kernel/linux/patches/linux-4.19,存放特定芯片架构驱动补丁。
1. 合入HDF补丁
如需使用特定芯片平台驱动的Patch,需要在内核仓代码完成对芯片平台驱动补丁合入。
在kernel/linux/build仓中,按照kernel.mk中HDF的补丁合入方法,合入不同内核版本对应的HDF内核补丁:
```
$(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE)
```
合入芯片平台驱动补丁,针对不同芯片平台合入对应的patch:
2. 合入芯片平台驱动补丁
以Hi3516dv300为例:
以Hi3516DV300为例:
在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件patch放到对应路径下:
```
DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
```
```
patch -p1 < device/hisilicon/hi3516dv300/sdk_linux/open_source/linux/hisi_linux-4.19_hos_l2.patch
```
3. 修改自己所需要编译的config
>![](../public_sys-resources/icon-notice.gif) **须知:**
>由于OpenHarmony的编译构建流程中会拷贝kernel/linux-4.19的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux-4.19保持原代码环境。
在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件config放到对应路径下:
```
KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
```
> **须知:**
>
>由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux/linux-\*\.\*的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux/linux-\*\.\*原代码环境。
>
>根据不同系统工程,编译完成后会在out目录下的kernel目录中生成对应实际编译的内核,基于此目录的内核,进行对应的config修改,将最后生成的\.config文件cp到config仓对应的路径文件里,即可生效。
......@@ -9,17 +9,12 @@
- [LiteOS使用说明](#section118811457303)
- [linux使用说明](#section1352114469620)
- [以hi3516dv300开源开发板+ubuntu x86主机开发环境为例](#section19369206113115)
- [场景1:版本级编译原生方式](#section1025111193220)
- [场景2:单独编译修改后的内核](#section17446652173211)
- [构建说明](#section19369206113115)
- [相关仓](#section27639463106)
## 简介<a name="section11660541593"></a>
OpenHarmony针对不同量级的系统,分别使用了不同形态的内核,分别为LiteOS和Linux。在轻量系统、小型系统和标准系统上,可以选用LiteOS;在标准系统上,可以选用Linux。
**表 1**
OpenHarmony针对不同量级的系统,分别使用了不同形态的内核,分别为LiteOS和Linux。在轻量系统、小型系统和标准系统上,可以选用LiteOS;在小型系统和标准系统上,可以选用Linux。
<a name="table91002058194612"></a>
<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>系统级别</p>
......@@ -43,8 +38,8 @@ OpenHarmony针对不同量级的系统,分别使用了不同形态的内核,
</tr>
<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>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.2 ">&nbsp;&nbsp;</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.5.1.3 ">&nbsp;&nbsp;</td>
<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>
<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>
<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>
</td>
</tr>
......@@ -64,37 +59,51 @@ OpenHarmonyLiteOS内核的源代码分为 kernel\_liteos\_a 和 kernel\_liteos\_
## Linux<a name="section143373618411"></a>
OpenHarmony的Linux内核基于开源Linux内核LTS 4.19.y分支演进,为满足不同的内核场景诉求,以内核 + patch的形式开展,其中内核在LTS 4.19内核的基础上合入CVE补丁 + OpenHarmony特性作为Common内核基线,针对性打上vendor厂商提供的板级芯片驱动补丁从而构成完整的内核。
Linux社区LTS 4.19.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y)
内核组成模块,以开源Linux内核为基线, 合入了公共补丁:CVE补丁/OpenHarmony特性,在编译构建流程中针对具体芯片平台合入对应的架构驱动代码进行编译对应的内核镜像。所有补丁来源均遵守GPL-2.0协议。
1. CVE补丁
补丁所涉及的CVE\(Common Vulnerabilities and Exposures\)安全漏洞是通过NVD \([https://nvd.nist.gov](内核子系统.md)/\)官方机构收集,且补丁已经进入LTS 4.19.y分支或主线,主要涉及存储\(btrfs/scsi/\)、网络\(net/bpf/mwifiex\) 、驱动\(xen/nfc\),对应CVE列表参考commit信息中CVE字段信息。
1. OpenHarmony特性
HDF驱动、binder ipc转发功能等特性支持。
2. 特定芯片架构驱动补丁(比如Hi3516DV300)
OpenHarmony的Linux内核基于开源Linux内核LTS **4.19.y / 5.10.y** 分支演进,在此基线基础上,回合CVE补丁及OpenHarmony特性,作为OpenHarmony Common Kernel基线。针对不同的芯片,各厂商合入对应的板级驱动补丁,完成对OpenHarmony的基线适配。
vendor厂商提供的特定芯片架构驱动代码:
Linux社区LTS 4.19.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y)
hisi\_linux-4.19\_hos\_l2.patch: 在Hi3516DV300芯片上支持arm架构的内核启动(DTS等)及对应的drm/mmc等驱动的支持
Linux社区LTS 5.10.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y)
内核的Patch组成模块,在编译构建流程中,针对具体芯片平台,合入对应的架构驱动代码,进行编译对应的内核镜像。所有补丁来源均遵守GPL-2.0协议。
## 目录<a name="section21571344112"></a>
```
kernel/
├── linux-4.19 # 4.19内核基线代码
├── linux/config/linux-4.19 # 内核config
│ └── standard_common_defconfig # 标准系统的内核的common defconfig
│ └── hi3516dv300_emmc_smp_hos_l2_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig
├── linux/patches/linux-4.19 # 内核patch及编译脚本
├── linux
│ ├── linux-4.19 # OpenHarmony linux-4.19 Common kernel
│ ├── linux-5.10 # OpenHarmony linux-5.10 Common kernel
│ ├── build
│ │ ├── BUILD.gn # 编译框架GN文件
│ │ ├── kernel.mk # 内核编译文件
│ │ └── ohos.build # 内核编译组件文件
│ ├── patches
│ │ ├── linux-4.19 # linux-4.19 相关patch
│ │ │   └── hi3516dv300_patch
│ │ │   ├── hi3516dv300.patch # linux-4.19 hi3516dv300 SOC patch
│ │ │   └── hdf.patch # linux-4.19 hi3516dv300 hdf patch
│ │ └── linux-5.10
│ │    └── hi3516dv300_patch
│ │    ├── hi3516dv300.patch # linux-5.10 hi3516dv300 SOC patch
│ │    └── hdf.patch # linux-5.10 hi3516dv300 hdf patch
│ └── config
│ ├── linux-4.19
│ │   └── arch
│ │   └── arm
│ │   └── configs
│ │   ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig
│ │   ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig
│ │   ├── small_common_defconfig # 小型系统的内核的common defconfig
│ │   └── standard_common_defconfig # 标准系统的内核的common defconfig
│ └── linux-5.10
│ └── arch
│ └── arm
│ └── configs
│    ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig
│    ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig
│    ├── small_common_defconfig # 小型系统的内核的common defconfig
│    └── standard_common_defconfig # 标准系统的内核的common defconfig
└── liteos_a # liteos内核基线代码
├── apps # 用户态的init和shell应用程序
├── arch # 体系架构的目录,如arm等
......@@ -148,57 +157,52 @@ Hi3518EV300默认使用jffs2文件系统,Hi3516DV300默认使用FAT文件系
### linux使用说明<a name="section1352114469620"></a>
如需使用上述patch,需要在内核代码完成对应芯片平台驱动补丁进行合入。
1. 合入HDF补丁
1. 合入芯片平台驱动补丁
在kernel/linux/build仓中,按照kernel.mk中HDF的补丁合入方法,合入不同内核版本对应的HDF内核补丁:
```
$(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE)
```
针对不同芯片平台合入对应的patch,以上述Hi3516DV300为例:
2. 合入芯片平台驱动补丁
```
patch -p1 < device/hisilicon/hi3516dv300/sdk_linux/open_source/linux/hisi_linux-4.19_hos_l2.patch
```
以Hi3516DV300为例:
在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件patch放到对应路径下:
```
DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
```
>![](public_sys-resources/icon-notice.gif) **须知:**
>由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux-4.19的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux-4.19保持原代码环境。
3. 修改自己所需要编译的config
在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件config放到对应路径下:
```
KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION}
DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
```
## 以hi3516dv300开源开发板+ubuntu x86主机开发环境为例<a name="section19369206113115"></a>
> **须知:**
>
>由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux/linux-\*\.\*的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux/linux-\*\.\*原代码环境。
>
>根据不同系统工程,编译完成后会在out目录下的kernel目录中生成对应实际编译的内核,基于此目录的内核,进行对应的config修改,将最后生成的\.config文件cp到config仓对应的路径文件里,即可生效。
### 场景1:版本级编译原生方式<a name="section1025111193220"></a>
## 构建说明<a name="section19369206113115"></a>
以hi3516dv300开源开发板+ubuntu x86主机开发环境为例
使用工程的全量编译命令,编译生成uImage内核镜像
```
./build.sh --product-name Hi3516DV300 # 编译hi3516dv300的uImage内核镜像
./build.sh --product-name Hi3516DV300 # 编译hi3516dv300镜像
--build-target build_kernel # 编译hi3516dv300的uImage内核镜像
--gn-args linux_kernel_version=\"linux-5.10\" # 编译指定内核版本
```
### 场景2:单独编译修改后的内核<a name="section17446652173211"></a>
1. 准备工作
准备编译环境,可以使用开源arm clang/gcc编译器,或者使用工程自带编译器。
进入工程主目录配置环境变量:
```
export PATH=`pwd`/prebuilts/clang/host/linux-x86/clang-r353983c/bin:`pwd`/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin/:$PATH # 配置编译环境
MAKE_OPTIONES="ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CC=clang HOSTCC=clang" # 使用工程项目自带的clang环境
```
2. 修改内核代码或内核config (OpenHarmony提供对应平台的defconfig供参考)。
3. 创建编译目录及生成内核.config。
```
make ${MAKE_OPTIONES} hi3516dv300_emmc_smp_hos_l2_defconfig # 使用自带的默认config 构建内核
```
4. 编译生成对应的内核Image。
```
make ${MAKE_OPTIONES} -j32 uImage # 编译uImage内核镜像
```
## 相关仓<a name="section27639463106"></a>
**内核子系统**
......@@ -217,11 +221,12 @@ LiteOS:
Linux:
<u>kernel\_linux\_patches</u>
[kernel\_linux\_patches](https://gitee.com/openharmony/kernel_linux_patches/blob/master/README_zh.md)
<u>device\_hisilicon\_hi3516dv300</u>
[kernel\_linux\_config](https://gitee.com/openharmony/kernel_linux_config/blob/master/README_zh.md)
<u>kernel\_linux\_config</u>
[kernel\_linux\_build](https://gitee.com/openharmony/kernel_linux_build/blob/master/README_zh.md)
<u>kernel\_linux-4.19</u>
[kernel\_linux\_4.19](https://gitee.com/openharmony/kernel_linux_4.19/blob/master/README)
[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册