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()。