Home > database >  Kernel patching in stm32mp1 yocto
Kernel patching in stm32mp1 yocto

Time:03-14

I am learning how to add a kernel patch in yocto. My yocto kernel meta-layer is based on linux-stm32mp_5.10.bb from meta-st-stm32mp. First thing i do is to create a patch from

/home/kj/stm32Yoctominimal/build-mp1/tmp/work-shared/stm32mp1/kernel-source

I modified init/main.c and create a patch: 0001-Stargazer-OS-Kernel-Enablement.patch

I created a meta-layer, in my layer. My recipe kernel has the following structure:

── recipes-kernel
    └── linux
        ├── linux-stm32mp
        │   ├── 5.10
        │   │   └── 5.10.61
        │   │       └── 0001-Stargazer-OS-Kernel-Enablement.patch
        │   ├── defconfig
        │   └── kj.cfg
        └── linux-stm32mp_5.10.bbappend

In the bbappend file of my layer I has the following content

kj@kj-Aspire-V3-471G:~/stm32Yoctominimal/meta-kjlau$ cat recipes-kernel/linux/linux-stm32mp_5.10.bbappend

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI  = "file://kj.cfg \
            file://${LINUX_VERSION}/${LINUX_VERSION}.${LINUX_SUBVERSION}/0001-Stargazer-OS-Kernel-Enablement.patch"

#Appply default kernel config
KERNEL_DEFCONFIG:stm31mp1 = "defconfig"

When I bitbake linux-stm32mp successfully, I found that the content of the patch is not applied.

Patch file link: 0001-Stargazer-OS-Kernel-Enablement.patch

My doubts here:

  1. I only add one line of code at init/main.c

    pr_notice("Stargazer OS Kernel development enablement\n");
    

    on top of

    pr_notice("Kernel command line: %s\n", saved_command_line);
    

    in function

    asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
    

    Why the patch file showing entire content of init/main.c? As I have previous build and boot this in my stm32mp1 board, I expect have one line different.

  2. Why is the patch not applied at all, and why no error was thrown during bitbake?

Any advice on debugging this will be helpful.

PS: I am aware of STM32MP1 wiki on modifying kernel but I want to try it on yocto cross compiling to understand the yocto build.

CodePudding user response:

I will put the commands to create the patch in case you did miss something:

The following commands I used on my custom build with machine (menzu).

Follow them carefully and compare them to yours.

File Modification

cd tmp/work-shared/menzu/kernel-source

Modify init/main.c and check the difference:

git status

Output:

modified:   init/main.c

Check the difference:

git diff init/main.c

Output:

diff --git a/init/main.c b/init/main.c
index c0206c507..57531a4a2 100644
--- a/init/main.c
    b/init/main.c
@@ -605,6  605,7 @@ asmlinkage __visible void __init start_kernel(void)
        build_all_zonelists(NULL);
        page_alloc_init();
 
        pr_notice("Stargazer OS Kernel development enablement\n");
        pr_notice("Kernel command line: %s\n", boot_command_line);
        /* parameters may set static keys */
        jump_label_init();
(END)

Patch Creation

Format the patch:

git add init/main.c
git commit -m "Update init main.c"
git format-patch -1 -o /home/talel/Documents/FinalGit/Authento/meta-authento/recipes-kernel/linux/files/

File is created as:

/home/talel/Documents/FinalGit/Authento/meta-authento/recipes-kernel/linux/files/0001-Update-init-main.c.patch

Add file to .bbappend:

SRC_URI_append = " file://0001-Update-init-main.c.patch"

Tasks

Manually unpack and check ${WORKDIR}:

bitbake linux-menzu -c unpack

Get ${WORKDIR}

bitbake -e linux-menzu | grep ^WORKDIR=

The patch is unpacked correctly under ${WORKDIR}.

Check if init/main.c does not have the modification ${WORKDIR}/git/init/main.c

Run the patch:

bitbake linux-menzu -c patch

Check init/main.c again, and it should have the new modification.

NOTE

  • ${WORKDIR}/git is a symbolic link to tmp/work-shared/menzu/kernel-source.
  • Only add the init/main.c file with git command to format the patch.

CodePudding user response:

Talel BELHADJSALEM answer should be the best known solution for most of the yocto patching, however it not working for stm32mp1. My work around for this,

  1. check the kernel recipe, identify the the kernel repo from the recipe

  2. clone the recipe manually in the host.

  3. create a patch from it and place it at bbappend file.

  4. build and boot the image

    root@stm32mp1:~# dmesg | grep Star

    [ 0.000000] Stargazer OS Kernel development enablement

  • Related