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. Oarcle 入门之注释与关键字

    --1.--单行注释 *输入法应定要为英文 --2./*多行注释 *与java相似*/   ------------------------------------------------------ ...

  2. MVC设计思路

    MVC 学会重复.学会总结.学会预习和练习 前端页面  <---->   服务器(控制层.业务层.DAO层) <--->  DB 说明:无论是框架还是servletJSP,用的 ...

  3. 一些sql优化原则

    1.我们在设计表的时候,尽量让字段拥有默认值,尽量不要让字段的值为null. 因为,在 where 子句中对字段进行 null 值判断(is null或is not null)将导致引擎放弃使用索引而 ...

  4. CentOS6.5升级GCC4.8

    # curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo # cat /etc/yum.repo ...

  5. Python3 批量更改文件后缀名

    Python3 批量更改文件后缀名 示例: # coding:utf8 import os import sys def Rename(): #Path = "F:\\test\\" ...

  6. Linux 创建自定义命令

    Linux 创建自定义命令 Linux 可以创建自定义使用命令 这里我们采取使用“alias”命令.这里我们首先了解两个文件,通过这两个文件我们可以根据环境配置相应的自定义命令. 该文件内创建的自定义 ...

  7. 复旦高等代数 I(17级)每周一题

    本学期将继续进行高等代数每周一题的活动.计划从第二教学周开始,到第十六教学周为止(根据法定节假日安排,中间个别周会适当地停止),每周的周末将公布1-2道思考题,供大家思考和解答.每周一题通过“谢启鸿高 ...

  8. G711 G723 G729线路占多少带宽问题

    G.711   G.711   也称为PCM(脉冲编码调制),是国际电信联盟订定出来的一套语音压缩标准,主要用于电话.它主要用脉冲编码调制对音频采样,采样率为8k每秒.它利用一个 64Kbps 未压缩 ...

  9. SQLServer “无法对数据库'XX' 执行删除,因为它正用于复制”的解决方法

    修改数据库某个字段的长度时出现: “无法修改表.无法对 表'dbo.N_Client_content' 执行 删除,因为它正用于复制.” 不能直接对该数据库进行操作,通过alter 的办法来修改,问题 ...

  10. Learning-Python【8】:Python字符编码

    1.内存和硬盘都是用来存储的 内存:速度快 硬盘:永久保存 2.文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就可以启动一个进程,是在内存中的,所以在编辑器编写的 ...