如果源码模块是git仓库的型式(远程的或者本地的mirror型式),直接使用git diff来生成patch就可以了。
模块源码为压缩包的型式,可以使用quilt工具来生成patch文件。拿imax6平台gstreamer的imx插件模块imx-gst1.0-plugin为例:
$ cd /home/zyliu/imax6-linux
$ source envsetup.sh
...
$ pwd
/home/zyliu/imax6-linux/build-xwayland
$ bitbake imx-gst1.0-plugin -c cleanall -f
$ bitbake imx-gst1.0-plugin -c patch -f
$ cd tmp/work/imx6qsabresd-poky-linux-gnueabi/imx-gst1.0-plugin/4.1.6-r0
$ cd imx-gst1.0-plugin-4.1.6
$ quilt new 20181126-gstvpudec-force-low-latency-mode.patch
Patch patches/20181126-gstvpudec-force-low-latency-mode.patch is now on top
$ quilt add plugins/vpu/gstvpudec.c
File plugins/vpu/gstvpudec.c added to patch patches/20181126-gstvpudec-force-low-latency-mode.patch
$ vi plugins/vpu/gstvpudec.c
$ quilt refresh
Refreshed patch patches/20181126-gstvpudec-force-low-latency-mode.patch
Index: imx-gst1.0-plugin-4.1.6/plugins/vpu/gstvpudec.c
===================================================================
--- imx-gst1.0-plugin-4.1.6.orig/plugins/vpu/gstvpudec.c
+++ imx-gst1.0-plugin-4.1.6/plugins/vpu/gstvpudec.c
@@ -282,13 +282,13 @@ gst_vpu_dec_set_format (GstVideoDecoder
}
gst_query_unref (query);
- if (is_live) {
+ // if (is_live) {
GST_INFO_OBJECT (dec, "Pipeline is live, set VPU to low latency mode.\n");
GST_VPU_DEC_LOW_LATENCY (dec->vpu_dec_object) = TRUE;
- } else {
- GST_INFO_OBJECT (dec, "Pipeline isn't live, set VPU to non-latency mode.\n");
- GST_VPU_DEC_LOW_LATENCY (dec->vpu_dec_object) = FALSE;
- }
+ // } else {
+ // GST_INFO_OBJECT (dec, "Pipeline isn't live, set VPU to non-latency mode.\n");
+ // GST_VPU_DEC_LOW_LATENCY (dec->vpu_dec_object) = FALSE;
+ // }
return gst_vpu_dec_object_config (dec->vpu_dec_object, bdec, state);
}
找到imx-gst1.0-plugin模块的bb文件位置为:
/home/zyliu/imax6-linux/sources/meta-fsl-bsp-release/imx/meta-bsp/recipes-multimedia/gstreamer/imx-gst1.0-plugin_4.1.6.bb
在同目录下新建imx-gst1.0-plugin目录,并将上一步中生成的patch文件复制进去:
$ cd /home/zyliu/imax6-linux/sources/meta-fsl-bsp-release/imx/meta-bsp/recipes-multimedia/gstreamer
$ mkdir imx-gst1.0-plugin
$ cp /home/zyliu/imax6-linux/tmp/work/imx6qsabresd-poky-linux-gnueabi/imx-gst1.0-plugin/4.1.6-r0/20181126-gstvpudec-force-low-latency-mode.patch ./imx-gst1.0-plugin
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI_append = " file://20181126-gstvpudec-force-low-latency-mode.patch"
$ cd /home/zyliu/imax6-linux
$ source envsetup.sh
$ bitbake imx-gst1.0-plugin -c cleanall -f
$ bitbake imx-gst1.0-plugin -c patch -f
$ cat tmp/work/imx6qsabresd-poky-linux-gnueabi/imx-gst1.0-plugin/4.1.6-r0/temp/log.do_patch.5120
DEBUG: Executing python function do_patch
DEBUG: Executing python function patch_do_patch
DEBUG: Searching for 20181126-gstvpudec-force-low-latency-mode.patch in paths:
/home/zyliu/imax6-linux/sources/meta-fsl-bsp-release/imx/meta-bsp/recipes-multimedia/gstreamer/imx-gst1.0-plugin/poky-ivi-systemd
...
/home/zyliu/imax6-linux/sources/meta-fsl-bsp-release/imx/meta-bsp/recipes-multimedia/gstreamer/files/
NOTE: Applying patch '20181126-gstvpudec-force-low-latency-mode.patch' (../sources/meta-fsl-bsp-release/imx/meta-bsp/recipes-multimedia/gstreamer/imx-gst1.0-plugin/20181126-gstvpudec-force-low-latency-mode.patch)
DEBUG: Python function patch_do_patch finished
DEBUG: Python function do_patch finished
可见,20181126-gstvpudec-force-low-latency-mode.patch已经成功打入。
今天使用quilt工具打patch遇到问题了,记录一下解决过程。
首先,还是采用之前的流程做了个patch文件,然后bitbake在do_patch时报错如下:
ERROR: Command Error: exit status: 1 Output:
Applying patch 20190613-AddVendorElementsToAssocResp.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: hostapd-2.4/src/ap/ap_drv_ops.c
|===================================================================
|--- hostapd-2.4.orig/src/ap/ap_drv_ops.c
|+++ hostapd-2.4/src/ap/ap_drv_ops.c
--------------------------
No file to patch. Skipping patch.
1 out of 1 hunk ignored
Patch 20190613-AddVendorElementsToAssocResp.patch does not apply (enforce with -f)
意思是找不到需要被打patch的文件。
花了一点时间trace了一下bitbake打patch的代码流程,主要相关的文件有2个,如下:
poke/meta/classes/patch.bbclass
poke/meta/lib/oe/patch.py
python函数patch_do_patch()中会根据配置先选择一个patchset的类和一个resolver的类,如果没有指定PATCHTOOL的话(有些模块可能会指定PATCHTOOL为git),默认是采用oe.patch.QuiltTree这个类来处理patch文件。
QuiltTree在构造时会指定一个patchdir(如果没有指定的话,默认为${S}的值),QuiltTree会先Import所有的patch文件,其实是在${patchdir}/patches/中制作一个link文件,链接到我们的patch文件上。最后通过在${patchdir}路径下执行quilt push来完成打patch的动作。
所以,这个patchdir的值就比较关键了,之前默认情况我都是去bitbake工作路径下的源码目录中使用quilt来做patch的。也就是默认了源码目录就是${S}的情况。
今天搞hostapd模块时遇到问题了:
${S}=…/tmp/work/cortexa7-vfp-neon-telechips-linux-gnueabi/hostapd/2.4-r0/hostapd-2.4/hostapd/
而我的源码unpack的路径其实是:
…/tmp/work/cortexa7-vfp-neon-telechips-linux-gnueabi/hostapd/2.4-r0/hostapd-2.4/
所以,我需要明确的指定一下patchdir这个值,方式如下:
FILESEXTRAPATHS_append := ":${THISDIR}/hostapd-${PV}"
MY_PATCH_DIR="${WORKDIR}/hostapd-${PV}"
SRC_URI += "file://20190613-AddVendorElementsToAssocResp.patch;patchdir=${MY_PATCH_DIR}/"
就是在patch文件后增加一个字段,patchdir=${MY_PATCH_DIR}