zoukankan      html  css  js  c++  java
  • Ubuntu中编译helloworld驱动

    1、 新建hello文件夹

    2、hello.c

    #ifndef __KERNEL__
    #  define __KERNEL__
    #endif
    #ifndef MODULE
    #  define MODULE
    #endif
    
    // 下面的是主要的内容
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/init.h>
    
    MODULE_LICENSE("GPL");
    
    static int year=2012;
    
    int hello_init()
    {
        printk(KERN_ALERT "Hello kernel, it's %d!
    ",year);
        return 0;
    }
    
    
    void hello_exit()
    {
        printk(KERN_ALERT "Bye, kernel!
    ");
    }
    
    // 下面两个为关键的模块函数
    module_init(hello_init);
    module_exit(hello_exit);

    3、 Makefile

    obj-m := hello.o
    
    all :
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

    注意:$(MAKE)前面为一个TAB键

    4、 make

    clip_image002

    3、 insmod hello.ko

    4、 dmesg

    clip_image001

  • 相关阅读:
    树莓派4B
    第一个实验-LED灯闪烁
    GPIO
    新建库函数模板
    开发环境搭建
    博弈论
    区间dp
    字典树
    快速排序
    MarkDown
  • 原文地址:https://www.cnblogs.com/smbx-ztbz/p/4769517.html
Copyright © 2011-2022 走看看