• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
yuzaipiaofei
博客园    首页    新随笔    联系   管理    订阅  订阅

在centos 6上的helloworld 模块测试


[root@localhost test]# ls
helloworld.c  Makefile
[root@localhost test]# make
make -C /lib/modules/2.6.32-71.29.1.el6.i686/build M=/home/android/test modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-71.29.1.el6.i686'
  CC [M]  /home/android/test/helloworld.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/android/test/helloworld.mod.o
  LD [M]  /home/android/test/helloworld.ko.unsigned
  NO SIGN [M] /home/android/test/helloworld.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.32-71.29.1.el6.i686'
[root@localhost test]# ls
helloworld.c            helloworld.mod.c  Makefile
helloworld.ko           helloworld.mod.o  modules.order
helloworld.ko.unsigned  helloworld.o      Module.symvers
[root@localhost test]# insmod helloworld.ko
insmod: error inserting 'helloworld.ko': -1 File exists
[root@localhost test]# rmmod helloworld.ko
[root@localhost test]# ls
helloworld.c            helloworld.mod.c  Makefile
helloworld.ko           helloworld.mod.o  modules.order
helloworld.ko.unsigned  helloworld.o      Module.symvers
[root@localhost test]# insmod helloworld.ko
[root@localhost test]# modinfo helloworld.ko
filename:       helloworld.ko
author:         yuanwei
license:        GPL
srcversion:     E074EFF1EF4BF929639B50D
depends:
vermagic:       2.6.32-71.29.1.el6.i686 SMP mod_unload modversions 686
[root@localhost test]#

附上 helloworld 源码和Makefile

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init hellokernel_init(void)
{
        printk(KERN_INFO "Hello kernel!\n");
        return 0;
}

static void __exit hellokernel_exit(void)
{
        printk(KERN_INFO "Exit kernel!\n");
}


module_init(hellokernel_init);
module_exit(hellokernel_exit);


MODULE_LICENSE("GPL");
MODULE_AUTHOR("yuanwei");
~
~
~
~

obj-m := helloworld.o

PWD       := $(shell pwd)

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        rm -rf *.o *~ core .*.cmd *.mod.c ./tmp_version *.ko.* modules.* Module.*


如果是CentOS 平台。需要安装kernel头文件

需要用YUM安装

[root@localhost test]# yum install kernel-devel
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * base: data.nicehosting.co.kr
 * extras: data.nicehosting.co.kr
 * updates: data.nicehosting.co.kr
Setting up Install Process
Package kernel-devel-2.6.32-71.29.1.el6.i686 already installed and latest version
Nothing to do



posted @ 2011-08-08 13:52  yuzaipiaofei  阅读(171)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3