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. 用HTML+CSS实现一个计科院网站首页静态页面

    链接:https://pan.baidu.com/s/1akwyc89q3nzKDQQulaFelQ 提取码:s6ys

  2. 虚拟机linux下安装tomcat外部可访问

    1.解压tomcat压缩包 tar -zxvf apache-tomcat 2.启动tomcat 进入bin目录下 ./catalina.sh run  (startup.sh不会显示日志信息) 3. ...

  3. 如何在eclipse添加SVN菜单

    首先需要在eclipse中安装svn插件,这个网上教程很多 那么我来说下如何在将svn添加到菜单中去吧. 很简单,

  4. Maven Web Projest经Update Projest报错:Cannot nest 'myApp/src/main/resource' inside 'myApp/src'. To enable the nesting exclude 'main/' from 'myApp/src'

    1,报错场景 2,解决方法 修改pom.xml,去掉该行:<sourceDirectory>src/</sourceDirectory>

  5. 【Python游戏编程01--初步认识pygame】

    一.pygame简介 Pygame 是一组用来开发游戏软件的 Python 程序模块,基于 SDL 库的基础上开发.允许你在 Python 程序中创建功能丰富的游戏和多媒体程序,Pygame 是一个高 ...

  6. 浅析Tomcat、JBOSS、WebSphere、WebLogic、Apache

    做任何web项目,都离不开服务器,有钱的公司用WebSphere.WebLogic,没钱公司用nginx+tomcat,不要小瞧nginx+tomcat麻雀虽小,五脏俱全. 服务器的知识,在笔试.面试 ...

  7. JS(JavaScript)的初了解3(更新中···)

    1. {} 在JS中我们把它叫代码块.如果代码块里的内容没有执行完,语句不会向下执行. 代码块是一个独立的整体.如果JS中某一条语句出错,那么就会在此终止不会向下执行. 2. 循环语句 循环,就是对一 ...

  8. Nginx教程--02.Nginx虚拟主机的配置

    1.Nginx虚拟主机的配置 1.1 在conf目录下,使用命令 : vim nginx.conf 对上图解释: //全局区 worker _processes 1; //表示当前有1个工作的子进程, ...

  9. Codefoces 277 E. Binary Tree on Plane

    题目链接:http://codeforces.com/problemset/problem/277/E 参考了这篇题解:http://blog.csdn.net/Sakai_Masato/articl ...

  10. JQuery学习二-字典操作

    1. 数组中添加map var arr = []; var key = 'Jeremy'; var value = '!!!!' arr.push({ 'key': key, 'value': val ...