linux hello 模块

linux 模块

/usr/src/<version>/Documentation/kbuild/modules.txt 有说明

hello.c

/* hello.c example minial module code */
#include <linux/module.h>
static int __init hello_init(void)
{
        printk( KERN_INFO "Hello ! " );
        return 0;
}
static void __exit hello_exit(void)
{
        printk( "Bye ! " );
        return ;
}
module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR( "kwingmei" );
MODULE_DESCRIPTION( "Hello example" );
MODULE_LICENSE( "GPL" );

Makefile:

obj-m := hello.o

doit:

make -C /lib/modules/`uname -r`/build M=$PWD
#make -C /usr/src/linux-source-3.5.0/ M=$PWD

end of doit

1 make -C /lib/modules/`uname -r`/build M=$PWD 一般都没有问题, 主要用于编译用于本地的模块

2 make -C /usr/src/linux-source-3.5.0/ M=$PWD  如果没有编译内核, 可能会失败, 依赖于系统的版本信息,及相关脚本

linux模块虽然2012 就会写了, 但没有深入 惭愧, 现已辞工作, 想深入学习linux,嵌入式 从此开始! 专注方可有所作为

原文地址:https://www.cnblogs.com/kwingmei/p/3224049.html