My First Linux Module

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 0;
}

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:

时间: 2024-08-01 07:01:33

My First Linux Module的相关文章

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

1.缺少Linux kernel头文件 To install just the headers in Ubuntu: sudo apt-get install linux-headers-$(uname -r) To install the entire Linux kernel source in Ubuntu: sudo apt-get install linux-source Note that you should use the kernel headers that match th

linux module 模块编程

转载自:http://blog.csdn.net/eroswang/archive/2008/09/13/2924875.aspx 摘要Linux内核模块编程的资料有些纷繁复杂,有的过于简单,有的过于庞杂,我试图用笔记的形式想读者展示怎样来进程Linux模块编程,力图做到简明扼要,这篇文章也是作为本人备忘的资料,所以有些地方过于简略是难免的.本来这篇文章的目的就是让用户知其然,至于所以然还是请参考相应的资料,其实最好的资料莫过于Linux Kernel Source. 适用范围: Linux K

linux module

insmod 是靠一个在kernel/module.c里定义的系统调用来实现的. 1. 此系统调用(sys_init_module )分配内核存储空间(kernel memory)给相关的模块,这个内存分配动作是由vmalloc完成: 2. 然后将该模块内容拷贝到这块存储空间里: 3. 接着声明内核引用该模块: 4. 呼叫该模块的初始化涵数 这样,一个插入模块的过程就完成了. 该函数准确应该是在 linux/kernel/module.c里, 但是在里面你不会找到sys_init_module这

简单实例讲解linux的module模块编译步骤(转)

注:原博文讲述较为详尽细致,故转到本地--aaronGao ------------------------------------------------------------------------------------------------------------------------------------------- 本文将直接了当的带你进入linux的模块编译.当然在介绍的过程当中,我也会添加一些必要的注释,以便初学者能够看懂.之所以要写这篇文章,主要是因为从书本上学的话,

linux kernel module

#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h> static int hello_init(void){ printk(KERN_ALERT "hello world!\n"); return 0;} static void hello_exit(void){ printk(KERN_ALERT "exit ok!\n");} mo

13.Linux键盘按键驱动 (详解)

版权声明:本文为博主原创文章,未经博主允许不得转载. 在上一节分析输入子系统内的intput_handler软件处理部分后,接下来我们开始写input_dev驱动 本节目标: 实现键盘驱动,让开发板的4个按键代表键盘中的L.S.空格键.回车键 1.先来介绍以下几个结构体使用和函数,下面代码中会用到 1)input_dev驱动设备结构体中常用成员如下: struct input_dev { void *private; const char *name; //设备名字 const char *ph

linux内核编译与开发

一.Linux内核简介linux kernel map: linux 系统体系结构: linux kernel体系结构: arm有7种工作模式,x86也实现了4个不同级别RING0-RING3,RING0级别最高, 这样linux用户代码运行在RING3下,内核运行在RING0,这样系统本身就得到了 充分的保护 用户空间(用户模式)转到内核空间(系统模式)方法: ·系统调用 ·硬件中断 linux kernel 体系结构: 虚拟文件系统VFS: VFS(虚拟文件系统)隐藏各种文件系统的具体细节,

Linux 内核模块设计

一.  内核模块 1.  头文件 Linux/init.h  和 Linux/module.h 2.  装载内核 insmod  对应的转载函数 module_init(); 3.  卸载内核 rmmod  对应的卸载函数 module_exit(); 二.  编写 helloworld.c 三.编写Makefile 四 .  把 helloworld.ko 移到Part3/rootfs 打开开发板下载. 直接运行Uboot insmod 挂载一下 helloworld.ko lsmod   查

Process Kill Technology &amp;&amp; Process Protection Against In Linux

目录 0. 引言 1. Kill Process By Kill Command 2. Kill Process By Resource Limits 3. Kill Process By Code Injection Into Running Process Via GDB 4. Kill Process By Using Cross Process Virtual Memory Modify 5. Kill Process By Using ptrace To Inject .so 6. P