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.
我有几年c编程经验。现在我决定致力于Linux内核模块开发。但是,我甚至无法开始。我在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?
但是,insmod无法正常工作,错误消息是“模块格式无效”。谷歌搜索后,我认为这可能是版本兼容性的一些问题。而且没有好办法解决它。那么一些真正的内核模块开发人员能给我一些建议吗?在我开始学习之前,我应该准备什么环境?
Thanks!
2 个解决方案
#1
10
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.
您缺少module_init()和module_exit()宏以及一些关键的#defines。我们还需要更多信息,例如make / gcc选项。它可能是报告“无效模块格式”,因为当您的内核为64位时,您正在编译32位,因此请确保使用-64编译和链接标志。
A great hello world tutorial for Kernel Modules is located here: http://archive.is/KNkEE (the original link to the article is broken).
内核模块的一个很棒的hello world教程位于:http://archive.is/KNkEE(该文章的原始链接已被破坏)。
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.
欢迎编写内核模块。与编写Windows驱动程序相比,它们非常有趣(我已经完成了两者)。 Linux内核模块接口使用起来更简单,并且可以委派许多基本驱动程序并更快地完成工作。
#2
1
A complete and simplified Blog about Linux Kernels, Module Programming and writing simple device drivers for embedded devices.
关于Linux内核,模块编程以及为嵌入式设备编写简单设备驱动程序的完整简化博客。
#1
10
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.
您缺少module_init()和module_exit()宏以及一些关键的#defines。我们还需要更多信息,例如make / gcc选项。它可能是报告“无效模块格式”,因为当您的内核为64位时,您正在编译32位,因此请确保使用-64编译和链接标志。
A great hello world tutorial for Kernel Modules is located here: http://archive.is/KNkEE (the original link to the article is broken).
内核模块的一个很棒的hello world教程位于:http://archive.is/KNkEE(该文章的原始链接已被破坏)。
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.
欢迎编写内核模块。与编写Windows驱动程序相比,它们非常有趣(我已经完成了两者)。 Linux内核模块接口使用起来更简单,并且可以委派许多基本驱动程序并更快地完成工作。
#2
1
A complete and simplified Blog about Linux Kernels, Module Programming and writing simple device drivers for embedded devices.
关于Linux内核,模块编程以及为嵌入式设备编写简单设备驱动程序的完整简化博客。