I have couple years c programming experience. Now I decided to working towards Linux kernel module development. However, I can't even get start. I have compiled this code in ubuntu.
#include <linux/module.h>
int init_module(void){ printk("<1> hellp"); return 0;}
void cleanup_module(void){ printk("<1> bye");}
however, the insmod is not working the error message is "Invalid module format". after googling i figured it may be some problem with version compatibility. And there is no good way to solve it. So Can some real kernel module developer give me some advice? what environment should I prepare before I start learning?
Thanks!
3 Answers 3
You are missing the module_init() and module_exit() macros and some crucial #defines. We need more information as well such as your make/gcc options. It may be reporting the "invalid module format" because you are compiling in 32bit when your kernel is 64bit, so ensure you are using the -64 compile and link flag.
A great hello world tutorial for Kernel Modules is located here: http://archive.is/KNkEE (the original link to the article is broken).
Welcome to writing kernel modules. They are a lot of fun compared to writing Windows drivers (I've done both). The linux kernel module interface is much simpler to use and there is a lot of base drivers you can delegate to and get the work done faster.
1 Comment
__init and __exit are not required; they only specify text section(s) that can be freed after booting is complete. What is required for a driver module are declarations for two entry points using module_init() and module_exit().A complete and simplified Blog about Linux Kernels, Module Programming and writing simple device drivers for embedded devices.
1 Comment
I would recommend getting started with reading "The Linux Kernel Module Programming Guide"
Even though it is based on a fairly old kernel version (2.6), it still worths your time reading it even today.
Comments
Explore related questions
See similar questions with these tags.