• 在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



  • 相关阅读:
    浅谈MSSQL2012中的列存储索引(columnstore indexes)
    《高性能SQL调优精要与案例解析》新书样章
    关系库执行计划中三种最常用连接方式的伪码实现
    python基础-字符串
    python基础-文件和目录
    python基础-列表
    python基础-对象
    python基础-入门
    python算法-二叉树广度优先遍历
    Python算法-二叉树深度优先遍历
  • 原文地址:https://www.cnblogs.com/yuzaipiaofei/p/4124407.html
Copyright © 2020-2023  润新知