Linux驱动开发1--内核入门之hello模块

Linux驱动开发1--内核入门之hello模块


3.1 创建项目驱动程序工作路径

[wudongxu@centos6_master ~]$ cd gitee/fl2440/
[wudongxu@centos6_master fl2440]$ ls
3rdparty bootloader crosstool LICENSE linux README.md x86_tools
[wudongxu@centos6_master fl2440]$ mkdir driver
[wudongxu@centos6_master fl2440]$ cd driver

3.2 编写hello模块C文件

[wudongxu@centos6_master driver]$ vim kernel_hello.c
kernel_hello.c ____________________________________________________________________________________________________________________
  1 /*********************************************************************************
  2  *      Copyright:  (C) 2018 Wu Dong Xu< [email protected]>
  3  *                  All rights reserved.
  4  *
  5  *       Filename:  knernel_hello.c
  6  *    Description:  This file
  7  *                 
  8  *        Version:  1.0.0(03/19/2018)
  9  *         Author:  Wu Dong Xu < [email protected]>
10  *      ChangeLog:  1, Release initial version on "03/19/2018 04:00:19 AM"
11  *                 
12  ********************************************************************************/
13 #include<linux/init.h>    //定义了一些相关的宏
14 #include<linux/module.h>    //定义了模块需要的
15 #include<linux/kernel.h>
16
//当使用insmod命令加载模块时,会调用该函数
17 static __init int hello_init(void)
18 {
19     printk(KERN_ALERT "hello,wudongxu IoT Studio!\n");    //打印hello,wudongxu IoT Studio
20     return 0;
21 }
22
//当使用rmmod命令卸载模块时,会调用该函数
23 static __exit void hello_exit(void)
24 {
25     printk(KERN_ALERT "Goodbye,I have found a good job!\n");   //打印Goodbye,I have found a good job
26 }
27
28 module_init(hello_init);      //声明模块加载函数,是内核模块的一个宏。也就是使insmod命令加载模块时,调用函数hello_init()。
29 module_exit(hello_exit);      // 声明模块卸载函数,是内核模块的一个宏。也就是使rmmod命令卸载模块时,调用函数hello_exit()。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值