Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎07-08-2013

How to compile loadable linux driver module using Xilinx SDK?

Is it possible to compile loadable linux driver modules using Xilinx SDK?  I've been trying to build a simple 'hello world' driver and I am falling at the first hurdle and struggling to set up the include path properly.
My source file is:


// example hello world driver

#if defined(CONFIG_SMP)
   #define __SMP__

   #define MODVERSIONS
   #include <linux/modversions.h>

#include <linux/module.h>    /* Needed by all modules */
#include <linux/kernel.h>    /* Needed for KERN_INFO */
#include <linux/init.h>        /* Needed for the macros */

static int __init helloworld_init(void)
    printk(KERN_INFO "Hello, world\n");
    return 0;

static void __exit helloworld_exit(void)
    printk(KERN_INFO "Goodbye, world\n");


I am using Xilinx SDK 2013.4 and I have the 'latest' version of  Linux Xilinx downloaded from (downloaded 1 Feb 2014), which I have built using m using Ubuntu.  
I have added __KERNEL__, __SMP__ and MODULE predefines and I have tried adding both ~/linux-xlnx/include and ~/linux-xlnx/usr/include to the include search path.  When I try building my example, however, I get warnings about missing header files, eg, asm/linkage.h, linux/module.h, etc.
Are there any step-by-step guidelines/tutorials/examples detailing how to setup and build a loadable driver module for use with Linux Xilinx either using Xilinx SDK or a make file?
Thanks in advance.

0 Kudos
3 Replies
Registered: ‎07-08-2013

Update: I haven't got my example building from Xilinx SDK but have got the following make file to work:


# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.

	obj-m := driver.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.

	# KERNELDIR ?= $(XILINX_LINUX_SOURCE)/lib/modules/3.12.0-xilinx/build
	PWD := $(shell pwd)

	$(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=arm modules


Where XILINX_LINUX_SOURCE is the path to the root of the Xilinx Linux source tree.  Two of my initial problems were that the kernel make file was looking for *.c files not *.cc and that I had omitted the "ARCH=arm", which, as I am only interested in targetting the Zynq I have added to my makefile.


I'm still not completely sorted, however because although I can now build and 'insmod' my *.ko file I cannot 'rmmod' it because '/lib/modules/3.12.0-xilinx' is missing.  I've tried doing 'make modules_install' but this fails as it insists on trying to write to '/lib/modules/3.12.0-xilinx' on the host.  Is it ok to simply create this folder manually on the Zynq's filesystem?



0 Kudos
Not applicable

I took a different route of adding my own module to the build with the petalinux-* tools. But there are a few holes in it for which I also don't have answers... FWIW, here's what I've got working.


Inside my project I ran "petalinux-create -t modules -n mymod --enable" which creates $PROJECT/components/modules/mymod/ containing a working template for a module (i.e. Makefile, mymod.c with init/exit functions).


Then, I can see this module when I run "petalinux-config -c rootfs" in the modules section, and it will build when I invoke "petalinux-build -c rootfs". So all this makes it easy to get going without writing module makefiles by hand, which seems like what you're doing.


But there are 2 holes in my process:

-after creating the module under components, the scripts also create another identical one in $PROJECT/build/linux/rootfs/modules/mymod/ and it will get built there; I'm not sure it should be done this way as the build directory should only contain build output and not my master source files

-one of the PDFs mentions that I should be able to run "petalinux-build -c modules -s mymod" to build the module, but this doesn't work at all


I would like to have my module live in $PROJECT/components/modules/ and be able to build just the module without having to build all of rootfs. Any ideas? Am I misusing the petalinux-* tools or are they lacking complete support for custom, out-of-tree modules?




0 Kudos
Registered: ‎04-19-2014

If you run: petalinux-build -c rootfs/mymod -v


It will copy over the new source, and recompile. I usually then tftp it over to my zynq.


petalinux$ cp build/linux/rootfs/modules/mymod/mymod.ko /tftpboot/


zynq$ tftp -g -r mymod.ko && insmod mymod.ko



0 Kudos