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!\n");
return ;
} static void __exit hello_exit(void)
{
printk(KERN_ERR " Goodbye, world!\n");
} 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:

My First Linux Module的更多相关文章

  1. Linux Module

    catalog . 概述 . 使用模块 . 插入和删除模块 . 自动化与热插拔 . 版本控制 1. 概述 模块(module)是一种向Linux内核添加设备驱动程序.文件系统及其他组件的有效方法,而无 ...

  2. linux/module.h: No such file or directory 内核模块编译过程

    1.缺少Linux kernel头文件 To install just the headers in Ubuntu: sudo apt-get install linux-headers-$(unam ...

  3. linux Module驱动开发-一切刚刚开始

    linux内核是可以高度定制的,通过配置编译选项达到定制的目的. 在配置kernel编译选项时驱动程序的编译选项一般有三种,不编译.编译为内核驱动.编译为模块驱动.所以linux驱动一般分为两类,内核 ...

  4. Linux Module框架【转】

    转自:http://www.cnblogs.com/LittleHann/p/4558719.html catalog 1. 概述 2. 使用模块 3. 插入和删除模块 4. 自动化与热插拔 5. 版 ...

  5. <linux/init.h>,<linux/module.h>头文件不存在等问题的解决方法

    这个问题真心是处理了一个下午,还自己去下载了个最新的内核拿来编译,其实是完全没必要的,因为ubuntu系统是可以直接下载新内核的. 你可以在/usr/src/文件夹下找到这些内核文件夹,比如说我自己的 ...

  6. 自己写Linux module来收集buddy info

    1 编写代码pslist.c 1: #include<linux/init.h> 2: #include<linux/module.h> 3: #include<linu ...

  7. Linux module 添加到bashrc 和临时ifort编译器 以及python2和3的配置

    第一步vim ~/.bashrc按键盘的i然后source /home/export/online1/bjpara/para/modules/scripts/cn-module.sh最后:x! bas ...

  8. 简单实例讲解linux的module模块编译步骤

    注:原博文地址http://blog.sina.com.cn/s/blog_4ba5b45e0102v25h.html ---------------------------------------- ...

  9. linux kernel module

    #include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h> static i ...

随机推荐

  1. Java并发——Fork/Join框架与ForkJoinPool

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/4631466. ...

  2. 像素与DPI之间的关系

    先说像素.像素是电子图像组成的基本单位,将图像放大数倍,会发现图像是由一个个“小色块”紧密排列组成的,每一个“小色块”就是一个像素点. 也就是说,每个图像都是由n多个像素点组成. 再说分辨率.所谓分辨 ...

  3. 腾讯云主机如何使用root账号登录,不能使用root登录怎么办

    1.先用ubuntu账号登录,执行sudo passwd root 2.按要求输入密码,请牢记. 3.执行sudo vi /etc/ssh/sshd_config 4.找到PermitRootLogi ...

  4. 使用C#爬小说

    最近因朋友需要在研究如何从网站上爬小说,说到爬,很多人首先想到的是Python,但是因为没有用过Python,加上时程比较紧,就直接使用C#. 其原理也很简单,就是利用HttpWebRequest对象 ...

  5. Html table、thead、tr、th、td 标签

    Html table.thead.tr.th.td 标签 案例一 <!-- table 表格标签,配置表格使用.border="1" 添加表格框架 --> <ta ...

  6. 动态从数据库获取数据,省市县三级联动,有校验,导出Excel模板

    话不多说,看效果图,直接上代码. sheet  商户表 hideSheet ,功能完成后隐藏的Sheet,用于储存下拉框中的信息,(以一定的规则将所需数据存储在表格中). 下面是代码 部分数据需要在导 ...

  7. onsubmit 事件

    onsubmit 事件 Event 对象 定义和用法 onsubmit 事件会在表单中的确认按钮被点击时发生. 语法 onsubmit="SomeJavaScriptCode" 参 ...

  8. 最新版的Chrome如何始终开启flash而不是先询问?

     链接:https://www.zhihu.com/question/266170237/answer/342137190  设置Chrome启用Flash,修改配置之前先看Chrome的版本,不同版 ...

  9. Convolutional Pose Machines

    Convolutional Pose Machines 2018-12-10 18:17:20 Paper:https://www.cv-foundation.org/openaccess/conte ...

  10. Learning-Python【29】:网络编程之粘包

    粘包问题 上一篇博客遗留了一个问题,在接收的最大字节数设置为 1024 时,当接收的结果大于1024,再执行下一条命令时还是会返回上一条命令未执行完成的结果.这就是粘包问题. 因为TCP协议又叫流式协 ...