Saturday, September 28, 2024

Yocto notes - 3

Dealing with the linux kernel

Here, I'm using yocto scarthgap for my beaglebone-white.

Refer to Yocto Linux Kernel Development Manual for the version you are using.

If you just flash the default core-image-minimal image, you won't see

/lib/modules/

Update the local.conf so that MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS includes kernel modules

MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"

With this, you will see /lib/modules/

Now, to do some kernel changes, let's create and add a layer

$ bitbake-layers create-layer ../meta-mylayer

$ bitbake-layers add-layer ../meta-mylayer

The new layer is added to conf/bblayers.conf 

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
  /home/dld/bbw-yocto/poky/meta \
  /home/dld/bbw-yocto/poky/meta-poky \
  /home/dld/bbw-yocto/poky/meta-yocto-bsp \
  /home/dld/bbw-yocto/meta-mylayer \
  "

Create kernel recipe in the new layer. We'll will patch the kernel by modifying a driver, and do some configuration changes by adding a config fragment

We can use devtool to patch the kernel as described in the documentation

$ devtool modify linux-yocto

It checks out the kernel source in the workspace. You'll see a layer added in conf/bblayers.conf 

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
  /home/dld/bbw-yocto/poky/meta \
  /home/dld/bbw-yocto/poky/meta-poky \
  /home/dld/bbw-yocto/poky/meta-yocto-bsp \
  /home/dld/bbw-yocto/meta-mylayer \
  /home/dld/bbw-yocto/build-bbw/workspace \
  "

Now, I do some changes to drivers/usb/musb/musb_gadget.c in the workspace sources and commit the changes

$ git status 

$ git add drivers/usb/musb/musb_gadget.c

$ git commit -m "musb gadget udev notification"

Export the patch and create an append file

$ devtool finish linux-yocto ../meta-mylayer/

and do some configuration changes by adding them as a config fragment file

With all this in place, we'll see something like

$ tree ../meta-mylayer/

../meta-mylayer/

├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-kernel
    └── linux
        ├── linux-yocto
        │   ├── 0001-musb-gadget-udev-notification.patch
        │   └── usb_configfs.cfg
        └── linux-yocto_%.bbappend

$ cat ../meta-mylayer/recipes-kernel/linux/linux-yocto_%.bbappend 

# The path ${THISDIR}/${PN} expands to “linux-yocto” in the current directory
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://usb_configfs.cfg \
            file://0001-musb-gadget-udev-notification.patch \
            "

Now, try to build, and you'll see it's giving an error saying something like

$ bitbake core-image-minimal

:
do_patch: QA Issue: Missing Upstream-Status in patch

and how to fix it

Please add according to https://docs.yoctoproject.org/contributor-guide/recipe-style-guide.html#patch-upstream-status . [patch-status]

So, I'll just add

Upstream-Status: Denied

to the patch file, and build, and it goes without any issue then.

We'll see in the next post the details of the patch and the config fragment, and what they do.


No comments: