Yocto Out-of-Tree Kernel Module

3,047 views
Skip to first unread message

Tim Smitty

unread,
Dec 12, 2013, 8:59:12 PM12/12/13
to wand...@googlegroups.com
Hello all,
    I am currently trying to build a kernel module using some homeade source code in Yocto. I would like to keep the core functionality of Yocto and have a .bb file reference the file sources (.h and .c) on my hard drive. From the sparse documentation I've found a hello world example of what I think I want to do. Yocto call this 'Out of Tree kernel module'.

For the Wandboard the 'hello-mod' example can be found in:

~/fsl-community-bsp/sources/poky/meta-skeleton/recipes-kernel/hello-mod

Within this example lies a 'hello-mod_0.1.bb' file and a 'files' folder which has the .c source code. This seems similar to what I would like to do, however cannot seem to put a few pieces together.

1. How does this kernel module get built and is it found inside the poky image? I cannot find the module in 'modules.dep' on the platform:
               /lib/modules/3.0.35-4.0.0-wandboard+gd35902c/module.dep
     found on the Wandboard running Yocto.

2. Is this kernel module built into the system already or is it a .ko somewhere?

3. Does anyone have a better example or can, maybe, walk me through this? 

4. Do I have to separately build this module?

Any details will help. Thanks a bunch.

T


Scott Ellis

unread,
Dec 13, 2013, 6:01:40 AM12/13/13
to wand...@googlegroups.com
The drivers are Gumstix Overo examples, but the same Yocto build system.

The driver sources are public Github repos. You could modify the SRC_URI
in the recipes for alternate sources (private Github repo, local repo, etc...)

The driver recipes specify where the drivers install. Choose your own convention.

The driver recipes

https://github.com/Pansenti/meta-pansenti/tree/master/recipes-kernel/drivers

Inclusion in a final image recipe

https://github.com/Pansenti/meta-pansenti/blob/master/recipes-pansenti/images/pansenti-console-image.bb

The driver packages for manual installation can be found in

<yocto-tmpdir>/deploy/<package-type>/<machine>

kernel-module-hrt_git-r0_overo.ipk
kernel-module-irqlat_git-r0_overo.ipk
kernel-module-mux_git-r0_overo.ipk
kernel-module-pwm_git-r0_overo.ipk
kernel-module-udelay_git-r0_overo.ipk

These are Yocto [dylan] branch examples. I haven't tried [dora] yet.

Tim Smitty

unread,
Dec 13, 2013, 7:48:40 PM12/13/13
to wand...@googlegroups.com
I think this created more questions than answers, a lot of the post was unclear as what you were answering. Forgive me but maybe it is all just flying over my head.

T

Tim Smitty

unread,
Dec 13, 2013, 9:42:26 PM12/13/13
to wand...@googlegroups.com
I may have gotten it. Sort of see what you were trying to tell me. It seems that was a leftover example and I had to put it in the right directory and call it in the right .bb file.

Thanks.

T

Scott Ellis

unread,
Dec 14, 2013, 5:34:57 AM12/14/13
to
I thought some working examples would be enough. Sorry if it wasn't clear
or I was making too many assumptions.

I do a lot of custom kernel drivers frequently on systems where we use
Yocto to build the images. You can ask me questions off list.

As as side note, I don't use the Yocto build system while developing drivers
unless it's some trivial mod to existing code. I find it too cumbersome. I only
use recipes when the driver is complete and I want it bundled up in the install.

Tim Smitty

unread,
Dec 14, 2013, 10:34:02 AM12/14/13
to wand...@googlegroups.com
Nice, thank you. I may have questions in the future.

Tim Smitty

unread,
Dec 14, 2013, 11:19:48 AM12/14/13
to wand...@googlegroups.com
Scott,
    So I have successfully loaded my first kernel module 'hello-mod' . Yocto makes everything really easy once you figure out how to work it. However, I do have a question about developing externally to Yocto as you mentioned earlier, since rerunning Yocto every time doesn't seem feasible I'd like to get to the point where I can edit a some source code, build the .ko file, scp the .ko file to the box, then modprobe the .ko file, etc., etc....This leads me to my next question:

How do you build kernel source code for the Wandboard externally to Yocto? I'd like to develop in Eclipse, however am willing to build outside of Eclipse if necessary.

Thanks a bunch.

T

Scott Ellis

unread,
Dec 14, 2013, 1:41:47 PM12/14/13
to wand...@googlegroups.com
Set up your build environment to use the already built Yocto cross-compiler.

An example is below. Modify MACHINE if you aren't working on a quad
and possibly the PATH to the tools if you aren't using hard float.

Source this file and then you can run 'make' as normal and manually
copy over the *.ko with scp and load it with lsmod.

I don't use eclipse, just the command line, but I'm sure you could point
eclipse at a different set of tools in a similar way.

 ---- example yocto-environment.sh ----

MACHINE=wandboard-quad

if [[ -z "${OETMP}" ]]; then
	echo "Need an OETMP defined!"
	exit 1
fi

SYSROOTSDIR=${OETMP}/sysroots
STAGEDIR=${SYSROOTSDIR}/`uname -m`-linux/usr

export KERNELDIR=${SYSROOTSDIR}/${MACHINE}/usr/src/kernel

PATH=${PATH}:${STAGEDIR}/bin:${STAGEDIR}/bin/cortexa9hf-vfp-neon-poky-linux-gnueabi

unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE

export ARCH="arm"
export CROSS_COMPILE="arm-poky-linux-gnueabi-"
export CC="arm-poky-linux-gnueabi-gcc"
export LD="arm-poky-linux-gnueabi-ld"
export STRIP="arm-poky-linux-gnueabi-strip"
export AR="arm-poky-linux-gnueabi-ar"


Scott Ellis

unread,
Dec 14, 2013, 1:45:10 PM12/14/13
to wand...@googlegroups.com
Set OETMP to the TMPDIR value in your Yocto local.conf and export
it in your environment before sourcing that yocto-environment.sh script.

Reply all
Reply to author
Forward
0 new messages