OpenHarmony开发者论坛
标题:
如何一键优雅的更新内核patch
[打印本页]
作者:
润开鸿_闻飞
时间:
2024-5-17 14:11
标题:
如何一键优雅的更新内核patch
[md][itopen组织](
https://gitee.com/itopen
)
1、提供OpenHarmony优雅实用的小工具
2、手把手适配riscv + qemu + linux的三方库移植
3、未来计划riscv + qemu + ohos的三方库移植 + 小程序开发
4、一切拥抱开源,拥抱国产化
## 一、进入内核,修改内核代码
```shell
cd kernel/linux/linux-5.10
vim drivers/Kconfig
# 在倒数第二行加入:source "drivers/tracepoint/Kconfig"
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
source "drivers/tracepoint/Kconfig"
endmenu
```
## 二、打patch
```shell
patch -p1 < ../patches/linux-5.10/rk3568_patch/kernel.patch
```
如果想撤回patch方法
```shell
patch -Rp1 < ../patches/linux-5.10/rk3568_patch/kernel.patch
```
## 三、解决冲突(如果存在)
```shell
$ git status | grep rej
Refresh index: 100% (70816/70816), done.
drivers/Kconfig.rej
```
上面表示drivers/Kconfig文件的打patch时候有冲突被拒绝了,需要手动进行修改
- **打开drivers/Kconfig.rej文件**
```shell
--- drivers/Kconfig
+++ drivers/Kconfig
@@ -239,4 +239,8 @@ source "drivers/counter/Kconfig"
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
+
+source "drivers/rkflash/Kconfig"
+
+source "drivers/rk_nand/Kconfig"
endmenu
```
这个文件的意思是需要在source "drivers/accesstokenid/Kconfig"的下面添加四行内容
- **打开drivers/Kconfig文件,手动解决patch添加**
```shell
# 修改前
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
source "drivers/tracepoint/Kconfig"
endmenu
# 修改后
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
source "drivers/tracepoint/Kconfig"
source "drivers/rkflash/Kconfig"
source "drivers/rk_nand/Kconfig"
endmenu
```
- **删除冲突生成的临时orig和rej文件**
```shell
rm -rf drivers/Kconfig.orig drivers/Kconfig.rej
```
- **至此冲突解决完**
## 四、生成新的patch
[git生成patch和打patch](
https://blog.csdn.net/u013318019/article/details/114860407
)
```shell
git add .
git commit . -m"add tracepoint"
# 如果只有一次提交使用format-patch方便
git format-patch HEAD^
# 如果想打commit1和commit2之间的patch
# 其中commit1是起始的commit; commit2是结束的commit
git diff commit1 commit2 > demo.patch
```
此时会生成一个patch文件0001-add-tracepoint.patch
## 五、原patch修改
```
我们比对0001-add-tracepoint.patch 和 ../patches/linux-5.10/rk3568_patch/kernel.patch文件发现差异特别大,那是因为每次生成的patch时候对应的文件顺序是不一样的,所以差异比较大,我们要做的是将我们修改的文件patch内容替换即可。
```
```shell
# 比较文件的方法
diff 0001-add-tracepoint.patch ../patches/linux-5.10/rk3568_patch/kernel.patch
```
打开0001-add-tracepoint.patch文件搜索drivers/Kconfig,将如下内容替换掉../patches/linux-5.10/rk3568_patch/kernel.patch中的相同位置内容,至此,patch修改完成
```shell
# 0001-add-tracepoint.patch中的内容
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 826b2b19d..5720a24fb 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -239,4 +239,10 @@ source "drivers/counter/Kconfig"
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
+
+source "drivers/tracepoint/Kconfig"
+
+source "drivers/rkflash/Kconfig"
+
+source "drivers/rk_nand/Kconfig"
endmenu
# 原../patches/linux-5.10/rk3568_patch/kernel.patch中的内容
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 826b2b19d..d7f2fc98b 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -239,4 +239,8 @@ source "drivers/counter/Kconfig"
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
+
+source "drivers/rkflash/Kconfig"
+
+source "drivers/rk_nand/Kconfig"
endmenu
# 替换后../patches/linux-5.10/rk3568_patch/kernel.patch中的内容
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 826b2b19d..5720a24fb 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -239,4 +239,10 @@ source "drivers/counter/Kconfig"
source "drivers/most/Kconfig"
source "drivers/accesstokenid/Kconfig"
+
+source "drivers/tracepoint/Kconfig"
+
+source "drivers/rkflash/Kconfig"
+
+source "drivers/rk_nand/Kconfig"
endmenu
```
## 六、内核版本回退
```shell
rm 0001-add-tracepoint.patch
git reset --hard HEAD^
```
## 七、至此kernel.patch修改完成
[/md]
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5