zoukankan      html  css  js  c++  java
  • My First Linux Module

    My First Linux Module

    Today, I successfully build my first linux hello module.

    First of all add a directory named hello in the kernel/driver, and add a file hello.c, write codes like bellow:

    #include <linux/init.h>
    #include <linux/module.h>
    
    static int __init hello_init(void)
    {
        printk(KERN_ERR " Hello, world!
    ");
        return 0;
    }
    
    static void __exit hello_exit(void)
    {
        printk(KERN_ERR " Goodbye, world!
    ");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);
    
    MODULE_AUTHOR("Bob, Zhang");
    MODULE_LICENSE("Dual BSD/GPL");
    
    MODULE_DESCRIPTION("A simple hello world demo");
    MODULE_ALIAS("A simple module");

    Then create a Kconfig file:

    config HELLO
        tristate "HELLO WORLD Driver!"
        default m
        help
            HELLO WORLD

    And create a Makefile file:

    obj-m += hello.o

    Next Add the Kconfig and Makefile into the Kconfig file and Makefile file in parent directory.

    Finally run the commands bellow:

    make ARCH=arm CROSS_COMPILE=$tool_prefix my_kernel_defconfig
    make ARCH=arm CROSS_COMPILE=$tool_prefix modules
    mkdir ./moduls_temp
    make ARCH=arm CROSS_COMPILE=$tool_prefix modules_install INSTALL_MOD_PATH=./modules_temp

    At last, the demo run like this:

  • 相关阅读:
    Android学习地址
    Android动画设计源码地址
    chromeWebBrowser之浏览器开发
    win8.1蓝屏解决
    打包应用程序
    win8.1解决鼠标右键反应慢的问题
    Rewrite服务器和robots文件屏蔽动态页面
    第08组 Alpha事后诸葛亮
    第08组 Alpha冲刺(6/6)
    第08组 Alpha冲刺(5/6)
  • 原文地址:https://www.cnblogs.com/zhanghang-BadCoder/p/7159961.html
Copyright © 2011-2022 走看看