Linux开发模块,在本机上看调试信息的方法走通了。当前版本号2.6.32-32-generic

uname –r

能够查询

这里取module_param()作为样例。

该宏被定义在include/linux/moduleparam.h文件里,详细定义例如以下:

#define module_param(name, type, perm)                

    module_param_named(name, name, type, perm)

当中使用了 3个參数:要传递的參数变量名, 变量的数据类型, 以及訪问參数的权限。

hello.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h> MODULE_LICENSE("Dual BSD/GPL"); static char *flag="world";
static int times = 5;
module_param(times,int,S_IRUSR);
module_param(flag,charp,S_IRUSR); static int hello_init(void)
{
int i;
for(i=0;i<=times;i++)
{
printk("(%d)hello ,%s\n",i,flag); //KERN_DEBUG
}
return 0;
} static void hello_exit(void)
{
printk("Goodbye,%s\n",flag); //KERN_DEBUG
} module_init(hello_init);
module_exit(hello_exit);

这个文件须要编译成模块,採用

Makefile

obj-m	:= hello.o
KERNELDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd) default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

1),-C $(KERNELDIR)

表示在$(KERNELDIR)文件夹下运行make命令。

2),M=$(PWD)

表示包括$(PWD)下的Makefile文件。

3),modules

表示模块编译

在终端中

make

生成hello.ko模块

Insmod hello.ko flag=”daniu” times=5

root@zhangw:/mnt/hgfs/test_curl/core# dmesg -c

[ 9057.070444] Goodbye,\xffffffe2\xffffff80\xffffff9d\xffffff80\xffffff9ddaniu\xffffffe2\xffffff80\xffffff9d\xffffff80\xffffff9d

[ 9059.357777] (0)hello ,daniu

[ 9059.357781] (1)hello ,daniu

[ 9059.357783] (2)hello ,daniu

[ 9059.357784] (3)hello ,daniu

[ 9059.357785] (4)hello ,daniu

[ 9059.357786] (5)hello ,daniu

rmmod hello.ko

hello.c内核模块编译 -- linux内核的更多相关文章

  1. Centos下编译Linux内核

    Linux内核编译是一件简单却费事的事.但是独立的编译linux内核会帮助你很好的理解Linux内核的工作机理. 首先编译linux内核我们需要在当前linux操作系统下安装gcc编译器,因为我是Ce ...

  2. 为什么要编译Linux内核?

    新的内核修订了旧内核的bug,并增加了许多新的特性.如果用户想要使用这些新特性,或想根据自己的系统度身定制一个更高效,更稳定的内核,就需要重新编译Linux内核. 通常,更新的内核会支持更多的硬件,具 ...

  3. 自定义配置编译linux内核

    1 编译linux内核原因一般情况下,我们是不需要重新去编译linux内核的,但如果你发现你需要修改内核的某个部分或者说你需要的某个模块并没有编译进内核,那里你可以通过重新编译内核来满足你的需求,比如 ...

  4. 35、在编译Linux内核中增加程序需要完成以下3项工作

    在编译Linux内核中增加程序需要完成以下3项工作: 将编写的源代码拷入Linux内核源代码的相应目录. 在目录的Kconfig文件中增加关于新源代码对应项目的编译配置选项 在目录的Makefile文 ...

  5. 安装debian总结以及编译linux内核

    1. 安装debian 使用unetbootin(http://unetbootin.sourceforge.net/)来创建启动盘,并且下载debian的基本包. 将磁盘进行压缩操作,并且保留出一个 ...

  6. 如何解决编译linux内核(解决声卡问题),遭遇fatal error: linux/limits.h: 没有那个文件或目录

    最近帮一位上海的朋友搞一块小板,在ubuntu15.04 vivid上已经加载了对应了.ko驱动包 但关键是系统根本就枚举不到该声卡ALC5640,试了OpenSUSE也是一样的结果,看来是内核漏加载 ...

  7. 编译linux内核时出错

    在编译linux内核的时候使用make menuconfig 可能出现下面的错误 *** Unable to find the ncurses libraries or the*** required ...

  8. Mac下重新编译Linux内核

    Mac下重新编译Linux内核 操作系统实验,要求添加系统调用并重新编译内核,这里记录一下编译内核的过程 0.下载VirtualBox 博主一直用parallel desk,但因为驱动等问题,在PD上 ...

  9. 编译Linux内核(Mac OS平台)

    操作系统第一次实验需要编译Linux内核,我之前在Mac上一直使用的都是Parallels Desktop这个软件,所以这次也将课程网站上提供的Ubuntu安装在了PD上,但是编译完内核后无法进入Ub ...

随机推荐

  1. 洛谷——P2515 [HAOI2010]软件安装

    https://www.luogu.org/problem/show?pid=2515#sub 题目描述 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中 ...

  2. [React Intl] Install and Configure the Entry Point of react-intl

    We’ll install react-intl, then add it to the mounting point of our React app. Then, we’ll use react- ...

  3. 学习redis--简介(一)

    1.什么是redis? Redis是使用c语言开发的一个高性能键值数据库.Redis通过键值类型来存储数据.它通过提供多种键值数据类型来适应不同场景的存储需求. 2.redis支持哪些数据类型 Key ...

  4. SQL Server 2008 Tempdb 数据库迁移

    1.首先检查数据文件位置及名称 SELECT name,physical_name FROM sys.database_files 2.迁移 USE master; GO ALTER DATABASE ...

  5. [Nuxt] Update Vuex State with Mutations and MapMutations in Vue.js

    You commit changes to state in Vuex using defined mutations. You can easily access these state mutat ...

  6. HDU 1408 盐水的故事 数学水题

    http://acm.hdu.edu.cn/showproblem.php?pid=1408 题目: 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下...,现 ...

  7. CD Linux U盘启动办法

    1.用ULtraISO打开cdlinux的ISO文件,用USB-HDD+写入到U盘上。 2.下载GRUB4DOS软件,复制grldr和menu.lst到U盘。 3.下载bootice软件,在U盘的分区 ...

  8. 【t048】水流

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 全球气候变暖,小镇A面临水灾.于是你必须买一些泵把水抽走.泵的抽水能力可以认为是无穷大,但你必须把泵放 ...

  9. webuploader 小demo

    页面写法 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  10. [CSS] Reduce Ambiguity in Class Names using a Naming Convention

    A solid naming convention makes it less likely to run into naming conflicts and helps establish a se ...