Patching Kernel in OpenEmbedded NOT seperately from build system

Hello,

there is fine blog about patching a kernel separately/manually from a build system:

What I do:

  1. build apalis image
  2. copy tmp_glibc/…/kernel-source to kernel-source-patch
  3. modify some *.h and *c files within kernel-source-patch
  4. diff Uran -X both folders > 001-kernel.patch
  5. add patch file to /layers/meta-toradex-tegra/recipes-kernel/linux/linux-toradex_3.10.40.bb
  6. bitbake linux-toradex -c menuconfig
  7. rebuild apalis tk1 image

But these steps depend on an already build kernel-source folder.
How can I apply patches based on recipes only?
I found patch files with entries like: “diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c”
whereas I have entries containing “+++kernel-source” and “—kernel-source-patch” instead of “+++a” and “—b”.
Is it possible to adapt the patch file accordingly?

Best regards
Dirk

Hi.

All you need to do is to create patches just like in other patches existent throughout yocto.

For kernel, you only need to specify the path in the kernel sources i.e. /arch/arm/boot is correct while /home/user/yocto/oe-core/build/tmp-glibc/apalis-imx6/kernel-source/arch/arm/boot is not correct

Here’s an example of a patch to BSP 4.9 and bbappend i created.

bbappend:

FILESEXTRAPATHS_prepend := "${THISDIR}/linux-toradex-custom:"

SRC_URI += "file://0002-Update-device-trees.patch \
            file://0004-Add-nfc-nxp-pn5xx-driver.patch \
            file://0005-Add-splash-screen-image.patch \
            file://0006-Modify-wireless-driver.patch \
"

COMPATIBLE_MACHINE = "(apalis-imx6)"

do_unpack_append() {
    import os

    s = d.getVar('S',True)
    os.system("cp " + s + "/arch/arm/configs/apalis_imx6_defconfig " + s + "/arch/arm/configs/apalis_imx6_custom_defconfig")
}

I had an issue on my WiFi module driver so I was messing around and I fixed it by commenting an if condition. Here’s my patch to it:

--- a/drivers/net/wireless/bcmdhd/dhd_linux.c
+++ b/drivers/net/wireless/bcmdhd/dhd_linux.c
@@ -4339,14 +4339,18 @@
 	 */
 
 	/* set default firmware and nvram path for built-in type driver */
-	if (!dhd_download_fw_on_driverload) {
+//	if (!dhd_download_fw_on_driverload) {
 #ifdef CONFIG_BCMDHD_FW_PATH
 		fw = CONFIG_BCMDHD_FW_PATH;
+        DHD_ERROR(("Entrei FW_PATH\n"));
+        //strcpy(nv,"/lib/firmware/bcm/fw_bcmdhd.bin");
 #endif /* CONFIG_BCMDHD_FW_PATH */
 #ifdef CONFIG_BCMDHD_NVRAM_PATH
 		nv = CONFIG_BCMDHD_NVRAM_PATH;
+        DHD_ERROR(("Entrei NVRAM_PATH\n"));
+        //strcpy(nv,"/lib/firmware/bcm/bcmdhd.cal");
 #endif /* CONFIG_BCMDHD_NVRAM_PATH */
-	}
+//	}
 
 	/* check if we need to initialize the path */
 	if (adapter && adapter->fw_path && adapter->fw_path[0] != '\0')
@@ -4384,7 +4388,14 @@
 		if (dhdinfo->nv_path[nv_len-1] == '\n')
 		       dhdinfo->nv_path[nv_len-1] = '\0';
 	}
-
+	DHD_ERROR(("%s: NVRAM path=%s\n",
+		__FUNCTION__, nv));
+	DHD_ERROR(("%s: firmware path=%s\n",
+		__FUNCTION__, fw));
+	DHD_ERROR(("%s: firmware path=%s\n",
+		__FUNCTION__, dhdinfo->fw_path));
+	DHD_ERROR(("%s: NVRAM path=%s\n",
+		__FUNCTION__, dhdinfo->nv_path));
 	/* clear the path in module parameter */
 	firmware_path[0] = '\0';
 	nvram_path[0] = '\0';

I hope this helps you, regards

Joao

Hi Joao,

thank you very much! This works fine as expected (a/b).

regards
Dirk