Reputation: 4302
I'm following Derek Molloys guide to building loadable kernel modules, but get stuct at some points.
I have the kernel code in a .c-file: hello.c
#include <linux/init.h> // Macros used to mark up functions e.g., __init __exit
#include <linux/module.h> // Core header for loading LKMs into the kernel
#include <linux/kernel.h> // Contains types, macros, functions for the kernel
MODULE_LICENSE("GPL"); ///< The license type -- this affects runtime behavior
MODULE_AUTHOR("Derek Molloy"); ///< The author -- visible when you use modinfo
MODULE_DESCRIPTION("A simple Linux driver for the BBB."); ///< The description -- see modinfo
MODULE_VERSION("0.1"); ///< The version of the module
static char *name = "world"; ///< An example LKM argument -- default value is "world"
module_param(name, charp, S_IRUGO); ///< Param desc. charp = char ptr, S_IRUGO can be read/not changed
MODULE_PARM_DESC(name, "The name to display in /var/log/kern.log"); ///< parameter description
/** @brief The LKM initialization function
* The static keyword restricts the visibility of the function to within this C file. The __init
* macro means that for a built-in driver (not a LKM) the function is only used at initialization
* time and that it can be discarded and its memory freed up after that point.
* @return returns 0 if successful
*/
static int __init helloBBB_init(void){
printk(KERN_INFO "EBB: Hello %s from the BBB LKM!\n", name);
return 0;
}
/** @brief The LKM cleanup function
* Similar to the initialization function, it is static. The __exit macro notifies that if this
* code is used for a built-in driver (not a LKM) that this function is not required.
*/
static void __exit helloBBB_exit(void){
printk(KERN_INFO "EBB: Goodbye %s from the BBB LKM!\n", name);
}
/** @brief A module must use the module_init() module_exit() macros from linux/init.h, which
* identify the initialization function at insertion time and the cleanup function (as
* listed above)
*/
module_init(helloBBB_init);
module_exit(helloBBB_exit);
and the makefile as this: Makefile
obj-m+=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean
when I try to run make
in a directory with onl the two above files, i get
Make: Nothing to be done for all
I'm running 3.8.13-bone47, but I wasn't able to find the exact header files matching on this link that Derek recommended, so I downloaded 3.8.13-bone71 instead. Could that be the problem? Do I have to download the headers, when I'm compiling in directly on the BeagleBone? I have also tried change the lines in the Makefile to a hardcoded distribution name that matches mine (3.8.13-bone47), doesn't work either.
Thank you very much guys!
Upvotes: 0
Views: 1465
Reputation: 4302
I solved my question. I had two problems:
Missing Tabs in Makefile I added a tab to the beginning of each line with a make statement. It has to be an actually tab, the <\t> didn't work for me.
Wrong Header files It turns out that the proper version of the header files is quite important :) I got the ones from http://rcn-ee.net/deb/trusty-armhf/v3.8.13-bone47/ and added the mach/timex.h file, and was the able to follow Derek's guide from then on.
Upvotes: 1