Adding kernel module in to our image and installing in root file system using yocto project

 Hello All,

In this article we are going to see how we can create a basic kernel module (hello world) and adding it to our image and installing in root file system using yocto project.

pre-requisite: you need to be familiar with my previous topics, as it contains the necessary steps to create the build environment for qemux86-64 and steps to create our own layer.

link to my previous article: https://learnyoctowithme.blogspot.com/2022/04/constructing-embedded-linux-image-for.html

https://learnyoctowithme.blogspot.com/2022/04/creating-our-own-meta-layer-creating.html 

Adding kernel module in to our image and installing in to root file system:

step 1:  Inside poky directory, we created our own layer directory called meta-mylayer , switch to meta-mylayer

$ cd poky/meta-mylayer/

step 2: Inside meta-mylayer, create a directory called recipes-kernel

$ mkdir recipes-kernel

step 3: Inside recipes-kernel directory, create a new folder called hello-mod

$ mkdir hello-mod

step 4: Inside hello-mod directory, create a folder called files and create a file called hello-mod_0.1.bb

$ mkdir files && touch hello-mod_0.1.bb

step 5: switch to files folder

$ cd files

step 6: One example of an external kernel module is available inside the meta-skeleton layer in the recipes-kernel/hello-mod layer

$ ls poky/meta-skeleton/recipes-kernel/hello-mod

from meta-skeleton layer, copy the required files to meta-mylayer/recipes-kernel/hello-mod/files directory

$ cp  poky/meta-skeleton/recipes-kernel/hello-mod/files/*  /home/shashank/poky/meta-mylayer/recipes-kernel/hello-mod/files

step 7: now open hello.c file and the content should look like


step 8: now open Makefile, and the content should look like



step 9: in step 4 we created a file called hello-mod_0.1.bb , open it and write the bitbake recipe for hello world module

$ vi hello-mod_0.1.bb and append the below content to it ( as we copied it from meta-skeleton layer, content will be there and kindly do not edit it)


step 10: Now add the module to our image

open the conf file and append the following

$ cd ../../../build_x86/conf

$ vi local.conf


NOTE : we are adding the kernel module using the variable IMAGE_INSTALL_append.

IMAGE_INSTALL_append += "hello-mod module-init-tools"

here module-init-tools will provide the required module utilities to perform various operations on kernel module

step 11: now compile the image as

$ bitbake core-image-minimal


step 11: now boot the image as

$ runqemu nographic

NOTE: default username will be root with empty password

step 12: after booting to qemux86-64 machine, switch to folder

$ cd /lib/modules/5.4.178-yocto-standard/extra/

inside extra folder we can see hello.ko module

$ modinfo hello.ko


step 13: insert the kernel module using insmod hello.ko


step 14: remove the module using rmmod hello.ko



That's it we have successfully created a kernel module hello and added it to our root file system..!!


Comments

Popular posts from this blog

Adding custom splash screen to yocto image

Adding libraries (pciutils,usbutils and util-linux) to our image using yocto project