hello world driver
2021-05-21 01:33:27 Author: terenceli.github.io(查看原文) 阅读量:97 收藏

2021-05-12

After several years kernel development, I still can’t remember the templeate of driver. So I write this post.

Ubuntu

Install kernel header.

    apt install linux-headers-`uname -r`

hello.c

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

    MODULE_LICENSE("GPL");

    static int hello_init(void)
    {
        printk("Hello word\n");
        return 0;
    }


    static void hello_exit(void)
    {
        printk("Goodbye,Hello word\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);

Makefile

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

redhat

yum install kernel-devel-uname -r



blog comments powered by


文章来源: http://terenceli.github.io/%E6%8A%80%E6%9C%AF/2021/05/12/hello-driver
如有侵权请联系:admin#unsafe.sh