Howto build a kernel module out of the kernel tree

From KoanSoftware Wiki
Jump to: navigation, search

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


Copy COPYING file into your files

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

# Yocto recipe to build a kernel module out of the kernel tree
# Marco Cavallini - KOAN sas -

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

inherit module

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

S = "${WORKDIR}"


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

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

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


 * 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:

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

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