Difference between revisions of "Howto build a kernel module out of the kernel tree"

From KoanSoftware Wiki
Jump to: navigation, search
 
Line 77: Line 77:
 
   printk(KERN_INFO "Goodbye world\n");
 
   printk(KERN_INFO "Goodbye world\n");
 
  }
 
  }
 +
 +
 +
----
 +
 +
 +
== ISSUE : Custom kernel module QA Issue warnings during do_package task execution ==
 +
 +
In case the module compiles with no errors, but a QA warning is thrown as shown below.
 +
 +
The module does not successfully get installed into build images.
 +
 +
WARNING: mymodule-1.0-r0 do_package: QA Issue: hellokernel: Files/directories were installed but not shipped in any package:
 +
  /lib
 +
  /lib/modules
 +
  /lib/modules/5.4.209-yocto-standard
 +
  /lib/modules/5.4.209-yocto-standard/extra
 +
 +
 +
To fix this issue, add below content to your custom kernel module recipe.
 +
 +
FILES_${PN} += "${base_libdir}/modules/"

Latest revision as of 13:44, 28 September 2022

Yocto recipe to build a kernel module out of the kernel tree

While it is always preferable to work with sources integrated into the Linux kernel sources, if you need an external kernel module, you could start from this simple recipe based on Yocto Project kernel Development Manual. This GPL2 recipe is available as a template from which you can create your own out-of-tree Linux kernel module recipe.


$ tree
.
├── files
│   ├── COPYING
│   ├── hellokernel.c
│   └── Makefile
└── kernmodule.bb


COPYING

Copy COPYING file into your files

cp meta-skeleton/recipes-kernel/hello-mod/files/COPYING  YOURPATH/kernmodule/files/


kernmodule.bb

#
# Yocto recipe to build a kernel module out of the kernel tree
# kernmodule.bb  
# Marco Cavallini - KOAN sas - www.koansoftware.com
#

DESCRIPTION = "Hello kernel module out of the kernel tree"
SECTION = "examples"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
PR = "r0"

inherit module

SRC_URI =   "file://hellokernel.c \
			file://Makefile \
			file://COPYING \
			"

S = "${WORKDIR}"

Makefile

obj-m += hellokernel.o
SRC := $(shell pwd)

all:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules

modules_install:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install

hellokernel.c

/*
 * hello.c - The simplest and dirty kernel module
 */

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
  printk(KERN_INFO "Hello world\n");
  
  return 0;
}

void cleanup_module(void)
{
  printk(KERN_INFO "Goodbye world\n");
}




ISSUE : Custom kernel module QA Issue warnings during do_package task execution

In case the module compiles with no errors, but a QA warning is thrown as shown below.

The module does not successfully get installed into build images.

WARNING: mymodule-1.0-r0 do_package: QA Issue: hellokernel: Files/directories were installed but not shipped in any package:
 /lib
 /lib/modules
 /lib/modules/5.4.209-yocto-standard
 /lib/modules/5.4.209-yocto-standard/extra


To fix this issue, add below content to your custom kernel module recipe.

FILES_${PN} += "${base_libdir}/modules/"